xref: /openbmc/linux/fs/nfs/nfs4xdr.c (revision bb4dae5e)
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 	dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
9101da177e4SLinus Torvalds 	BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
911811652bdSBenny Halevy 	p = reserve_space(xdr, 4 + hdr->taglen + 8);
912811652bdSBenny Halevy 	p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
913e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(hdr->minorversion);
914d017931cSAndy Adamson 	hdr->nops_p = p;
91534558513SBenny Halevy 	*p = cpu_to_be32(hdr->nops);
916d017931cSAndy Adamson }
917d017931cSAndy Adamson 
918d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr)
919d017931cSAndy Adamson {
920fc931582SAndy Adamson 	BUG_ON(hdr->nops > NFS4_MAX_OPS);
921d017931cSAndy Adamson 	*hdr->nops_p = htonl(hdr->nops);
9221da177e4SLinus Torvalds }
9231da177e4SLinus Torvalds 
9241da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
9251da177e4SLinus Torvalds {
9268687b63aSAl Viro 	__be32 *p;
9271da177e4SLinus Torvalds 
9281da177e4SLinus Torvalds 	p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
9291da177e4SLinus Torvalds 	BUG_ON(p == NULL);
9301da177e4SLinus Torvalds 	xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
9311da177e4SLinus Torvalds }
9321da177e4SLinus Torvalds 
933cf8cdbe5SAndy Adamson static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
9341da177e4SLinus Torvalds {
9351da177e4SLinus Torvalds 	char owner_name[IDMAP_NAMESZ];
9361da177e4SLinus Torvalds 	char owner_group[IDMAP_NAMESZ];
9371da177e4SLinus Torvalds 	int owner_namelen = 0;
9381da177e4SLinus Torvalds 	int owner_grouplen = 0;
9398687b63aSAl Viro 	__be32 *p;
9408687b63aSAl Viro 	__be32 *q;
9411da177e4SLinus Torvalds 	int len;
9421da177e4SLinus Torvalds 	uint32_t bmval0 = 0;
9431da177e4SLinus Torvalds 	uint32_t bmval1 = 0;
9441da177e4SLinus Torvalds 
9451da177e4SLinus Torvalds 	/*
9461da177e4SLinus Torvalds 	 * We reserve enough space to write the entire attribute buffer at once.
9471da177e4SLinus Torvalds 	 * In the worst-case, this would be
9481da177e4SLinus Torvalds 	 *   12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
9491da177e4SLinus Torvalds 	 *          = 36 bytes, plus any contribution from variable-length fields
95023ec6965SJ. Bruce Fields 	 *            such as owner/group.
9511da177e4SLinus Torvalds 	 */
9521da177e4SLinus Torvalds 	len = 16;
9531da177e4SLinus Torvalds 
9541da177e4SLinus Torvalds 	/* Sigh */
9551da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_SIZE)
9561da177e4SLinus Torvalds 		len += 8;
9571da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_MODE)
9581da177e4SLinus Torvalds 		len += 4;
9591da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_UID) {
960e4fd72a1STrond Myklebust 		owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
9611da177e4SLinus Torvalds 		if (owner_namelen < 0) {
962fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve uid %d to string\n",
9631da177e4SLinus Torvalds 					iap->ia_uid);
9641da177e4SLinus Torvalds 			/* XXX */
9651da177e4SLinus Torvalds 			strcpy(owner_name, "nobody");
9661da177e4SLinus Torvalds 			owner_namelen = sizeof("nobody") - 1;
9671da177e4SLinus Torvalds 			/* goto out; */
9681da177e4SLinus Torvalds 		}
9691da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
9701da177e4SLinus Torvalds 	}
9711da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_GID) {
972e4fd72a1STrond Myklebust 		owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
9731da177e4SLinus Torvalds 		if (owner_grouplen < 0) {
974fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve gid %d to string\n",
9751da177e4SLinus Torvalds 					iap->ia_gid);
9761da177e4SLinus Torvalds 			strcpy(owner_group, "nobody");
9771da177e4SLinus Torvalds 			owner_grouplen = sizeof("nobody") - 1;
9781da177e4SLinus Torvalds 			/* goto out; */
9791da177e4SLinus Torvalds 		}
9801da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
9811da177e4SLinus Torvalds 	}
9821da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_ATIME_SET)
9831da177e4SLinus Torvalds 		len += 16;
9841da177e4SLinus Torvalds 	else if (iap->ia_valid & ATTR_ATIME)
9851da177e4SLinus Torvalds 		len += 4;
9861da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_MTIME_SET)
9871da177e4SLinus Torvalds 		len += 16;
9881da177e4SLinus Torvalds 	else if (iap->ia_valid & ATTR_MTIME)
9891da177e4SLinus Torvalds 		len += 4;
99013c65ce9SBenny Halevy 	p = reserve_space(xdr, len);
9911da177e4SLinus Torvalds 
9921da177e4SLinus Torvalds 	/*
9931da177e4SLinus Torvalds 	 * We write the bitmap length now, but leave the bitmap and the attribute
9941da177e4SLinus Torvalds 	 * buffer length to be backfilled at the end of this routine.
9951da177e4SLinus Torvalds 	 */
996e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(2);
9971da177e4SLinus Torvalds 	q = p;
9981da177e4SLinus Torvalds 	p += 3;
9991da177e4SLinus Torvalds 
10001da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_SIZE) {
10011da177e4SLinus Torvalds 		bmval0 |= FATTR4_WORD0_SIZE;
1002b95be5a9SBenny Halevy 		p = xdr_encode_hyper(p, iap->ia_size);
10031da177e4SLinus Torvalds 	}
10041da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_MODE) {
10051da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_MODE;
1006e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
10071da177e4SLinus Torvalds 	}
10081da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_UID) {
10091da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_OWNER;
1010811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_name, owner_namelen);
10111da177e4SLinus Torvalds 	}
10121da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_GID) {
10131da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_OWNER_GROUP;
1014811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_group, owner_grouplen);
10151da177e4SLinus Torvalds 	}
10161da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_ATIME_SET) {
10171da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1018e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1019e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(0);
1020d3f6baaaSTrond Myklebust 		*p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1021d3f6baaaSTrond Myklebust 		*p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
10221da177e4SLinus Torvalds 	}
10231da177e4SLinus Torvalds 	else if (iap->ia_valid & ATTR_ATIME) {
10241da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1025e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
10261da177e4SLinus Torvalds 	}
10271da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_MTIME_SET) {
10281da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1029e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1030e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(0);
1031e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1032e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
10331da177e4SLinus Torvalds 	}
10341da177e4SLinus Torvalds 	else if (iap->ia_valid & ATTR_MTIME) {
10351da177e4SLinus Torvalds 		bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1036e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
10371da177e4SLinus Torvalds 	}
10381da177e4SLinus Torvalds 
10391da177e4SLinus Torvalds 	/*
10401da177e4SLinus Torvalds 	 * Now we backfill the bitmap and the attribute buffer length.
10411da177e4SLinus Torvalds 	 */
10421da177e4SLinus Torvalds 	if (len != ((char *)p - (char *)q) + 4) {
1043f9fd2d9cSWeston Andros Adamson 		printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
10441da177e4SLinus Torvalds 				len, ((char *)p - (char *)q) + 4);
10451da177e4SLinus Torvalds 		BUG();
10461da177e4SLinus Torvalds 	}
10471da177e4SLinus Torvalds 	len = (char *)p - (char *)q - 12;
10481da177e4SLinus Torvalds 	*q++ = htonl(bmval0);
10491da177e4SLinus Torvalds 	*q++ = htonl(bmval1);
105034558513SBenny Halevy 	*q = htonl(len);
10511da177e4SLinus Torvalds 
10521da177e4SLinus Torvalds /* out: */
10531da177e4SLinus Torvalds }
10541da177e4SLinus Torvalds 
1055cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
10561da177e4SLinus Torvalds {
10578687b63aSAl Viro 	__be32 *p;
10581da177e4SLinus Torvalds 
105913c65ce9SBenny Halevy 	p = reserve_space(xdr, 8);
1060e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_ACCESS);
106134558513SBenny Halevy 	*p = cpu_to_be32(access);
1062d017931cSAndy Adamson 	hdr->nops++;
1063dadf0c27SBenny Halevy 	hdr->replen += decode_access_maxsz;
10641da177e4SLinus Torvalds }
10651da177e4SLinus Torvalds 
1066cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
10671da177e4SLinus Torvalds {
10688687b63aSAl Viro 	__be32 *p;
10691da177e4SLinus Torvalds 
107013c65ce9SBenny Halevy 	p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
1071e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_CLOSE);
1072e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(arg->seqid->sequence->counter);
107334558513SBenny Halevy 	xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1074d017931cSAndy Adamson 	hdr->nops++;
1075dadf0c27SBenny Halevy 	hdr->replen += decode_close_maxsz;
10761da177e4SLinus Torvalds }
10771da177e4SLinus Torvalds 
1078cf8cdbe5SAndy Adamson static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
10791da177e4SLinus Torvalds {
10808687b63aSAl Viro 	__be32 *p;
10811da177e4SLinus Torvalds 
108213c65ce9SBenny Halevy 	p = reserve_space(xdr, 16);
1083e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_COMMIT);
1084b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
108534558513SBenny Halevy 	*p = cpu_to_be32(args->count);
1086d017931cSAndy Adamson 	hdr->nops++;
1087dadf0c27SBenny Halevy 	hdr->replen += decode_commit_maxsz;
10881da177e4SLinus Torvalds }
10891da177e4SLinus Torvalds 
1090cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
10911da177e4SLinus Torvalds {
10928687b63aSAl Viro 	__be32 *p;
10931da177e4SLinus Torvalds 
109413c65ce9SBenny Halevy 	p = reserve_space(xdr, 8);
1095e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_CREATE);
109634558513SBenny Halevy 	*p = cpu_to_be32(create->ftype);
10971da177e4SLinus Torvalds 
10981da177e4SLinus Torvalds 	switch (create->ftype) {
10991da177e4SLinus Torvalds 	case NF4LNK:
110013c65ce9SBenny Halevy 		p = reserve_space(xdr, 4);
110134558513SBenny Halevy 		*p = cpu_to_be32(create->u.symlink.len);
110294a6d753SChuck Lever 		xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
11031da177e4SLinus Torvalds 		break;
11041da177e4SLinus Torvalds 
11051da177e4SLinus Torvalds 	case NF4BLK: case NF4CHR:
110613c65ce9SBenny Halevy 		p = reserve_space(xdr, 8);
1107e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(create->u.device.specdata1);
110834558513SBenny Halevy 		*p = cpu_to_be32(create->u.device.specdata2);
11091da177e4SLinus Torvalds 		break;
11101da177e4SLinus Torvalds 
11111da177e4SLinus Torvalds 	default:
11121da177e4SLinus Torvalds 		break;
11131da177e4SLinus Torvalds 	}
11141da177e4SLinus Torvalds 
1115811652bdSBenny Halevy 	encode_string(xdr, create->name->len, create->name->name);
1116d017931cSAndy Adamson 	hdr->nops++;
1117dadf0c27SBenny Halevy 	hdr->replen += decode_create_maxsz;
11181da177e4SLinus Torvalds 
1119cf8cdbe5SAndy Adamson 	encode_attrs(xdr, create->attrs, create->server);
11201da177e4SLinus Torvalds }
11211da177e4SLinus Torvalds 
1122cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
11231da177e4SLinus Torvalds {
11248687b63aSAl Viro 	__be32 *p;
11251da177e4SLinus Torvalds 
112613c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1127e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_GETATTR);
1128e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
112934558513SBenny Halevy 	*p = cpu_to_be32(bitmap);
1130d017931cSAndy Adamson 	hdr->nops++;
1131dadf0c27SBenny Halevy 	hdr->replen += decode_getattr_maxsz;
11321da177e4SLinus Torvalds }
11331da177e4SLinus Torvalds 
1134cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
11351da177e4SLinus Torvalds {
11368687b63aSAl Viro 	__be32 *p;
11371da177e4SLinus Torvalds 
113813c65ce9SBenny Halevy 	p = reserve_space(xdr, 16);
1139e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_GETATTR);
1140e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(2);
1141e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(bm0);
114234558513SBenny Halevy 	*p = cpu_to_be32(bm1);
1143d017931cSAndy Adamson 	hdr->nops++;
1144dadf0c27SBenny Halevy 	hdr->replen += decode_getattr_maxsz;
11451da177e4SLinus Torvalds }
11461da177e4SLinus Torvalds 
1147dae100c2SFred Isaman static void
1148dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr,
1149dae100c2SFred Isaman 		     uint32_t bm0, uint32_t bm1, uint32_t bm2,
1150dae100c2SFred Isaman 		     struct compound_hdr *hdr)
1151dae100c2SFred Isaman {
1152dae100c2SFred Isaman 	__be32 *p;
1153dae100c2SFred Isaman 
1154dae100c2SFred Isaman 	p = reserve_space(xdr, 4);
1155dae100c2SFred Isaman 	*p = cpu_to_be32(OP_GETATTR);
1156dae100c2SFred Isaman 	if (bm2) {
1157dae100c2SFred Isaman 		p = reserve_space(xdr, 16);
1158dae100c2SFred Isaman 		*p++ = cpu_to_be32(3);
1159dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm0);
1160dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm1);
1161dae100c2SFred Isaman 		*p = cpu_to_be32(bm2);
1162dae100c2SFred Isaman 	} else if (bm1) {
1163dae100c2SFred Isaman 		p = reserve_space(xdr, 12);
1164dae100c2SFred Isaman 		*p++ = cpu_to_be32(2);
1165dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm0);
1166dae100c2SFred Isaman 		*p = cpu_to_be32(bm1);
1167dae100c2SFred Isaman 	} else {
1168dae100c2SFred Isaman 		p = reserve_space(xdr, 8);
1169dae100c2SFred Isaman 		*p++ = cpu_to_be32(1);
1170dae100c2SFred Isaman 		*p = cpu_to_be32(bm0);
1171dae100c2SFred Isaman 	}
1172dae100c2SFred Isaman 	hdr->nops++;
1173dae100c2SFred Isaman 	hdr->replen += decode_getattr_maxsz;
1174dae100c2SFred Isaman }
1175dae100c2SFred Isaman 
1176cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
11771da177e4SLinus Torvalds {
1178cf8cdbe5SAndy Adamson 	encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1179d017931cSAndy Adamson 			   bitmask[1] & nfs4_fattr_bitmap[1], hdr);
11801da177e4SLinus Torvalds }
11811da177e4SLinus Torvalds 
1182cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
11831da177e4SLinus Torvalds {
1184dae100c2SFred Isaman 	encode_getattr_three(xdr,
1185dae100c2SFred Isaman 			     bitmask[0] & nfs4_fsinfo_bitmap[0],
1186dae100c2SFred Isaman 			     bitmask[1] & nfs4_fsinfo_bitmap[1],
1187dae100c2SFred Isaman 			     bitmask[2] & nfs4_fsinfo_bitmap[2],
1188dae100c2SFred Isaman 			     hdr);
11891da177e4SLinus Torvalds }
11901da177e4SLinus Torvalds 
1191cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1192830b8e33SManoj Naik {
1193cf8cdbe5SAndy Adamson 	encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1194cf8cdbe5SAndy Adamson 			   bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1195830b8e33SManoj Naik }
1196830b8e33SManoj Naik 
1197cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
11981da177e4SLinus Torvalds {
11998687b63aSAl Viro 	__be32 *p;
12001da177e4SLinus Torvalds 
120113c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
120234558513SBenny Halevy 	*p = cpu_to_be32(OP_GETFH);
1203d017931cSAndy Adamson 	hdr->nops++;
1204dadf0c27SBenny Halevy 	hdr->replen += decode_getfh_maxsz;
12051da177e4SLinus Torvalds }
12061da177e4SLinus Torvalds 
1207cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
12081da177e4SLinus Torvalds {
12098687b63aSAl Viro 	__be32 *p;
12101da177e4SLinus Torvalds 
121113c65ce9SBenny Halevy 	p = reserve_space(xdr, 8 + name->len);
1212e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_LINK);
1213811652bdSBenny Halevy 	xdr_encode_opaque(p, name->name, name->len);
1214d017931cSAndy Adamson 	hdr->nops++;
1215dadf0c27SBenny Halevy 	hdr->replen += decode_link_maxsz;
12161da177e4SLinus Torvalds }
12171da177e4SLinus Torvalds 
1218911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block)
1219911d1aafSTrond Myklebust {
1220911d1aafSTrond Myklebust 	if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1221911d1aafSTrond Myklebust 		return block ? NFS4_READW_LT : NFS4_READ_LT;
1222911d1aafSTrond Myklebust 	return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1223911d1aafSTrond Myklebust }
1224911d1aafSTrond Myklebust 
1225911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1226911d1aafSTrond Myklebust {
1227911d1aafSTrond Myklebust 	if (fl->fl_end == OFFSET_MAX)
1228911d1aafSTrond Myklebust 		return ~(uint64_t)0;
1229911d1aafSTrond Myklebust 	return fl->fl_end - fl->fl_start + 1;
1230911d1aafSTrond Myklebust }
1231911d1aafSTrond Myklebust 
1232daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1233daccbdedSTrond Myklebust {
1234daccbdedSTrond Myklebust 	__be32 *p;
1235daccbdedSTrond Myklebust 
1236d035c36cSTrond Myklebust 	p = reserve_space(xdr, 32);
1237daccbdedSTrond Myklebust 	p = xdr_encode_hyper(p, lowner->clientid);
1238d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(20);
1239daccbdedSTrond Myklebust 	p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1240d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(lowner->s_dev);
1241daccbdedSTrond Myklebust 	xdr_encode_hyper(p, lowner->id);
1242daccbdedSTrond Myklebust }
1243daccbdedSTrond Myklebust 
12441da177e4SLinus Torvalds /*
12451da177e4SLinus Torvalds  * opcode,type,reclaim,offset,length,new_lock_owner = 32
12461da177e4SLinus Torvalds  * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
12471da177e4SLinus Torvalds  */
1248cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
12491da177e4SLinus Torvalds {
12508687b63aSAl Viro 	__be32 *p;
12511da177e4SLinus Torvalds 
125213c65ce9SBenny Halevy 	p = reserve_space(xdr, 32);
1253e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_LOCK);
1254e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1255e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->reclaim);
1256b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1257b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
125834558513SBenny Halevy 	*p = cpu_to_be32(args->new_lock_owner);
1259911d1aafSTrond Myklebust 	if (args->new_lock_owner){
1260daccbdedSTrond Myklebust 		p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1261e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(args->open_seqid->sequence->counter);
126293f0cf25SBenny Halevy 		p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
1263e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
1264daccbdedSTrond Myklebust 		encode_lockowner(xdr, &args->lock_owner);
12651da177e4SLinus Torvalds 	}
12661da177e4SLinus Torvalds 	else {
126713c65ce9SBenny Halevy 		p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
126893f0cf25SBenny Halevy 		p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
126934558513SBenny Halevy 		*p = cpu_to_be32(args->lock_seqid->sequence->counter);
12701da177e4SLinus Torvalds 	}
1271d017931cSAndy Adamson 	hdr->nops++;
1272dadf0c27SBenny Halevy 	hdr->replen += decode_lock_maxsz;
12731da177e4SLinus Torvalds }
12741da177e4SLinus Torvalds 
1275cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
12761da177e4SLinus Torvalds {
12778687b63aSAl Viro 	__be32 *p;
12781da177e4SLinus Torvalds 
1279daccbdedSTrond Myklebust 	p = reserve_space(xdr, 24);
1280e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_LOCKT);
1281e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1282b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1283b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1284daccbdedSTrond Myklebust 	encode_lockowner(xdr, &args->lock_owner);
1285d017931cSAndy Adamson 	hdr->nops++;
1286dadf0c27SBenny Halevy 	hdr->replen += decode_lockt_maxsz;
12871da177e4SLinus Torvalds }
12881da177e4SLinus Torvalds 
1289cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
12901da177e4SLinus Torvalds {
12918687b63aSAl Viro 	__be32 *p;
12921da177e4SLinus Torvalds 
129313c65ce9SBenny Halevy 	p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
1294e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_LOCKU);
1295e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1296e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->seqid->sequence->counter);
129793f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
1298b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
129934558513SBenny Halevy 	xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1300d017931cSAndy Adamson 	hdr->nops++;
1301dadf0c27SBenny Halevy 	hdr->replen += decode_locku_maxsz;
13021da177e4SLinus Torvalds }
13031da177e4SLinus Torvalds 
1304d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1305d3c7b7ccSTrond Myklebust {
1306d3c7b7ccSTrond Myklebust 	__be32 *p;
1307d3c7b7ccSTrond Myklebust 
1308d3c7b7ccSTrond Myklebust 	p = reserve_space(xdr, 4);
1309d3c7b7ccSTrond Myklebust 	*p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1310d3c7b7ccSTrond Myklebust 	encode_lockowner(xdr, lowner);
1311d3c7b7ccSTrond Myklebust 	hdr->nops++;
1312d3c7b7ccSTrond Myklebust 	hdr->replen += decode_release_lockowner_maxsz;
1313d3c7b7ccSTrond Myklebust }
1314d3c7b7ccSTrond Myklebust 
1315cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
13161da177e4SLinus Torvalds {
13171da177e4SLinus Torvalds 	int len = name->len;
13188687b63aSAl Viro 	__be32 *p;
13191da177e4SLinus Torvalds 
132013c65ce9SBenny Halevy 	p = reserve_space(xdr, 8 + len);
1321e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_LOOKUP);
1322811652bdSBenny Halevy 	xdr_encode_opaque(p, name->name, len);
1323d017931cSAndy Adamson 	hdr->nops++;
1324dadf0c27SBenny Halevy 	hdr->replen += decode_lookup_maxsz;
13251da177e4SLinus Torvalds }
13261da177e4SLinus Torvalds 
1327dc0b027dSTrond Myklebust static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
13281da177e4SLinus Torvalds {
13298687b63aSAl Viro 	__be32 *p;
13301da177e4SLinus Torvalds 
133113c65ce9SBenny Halevy 	p = reserve_space(xdr, 8);
1332dc0b027dSTrond Myklebust 	switch (fmode & (FMODE_READ|FMODE_WRITE)) {
13331da177e4SLinus Torvalds 	case FMODE_READ:
1334e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
13351da177e4SLinus Torvalds 		break;
13361da177e4SLinus Torvalds 	case FMODE_WRITE:
1337e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
13381da177e4SLinus Torvalds 		break;
13391da177e4SLinus Torvalds 	case FMODE_READ|FMODE_WRITE:
1340e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
13411da177e4SLinus Torvalds 		break;
13421da177e4SLinus Torvalds 	default:
1343e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(0);
13441da177e4SLinus Torvalds 	}
134534558513SBenny Halevy 	*p = cpu_to_be32(0);		/* for linux, share_deny = 0 always */
13461da177e4SLinus Torvalds }
13471da177e4SLinus Torvalds 
13481da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
13491da177e4SLinus Torvalds {
13508687b63aSAl Viro 	__be32 *p;
13511da177e4SLinus Torvalds  /*
13521da177e4SLinus Torvalds  * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
13531da177e4SLinus Torvalds  * owner 4 = 32
13541da177e4SLinus Torvalds  */
135513c65ce9SBenny Halevy 	p = reserve_space(xdr, 8);
1356e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_OPEN);
135734558513SBenny Halevy 	*p = cpu_to_be32(arg->seqid->sequence->counter);
1358dc0b027dSTrond Myklebust 	encode_share_access(xdr, arg->fmode);
1359d035c36cSTrond Myklebust 	p = reserve_space(xdr, 32);
1360b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, arg->clientid);
1361d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(20);
136293f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, "open id:", 8);
1363d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(arg->server->s_dev);
136434558513SBenny Halevy 	xdr_encode_hyper(p, arg->id);
13651da177e4SLinus Torvalds }
13661da177e4SLinus Torvalds 
13671da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
13681da177e4SLinus Torvalds {
13698687b63aSAl Viro 	__be32 *p;
13704882ef72SAlexandros Batsakis 	struct nfs_client *clp;
13711da177e4SLinus Torvalds 
137213c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
13731da177e4SLinus Torvalds 	switch(arg->open_flags & O_EXCL) {
13741da177e4SLinus Torvalds 	case 0:
137534558513SBenny Halevy 		*p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
13761da177e4SLinus Torvalds 		encode_attrs(xdr, arg->u.attrs, arg->server);
13771da177e4SLinus Torvalds 		break;
13781da177e4SLinus Torvalds 	default:
13794882ef72SAlexandros Batsakis 		clp = arg->server->nfs_client;
1380a4432345STrond Myklebust 		if (clp->cl_mvops->minor_version > 0) {
13814882ef72SAlexandros Batsakis 			if (nfs4_has_persistent_session(clp)) {
13824882ef72SAlexandros Batsakis 				*p = cpu_to_be32(NFS4_CREATE_GUARDED);
13834882ef72SAlexandros Batsakis 				encode_attrs(xdr, arg->u.attrs, arg->server);
13844882ef72SAlexandros Batsakis 			} else {
13854882ef72SAlexandros Batsakis 				struct iattr dummy;
13864882ef72SAlexandros Batsakis 
13874882ef72SAlexandros Batsakis 				*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
13884882ef72SAlexandros Batsakis 				encode_nfs4_verifier(xdr, &arg->u.verifier);
13894882ef72SAlexandros Batsakis 				dummy.ia_valid = 0;
13904882ef72SAlexandros Batsakis 				encode_attrs(xdr, &dummy, arg->server);
13914882ef72SAlexandros Batsakis 			}
13924882ef72SAlexandros Batsakis 		} else {
139334558513SBenny Halevy 			*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
13941da177e4SLinus Torvalds 			encode_nfs4_verifier(xdr, &arg->u.verifier);
13951da177e4SLinus Torvalds 		}
13961da177e4SLinus Torvalds 	}
13974882ef72SAlexandros Batsakis }
13981da177e4SLinus Torvalds 
13991da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14001da177e4SLinus Torvalds {
14018687b63aSAl Viro 	__be32 *p;
14021da177e4SLinus Torvalds 
140313c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14041da177e4SLinus Torvalds 	switch (arg->open_flags & O_CREAT) {
14051da177e4SLinus Torvalds 	case 0:
140634558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_NOCREATE);
14071da177e4SLinus Torvalds 		break;
14081da177e4SLinus Torvalds 	default:
14091da177e4SLinus Torvalds 		BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
141034558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_CREATE);
14111da177e4SLinus Torvalds 		encode_createmode(xdr, arg);
14121da177e4SLinus Torvalds 	}
14131da177e4SLinus Torvalds }
14141da177e4SLinus Torvalds 
1415bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
14161da177e4SLinus Torvalds {
14178687b63aSAl Viro 	__be32 *p;
14181da177e4SLinus Torvalds 
141913c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14201da177e4SLinus Torvalds 	switch (delegation_type) {
14211da177e4SLinus Torvalds 	case 0:
142234558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
14231da177e4SLinus Torvalds 		break;
14241da177e4SLinus Torvalds 	case FMODE_READ:
142534558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
14261da177e4SLinus Torvalds 		break;
14271da177e4SLinus Torvalds 	case FMODE_WRITE|FMODE_READ:
142834558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
14291da177e4SLinus Torvalds 		break;
14301da177e4SLinus Torvalds 	default:
14311da177e4SLinus Torvalds 		BUG();
14321da177e4SLinus Torvalds 	}
14331da177e4SLinus Torvalds }
14341da177e4SLinus Torvalds 
14351da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
14361da177e4SLinus Torvalds {
14378687b63aSAl Viro 	__be32 *p;
14381da177e4SLinus Torvalds 
143913c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
144034558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
14411da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14421da177e4SLinus Torvalds }
14431da177e4SLinus Torvalds 
1444bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
14451da177e4SLinus Torvalds {
14468687b63aSAl Viro 	__be32 *p;
14471da177e4SLinus Torvalds 
144813c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
144934558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
14501da177e4SLinus Torvalds 	encode_delegation_type(xdr, type);
14511da177e4SLinus Torvalds }
14521da177e4SLinus Torvalds 
14531da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
14541da177e4SLinus Torvalds {
14558687b63aSAl Viro 	__be32 *p;
14561da177e4SLinus Torvalds 
145713c65ce9SBenny Halevy 	p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1458e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
145934558513SBenny Halevy 	xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
14601da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14611da177e4SLinus Torvalds }
14621da177e4SLinus Torvalds 
1463cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
14641da177e4SLinus Torvalds {
14651da177e4SLinus Torvalds 	encode_openhdr(xdr, arg);
14661da177e4SLinus Torvalds 	encode_opentype(xdr, arg);
14671da177e4SLinus Torvalds 	switch (arg->claim) {
14681da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_NULL:
14691da177e4SLinus Torvalds 		encode_claim_null(xdr, arg->name);
14701da177e4SLinus Torvalds 		break;
14711da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_PREVIOUS:
14721da177e4SLinus Torvalds 		encode_claim_previous(xdr, arg->u.delegation_type);
14731da177e4SLinus Torvalds 		break;
14741da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_DELEGATE_CUR:
14751da177e4SLinus Torvalds 		encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
14761da177e4SLinus Torvalds 		break;
14771da177e4SLinus Torvalds 	default:
14781da177e4SLinus Torvalds 		BUG();
14791da177e4SLinus Torvalds 	}
1480d017931cSAndy Adamson 	hdr->nops++;
1481dadf0c27SBenny Halevy 	hdr->replen += decode_open_maxsz;
14821da177e4SLinus Torvalds }
14831da177e4SLinus Torvalds 
1484cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
14851da177e4SLinus Torvalds {
14868687b63aSAl Viro 	__be32 *p;
14871da177e4SLinus Torvalds 
148813c65ce9SBenny Halevy 	p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1489e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_OPEN_CONFIRM);
149093f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
149134558513SBenny Halevy 	*p = cpu_to_be32(arg->seqid->sequence->counter);
1492d017931cSAndy Adamson 	hdr->nops++;
1493dadf0c27SBenny Halevy 	hdr->replen += decode_open_confirm_maxsz;
14941da177e4SLinus Torvalds }
14951da177e4SLinus Torvalds 
1496cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
14971da177e4SLinus Torvalds {
14988687b63aSAl Viro 	__be32 *p;
14991da177e4SLinus Torvalds 
150013c65ce9SBenny Halevy 	p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1501e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
150293f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
150334558513SBenny Halevy 	*p = cpu_to_be32(arg->seqid->sequence->counter);
1504dc0b027dSTrond Myklebust 	encode_share_access(xdr, arg->fmode);
1505d017931cSAndy Adamson 	hdr->nops++;
1506dadf0c27SBenny Halevy 	hdr->replen += decode_open_downgrade_maxsz;
15071da177e4SLinus Torvalds }
15081da177e4SLinus Torvalds 
1509cf8cdbe5SAndy Adamson static void
1510d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
15111da177e4SLinus Torvalds {
15121da177e4SLinus Torvalds 	int len = fh->size;
15138687b63aSAl Viro 	__be32 *p;
15141da177e4SLinus Torvalds 
151513c65ce9SBenny Halevy 	p = reserve_space(xdr, 8 + len);
1516e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_PUTFH);
1517811652bdSBenny Halevy 	xdr_encode_opaque(p, fh->data, len);
1518d017931cSAndy Adamson 	hdr->nops++;
1519dadf0c27SBenny Halevy 	hdr->replen += decode_putfh_maxsz;
15201da177e4SLinus Torvalds }
15211da177e4SLinus Torvalds 
1522cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
15231da177e4SLinus Torvalds {
15248687b63aSAl Viro 	__be32 *p;
15251da177e4SLinus Torvalds 
152613c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
152734558513SBenny Halevy 	*p = cpu_to_be32(OP_PUTROOTFH);
1528d017931cSAndy Adamson 	hdr->nops++;
1529dadf0c27SBenny Halevy 	hdr->replen += decode_putrootfh_maxsz;
15301da177e4SLinus Torvalds }
15311da177e4SLinus Torvalds 
153289d1ea65SAndy Adamson static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
15331da177e4SLinus Torvalds {
15341da177e4SLinus Torvalds 	nfs4_stateid stateid;
15358687b63aSAl Viro 	__be32 *p;
15361da177e4SLinus Torvalds 
153713c65ce9SBenny Halevy 	p = reserve_space(xdr, NFS4_STATEID_SIZE);
15381da177e4SLinus Torvalds 	if (ctx->state != NULL) {
153977041ed9STrond Myklebust 		nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
154089d1ea65SAndy Adamson 		if (zero_seqid)
154189d1ea65SAndy Adamson 			stateid.stateid.seqid = 0;
154234558513SBenny Halevy 		xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
15431da177e4SLinus Torvalds 	} else
154434558513SBenny Halevy 		xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
15451da177e4SLinus Torvalds }
15461da177e4SLinus Torvalds 
1547cf8cdbe5SAndy Adamson static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
15481da177e4SLinus Torvalds {
15498687b63aSAl Viro 	__be32 *p;
15501da177e4SLinus Torvalds 
155113c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
155234558513SBenny Halevy 	*p = cpu_to_be32(OP_READ);
15531da177e4SLinus Torvalds 
155489d1ea65SAndy Adamson 	encode_stateid(xdr, args->context, args->lock_context,
155589d1ea65SAndy Adamson 		       hdr->minorversion);
15561da177e4SLinus Torvalds 
155713c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1558b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
155934558513SBenny Halevy 	*p = cpu_to_be32(args->count);
1560d017931cSAndy Adamson 	hdr->nops++;
1561dadf0c27SBenny Halevy 	hdr->replen += decode_read_maxsz;
15621da177e4SLinus Torvalds }
15631da177e4SLinus Torvalds 
1564cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
15651da177e4SLinus Torvalds {
156628331a46STrond Myklebust 	uint32_t attrs[2] = {
156728331a46STrond Myklebust 		FATTR4_WORD0_RDATTR_ERROR,
156828331a46STrond Myklebust 		FATTR4_WORD1_MOUNTED_ON_FILEID,
156928331a46STrond Myklebust 	};
15706f7a35bdSTrond Myklebust 	uint32_t dircount = readdir->count >> 1;
15718687b63aSAl Viro 	__be32 *p;
15721da177e4SLinus Torvalds 
157382f2e547SBryan Schumaker 	if (readdir->plus) {
157482f2e547SBryan Schumaker 		attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
157528331a46STrond Myklebust 			FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
157682f2e547SBryan Schumaker 		attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
157782f2e547SBryan Schumaker 			FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
157882f2e547SBryan Schumaker 			FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
157982f2e547SBryan Schumaker 			FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
15806f7a35bdSTrond Myklebust 		dircount >>= 1;
158182f2e547SBryan Schumaker 	}
158228331a46STrond Myklebust 	/* Use mounted_on_fileid only if the server supports it */
158328331a46STrond Myklebust 	if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
158428331a46STrond Myklebust 		attrs[0] |= FATTR4_WORD0_FILEID;
15856f7a35bdSTrond Myklebust 
15866f7a35bdSTrond Myklebust 	p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
15876f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(OP_READDIR);
15886f7a35bdSTrond Myklebust 	p = xdr_encode_hyper(p, readdir->cookie);
15896f7a35bdSTrond Myklebust 	p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
15906f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(dircount);
15916f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(readdir->count);
15926f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(2);
159382f2e547SBryan Schumaker 
1594e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
159534558513SBenny Halevy 	*p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1596d017931cSAndy Adamson 	hdr->nops++;
1597dadf0c27SBenny Halevy 	hdr->replen += decode_readdir_maxsz;
159844109241SFred Isaman 	dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
159944109241SFred Isaman 			__func__,
1600eadf4598STrond Myklebust 			(unsigned long long)readdir->cookie,
1601eadf4598STrond Myklebust 			((u32 *)readdir->verifier.data)[0],
1602eadf4598STrond Myklebust 			((u32 *)readdir->verifier.data)[1],
1603eadf4598STrond Myklebust 			attrs[0] & readdir->bitmask[0],
1604eadf4598STrond Myklebust 			attrs[1] & readdir->bitmask[1]);
16051da177e4SLinus Torvalds }
16061da177e4SLinus Torvalds 
1607cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
16081da177e4SLinus Torvalds {
16098687b63aSAl Viro 	__be32 *p;
16101da177e4SLinus Torvalds 
161113c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
161234558513SBenny Halevy 	*p = cpu_to_be32(OP_READLINK);
1613d017931cSAndy Adamson 	hdr->nops++;
1614dadf0c27SBenny Halevy 	hdr->replen += decode_readlink_maxsz;
16151da177e4SLinus Torvalds }
16161da177e4SLinus Torvalds 
1617cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
16181da177e4SLinus Torvalds {
16198687b63aSAl Viro 	__be32 *p;
16201da177e4SLinus Torvalds 
162113c65ce9SBenny Halevy 	p = reserve_space(xdr, 8 + name->len);
1622e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_REMOVE);
1623811652bdSBenny Halevy 	xdr_encode_opaque(p, name->name, name->len);
1624d017931cSAndy Adamson 	hdr->nops++;
1625dadf0c27SBenny Halevy 	hdr->replen += decode_remove_maxsz;
16261da177e4SLinus Torvalds }
16271da177e4SLinus Torvalds 
1628cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
16291da177e4SLinus Torvalds {
16308687b63aSAl Viro 	__be32 *p;
16311da177e4SLinus Torvalds 
1632811652bdSBenny Halevy 	p = reserve_space(xdr, 4);
1633811652bdSBenny Halevy 	*p = cpu_to_be32(OP_RENAME);
1634811652bdSBenny Halevy 	encode_string(xdr, oldname->len, oldname->name);
1635811652bdSBenny Halevy 	encode_string(xdr, newname->len, newname->name);
1636d017931cSAndy Adamson 	hdr->nops++;
1637dadf0c27SBenny Halevy 	hdr->replen += decode_rename_maxsz;
16381da177e4SLinus Torvalds }
16391da177e4SLinus Torvalds 
1640bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1641bb4dae5eSChuck Lever 			 struct compound_hdr *hdr)
16421da177e4SLinus Torvalds {
16438687b63aSAl Viro 	__be32 *p;
16441da177e4SLinus Torvalds 
164513c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1646e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_RENEW);
1647bb4dae5eSChuck Lever 	xdr_encode_hyper(p, clid);
1648d017931cSAndy Adamson 	hdr->nops++;
1649dadf0c27SBenny Halevy 	hdr->replen += decode_renew_maxsz;
16501da177e4SLinus Torvalds }
16511da177e4SLinus Torvalds 
1652cf8cdbe5SAndy Adamson static void
1653d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
165456ae19f3STrond Myklebust {
16558687b63aSAl Viro 	__be32 *p;
165656ae19f3STrond Myklebust 
165713c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
165834558513SBenny Halevy 	*p = cpu_to_be32(OP_RESTOREFH);
1659d017931cSAndy Adamson 	hdr->nops++;
1660dadf0c27SBenny Halevy 	hdr->replen += decode_restorefh_maxsz;
166156ae19f3STrond Myklebust }
166256ae19f3STrond Myklebust 
16639f06c719SChuck Lever static void
1664d017931cSAndy Adamson encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
166523ec6965SJ. Bruce Fields {
16668687b63aSAl Viro 	__be32 *p;
166723ec6965SJ. Bruce Fields 
166813c65ce9SBenny Halevy 	p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1669e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_SETATTR);
167034558513SBenny Halevy 	xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
167113c65ce9SBenny Halevy 	p = reserve_space(xdr, 2*4);
1672e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
167334558513SBenny Halevy 	*p = cpu_to_be32(FATTR4_WORD0_ACL);
16749f06c719SChuck Lever 	BUG_ON(arg->acl_len % 4);
167513c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
167634558513SBenny Halevy 	*p = cpu_to_be32(arg->acl_len);
167723ec6965SJ. Bruce Fields 	xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1678d017931cSAndy Adamson 	hdr->nops++;
1679dadf0c27SBenny Halevy 	hdr->replen += decode_setacl_maxsz;
168023ec6965SJ. Bruce Fields }
168123ec6965SJ. Bruce Fields 
1682cf8cdbe5SAndy Adamson static void
1683d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
16841da177e4SLinus Torvalds {
16858687b63aSAl Viro 	__be32 *p;
16861da177e4SLinus Torvalds 
168713c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
168834558513SBenny Halevy 	*p = cpu_to_be32(OP_SAVEFH);
1689d017931cSAndy Adamson 	hdr->nops++;
1690dadf0c27SBenny Halevy 	hdr->replen += decode_savefh_maxsz;
16911da177e4SLinus Torvalds }
16921da177e4SLinus Torvalds 
1693cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
16941da177e4SLinus Torvalds {
16958687b63aSAl Viro 	__be32 *p;
16961da177e4SLinus Torvalds 
169713c65ce9SBenny Halevy 	p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1698e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_SETATTR);
169934558513SBenny Halevy 	xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
1700d017931cSAndy Adamson 	hdr->nops++;
1701dadf0c27SBenny Halevy 	hdr->replen += decode_setattr_maxsz;
1702cf8cdbe5SAndy Adamson 	encode_attrs(xdr, arg->iap, server);
17031da177e4SLinus Torvalds }
17041da177e4SLinus Torvalds 
1705cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
17061da177e4SLinus Torvalds {
17078687b63aSAl Viro 	__be32 *p;
17081da177e4SLinus Torvalds 
170913c65ce9SBenny Halevy 	p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
1710e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_SETCLIENTID);
171134558513SBenny Halevy 	xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
17121da177e4SLinus Torvalds 
17131da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
171413c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
171534558513SBenny Halevy 	*p = cpu_to_be32(setclientid->sc_prog);
17161da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
17171da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
171813c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
171934558513SBenny Halevy 	*p = cpu_to_be32(setclientid->sc_cb_ident);
1720d017931cSAndy Adamson 	hdr->nops++;
1721dadf0c27SBenny Halevy 	hdr->replen += decode_setclientid_maxsz;
17221da177e4SLinus Torvalds }
17231da177e4SLinus Torvalds 
1724bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
17251da177e4SLinus Torvalds {
17268687b63aSAl Viro 	__be32 *p;
17271da177e4SLinus Torvalds 
172813c65ce9SBenny Halevy 	p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
1729e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
1730bb8b27e5STrond Myklebust 	p = xdr_encode_hyper(p, arg->clientid);
1731bb8b27e5STrond Myklebust 	xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
1732d017931cSAndy Adamson 	hdr->nops++;
1733dadf0c27SBenny Halevy 	hdr->replen += decode_setclientid_confirm_maxsz;
17341da177e4SLinus Torvalds }
17351da177e4SLinus Torvalds 
1736cf8cdbe5SAndy Adamson static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
17371da177e4SLinus Torvalds {
17388687b63aSAl Viro 	__be32 *p;
17391da177e4SLinus Torvalds 
174013c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
174134558513SBenny Halevy 	*p = cpu_to_be32(OP_WRITE);
17421da177e4SLinus Torvalds 
174389d1ea65SAndy Adamson 	encode_stateid(xdr, args->context, args->lock_context,
174489d1ea65SAndy Adamson 		       hdr->minorversion);
17451da177e4SLinus Torvalds 
174613c65ce9SBenny Halevy 	p = reserve_space(xdr, 16);
1747b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
1748e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->stable);
174934558513SBenny Halevy 	*p = cpu_to_be32(args->count);
17501da177e4SLinus Torvalds 
17511da177e4SLinus Torvalds 	xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1752d017931cSAndy Adamson 	hdr->nops++;
1753dadf0c27SBenny Halevy 	hdr->replen += decode_write_maxsz;
17541da177e4SLinus Torvalds }
17551da177e4SLinus Torvalds 
1756cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
17571da177e4SLinus Torvalds {
17588687b63aSAl Viro 	__be32 *p;
17591da177e4SLinus Torvalds 
176013c65ce9SBenny Halevy 	p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
17611da177e4SLinus Torvalds 
1762e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_DELEGRETURN);
176334558513SBenny Halevy 	xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1764d017931cSAndy Adamson 	hdr->nops++;
1765dadf0c27SBenny Halevy 	hdr->replen += decode_delegreturn_maxsz;
17661da177e4SLinus Torvalds }
17679b7b9fccSAndy Adamson 
17685a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
17695a5ea0d4SBryan Schumaker {
17705a5ea0d4SBryan Schumaker 	int len = name->len;
17715a5ea0d4SBryan Schumaker 	__be32 *p;
17725a5ea0d4SBryan Schumaker 
17735a5ea0d4SBryan Schumaker 	p = reserve_space(xdr, 8 + len);
17745a5ea0d4SBryan Schumaker 	*p++ = cpu_to_be32(OP_SECINFO);
17755a5ea0d4SBryan Schumaker 	xdr_encode_opaque(p, name->name, len);
17765a5ea0d4SBryan Schumaker 	hdr->nops++;
17775a5ea0d4SBryan Schumaker 	hdr->replen += decode_secinfo_maxsz;
17785a5ea0d4SBryan Schumaker }
17795a5ea0d4SBryan Schumaker 
178099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
17819b7b9fccSAndy Adamson /* NFSv4.1 operations */
178299fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr,
178399fe60d0SBenny Halevy 			       struct nfs41_exchange_id_args *args,
178499fe60d0SBenny Halevy 			       struct compound_hdr *hdr)
178599fe60d0SBenny Halevy {
178699fe60d0SBenny Halevy 	__be32 *p;
1787db8ac8baSWeston Andros Adamson 	char impl_name[NFS4_OPAQUE_LIMIT];
1788db8ac8baSWeston Andros Adamson 	int len = 0;
178999fe60d0SBenny Halevy 
179013c65ce9SBenny Halevy 	p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
1791e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_EXCHANGE_ID);
179234558513SBenny Halevy 	xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
179399fe60d0SBenny Halevy 
179499fe60d0SBenny Halevy 	encode_string(xdr, args->id_len, args->id);
179599fe60d0SBenny Halevy 
179613c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1797e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->flags);
1798e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);	/* zero length state_protect4_a */
1799db8ac8baSWeston Andros Adamson 
1800db8ac8baSWeston Andros Adamson 	if (send_implementation_id &&
1801db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1802db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1803db8ac8baSWeston Andros Adamson 		<= NFS4_OPAQUE_LIMIT + 1)
1804db8ac8baSWeston Andros Adamson 		len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1805db8ac8baSWeston Andros Adamson 			       utsname()->sysname, utsname()->release,
1806db8ac8baSWeston Andros Adamson 			       utsname()->version, utsname()->machine);
1807db8ac8baSWeston Andros Adamson 
1808db8ac8baSWeston Andros Adamson 	if (len > 0) {
1809db8ac8baSWeston Andros Adamson 		*p = cpu_to_be32(1);	/* implementation id array length=1 */
1810db8ac8baSWeston Andros Adamson 
1811db8ac8baSWeston Andros Adamson 		encode_string(xdr,
1812db8ac8baSWeston Andros Adamson 			sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1813db8ac8baSWeston Andros Adamson 			CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1814db8ac8baSWeston Andros Adamson 		encode_string(xdr, len, impl_name);
1815db8ac8baSWeston Andros Adamson 		/* just send zeros for nii_date - the date is in nii_name */
1816db8ac8baSWeston Andros Adamson 		p = reserve_space(xdr, 12);
1817db8ac8baSWeston Andros Adamson 		p = xdr_encode_hyper(p, 0);
1818db8ac8baSWeston Andros Adamson 		*p = cpu_to_be32(0);
1819db8ac8baSWeston Andros Adamson 	} else
1820db8ac8baSWeston Andros Adamson 		*p = cpu_to_be32(0);	/* implementation id array length=0 */
1821db8ac8baSWeston Andros Adamson 
182299fe60d0SBenny Halevy 	hdr->nops++;
182399fe60d0SBenny Halevy 	hdr->replen += decode_exchange_id_maxsz;
182499fe60d0SBenny Halevy }
1825fc931582SAndy Adamson 
1826fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr,
1827fc931582SAndy Adamson 				  struct nfs41_create_session_args *args,
1828fc931582SAndy Adamson 				  struct compound_hdr *hdr)
1829fc931582SAndy Adamson {
1830fc931582SAndy Adamson 	__be32 *p;
1831fc931582SAndy Adamson 	char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1832fc931582SAndy Adamson 	uint32_t len;
1833fc931582SAndy Adamson 	struct nfs_client *clp = args->client;
18348e0d46e1SMike Sager 	u32 max_resp_sz_cached;
18358e0d46e1SMike Sager 
18368e0d46e1SMike Sager 	/*
18378e0d46e1SMike Sager 	 * Assumes OPEN is the biggest non-idempotent compound.
18388e0d46e1SMike Sager 	 * 2 is the verifier.
18398e0d46e1SMike Sager 	 */
18408e0d46e1SMike Sager 	max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
18418e0d46e1SMike Sager 			      RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1842fc931582SAndy Adamson 
1843fc931582SAndy Adamson 	len = scnprintf(machine_name, sizeof(machine_name), "%s",
1844fc931582SAndy Adamson 			clp->cl_ipaddr);
184542edd698SBenny Halevy 
184613c65ce9SBenny Halevy 	p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
1847e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_CREATE_SESSION);
1848114f64b5SAndy Adamson 	p = xdr_encode_hyper(p, clp->cl_clientid);
1849e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(clp->cl_seqid);			/*Sequence id */
1850e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->flags);			/*flags */
1851fc931582SAndy Adamson 
1852fc931582SAndy Adamson 	/* Fore Channel */
1853c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1854e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz);	/* max req size */
1855e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_resp_sz);	/* max resp size */
18568e0d46e1SMike Sager 	*p++ = cpu_to_be32(max_resp_sz_cached);		/* Max resp sz cached */
1857e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_ops);	/* max operations */
1858e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_reqs);	/* max requests */
1859e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1860fc931582SAndy Adamson 
1861fc931582SAndy Adamson 	/* Back Channel */
1862c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1863e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz);	/* max req size */
1864e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz);	/* max resp size */
1865e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached);	/* Max resp sz cached */
1866e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_ops);	/* max operations */
1867e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_reqs);	/* max requests */
1868e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1869fc931582SAndy Adamson 
1870e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->cb_program);		/* cb_program */
1871e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
1872e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(RPC_AUTH_UNIX);			/* auth_sys */
1873fc931582SAndy Adamson 
1874fc931582SAndy Adamson 	/* authsys_parms rfc1831 */
1875e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec);	/* stamp */
1876811652bdSBenny Halevy 	p = xdr_encode_opaque(p, machine_name, len);
1877e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* UID */
1878e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* GID */
187934558513SBenny Halevy 	*p = cpu_to_be32(0);				/* No more gids */
1880fc931582SAndy Adamson 	hdr->nops++;
1881fc931582SAndy Adamson 	hdr->replen += decode_create_session_maxsz;
1882fc931582SAndy Adamson }
18830f3e66c6SAndy Adamson 
18840f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr,
18850f3e66c6SAndy Adamson 				   struct nfs4_session *session,
18860f3e66c6SAndy Adamson 				   struct compound_hdr *hdr)
18870f3e66c6SAndy Adamson {
18880f3e66c6SAndy Adamson 	__be32 *p;
188913c65ce9SBenny Halevy 	p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
1890e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_DESTROY_SESSION);
189134558513SBenny Halevy 	xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
18920f3e66c6SAndy Adamson 	hdr->nops++;
18930f3e66c6SAndy Adamson 	hdr->replen += decode_destroy_session_maxsz;
18940f3e66c6SAndy Adamson }
189518019753SRicardo Labiaga 
189618019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr,
189718019753SRicardo Labiaga 				    struct nfs41_reclaim_complete_args *args,
189818019753SRicardo Labiaga 				    struct compound_hdr *hdr)
189918019753SRicardo Labiaga {
190018019753SRicardo Labiaga 	__be32 *p;
190118019753SRicardo Labiaga 
190218019753SRicardo Labiaga 	p = reserve_space(xdr, 8);
190318019753SRicardo Labiaga 	*p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
190418019753SRicardo Labiaga 	*p++ = cpu_to_be32(args->one_fs);
190518019753SRicardo Labiaga 	hdr->nops++;
190618019753SRicardo Labiaga 	hdr->replen += decode_reclaim_complete_maxsz;
190718019753SRicardo Labiaga }
190899fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
190999fe60d0SBenny Halevy 
19109b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr,
19119b7b9fccSAndy Adamson 			    const struct nfs4_sequence_args *args,
19129b7b9fccSAndy Adamson 			    struct compound_hdr *hdr)
19139b7b9fccSAndy Adamson {
19149b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
19159b7b9fccSAndy Adamson 	struct nfs4_session *session = args->sa_session;
1916fc01cea9SAndy Adamson 	struct nfs4_slot_table *tp;
1917fc01cea9SAndy Adamson 	struct nfs4_slot *slot;
1918fc01cea9SAndy Adamson 	__be32 *p;
19199b7b9fccSAndy Adamson 
19209b7b9fccSAndy Adamson 	if (!session)
19219b7b9fccSAndy Adamson 		return;
19229b7b9fccSAndy Adamson 
1923fc01cea9SAndy Adamson 	tp = &session->fc_slot_table;
1924fc01cea9SAndy Adamson 
1925fc01cea9SAndy Adamson 	WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1926fc01cea9SAndy Adamson 	slot = tp->slots + args->sa_slotid;
1927fc01cea9SAndy Adamson 
192813c65ce9SBenny Halevy 	p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
1929e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(OP_SEQUENCE);
1930fc01cea9SAndy Adamson 
1931fc01cea9SAndy Adamson 	/*
1932fc01cea9SAndy Adamson 	 * Sessionid + seqid + slotid + max slotid + cache_this
1933fc01cea9SAndy Adamson 	 */
1934fc01cea9SAndy Adamson 	dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1935fc01cea9SAndy Adamson 		"max_slotid=%d cache_this=%d\n",
1936fc01cea9SAndy Adamson 		__func__,
1937fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[0],
1938fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[1],
1939fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[2],
1940fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[3],
1941fc01cea9SAndy Adamson 		slot->seq_nr, args->sa_slotid,
1942fc01cea9SAndy Adamson 		tp->highest_used_slotid, args->sa_cache_this);
194393f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1944e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(slot->seq_nr);
1945e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->sa_slotid);
1946e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(tp->highest_used_slotid);
194734558513SBenny Halevy 	*p = cpu_to_be32(args->sa_cache_this);
19489b7b9fccSAndy Adamson 	hdr->nops++;
19499b7b9fccSAndy Adamson 	hdr->replen += decode_sequence_maxsz;
19509b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
19519b7b9fccSAndy Adamson }
19529b7b9fccSAndy Adamson 
1953b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1
1954b1f69b75SAndy Adamson static void
19557f11d8d3SAndy Adamson encode_getdevicelist(struct xdr_stream *xdr,
19567f11d8d3SAndy Adamson 		     const struct nfs4_getdevicelist_args *args,
19577f11d8d3SAndy Adamson 		     struct compound_hdr *hdr)
19587f11d8d3SAndy Adamson {
19597f11d8d3SAndy Adamson 	__be32 *p;
19607f11d8d3SAndy Adamson 	nfs4_verifier dummy = {
19617f11d8d3SAndy Adamson 		.data = "dummmmmy",
19627f11d8d3SAndy Adamson 	};
19637f11d8d3SAndy Adamson 
19647f11d8d3SAndy Adamson 	p = reserve_space(xdr, 20);
19657f11d8d3SAndy Adamson 	*p++ = cpu_to_be32(OP_GETDEVICELIST);
19667f11d8d3SAndy Adamson 	*p++ = cpu_to_be32(args->layoutclass);
19677f11d8d3SAndy Adamson 	*p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
19687f11d8d3SAndy Adamson 	xdr_encode_hyper(p, 0ULL);                          /* cookie */
19697f11d8d3SAndy Adamson 	encode_nfs4_verifier(xdr, &dummy);
19707f11d8d3SAndy Adamson 	hdr->nops++;
19717f11d8d3SAndy Adamson 	hdr->replen += decode_getdevicelist_maxsz;
19727f11d8d3SAndy Adamson }
19737f11d8d3SAndy Adamson 
19747f11d8d3SAndy Adamson static void
1975b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr,
1976b1f69b75SAndy Adamson 		     const struct nfs4_getdeviceinfo_args *args,
1977b1f69b75SAndy Adamson 		     struct compound_hdr *hdr)
1978b1f69b75SAndy Adamson {
1979b1f69b75SAndy Adamson 	__be32 *p;
1980b1f69b75SAndy Adamson 
1981b1f69b75SAndy Adamson 	p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1982b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(OP_GETDEVICEINFO);
1983b1f69b75SAndy Adamson 	p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1984b1f69b75SAndy Adamson 				    NFS4_DEVICEID4_SIZE);
1985b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->pdev->layout_type);
1986b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->pdev->pglen);		/* gdia_maxcount */
1987b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(0);				/* bitmap length 0 */
1988b1f69b75SAndy Adamson 	hdr->nops++;
1989b1f69b75SAndy Adamson 	hdr->replen += decode_getdeviceinfo_maxsz;
1990b1f69b75SAndy Adamson }
1991b1f69b75SAndy Adamson 
1992b1f69b75SAndy Adamson static void
1993b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr,
1994b1f69b75SAndy Adamson 		      const struct nfs4_layoutget_args *args,
1995b1f69b75SAndy Adamson 		      struct compound_hdr *hdr)
1996b1f69b75SAndy Adamson {
1997b1f69b75SAndy Adamson 	__be32 *p;
1998b1f69b75SAndy Adamson 
1999b1f69b75SAndy Adamson 	p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
2000b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(OP_LAYOUTGET);
2001b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(0);     /* Signal layout available */
2002b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->type);
2003b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->range.iomode);
2004b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.offset);
2005b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.length);
2006b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->minlength);
2007cf7d63f1SFred Isaman 	p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
2008b1f69b75SAndy Adamson 	*p = cpu_to_be32(args->maxcount);
2009b1f69b75SAndy Adamson 
2010b1f69b75SAndy Adamson 	dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
2011b1f69b75SAndy Adamson 		__func__,
2012b1f69b75SAndy Adamson 		args->type,
2013b1f69b75SAndy Adamson 		args->range.iomode,
2014b1f69b75SAndy Adamson 		(unsigned long)args->range.offset,
2015b1f69b75SAndy Adamson 		(unsigned long)args->range.length,
2016b1f69b75SAndy Adamson 		args->maxcount);
2017b1f69b75SAndy Adamson 	hdr->nops++;
2018b1f69b75SAndy Adamson 	hdr->replen += decode_layoutget_maxsz;
2019b1f69b75SAndy Adamson }
2020863a3c6cSAndy Adamson 
2021863a3c6cSAndy Adamson static int
2022863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr,
2023ac7db726SBenny Halevy 		    struct inode *inode,
2024863a3c6cSAndy Adamson 		    const struct nfs4_layoutcommit_args *args,
2025863a3c6cSAndy Adamson 		    struct compound_hdr *hdr)
2026863a3c6cSAndy Adamson {
2027863a3c6cSAndy Adamson 	__be32 *p;
2028863a3c6cSAndy Adamson 
2029863a3c6cSAndy Adamson 	dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2030863a3c6cSAndy Adamson 		NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2031863a3c6cSAndy Adamson 
2032ac7db726SBenny Halevy 	p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
2033863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
2034863a3c6cSAndy Adamson 	/* Only whole file layouts */
2035863a3c6cSAndy Adamson 	p = xdr_encode_hyper(p, 0); /* offset */
20363557c6c3SPeng Tao 	p = xdr_encode_hyper(p, args->lastbytewritten + 1);	/* length */
2037863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(0); /* reclaim */
2038863a3c6cSAndy Adamson 	p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
2039863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(1); /* newoffset = TRUE */
2040863a3c6cSAndy Adamson 	p = xdr_encode_hyper(p, args->lastbytewritten);
2041863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2042863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2043ac7db726SBenny Halevy 
2044ac7db726SBenny Halevy 	if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2045ac7db726SBenny Halevy 		NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2046ac7db726SBenny Halevy 			NFS_I(inode)->layout, xdr, args);
2047ac7db726SBenny Halevy 	else {
2048ac7db726SBenny Halevy 		p = reserve_space(xdr, 4);
2049ac7db726SBenny Halevy 		*p = cpu_to_be32(0); /* no layout-type payload */
2050ac7db726SBenny Halevy 	}
2051863a3c6cSAndy Adamson 
2052863a3c6cSAndy Adamson 	hdr->nops++;
2053863a3c6cSAndy Adamson 	hdr->replen += decode_layoutcommit_maxsz;
2054863a3c6cSAndy Adamson 	return 0;
2055863a3c6cSAndy Adamson }
2056cbe82603SBenny Halevy 
2057cbe82603SBenny Halevy static void
2058cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr,
2059cbe82603SBenny Halevy 		    const struct nfs4_layoutreturn_args *args,
2060cbe82603SBenny Halevy 		    struct compound_hdr *hdr)
2061cbe82603SBenny Halevy {
2062cbe82603SBenny Halevy 	__be32 *p;
2063cbe82603SBenny Halevy 
2064cbe82603SBenny Halevy 	p = reserve_space(xdr, 20);
2065cbe82603SBenny Halevy 	*p++ = cpu_to_be32(OP_LAYOUTRETURN);
2066cbe82603SBenny Halevy 	*p++ = cpu_to_be32(0);		/* reclaim. always 0 for now */
2067cbe82603SBenny Halevy 	*p++ = cpu_to_be32(args->layout_type);
2068cbe82603SBenny Halevy 	*p++ = cpu_to_be32(IOMODE_ANY);
2069cbe82603SBenny Halevy 	*p = cpu_to_be32(RETURN_FILE);
2070cbe82603SBenny Halevy 	p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
2071cbe82603SBenny Halevy 	p = xdr_encode_hyper(p, 0);
2072cbe82603SBenny Halevy 	p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2073cbe82603SBenny Halevy 	spin_lock(&args->inode->i_lock);
2074cbe82603SBenny Halevy 	xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
2075cbe82603SBenny Halevy 	spin_unlock(&args->inode->i_lock);
207604a55549SAndy Adamson 	if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
207704a55549SAndy Adamson 		NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
207804a55549SAndy Adamson 			NFS_I(args->inode)->layout, xdr, args);
207904a55549SAndy Adamson 	} else {
2080cbe82603SBenny Halevy 		p = reserve_space(xdr, 4);
2081cbe82603SBenny Halevy 		*p = cpu_to_be32(0);
208204a55549SAndy Adamson 	}
2083cbe82603SBenny Halevy 	hdr->nops++;
2084cbe82603SBenny Halevy 	hdr->replen += decode_layoutreturn_maxsz;
2085cbe82603SBenny Halevy }
2086fca78d6dSBryan Schumaker 
2087fca78d6dSBryan Schumaker static int
2088fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr,
2089fca78d6dSBryan Schumaker 		       const struct nfs41_secinfo_no_name_args *args,
2090fca78d6dSBryan Schumaker 		       struct compound_hdr *hdr)
2091fca78d6dSBryan Schumaker {
2092fca78d6dSBryan Schumaker 	__be32 *p;
2093fca78d6dSBryan Schumaker 	p = reserve_space(xdr, 8);
2094fca78d6dSBryan Schumaker 	*p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2095fca78d6dSBryan Schumaker 	*p++ = cpu_to_be32(args->style);
2096fca78d6dSBryan Schumaker 	hdr->nops++;
2097fca78d6dSBryan Schumaker 	hdr->replen += decode_secinfo_no_name_maxsz;
2098fca78d6dSBryan Schumaker 	return 0;
2099fca78d6dSBryan Schumaker }
21007d974794SBryan Schumaker 
21017d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr,
21027d974794SBryan Schumaker 				struct nfs41_test_stateid_args *args,
21037d974794SBryan Schumaker 				struct compound_hdr *hdr)
21047d974794SBryan Schumaker {
21057d974794SBryan Schumaker 	__be32 *p;
21067d974794SBryan Schumaker 
21077d974794SBryan Schumaker 	p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
21087d974794SBryan Schumaker 	*p++ = cpu_to_be32(OP_TEST_STATEID);
21097d974794SBryan Schumaker 	*p++ = cpu_to_be32(1);
21107d974794SBryan Schumaker 	xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
21117d974794SBryan Schumaker 	hdr->nops++;
21127d974794SBryan Schumaker 	hdr->replen += decode_test_stateid_maxsz;
21137d974794SBryan Schumaker }
21149aeda35fSBryan Schumaker 
21159aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr,
21169aeda35fSBryan Schumaker 				struct nfs41_free_stateid_args *args,
21179aeda35fSBryan Schumaker 				struct compound_hdr *hdr)
21189aeda35fSBryan Schumaker {
21199aeda35fSBryan Schumaker 	__be32 *p;
21209aeda35fSBryan Schumaker 	p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
21219aeda35fSBryan Schumaker 	*p++ = cpu_to_be32(OP_FREE_STATEID);
21229aeda35fSBryan Schumaker 	xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
21239aeda35fSBryan Schumaker 	hdr->nops++;
21249aeda35fSBryan Schumaker 	hdr->replen += decode_free_stateid_maxsz;
21259aeda35fSBryan Schumaker }
2126b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
2127b1f69b75SAndy Adamson 
21281da177e4SLinus Torvalds /*
21291da177e4SLinus Torvalds  * END OF "GENERIC" ENCODE ROUTINES.
21301da177e4SLinus Torvalds  */
21311da177e4SLinus Torvalds 
213266cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
213366cc0429SBenny Halevy {
213466cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1)
213566cc0429SBenny Halevy 	if (args->sa_session)
2136a4432345STrond Myklebust 		return args->sa_session->clp->cl_mvops->minor_version;
213766cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
213866cc0429SBenny Halevy 	return 0;
213966cc0429SBenny Halevy }
214066cc0429SBenny Halevy 
21411da177e4SLinus Torvalds /*
21421da177e4SLinus Torvalds  * Encode an ACCESS request
21431da177e4SLinus Torvalds  */
21449f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
21459f06c719SChuck Lever 				const struct nfs4_accessargs *args)
21461da177e4SLinus Torvalds {
21471da177e4SLinus Torvalds 	struct compound_hdr hdr = {
214866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21491da177e4SLinus Torvalds 	};
21501da177e4SLinus Torvalds 
21519f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21529f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21539f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21549f06c719SChuck Lever 	encode_access(xdr, args->access, &hdr);
21559f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2156d017931cSAndy Adamson 	encode_nops(&hdr);
21571da177e4SLinus Torvalds }
21581da177e4SLinus Torvalds 
21591da177e4SLinus Torvalds /*
21601da177e4SLinus Torvalds  * Encode LOOKUP request
21611da177e4SLinus Torvalds  */
21629f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
21639f06c719SChuck Lever 				const struct nfs4_lookup_arg *args)
21641da177e4SLinus Torvalds {
21651da177e4SLinus Torvalds 	struct compound_hdr hdr = {
216666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21671da177e4SLinus Torvalds 	};
21681da177e4SLinus Torvalds 
21699f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21709f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21719f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
21729f06c719SChuck Lever 	encode_lookup(xdr, args->name, &hdr);
21739f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21749f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2175d017931cSAndy Adamson 	encode_nops(&hdr);
21761da177e4SLinus Torvalds }
21771da177e4SLinus Torvalds 
21781da177e4SLinus Torvalds /*
21791da177e4SLinus Torvalds  * Encode LOOKUP_ROOT request
21801da177e4SLinus Torvalds  */
21819f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
21829f06c719SChuck Lever 				     struct xdr_stream *xdr,
21839f06c719SChuck Lever 				     const struct nfs4_lookup_root_arg *args)
21841da177e4SLinus Torvalds {
21851da177e4SLinus Torvalds 	struct compound_hdr hdr = {
218666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21871da177e4SLinus Torvalds 	};
21881da177e4SLinus Torvalds 
21899f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21909f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21919f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
21929f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21939f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2194d017931cSAndy Adamson 	encode_nops(&hdr);
21951da177e4SLinus Torvalds }
21961da177e4SLinus Torvalds 
21971da177e4SLinus Torvalds /*
21981da177e4SLinus Torvalds  * Encode REMOVE request
21991da177e4SLinus Torvalds  */
22009f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
22019f06c719SChuck Lever 				const struct nfs_removeargs *args)
22021da177e4SLinus Torvalds {
22031da177e4SLinus Torvalds 	struct compound_hdr hdr = {
220466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22051da177e4SLinus Torvalds 	};
22061da177e4SLinus Torvalds 
22079f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22089f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22099f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22109f06c719SChuck Lever 	encode_remove(xdr, &args->name, &hdr);
22119f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2212d017931cSAndy Adamson 	encode_nops(&hdr);
22131da177e4SLinus Torvalds }
22141da177e4SLinus Torvalds 
22151da177e4SLinus Torvalds /*
22161da177e4SLinus Torvalds  * Encode RENAME request
22171da177e4SLinus Torvalds  */
22189f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
22199f06c719SChuck Lever 				const struct nfs_renameargs *args)
22201da177e4SLinus Torvalds {
22211da177e4SLinus Torvalds 	struct compound_hdr hdr = {
222266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22231da177e4SLinus Torvalds 	};
22241da177e4SLinus Torvalds 
22259f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22269f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22279f06c719SChuck Lever 	encode_putfh(xdr, args->old_dir, &hdr);
22289f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
22299f06c719SChuck Lever 	encode_putfh(xdr, args->new_dir, &hdr);
22309f06c719SChuck Lever 	encode_rename(xdr, args->old_name, args->new_name, &hdr);
22319f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
22329f06c719SChuck Lever 	encode_restorefh(xdr, &hdr);
22339f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2234d017931cSAndy Adamson 	encode_nops(&hdr);
22351da177e4SLinus Torvalds }
22361da177e4SLinus Torvalds 
22371da177e4SLinus Torvalds /*
22381da177e4SLinus Torvalds  * Encode LINK request
22391da177e4SLinus Torvalds  */
22409f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
22419f06c719SChuck Lever 			     const struct nfs4_link_arg *args)
22421da177e4SLinus Torvalds {
22431da177e4SLinus Torvalds 	struct compound_hdr hdr = {
224466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22451da177e4SLinus Torvalds 	};
22461da177e4SLinus Torvalds 
22479f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22489f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22499f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22509f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
22519f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
22529f06c719SChuck Lever 	encode_link(xdr, args->name, &hdr);
22539f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
22549f06c719SChuck Lever 	encode_restorefh(xdr, &hdr);
22559f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2256d017931cSAndy Adamson 	encode_nops(&hdr);
22571da177e4SLinus Torvalds }
22581da177e4SLinus Torvalds 
22591da177e4SLinus Torvalds /*
22601da177e4SLinus Torvalds  * Encode CREATE request
22611da177e4SLinus Torvalds  */
22629f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
22639f06c719SChuck Lever 				const struct nfs4_create_arg *args)
22641da177e4SLinus Torvalds {
22651da177e4SLinus Torvalds 	struct compound_hdr hdr = {
226666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22671da177e4SLinus Torvalds 	};
22681da177e4SLinus Torvalds 
22699f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22709f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22719f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
22729f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
22739f06c719SChuck Lever 	encode_create(xdr, args, &hdr);
22749f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
22759f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
22769f06c719SChuck Lever 	encode_restorefh(xdr, &hdr);
22779f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2278d017931cSAndy Adamson 	encode_nops(&hdr);
22791da177e4SLinus Torvalds }
22801da177e4SLinus Torvalds 
22811da177e4SLinus Torvalds /*
22821da177e4SLinus Torvalds  * Encode SYMLINK request
22831da177e4SLinus Torvalds  */
22849f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
22859f06c719SChuck Lever 				 const struct nfs4_create_arg *args)
22861da177e4SLinus Torvalds {
22879f06c719SChuck Lever 	nfs4_xdr_enc_create(req, xdr, args);
22881da177e4SLinus Torvalds }
22891da177e4SLinus Torvalds 
22901da177e4SLinus Torvalds /*
22911da177e4SLinus Torvalds  * Encode GETATTR request
22921da177e4SLinus Torvalds  */
22939f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
22949f06c719SChuck Lever 				 const struct nfs4_getattr_arg *args)
22951da177e4SLinus Torvalds {
22961da177e4SLinus Torvalds 	struct compound_hdr hdr = {
229766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22981da177e4SLinus Torvalds 	};
22991da177e4SLinus Torvalds 
23009f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23019f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23029f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23039f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2304d017931cSAndy Adamson 	encode_nops(&hdr);
23051da177e4SLinus Torvalds }
23061da177e4SLinus Torvalds 
23071da177e4SLinus Torvalds /*
23081da177e4SLinus Torvalds  * Encode a CLOSE request
23091da177e4SLinus Torvalds  */
23109f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
23119f06c719SChuck Lever 			       struct nfs_closeargs *args)
23121da177e4SLinus Torvalds {
23131da177e4SLinus Torvalds 	struct compound_hdr hdr = {
231466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23151da177e4SLinus Torvalds 	};
23161da177e4SLinus Torvalds 
23179f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23189f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23199f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23209f06c719SChuck Lever 	encode_close(xdr, args, &hdr);
23219f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2322d017931cSAndy Adamson 	encode_nops(&hdr);
23231da177e4SLinus Torvalds }
23241da177e4SLinus Torvalds 
23251da177e4SLinus Torvalds /*
23261da177e4SLinus Torvalds  * Encode an OPEN request
23271da177e4SLinus Torvalds  */
23289f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
23299f06c719SChuck Lever 			      struct nfs_openargs *args)
23301da177e4SLinus Torvalds {
23311da177e4SLinus Torvalds 	struct compound_hdr hdr = {
233266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23331da177e4SLinus Torvalds 	};
23341da177e4SLinus Torvalds 
23359f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23369f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23379f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23389f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
23399f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
23409f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
23419f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
23429f06c719SChuck Lever 	encode_restorefh(xdr, &hdr);
23436926afd1STrond Myklebust 	encode_getfattr(xdr, args->dir_bitmask, &hdr);
2344d017931cSAndy Adamson 	encode_nops(&hdr);
23451da177e4SLinus Torvalds }
23461da177e4SLinus Torvalds 
23471da177e4SLinus Torvalds /*
23481da177e4SLinus Torvalds  * Encode an OPEN_CONFIRM request
23491da177e4SLinus Torvalds  */
23509f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
23519f06c719SChuck Lever 				      struct xdr_stream *xdr,
23529f06c719SChuck Lever 				      struct nfs_open_confirmargs *args)
23531da177e4SLinus Torvalds {
23541da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2355d017931cSAndy Adamson 		.nops   = 0,
23561da177e4SLinus Torvalds 	};
23571da177e4SLinus Torvalds 
23589f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23599f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23609f06c719SChuck Lever 	encode_open_confirm(xdr, args, &hdr);
2361d017931cSAndy Adamson 	encode_nops(&hdr);
23621da177e4SLinus Torvalds }
23631da177e4SLinus Torvalds 
23641da177e4SLinus Torvalds /*
23651da177e4SLinus Torvalds  * Encode an OPEN request with no attributes.
23661da177e4SLinus Torvalds  */
23679f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
23689f06c719SChuck Lever 				     struct xdr_stream *xdr,
23699f06c719SChuck Lever 				     struct nfs_openargs *args)
23701da177e4SLinus Torvalds {
23711da177e4SLinus Torvalds 	struct compound_hdr hdr = {
237266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23731da177e4SLinus Torvalds 	};
23741da177e4SLinus Torvalds 
23759f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23769f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23779f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23789f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
23799f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2380d017931cSAndy Adamson 	encode_nops(&hdr);
23811da177e4SLinus Torvalds }
23821da177e4SLinus Torvalds 
23831da177e4SLinus Torvalds /*
23841da177e4SLinus Torvalds  * Encode an OPEN_DOWNGRADE request
23851da177e4SLinus Torvalds  */
23869f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
23879f06c719SChuck Lever 					struct xdr_stream *xdr,
23889f06c719SChuck Lever 					struct nfs_closeargs *args)
23891da177e4SLinus Torvalds {
23901da177e4SLinus Torvalds 	struct compound_hdr hdr = {
239166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23921da177e4SLinus Torvalds 	};
23931da177e4SLinus Torvalds 
23949f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23959f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23969f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23979f06c719SChuck Lever 	encode_open_downgrade(xdr, args, &hdr);
23989f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2399d017931cSAndy Adamson 	encode_nops(&hdr);
24001da177e4SLinus Torvalds }
24011da177e4SLinus Torvalds 
24021da177e4SLinus Torvalds /*
24031da177e4SLinus Torvalds  * Encode a LOCK request
24041da177e4SLinus Torvalds  */
24059f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
24069f06c719SChuck Lever 			      struct nfs_lock_args *args)
24071da177e4SLinus Torvalds {
24081da177e4SLinus Torvalds 	struct compound_hdr hdr = {
240966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24101da177e4SLinus Torvalds 	};
24111da177e4SLinus Torvalds 
24129f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24139f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24149f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24159f06c719SChuck Lever 	encode_lock(xdr, args, &hdr);
2416d017931cSAndy Adamson 	encode_nops(&hdr);
24171da177e4SLinus Torvalds }
24181da177e4SLinus Torvalds 
24191da177e4SLinus Torvalds /*
24201da177e4SLinus Torvalds  * Encode a LOCKT request
24211da177e4SLinus Torvalds  */
24229f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
24239f06c719SChuck Lever 			       struct nfs_lockt_args *args)
24241da177e4SLinus Torvalds {
24251da177e4SLinus Torvalds 	struct compound_hdr hdr = {
242666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24271da177e4SLinus Torvalds 	};
24281da177e4SLinus Torvalds 
24299f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24309f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24319f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24329f06c719SChuck Lever 	encode_lockt(xdr, args, &hdr);
2433d017931cSAndy Adamson 	encode_nops(&hdr);
24341da177e4SLinus Torvalds }
24351da177e4SLinus Torvalds 
24361da177e4SLinus Torvalds /*
24371da177e4SLinus Torvalds  * Encode a LOCKU request
24381da177e4SLinus Torvalds  */
24399f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
24409f06c719SChuck Lever 			       struct nfs_locku_args *args)
24411da177e4SLinus Torvalds {
24421da177e4SLinus Torvalds 	struct compound_hdr hdr = {
244366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24441da177e4SLinus Torvalds 	};
24451da177e4SLinus Torvalds 
24469f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24479f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24489f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24499f06c719SChuck Lever 	encode_locku(xdr, args, &hdr);
2450d017931cSAndy Adamson 	encode_nops(&hdr);
24511da177e4SLinus Torvalds }
24521da177e4SLinus Torvalds 
24539f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
24549f06c719SChuck Lever 					   struct xdr_stream *xdr,
24559f06c719SChuck Lever 					struct nfs_release_lockowner_args *args)
2456d3c7b7ccSTrond Myklebust {
2457d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr = {
2458d3c7b7ccSTrond Myklebust 		.minorversion = 0,
2459d3c7b7ccSTrond Myklebust 	};
2460d3c7b7ccSTrond Myklebust 
24619f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24629f06c719SChuck Lever 	encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2463d3c7b7ccSTrond Myklebust 	encode_nops(&hdr);
2464d3c7b7ccSTrond Myklebust }
2465d3c7b7ccSTrond Myklebust 
24661da177e4SLinus Torvalds /*
24671da177e4SLinus Torvalds  * Encode a READLINK request
24681da177e4SLinus Torvalds  */
24699f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
24709f06c719SChuck Lever 				  const struct nfs4_readlink *args)
24711da177e4SLinus Torvalds {
24721da177e4SLinus Torvalds 	struct compound_hdr hdr = {
247366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24741da177e4SLinus Torvalds 	};
24751da177e4SLinus Torvalds 
24769f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24779f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24789f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24799f06c719SChuck Lever 	encode_readlink(xdr, args, req, &hdr);
2480e3a535e1STrond Myklebust 
248128f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2482e3a535e1STrond Myklebust 			args->pgbase, args->pglen);
2483d017931cSAndy Adamson 	encode_nops(&hdr);
24841da177e4SLinus Torvalds }
24851da177e4SLinus Torvalds 
24861da177e4SLinus Torvalds /*
24871da177e4SLinus Torvalds  * Encode a READDIR request
24881da177e4SLinus Torvalds  */
24899f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
24909f06c719SChuck Lever 				 const struct nfs4_readdir_arg *args)
24911da177e4SLinus Torvalds {
24921da177e4SLinus Torvalds 	struct compound_hdr hdr = {
249366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24941da177e4SLinus Torvalds 	};
24951da177e4SLinus Torvalds 
24969f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24979f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24989f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24999f06c719SChuck Lever 	encode_readdir(xdr, args, req, &hdr);
2500d6ac02dfSTrond Myklebust 
250128f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2502d6ac02dfSTrond Myklebust 			 args->pgbase, args->count);
2503d6ac02dfSTrond Myklebust 	dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
250428f56694SBenny Halevy 			__func__, hdr.replen << 2, args->pages,
2505d6ac02dfSTrond Myklebust 			args->pgbase, args->count);
2506d017931cSAndy Adamson 	encode_nops(&hdr);
25071da177e4SLinus Torvalds }
25081da177e4SLinus Torvalds 
25091da177e4SLinus Torvalds /*
25101da177e4SLinus Torvalds  * Encode a READ request
25111da177e4SLinus Torvalds  */
25129f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
25139f06c719SChuck Lever 			      struct nfs_readargs *args)
25141da177e4SLinus Torvalds {
25151da177e4SLinus Torvalds 	struct compound_hdr hdr = {
251666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25171da177e4SLinus Torvalds 	};
25181da177e4SLinus Torvalds 
25199f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25209f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25219f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25229f06c719SChuck Lever 	encode_read(xdr, args, &hdr);
25231da177e4SLinus Torvalds 
252428f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
25251da177e4SLinus Torvalds 			 args->pages, args->pgbase, args->count);
25264f22ccc3S\"Talpey, Thomas\ 	req->rq_rcv_buf.flags |= XDRBUF_READ;
2527d017931cSAndy Adamson 	encode_nops(&hdr);
25281da177e4SLinus Torvalds }
25291da177e4SLinus Torvalds 
25301da177e4SLinus Torvalds /*
25311da177e4SLinus Torvalds  * Encode an SETATTR request
25321da177e4SLinus Torvalds  */
25339f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
25349f06c719SChuck Lever 				 struct nfs_setattrargs *args)
25351da177e4SLinus Torvalds {
25361da177e4SLinus Torvalds 	struct compound_hdr hdr = {
253766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25381da177e4SLinus Torvalds 	};
25391da177e4SLinus Torvalds 
25409f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25419f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25429f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25439f06c719SChuck Lever 	encode_setattr(xdr, args, args->server, &hdr);
25449f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2545d017931cSAndy Adamson 	encode_nops(&hdr);
25461da177e4SLinus Torvalds }
25471da177e4SLinus Torvalds 
25481da177e4SLinus Torvalds /*
2549029d105eSJ. Bruce Fields  * Encode a GETACL request
2550029d105eSJ. Bruce Fields  */
25519f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2552029d105eSJ. Bruce Fields 				struct nfs_getaclargs *args)
2553029d105eSJ. Bruce Fields {
2554029d105eSJ. Bruce Fields 	struct compound_hdr hdr = {
255566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2556029d105eSJ. Bruce Fields 	};
255728f56694SBenny Halevy 	uint32_t replen;
2558029d105eSJ. Bruce Fields 
25599f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25609f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25619f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
2562bf118a34SAndy Adamson 	replen = hdr.replen + op_decode_hdr_maxsz + 1;
25639f06c719SChuck Lever 	encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2564cf8cdbe5SAndy Adamson 
256528f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2566029d105eSJ. Bruce Fields 		args->acl_pages, args->acl_pgbase, args->acl_len);
2567bf118a34SAndy Adamson 	xdr_set_scratch_buffer(xdr, page_address(args->acl_scratch), PAGE_SIZE);
2568bf118a34SAndy Adamson 
2569d017931cSAndy Adamson 	encode_nops(&hdr);
2570029d105eSJ. Bruce Fields }
2571029d105eSJ. Bruce Fields 
2572029d105eSJ. Bruce Fields /*
25731da177e4SLinus Torvalds  * Encode a WRITE request
25741da177e4SLinus Torvalds  */
25759f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
25769f06c719SChuck Lever 			       struct nfs_writeargs *args)
25771da177e4SLinus Torvalds {
25781da177e4SLinus Torvalds 	struct compound_hdr hdr = {
257966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25801da177e4SLinus Torvalds 	};
25811da177e4SLinus Torvalds 
25829f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25839f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25849f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25859f06c719SChuck Lever 	encode_write(xdr, args, &hdr);
25864f22ccc3S\"Talpey, Thomas\ 	req->rq_snd_buf.flags |= XDRBUF_WRITE;
25877ffd1064SFred Isaman 	if (args->bitmask)
25889f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2589d017931cSAndy Adamson 	encode_nops(&hdr);
25901da177e4SLinus Torvalds }
25911da177e4SLinus Torvalds 
25921da177e4SLinus Torvalds /*
25931da177e4SLinus Torvalds  *  a COMMIT request
25941da177e4SLinus Torvalds  */
25959f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
25969f06c719SChuck Lever 				struct nfs_writeargs *args)
25971da177e4SLinus Torvalds {
25981da177e4SLinus Torvalds 	struct compound_hdr hdr = {
259966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26001da177e4SLinus Torvalds 	};
26011da177e4SLinus Torvalds 
26029f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26039f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26049f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26059f06c719SChuck Lever 	encode_commit(xdr, args, &hdr);
2606988b6dceSFred Isaman 	if (args->bitmask)
26079f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2608d017931cSAndy Adamson 	encode_nops(&hdr);
26091da177e4SLinus Torvalds }
26101da177e4SLinus Torvalds 
26111da177e4SLinus Torvalds /*
26121da177e4SLinus Torvalds  * FSINFO request
26131da177e4SLinus Torvalds  */
26149f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
26159f06c719SChuck Lever 				struct nfs4_fsinfo_arg *args)
26161da177e4SLinus Torvalds {
26171da177e4SLinus Torvalds 	struct compound_hdr hdr = {
261866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26191da177e4SLinus Torvalds 	};
26201da177e4SLinus Torvalds 
26219f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26229f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26239f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26249f06c719SChuck Lever 	encode_fsinfo(xdr, args->bitmask, &hdr);
2625d017931cSAndy Adamson 	encode_nops(&hdr);
26261da177e4SLinus Torvalds }
26271da177e4SLinus Torvalds 
26281da177e4SLinus Torvalds /*
26291da177e4SLinus Torvalds  * a PATHCONF request
26301da177e4SLinus Torvalds  */
26319f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
26329f06c719SChuck Lever 				  const struct nfs4_pathconf_arg *args)
26331da177e4SLinus Torvalds {
26341da177e4SLinus Torvalds 	struct compound_hdr hdr = {
263566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26361da177e4SLinus Torvalds 	};
26371da177e4SLinus Torvalds 
26389f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26399f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26409f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26419f06c719SChuck Lever 	encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2642d017931cSAndy Adamson 			   &hdr);
2643d017931cSAndy Adamson 	encode_nops(&hdr);
26441da177e4SLinus Torvalds }
26451da177e4SLinus Torvalds 
26461da177e4SLinus Torvalds /*
26471da177e4SLinus Torvalds  * a STATFS request
26481da177e4SLinus Torvalds  */
26499f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
26509f06c719SChuck Lever 				const struct nfs4_statfs_arg *args)
26511da177e4SLinus Torvalds {
26521da177e4SLinus Torvalds 	struct compound_hdr hdr = {
265366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26541da177e4SLinus Torvalds 	};
26551da177e4SLinus Torvalds 
26569f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26579f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26589f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26599f06c719SChuck Lever 	encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2660d017931cSAndy Adamson 			   args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2661d017931cSAndy Adamson 	encode_nops(&hdr);
26621da177e4SLinus Torvalds }
26631da177e4SLinus Torvalds 
26641da177e4SLinus Torvalds /*
26651da177e4SLinus Torvalds  * GETATTR_BITMAP request
26661da177e4SLinus Torvalds  */
26679f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
26689f06c719SChuck Lever 				     struct xdr_stream *xdr,
266943652ad5SBenny Halevy 				     struct nfs4_server_caps_arg *args)
26701da177e4SLinus Torvalds {
26711da177e4SLinus Torvalds 	struct compound_hdr hdr = {
267266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26731da177e4SLinus Torvalds 	};
26741da177e4SLinus Torvalds 
26759f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26769f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26779f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
26789f06c719SChuck Lever 	encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
26791da177e4SLinus Torvalds 			   FATTR4_WORD0_LINK_SUPPORT|
26801da177e4SLinus Torvalds 			   FATTR4_WORD0_SYMLINK_SUPPORT|
2681d017931cSAndy Adamson 			   FATTR4_WORD0_ACLSUPPORT, &hdr);
2682d017931cSAndy Adamson 	encode_nops(&hdr);
26831da177e4SLinus Torvalds }
26841da177e4SLinus Torvalds 
26851da177e4SLinus Torvalds /*
26861da177e4SLinus Torvalds  * a RENEW request
26871da177e4SLinus Torvalds  */
26889f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
26899f06c719SChuck Lever 			       struct nfs_client *clp)
26901da177e4SLinus Torvalds {
26911da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2692d017931cSAndy Adamson 		.nops	= 0,
26931da177e4SLinus Torvalds 	};
26941da177e4SLinus Torvalds 
26959f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
2696bb4dae5eSChuck Lever 	encode_renew(xdr, clp->cl_clientid, &hdr);
2697d017931cSAndy Adamson 	encode_nops(&hdr);
26981da177e4SLinus Torvalds }
26991da177e4SLinus Torvalds 
27001da177e4SLinus Torvalds /*
27011da177e4SLinus Torvalds  * a SETCLIENTID request
27021da177e4SLinus Torvalds  */
27039f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
27049f06c719SChuck Lever 				     struct xdr_stream *xdr,
27059f06c719SChuck Lever 				     struct nfs4_setclientid *sc)
27061da177e4SLinus Torvalds {
27071da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2708d017931cSAndy Adamson 		.nops	= 0,
27091da177e4SLinus Torvalds 	};
27101da177e4SLinus Torvalds 
27119f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27129f06c719SChuck Lever 	encode_setclientid(xdr, sc, &hdr);
2713d017931cSAndy Adamson 	encode_nops(&hdr);
27141da177e4SLinus Torvalds }
27151da177e4SLinus Torvalds 
27161da177e4SLinus Torvalds /*
27171da177e4SLinus Torvalds  * a SETCLIENTID_CONFIRM request
27181da177e4SLinus Torvalds  */
27199f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
27209f06c719SChuck Lever 					     struct xdr_stream *xdr,
27219f06c719SChuck Lever 					     struct nfs4_setclientid_res *arg)
27221da177e4SLinus Torvalds {
27231da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2724d017931cSAndy Adamson 		.nops	= 0,
27251da177e4SLinus Torvalds 	};
2726dae100c2SFred Isaman 	const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
27271da177e4SLinus Torvalds 
27289f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27299f06c719SChuck Lever 	encode_setclientid_confirm(xdr, arg, &hdr);
27309f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
27319f06c719SChuck Lever 	encode_fsinfo(xdr, lease_bitmap, &hdr);
2732d017931cSAndy Adamson 	encode_nops(&hdr);
27331da177e4SLinus Torvalds }
27341da177e4SLinus Torvalds 
27351da177e4SLinus Torvalds /*
27361da177e4SLinus Torvalds  * DELEGRETURN request
27371da177e4SLinus Torvalds  */
27389f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
27399f06c719SChuck Lever 				     struct xdr_stream *xdr,
27409f06c719SChuck Lever 				     const struct nfs4_delegreturnargs *args)
27411da177e4SLinus Torvalds {
27421da177e4SLinus Torvalds 	struct compound_hdr hdr = {
274366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
27441da177e4SLinus Torvalds 	};
27451da177e4SLinus Torvalds 
27469f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27479f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
27489f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
27499f06c719SChuck Lever 	encode_delegreturn(xdr, args->stateid, &hdr);
27509f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2751d017931cSAndy Adamson 	encode_nops(&hdr);
27521da177e4SLinus Torvalds }
27531da177e4SLinus Torvalds 
27541da177e4SLinus Torvalds /*
2755683b57b4STrond Myklebust  * Encode FS_LOCATIONS request
2756683b57b4STrond Myklebust  */
27579f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
27589f06c719SChuck Lever 				      struct xdr_stream *xdr,
27599f06c719SChuck Lever 				      struct nfs4_fs_locations_arg *args)
2760683b57b4STrond Myklebust {
2761683b57b4STrond Myklebust 	struct compound_hdr hdr = {
276266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2763683b57b4STrond Myklebust 	};
276428f56694SBenny Halevy 	uint32_t replen;
2765683b57b4STrond Myklebust 
27669f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27679f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
27689f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
27699f06c719SChuck Lever 	encode_lookup(xdr, args->name, &hdr);
277028f56694SBenny Halevy 	replen = hdr.replen;	/* get the attribute into args->page */
27719f06c719SChuck Lever 	encode_fs_locations(xdr, args->bitmask, &hdr);
2772cf8cdbe5SAndy Adamson 
277328f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2774683b57b4STrond Myklebust 			0, PAGE_SIZE);
2775d017931cSAndy Adamson 	encode_nops(&hdr);
2776683b57b4STrond Myklebust }
2777683b57b4STrond Myklebust 
27785a5ea0d4SBryan Schumaker /*
27795a5ea0d4SBryan Schumaker  * Encode SECINFO request
27805a5ea0d4SBryan Schumaker  */
27815a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
27825a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
27835a5ea0d4SBryan Schumaker 				struct nfs4_secinfo_arg *args)
27845a5ea0d4SBryan Schumaker {
27855a5ea0d4SBryan Schumaker 	struct compound_hdr hdr = {
27865a5ea0d4SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
27875a5ea0d4SBryan Schumaker 	};
27885a5ea0d4SBryan Schumaker 
27895a5ea0d4SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
27905a5ea0d4SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
27915a5ea0d4SBryan Schumaker 	encode_putfh(xdr, args->dir_fh, &hdr);
27925a5ea0d4SBryan Schumaker 	encode_secinfo(xdr, args->name, &hdr);
27935a5ea0d4SBryan Schumaker 	encode_nops(&hdr);
27945a5ea0d4SBryan Schumaker }
27955a5ea0d4SBryan Schumaker 
279699fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
279799fe60d0SBenny Halevy /*
279899fe60d0SBenny Halevy  * EXCHANGE_ID request
279999fe60d0SBenny Halevy  */
28009f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
28019f06c719SChuck Lever 				     struct xdr_stream *xdr,
280299fe60d0SBenny Halevy 				     struct nfs41_exchange_id_args *args)
280399fe60d0SBenny Halevy {
280499fe60d0SBenny Halevy 	struct compound_hdr hdr = {
2805a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
280699fe60d0SBenny Halevy 	};
280799fe60d0SBenny Halevy 
28089f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28099f06c719SChuck Lever 	encode_exchange_id(xdr, args, &hdr);
281099fe60d0SBenny Halevy 	encode_nops(&hdr);
281199fe60d0SBenny Halevy }
28122050f0ccSAndy Adamson 
28132050f0ccSAndy Adamson /*
2814fc931582SAndy Adamson  * a CREATE_SESSION request
2815fc931582SAndy Adamson  */
28169f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
28179f06c719SChuck Lever 					struct xdr_stream *xdr,
2818fc931582SAndy Adamson 					struct nfs41_create_session_args *args)
2819fc931582SAndy Adamson {
2820fc931582SAndy Adamson 	struct compound_hdr hdr = {
2821a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
2822fc931582SAndy Adamson 	};
2823fc931582SAndy Adamson 
28249f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28259f06c719SChuck Lever 	encode_create_session(xdr, args, &hdr);
2826fc931582SAndy Adamson 	encode_nops(&hdr);
2827fc931582SAndy Adamson }
2828fc931582SAndy Adamson 
2829fc931582SAndy Adamson /*
28300f3e66c6SAndy Adamson  * a DESTROY_SESSION request
28310f3e66c6SAndy Adamson  */
28329f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
28339f06c719SChuck Lever 					 struct xdr_stream *xdr,
28340f3e66c6SAndy Adamson 					 struct nfs4_session *session)
28350f3e66c6SAndy Adamson {
28360f3e66c6SAndy Adamson 	struct compound_hdr hdr = {
2837a4432345STrond Myklebust 		.minorversion = session->clp->cl_mvops->minor_version,
28380f3e66c6SAndy Adamson 	};
28390f3e66c6SAndy Adamson 
28409f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28419f06c719SChuck Lever 	encode_destroy_session(xdr, session, &hdr);
28420f3e66c6SAndy Adamson 	encode_nops(&hdr);
28430f3e66c6SAndy Adamson }
28440f3e66c6SAndy Adamson 
28450f3e66c6SAndy Adamson /*
2846fc01cea9SAndy Adamson  * a SEQUENCE request
2847fc01cea9SAndy Adamson  */
28489f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2849fc01cea9SAndy Adamson 				  struct nfs4_sequence_args *args)
2850fc01cea9SAndy Adamson {
2851fc01cea9SAndy Adamson 	struct compound_hdr hdr = {
2852fc01cea9SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(args),
2853fc01cea9SAndy Adamson 	};
2854fc01cea9SAndy Adamson 
28559f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28569f06c719SChuck Lever 	encode_sequence(xdr, args, &hdr);
2857fc01cea9SAndy Adamson 	encode_nops(&hdr);
2858fc01cea9SAndy Adamson }
2859fc01cea9SAndy Adamson 
2860fc01cea9SAndy Adamson /*
28612050f0ccSAndy Adamson  * a GET_LEASE_TIME request
28622050f0ccSAndy Adamson  */
28639f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
28649f06c719SChuck Lever 					struct xdr_stream *xdr,
28652050f0ccSAndy Adamson 					struct nfs4_get_lease_time_args *args)
28662050f0ccSAndy Adamson {
28672050f0ccSAndy Adamson 	struct compound_hdr hdr = {
28682050f0ccSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
28692050f0ccSAndy Adamson 	};
2870dae100c2SFred Isaman 	const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
28712050f0ccSAndy Adamson 
28729f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28739f06c719SChuck Lever 	encode_sequence(xdr, &args->la_seq_args, &hdr);
28749f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
28759f06c719SChuck Lever 	encode_fsinfo(xdr, lease_bitmap, &hdr);
28762050f0ccSAndy Adamson 	encode_nops(&hdr);
28772050f0ccSAndy Adamson }
287818019753SRicardo Labiaga 
287918019753SRicardo Labiaga /*
288018019753SRicardo Labiaga  * a RECLAIM_COMPLETE request
288118019753SRicardo Labiaga  */
28829f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
28839f06c719SChuck Lever 					  struct xdr_stream *xdr,
288418019753SRicardo Labiaga 				struct nfs41_reclaim_complete_args *args)
288518019753SRicardo Labiaga {
288618019753SRicardo Labiaga 	struct compound_hdr hdr = {
288718019753SRicardo Labiaga 		.minorversion = nfs4_xdr_minorversion(&args->seq_args)
288818019753SRicardo Labiaga 	};
288918019753SRicardo Labiaga 
28909f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28919f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
28929f06c719SChuck Lever 	encode_reclaim_complete(xdr, args, &hdr);
289318019753SRicardo Labiaga 	encode_nops(&hdr);
289418019753SRicardo Labiaga }
289518019753SRicardo Labiaga 
2896b1f69b75SAndy Adamson /*
28977f11d8d3SAndy Adamson  * Encode GETDEVICELIST request
28987f11d8d3SAndy Adamson  */
28997f11d8d3SAndy Adamson static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
29007f11d8d3SAndy Adamson 				       struct xdr_stream *xdr,
29017f11d8d3SAndy Adamson 				       struct nfs4_getdevicelist_args *args)
29027f11d8d3SAndy Adamson {
29037f11d8d3SAndy Adamson 	struct compound_hdr hdr = {
29047f11d8d3SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
29057f11d8d3SAndy Adamson 	};
29067f11d8d3SAndy Adamson 
29077f11d8d3SAndy Adamson 	encode_compound_hdr(xdr, req, &hdr);
29087f11d8d3SAndy Adamson 	encode_sequence(xdr, &args->seq_args, &hdr);
29097f11d8d3SAndy Adamson 	encode_putfh(xdr, args->fh, &hdr);
29107f11d8d3SAndy Adamson 	encode_getdevicelist(xdr, args, &hdr);
29117f11d8d3SAndy Adamson 	encode_nops(&hdr);
29127f11d8d3SAndy Adamson }
29137f11d8d3SAndy Adamson 
29147f11d8d3SAndy Adamson /*
2915b1f69b75SAndy Adamson  * Encode GETDEVICEINFO request
2916b1f69b75SAndy Adamson  */
29179f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
29189f06c719SChuck Lever 				       struct xdr_stream *xdr,
2919b1f69b75SAndy Adamson 				       struct nfs4_getdeviceinfo_args *args)
2920b1f69b75SAndy Adamson {
2921b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
2922b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2923b1f69b75SAndy Adamson 	};
2924b1f69b75SAndy Adamson 
29259f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29269f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
29279f06c719SChuck Lever 	encode_getdeviceinfo(xdr, args, &hdr);
2928b1f69b75SAndy Adamson 
2929b1f69b75SAndy Adamson 	/* set up reply kvec. Subtract notification bitmap max size (2)
2930b1f69b75SAndy Adamson 	 * so that notification bitmap is put in xdr_buf tail */
2931b1f69b75SAndy Adamson 	xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2932b1f69b75SAndy Adamson 			 args->pdev->pages, args->pdev->pgbase,
2933b1f69b75SAndy Adamson 			 args->pdev->pglen);
2934b1f69b75SAndy Adamson 
2935b1f69b75SAndy Adamson 	encode_nops(&hdr);
2936b1f69b75SAndy Adamson }
2937b1f69b75SAndy Adamson 
2938b1f69b75SAndy Adamson /*
2939b1f69b75SAndy Adamson  *  Encode LAYOUTGET request
2940b1f69b75SAndy Adamson  */
29419f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
29429f06c719SChuck Lever 				   struct xdr_stream *xdr,
2943b1f69b75SAndy Adamson 				   struct nfs4_layoutget_args *args)
2944b1f69b75SAndy Adamson {
2945b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
2946b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2947b1f69b75SAndy Adamson 	};
2948b1f69b75SAndy Adamson 
29499f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29509f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
29519f06c719SChuck Lever 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
29529f06c719SChuck Lever 	encode_layoutget(xdr, args, &hdr);
295335124a09SWeston Andros Adamson 
295435124a09SWeston Andros Adamson 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
295535124a09SWeston Andros Adamson 	    args->layout.pages, 0, args->layout.pglen);
295635124a09SWeston Andros Adamson 
2957b1f69b75SAndy Adamson 	encode_nops(&hdr);
2958b1f69b75SAndy Adamson }
2959863a3c6cSAndy Adamson 
2960863a3c6cSAndy Adamson /*
2961863a3c6cSAndy Adamson  *  Encode LAYOUTCOMMIT request
2962863a3c6cSAndy Adamson  */
2963cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2964863a3c6cSAndy Adamson 				      struct xdr_stream *xdr,
2965863a3c6cSAndy Adamson 				      struct nfs4_layoutcommit_args *args)
2966863a3c6cSAndy Adamson {
2967ac7db726SBenny Halevy 	struct nfs4_layoutcommit_data *data =
2968ac7db726SBenny Halevy 		container_of(args, struct nfs4_layoutcommit_data, args);
2969863a3c6cSAndy Adamson 	struct compound_hdr hdr = {
2970863a3c6cSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2971863a3c6cSAndy Adamson 	};
2972863a3c6cSAndy Adamson 
2973863a3c6cSAndy Adamson 	encode_compound_hdr(xdr, req, &hdr);
2974863a3c6cSAndy Adamson 	encode_sequence(xdr, &args->seq_args, &hdr);
2975863a3c6cSAndy Adamson 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2976ac7db726SBenny Halevy 	encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2977863a3c6cSAndy Adamson 	encode_getfattr(xdr, args->bitmask, &hdr);
2978863a3c6cSAndy Adamson 	encode_nops(&hdr);
2979cbe82603SBenny Halevy }
2980cbe82603SBenny Halevy 
2981cbe82603SBenny Halevy /*
2982cbe82603SBenny Halevy  * Encode LAYOUTRETURN request
2983cbe82603SBenny Halevy  */
2984cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2985cbe82603SBenny Halevy 				      struct xdr_stream *xdr,
2986cbe82603SBenny Halevy 				      struct nfs4_layoutreturn_args *args)
2987cbe82603SBenny Halevy {
2988cbe82603SBenny Halevy 	struct compound_hdr hdr = {
2989cbe82603SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2990cbe82603SBenny Halevy 	};
2991cbe82603SBenny Halevy 
2992cbe82603SBenny Halevy 	encode_compound_hdr(xdr, req, &hdr);
2993cbe82603SBenny Halevy 	encode_sequence(xdr, &args->seq_args, &hdr);
2994cbe82603SBenny Halevy 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2995cbe82603SBenny Halevy 	encode_layoutreturn(xdr, args, &hdr);
2996cbe82603SBenny Halevy 	encode_nops(&hdr);
2997863a3c6cSAndy Adamson }
2998fca78d6dSBryan Schumaker 
2999fca78d6dSBryan Schumaker /*
3000fca78d6dSBryan Schumaker  * Encode SECINFO_NO_NAME request
3001fca78d6dSBryan Schumaker  */
3002fca78d6dSBryan Schumaker static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3003fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
3004fca78d6dSBryan Schumaker 					struct nfs41_secinfo_no_name_args *args)
3005fca78d6dSBryan Schumaker {
3006fca78d6dSBryan Schumaker 	struct compound_hdr hdr = {
3007fca78d6dSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3008fca78d6dSBryan Schumaker 	};
3009fca78d6dSBryan Schumaker 
3010fca78d6dSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
3011fca78d6dSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
3012fca78d6dSBryan Schumaker 	encode_putrootfh(xdr, &hdr);
3013fca78d6dSBryan Schumaker 	encode_secinfo_no_name(xdr, args, &hdr);
3014fca78d6dSBryan Schumaker 	encode_nops(&hdr);
3015fca78d6dSBryan Schumaker 	return 0;
3016fca78d6dSBryan Schumaker }
30177d974794SBryan Schumaker 
30187d974794SBryan Schumaker /*
30197d974794SBryan Schumaker  *  Encode TEST_STATEID request
30207d974794SBryan Schumaker  */
30217d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
30227d974794SBryan Schumaker 				      struct xdr_stream *xdr,
30237d974794SBryan Schumaker 				      struct nfs41_test_stateid_args *args)
30247d974794SBryan Schumaker {
30257d974794SBryan Schumaker 	struct compound_hdr hdr = {
30267d974794SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
30277d974794SBryan Schumaker 	};
30287d974794SBryan Schumaker 
30297d974794SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
30307d974794SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
30317d974794SBryan Schumaker 	encode_test_stateid(xdr, args, &hdr);
30327d974794SBryan Schumaker 	encode_nops(&hdr);
30337d974794SBryan Schumaker }
30349aeda35fSBryan Schumaker 
30359aeda35fSBryan Schumaker /*
30369aeda35fSBryan Schumaker  *  Encode FREE_STATEID request
30379aeda35fSBryan Schumaker  */
30389aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
30399aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
30409aeda35fSBryan Schumaker 				     struct nfs41_free_stateid_args *args)
30419aeda35fSBryan Schumaker {
30429aeda35fSBryan Schumaker 	struct compound_hdr hdr = {
30439aeda35fSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
30449aeda35fSBryan Schumaker 	};
30459aeda35fSBryan Schumaker 
30469aeda35fSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
30479aeda35fSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
30489aeda35fSBryan Schumaker 	encode_free_stateid(xdr, args, &hdr);
30499aeda35fSBryan Schumaker 	encode_nops(&hdr);
30509aeda35fSBryan Schumaker }
305199fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
305299fe60d0SBenny Halevy 
3053686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3054686841b3SBenny Halevy {
3055686841b3SBenny Halevy 	dprintk("nfs: %s: prematurely hit end of receive buffer. "
3056686841b3SBenny Halevy 		"Remaining buffer length is %tu words.\n",
3057686841b3SBenny Halevy 		func, xdr->end - xdr->p);
3058686841b3SBenny Halevy }
30591da177e4SLinus Torvalds 
3060683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
30611da177e4SLinus Torvalds {
30628687b63aSAl Viro 	__be32 *p;
30631da177e4SLinus Torvalds 
3064c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3065c0eae66eSBenny Halevy 	if (unlikely(!p))
3066c0eae66eSBenny Halevy 		goto out_overflow;
3067cccddf4fSBenny Halevy 	*len = be32_to_cpup(p);
3068c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, *len);
3069c0eae66eSBenny Halevy 	if (unlikely(!p))
3070c0eae66eSBenny Halevy 		goto out_overflow;
30711da177e4SLinus Torvalds 	*string = (char *)p;
30721da177e4SLinus Torvalds 	return 0;
3073c0eae66eSBenny Halevy out_overflow:
3074c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3075c0eae66eSBenny Halevy 	return -EIO;
30761da177e4SLinus Torvalds }
30771da177e4SLinus Torvalds 
30781da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
30791da177e4SLinus Torvalds {
30808687b63aSAl Viro 	__be32 *p;
30811da177e4SLinus Torvalds 
3082c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3083c0eae66eSBenny Halevy 	if (unlikely(!p))
3084c0eae66eSBenny Halevy 		goto out_overflow;
30856f723f77SBenny Halevy 	hdr->status = be32_to_cpup(p++);
3086cccddf4fSBenny Halevy 	hdr->taglen = be32_to_cpup(p);
30871da177e4SLinus Torvalds 
3088c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, hdr->taglen + 4);
3089c0eae66eSBenny Halevy 	if (unlikely(!p))
3090c0eae66eSBenny Halevy 		goto out_overflow;
30911da177e4SLinus Torvalds 	hdr->tag = (char *)p;
30921da177e4SLinus Torvalds 	p += XDR_QUADLEN(hdr->taglen);
3093cccddf4fSBenny Halevy 	hdr->nops = be32_to_cpup(p);
3094aadf6152SBenny Halevy 	if (unlikely(hdr->nops < 1))
3095aadf6152SBenny Halevy 		return nfs4_stat_to_errno(hdr->status);
30961da177e4SLinus Torvalds 	return 0;
3097c0eae66eSBenny Halevy out_overflow:
3098c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3099c0eae66eSBenny Halevy 	return -EIO;
31001da177e4SLinus Torvalds }
31011da177e4SLinus Torvalds 
31021da177e4SLinus Torvalds static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
31031da177e4SLinus Torvalds {
31048687b63aSAl Viro 	__be32 *p;
31051da177e4SLinus Torvalds 	uint32_t opnum;
31061da177e4SLinus Torvalds 	int32_t nfserr;
31071da177e4SLinus Torvalds 
3108c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3109c0eae66eSBenny Halevy 	if (unlikely(!p))
3110c0eae66eSBenny Halevy 		goto out_overflow;
31116f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
31121da177e4SLinus Torvalds 	if (opnum != expected) {
3113fe82a183SChuck Lever 		dprintk("nfs: Server returned operation"
31141da177e4SLinus Torvalds 			" %d but we issued a request for %d\n",
31151da177e4SLinus Torvalds 				opnum, expected);
31161da177e4SLinus Torvalds 		return -EIO;
31171da177e4SLinus Torvalds 	}
3118cccddf4fSBenny Halevy 	nfserr = be32_to_cpup(p);
31191da177e4SLinus Torvalds 	if (nfserr != NFS_OK)
3120856dff3dSBenny Halevy 		return nfs4_stat_to_errno(nfserr);
31211da177e4SLinus Torvalds 	return 0;
3122c0eae66eSBenny Halevy out_overflow:
3123c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3124c0eae66eSBenny Halevy 	return -EIO;
31251da177e4SLinus Torvalds }
31261da177e4SLinus Torvalds 
31271da177e4SLinus Torvalds /* Dummy routine */
3128adfa6f98SDavid Howells static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
31291da177e4SLinus Torvalds {
31308687b63aSAl Viro 	__be32 *p;
3131683b57b4STrond Myklebust 	unsigned int strlen;
31321da177e4SLinus Torvalds 	char *str;
31331da177e4SLinus Torvalds 
3134c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
3135c0eae66eSBenny Halevy 	if (likely(p))
31361da177e4SLinus Torvalds 		return decode_opaque_inline(xdr, &strlen, &str);
3137c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3138c0eae66eSBenny Halevy 	return -EIO;
31391da177e4SLinus Torvalds }
31401da177e4SLinus Torvalds 
31411da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
31421da177e4SLinus Torvalds {
31438687b63aSAl Viro 	uint32_t bmlen;
31448687b63aSAl Viro 	__be32 *p;
31451da177e4SLinus Torvalds 
3146c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3147c0eae66eSBenny Halevy 	if (unlikely(!p))
3148c0eae66eSBenny Halevy 		goto out_overflow;
3149cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
31501da177e4SLinus Torvalds 
3151dae100c2SFred Isaman 	bitmap[0] = bitmap[1] = bitmap[2] = 0;
3152c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, (bmlen << 2));
3153c0eae66eSBenny Halevy 	if (unlikely(!p))
3154c0eae66eSBenny Halevy 		goto out_overflow;
31551da177e4SLinus Torvalds 	if (bmlen > 0) {
31566f723f77SBenny Halevy 		bitmap[0] = be32_to_cpup(p++);
3157dae100c2SFred Isaman 		if (bmlen > 1) {
3158dae100c2SFred Isaman 			bitmap[1] = be32_to_cpup(p++);
3159dae100c2SFred Isaman 			if (bmlen > 2)
3160dae100c2SFred Isaman 				bitmap[2] = be32_to_cpup(p);
3161dae100c2SFred Isaman 		}
31621da177e4SLinus Torvalds 	}
31631da177e4SLinus Torvalds 	return 0;
3164c0eae66eSBenny Halevy out_overflow:
3165c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3166c0eae66eSBenny Halevy 	return -EIO;
31671da177e4SLinus Torvalds }
31681da177e4SLinus Torvalds 
31698687b63aSAl Viro static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
31701da177e4SLinus Torvalds {
31718687b63aSAl Viro 	__be32 *p;
31721da177e4SLinus Torvalds 
3173c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3174c0eae66eSBenny Halevy 	if (unlikely(!p))
3175c0eae66eSBenny Halevy 		goto out_overflow;
3176cccddf4fSBenny Halevy 	*attrlen = be32_to_cpup(p);
31771da177e4SLinus Torvalds 	*savep = xdr->p;
31781da177e4SLinus Torvalds 	return 0;
3179c0eae66eSBenny Halevy out_overflow:
3180c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3181c0eae66eSBenny Halevy 	return -EIO;
31821da177e4SLinus Torvalds }
31831da177e4SLinus Torvalds 
31841da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
31851da177e4SLinus Torvalds {
31861da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
31873388bff5SRoman Borisov 		int ret;
31883388bff5SRoman Borisov 		ret = decode_attr_bitmap(xdr, bitmask);
31893388bff5SRoman Borisov 		if (unlikely(ret < 0))
31903388bff5SRoman Borisov 			return ret;
31911da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
31921da177e4SLinus Torvalds 	} else
3193dae100c2SFred Isaman 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
3194dae100c2SFred Isaman 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3195dae100c2SFred Isaman 		bitmask[0], bitmask[1], bitmask[2]);
31961da177e4SLinus Torvalds 	return 0;
31971da177e4SLinus Torvalds }
31981da177e4SLinus Torvalds 
31991da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
32001da177e4SLinus Torvalds {
32018687b63aSAl Viro 	__be32 *p;
3202409924e4STrond Myklebust 	int ret = 0;
32031da177e4SLinus Torvalds 
32041da177e4SLinus Torvalds 	*type = 0;
32051da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
32061da177e4SLinus Torvalds 		return -EIO;
32071da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3208c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3209c0eae66eSBenny Halevy 		if (unlikely(!p))
3210c0eae66eSBenny Halevy 			goto out_overflow;
3211cccddf4fSBenny Halevy 		*type = be32_to_cpup(p);
32121da177e4SLinus Torvalds 		if (*type < NF4REG || *type > NF4NAMEDATTR) {
32133110ff80SHarvey Harrison 			dprintk("%s: bad type %d\n", __func__, *type);
32141da177e4SLinus Torvalds 			return -EIO;
32151da177e4SLinus Torvalds 		}
32161da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_TYPE;
3217409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_TYPE;
32181da177e4SLinus Torvalds 	}
3219bca79478STrond Myklebust 	dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3220409924e4STrond Myklebust 	return ret;
3221c0eae66eSBenny Halevy out_overflow:
3222c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3223c0eae66eSBenny Halevy 	return -EIO;
32241da177e4SLinus Torvalds }
32251da177e4SLinus Torvalds 
32261da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
32271da177e4SLinus Torvalds {
32288687b63aSAl Viro 	__be32 *p;
3229409924e4STrond Myklebust 	int ret = 0;
32301da177e4SLinus Torvalds 
32311da177e4SLinus Torvalds 	*change = 0;
32321da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
32331da177e4SLinus Torvalds 		return -EIO;
32341da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3235c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3236c0eae66eSBenny Halevy 		if (unlikely(!p))
3237c0eae66eSBenny Halevy 			goto out_overflow;
3238cccddf4fSBenny Halevy 		xdr_decode_hyper(p, change);
32391da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3240409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_CHANGE;
32411da177e4SLinus Torvalds 	}
32423110ff80SHarvey Harrison 	dprintk("%s: change attribute=%Lu\n", __func__,
32431da177e4SLinus Torvalds 			(unsigned long long)*change);
3244409924e4STrond Myklebust 	return ret;
3245c0eae66eSBenny Halevy out_overflow:
3246c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3247c0eae66eSBenny Halevy 	return -EIO;
32481da177e4SLinus Torvalds }
32491da177e4SLinus Torvalds 
32501da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
32511da177e4SLinus Torvalds {
32528687b63aSAl Viro 	__be32 *p;
3253409924e4STrond Myklebust 	int ret = 0;
32541da177e4SLinus Torvalds 
32551da177e4SLinus Torvalds 	*size = 0;
32561da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
32571da177e4SLinus Torvalds 		return -EIO;
32581da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3259c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3260c0eae66eSBenny Halevy 		if (unlikely(!p))
3261c0eae66eSBenny Halevy 			goto out_overflow;
3262cccddf4fSBenny Halevy 		xdr_decode_hyper(p, size);
32631da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SIZE;
3264409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SIZE;
32651da177e4SLinus Torvalds 	}
32663110ff80SHarvey Harrison 	dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3267409924e4STrond Myklebust 	return ret;
3268c0eae66eSBenny Halevy out_overflow:
3269c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3270c0eae66eSBenny Halevy 	return -EIO;
32711da177e4SLinus Torvalds }
32721da177e4SLinus Torvalds 
32731da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
32741da177e4SLinus Torvalds {
32758687b63aSAl Viro 	__be32 *p;
32761da177e4SLinus Torvalds 
32771da177e4SLinus Torvalds 	*res = 0;
32781da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
32791da177e4SLinus Torvalds 		return -EIO;
32801da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3281c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3282c0eae66eSBenny Halevy 		if (unlikely(!p))
3283c0eae66eSBenny Halevy 			goto out_overflow;
3284cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
32851da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
32861da177e4SLinus Torvalds 	}
32873110ff80SHarvey Harrison 	dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
32881da177e4SLinus Torvalds 	return 0;
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_symlink_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_SYMLINK_SUPPORT - 1U)))
33001da177e4SLinus Torvalds 		return -EIO;
33011da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_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_SYMLINK_SUPPORT;
33071da177e4SLinus Torvalds 	}
33083110ff80SHarvey Harrison 	dprintk("%s: symlink 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 
33158b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
33161da177e4SLinus Torvalds {
33178687b63aSAl Viro 	__be32 *p;
3318409924e4STrond Myklebust 	int ret = 0;
33191da177e4SLinus Torvalds 
33201da177e4SLinus Torvalds 	fsid->major = 0;
33211da177e4SLinus Torvalds 	fsid->minor = 0;
33221da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
33231da177e4SLinus Torvalds 		return -EIO;
33241da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3325c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 16);
3326c0eae66eSBenny Halevy 		if (unlikely(!p))
3327c0eae66eSBenny Halevy 			goto out_overflow;
33283ceb4dbbSBenny Halevy 		p = xdr_decode_hyper(p, &fsid->major);
3329cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &fsid->minor);
33301da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FSID;
3331409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FSID;
33321da177e4SLinus Torvalds 	}
33333110ff80SHarvey Harrison 	dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
33341da177e4SLinus Torvalds 			(unsigned long long)fsid->major,
33351da177e4SLinus Torvalds 			(unsigned long long)fsid->minor);
3336409924e4STrond Myklebust 	return ret;
3337c0eae66eSBenny Halevy out_overflow:
3338c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3339c0eae66eSBenny Halevy 	return -EIO;
33401da177e4SLinus Torvalds }
33411da177e4SLinus Torvalds 
33421da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33431da177e4SLinus Torvalds {
33448687b63aSAl Viro 	__be32 *p;
33451da177e4SLinus Torvalds 
33461da177e4SLinus Torvalds 	*res = 60;
33471da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
33481da177e4SLinus Torvalds 		return -EIO;
33491da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3350c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3351c0eae66eSBenny Halevy 		if (unlikely(!p))
3352c0eae66eSBenny Halevy 			goto out_overflow;
3353cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33541da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
33551da177e4SLinus Torvalds 	}
33563110ff80SHarvey Harrison 	dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
33571da177e4SLinus Torvalds 	return 0;
3358c0eae66eSBenny Halevy out_overflow:
3359c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3360c0eae66eSBenny Halevy 	return -EIO;
33611da177e4SLinus Torvalds }
33621da177e4SLinus Torvalds 
3363ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3364ae42c70aSBryan Schumaker {
3365ae42c70aSBryan Schumaker 	__be32 *p;
3366ae42c70aSBryan Schumaker 
3367ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3368ae42c70aSBryan Schumaker 		return -EIO;
3369ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3370ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3371ae42c70aSBryan Schumaker 		if (unlikely(!p))
3372ae42c70aSBryan Schumaker 			goto out_overflow;
3373ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3374ee7b75fcSTrond Myklebust 		*res = -be32_to_cpup(p);
3375ae42c70aSBryan Schumaker 	}
3376ae42c70aSBryan Schumaker 	return 0;
3377ae42c70aSBryan Schumaker out_overflow:
3378ae42c70aSBryan Schumaker 	print_overflow_msg(__func__, xdr);
3379ae42c70aSBryan Schumaker 	return -EIO;
3380ae42c70aSBryan Schumaker }
3381ae42c70aSBryan Schumaker 
3382ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3383ae42c70aSBryan Schumaker {
3384ae42c70aSBryan Schumaker 	__be32 *p;
3385ae42c70aSBryan Schumaker 	int len;
3386ae42c70aSBryan Schumaker 
33877ad07353STrond Myklebust 	if (fh != NULL)
3388ae42c70aSBryan Schumaker 		memset(fh, 0, sizeof(*fh));
3389ae42c70aSBryan Schumaker 
3390ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3391ae42c70aSBryan Schumaker 		return -EIO;
3392ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3393ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3394ae42c70aSBryan Schumaker 		if (unlikely(!p))
3395ae42c70aSBryan Schumaker 			goto out_overflow;
3396ae42c70aSBryan Schumaker 		len = be32_to_cpup(p);
3397ae42c70aSBryan Schumaker 		if (len > NFS4_FHSIZE)
3398ae42c70aSBryan Schumaker 			return -EIO;
3399ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, len);
3400ae42c70aSBryan Schumaker 		if (unlikely(!p))
3401ae42c70aSBryan Schumaker 			goto out_overflow;
34027ad07353STrond Myklebust 		if (fh != NULL) {
3403ae42c70aSBryan Schumaker 			memcpy(fh->data, p, len);
34047ad07353STrond Myklebust 			fh->size = len;
34057ad07353STrond Myklebust 		}
3406ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3407ae42c70aSBryan Schumaker 	}
3408ae42c70aSBryan Schumaker 	return 0;
3409ae42c70aSBryan Schumaker out_overflow:
3410ae42c70aSBryan Schumaker 	print_overflow_msg(__func__, xdr);
3411ae42c70aSBryan Schumaker 	return -EIO;
3412ae42c70aSBryan Schumaker }
3413ae42c70aSBryan Schumaker 
34141da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
34151da177e4SLinus Torvalds {
34168687b63aSAl Viro 	__be32 *p;
34171da177e4SLinus Torvalds 
34181da177e4SLinus Torvalds 	*res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
34191da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
34201da177e4SLinus Torvalds 		return -EIO;
34211da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3422c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3423c0eae66eSBenny Halevy 		if (unlikely(!p))
3424c0eae66eSBenny Halevy 			goto out_overflow;
3425cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
34261da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
34271da177e4SLinus Torvalds 	}
34283110ff80SHarvey Harrison 	dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
34291da177e4SLinus Torvalds 	return 0;
3430c0eae66eSBenny Halevy out_overflow:
3431c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3432c0eae66eSBenny Halevy 	return -EIO;
34331da177e4SLinus Torvalds }
34341da177e4SLinus Torvalds 
34351da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
34361da177e4SLinus Torvalds {
34378687b63aSAl Viro 	__be32 *p;
3438409924e4STrond Myklebust 	int ret = 0;
34391da177e4SLinus Torvalds 
34401da177e4SLinus Torvalds 	*fileid = 0;
34411da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
34421da177e4SLinus Torvalds 		return -EIO;
34431da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3444c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3445c0eae66eSBenny Halevy 		if (unlikely(!p))
3446c0eae66eSBenny Halevy 			goto out_overflow;
3447cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
34481da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILEID;
3449409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FILEID;
34501da177e4SLinus Torvalds 	}
34513110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3452409924e4STrond Myklebust 	return ret;
3453c0eae66eSBenny Halevy out_overflow:
3454c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3455c0eae66eSBenny Halevy 	return -EIO;
34561da177e4SLinus Torvalds }
34571da177e4SLinus Torvalds 
345899baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
345999baf625SManoj Naik {
34608687b63aSAl Viro 	__be32 *p;
3461409924e4STrond Myklebust 	int ret = 0;
346299baf625SManoj Naik 
346399baf625SManoj Naik 	*fileid = 0;
346499baf625SManoj Naik 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
346599baf625SManoj Naik 		return -EIO;
346699baf625SManoj Naik 	if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3467c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3468c0eae66eSBenny Halevy 		if (unlikely(!p))
3469c0eae66eSBenny Halevy 			goto out_overflow;
3470cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
347199baf625SManoj Naik 		bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
347228331a46STrond Myklebust 		ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
347399baf625SManoj Naik 	}
34743110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3475409924e4STrond Myklebust 	return ret;
3476c0eae66eSBenny Halevy out_overflow:
3477c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3478c0eae66eSBenny Halevy 	return -EIO;
347999baf625SManoj Naik }
348099baf625SManoj Naik 
34811da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
34821da177e4SLinus Torvalds {
34838687b63aSAl Viro 	__be32 *p;
34841da177e4SLinus Torvalds 	int status = 0;
34851da177e4SLinus Torvalds 
34861da177e4SLinus Torvalds 	*res = 0;
34871da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
34881da177e4SLinus Torvalds 		return -EIO;
34891da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3490c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3491c0eae66eSBenny Halevy 		if (unlikely(!p))
3492c0eae66eSBenny Halevy 			goto out_overflow;
3493cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
34941da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
34951da177e4SLinus Torvalds 	}
34963110ff80SHarvey Harrison 	dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
34971da177e4SLinus Torvalds 	return status;
3498c0eae66eSBenny Halevy out_overflow:
3499c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3500c0eae66eSBenny Halevy 	return -EIO;
35011da177e4SLinus Torvalds }
35021da177e4SLinus Torvalds 
35031da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35041da177e4SLinus Torvalds {
35058687b63aSAl Viro 	__be32 *p;
35061da177e4SLinus Torvalds 	int status = 0;
35071da177e4SLinus Torvalds 
35081da177e4SLinus Torvalds 	*res = 0;
35091da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
35101da177e4SLinus Torvalds 		return -EIO;
35111da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3512c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3513c0eae66eSBenny Halevy 		if (unlikely(!p))
3514c0eae66eSBenny Halevy 			goto out_overflow;
3515cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35161da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
35171da177e4SLinus Torvalds 	}
35183110ff80SHarvey Harrison 	dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
35191da177e4SLinus Torvalds 	return status;
3520c0eae66eSBenny Halevy out_overflow:
3521c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3522c0eae66eSBenny Halevy 	return -EIO;
35231da177e4SLinus Torvalds }
35241da177e4SLinus Torvalds 
35251da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35261da177e4SLinus Torvalds {
35278687b63aSAl Viro 	__be32 *p;
35281da177e4SLinus Torvalds 	int status = 0;
35291da177e4SLinus Torvalds 
35301da177e4SLinus Torvalds 	*res = 0;
35311da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
35321da177e4SLinus Torvalds 		return -EIO;
35331da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3534c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3535c0eae66eSBenny Halevy 		if (unlikely(!p))
3536c0eae66eSBenny Halevy 			goto out_overflow;
3537cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35381da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
35391da177e4SLinus Torvalds 	}
35403110ff80SHarvey Harrison 	dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
35411da177e4SLinus Torvalds 	return status;
3542c0eae66eSBenny Halevy out_overflow:
3543c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3544c0eae66eSBenny Halevy 	return -EIO;
35451da177e4SLinus Torvalds }
35461da177e4SLinus Torvalds 
35477aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
35487aaa0b3bSManoj Naik {
3549464ad6b1SChuck Lever 	u32 n;
35508687b63aSAl Viro 	__be32 *p;
35517aaa0b3bSManoj Naik 	int status = 0;
35527aaa0b3bSManoj Naik 
3553c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3554c0eae66eSBenny Halevy 	if (unlikely(!p))
3555c0eae66eSBenny Halevy 		goto out_overflow;
3556cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
355733a43f28SAndy Adamson 	if (n == 0)
355833a43f28SAndy Adamson 		goto root_path;
355902a2976cSChuck Lever 	dprintk("pathname4: ");
35607aaa0b3bSManoj Naik 	path->ncomponents = 0;
35617aaa0b3bSManoj Naik 	while (path->ncomponents < n) {
35627aaa0b3bSManoj Naik 		struct nfs4_string *component = &path->components[path->ncomponents];
35637aaa0b3bSManoj Naik 		status = decode_opaque_inline(xdr, &component->len, &component->data);
35647aaa0b3bSManoj Naik 		if (unlikely(status != 0))
35657aaa0b3bSManoj Naik 			goto out_eio;
356602a2976cSChuck Lever 		if (unlikely(nfs_debug & NFSDBG_XDR))
356702a2976cSChuck Lever 			pr_cont("%s%.*s ",
356802a2976cSChuck Lever 				(path->ncomponents != n ? "/ " : ""),
356902a2976cSChuck Lever 				component->len, component->data);
35707aaa0b3bSManoj Naik 		if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
35717aaa0b3bSManoj Naik 			path->ncomponents++;
35727aaa0b3bSManoj Naik 		else {
35737aaa0b3bSManoj Naik 			dprintk("cannot parse %d components in path\n", n);
35747aaa0b3bSManoj Naik 			goto out_eio;
35757aaa0b3bSManoj Naik 		}
35767aaa0b3bSManoj Naik 	}
35777aaa0b3bSManoj Naik out:
35787aaa0b3bSManoj Naik 	return status;
357933a43f28SAndy Adamson root_path:
358033a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */
358133a43f28SAndy Adamson 	path->ncomponents = 1;
358233a43f28SAndy Adamson 	path->components[0].len=0;
358333a43f28SAndy Adamson 	path->components[0].data=NULL;
358402a2976cSChuck Lever 	dprintk("pathname4: /\n");
358533a43f28SAndy Adamson 	goto out;
35867aaa0b3bSManoj Naik out_eio:
35877aaa0b3bSManoj Naik 	dprintk(" status %d", status);
35887aaa0b3bSManoj Naik 	status = -EIO;
35897aaa0b3bSManoj Naik 	goto out;
3590c0eae66eSBenny Halevy out_overflow:
3591c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3592c0eae66eSBenny Halevy 	return -EIO;
35937aaa0b3bSManoj Naik }
35947aaa0b3bSManoj Naik 
35957aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3596683b57b4STrond Myklebust {
3597683b57b4STrond Myklebust 	int n;
35988687b63aSAl Viro 	__be32 *p;
3599683b57b4STrond Myklebust 	int status = -EIO;
3600683b57b4STrond Myklebust 
3601683b57b4STrond Myklebust 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3602683b57b4STrond Myklebust 		goto out;
3603683b57b4STrond Myklebust 	status = 0;
3604683b57b4STrond Myklebust 	if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3605683b57b4STrond Myklebust 		goto out;
36068b7e3f49STrond Myklebust 	status = -EIO;
36078b7e3f49STrond Myklebust 	/* Ignore borken servers that return unrequested attrs */
36088b7e3f49STrond Myklebust 	if (unlikely(res == NULL))
36098b7e3f49STrond Myklebust 		goto out;
361002a2976cSChuck Lever 	dprintk("%s: fsroot:\n", __func__);
36117aaa0b3bSManoj Naik 	status = decode_pathname(xdr, &res->fs_path);
3612683b57b4STrond Myklebust 	if (unlikely(status != 0))
3613683b57b4STrond Myklebust 		goto out;
3614c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3615c0eae66eSBenny Halevy 	if (unlikely(!p))
3616c0eae66eSBenny Halevy 		goto out_overflow;
3617cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
3618683b57b4STrond Myklebust 	if (n <= 0)
3619683b57b4STrond Myklebust 		goto out_eio;
3620683b57b4STrond Myklebust 	res->nlocations = 0;
3621683b57b4STrond Myklebust 	while (res->nlocations < n) {
3622464ad6b1SChuck Lever 		u32 m;
36237aaa0b3bSManoj Naik 		struct nfs4_fs_location *loc = &res->locations[res->nlocations];
3624683b57b4STrond Myklebust 
3625c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3626c0eae66eSBenny Halevy 		if (unlikely(!p))
3627c0eae66eSBenny Halevy 			goto out_overflow;
3628cccddf4fSBenny Halevy 		m = be32_to_cpup(p);
36297aaa0b3bSManoj Naik 
36307aaa0b3bSManoj Naik 		loc->nservers = 0;
363102a2976cSChuck Lever 		dprintk("%s: servers:\n", __func__);
36327aaa0b3bSManoj Naik 		while (loc->nservers < m) {
36337aaa0b3bSManoj Naik 			struct nfs4_string *server = &loc->servers[loc->nservers];
36347aaa0b3bSManoj Naik 			status = decode_opaque_inline(xdr, &server->len, &server->data);
3635683b57b4STrond Myklebust 			if (unlikely(status != 0))
3636683b57b4STrond Myklebust 				goto out_eio;
36377aaa0b3bSManoj Naik 			dprintk("%s ", server->data);
36387aaa0b3bSManoj Naik 			if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
36397aaa0b3bSManoj Naik 				loc->nservers++;
36407aaa0b3bSManoj Naik 			else {
3641464ad6b1SChuck Lever 				unsigned int i;
3642464ad6b1SChuck Lever 				dprintk("%s: using first %u of %u servers "
3643464ad6b1SChuck Lever 					"returned for location %u\n",
36443110ff80SHarvey Harrison 						__func__,
3645464ad6b1SChuck Lever 						NFS4_FS_LOCATION_MAXSERVERS,
3646464ad6b1SChuck Lever 						m, res->nlocations);
36477aaa0b3bSManoj Naik 				for (i = loc->nservers; i < m; i++) {
36482e42c3e2STrond Myklebust 					unsigned int len;
36497aaa0b3bSManoj Naik 					char *data;
36507aaa0b3bSManoj Naik 					status = decode_opaque_inline(xdr, &len, &data);
3651683b57b4STrond Myklebust 					if (unlikely(status != 0))
3652683b57b4STrond Myklebust 						goto out_eio;
36537aaa0b3bSManoj Naik 				}
36547aaa0b3bSManoj Naik 			}
36557aaa0b3bSManoj Naik 		}
36567aaa0b3bSManoj Naik 		status = decode_pathname(xdr, &loc->rootpath);
36577aaa0b3bSManoj Naik 		if (unlikely(status != 0))
36587aaa0b3bSManoj Naik 			goto out_eio;
36597aaa0b3bSManoj Naik 		if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
3660683b57b4STrond Myklebust 			res->nlocations++;
3661683b57b4STrond Myklebust 	}
3662409924e4STrond Myklebust 	if (res->nlocations != 0)
3663409924e4STrond Myklebust 		status = NFS_ATTR_FATTR_V4_REFERRAL;
3664683b57b4STrond Myklebust out:
36653110ff80SHarvey Harrison 	dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3666683b57b4STrond Myklebust 	return status;
3667c0eae66eSBenny Halevy out_overflow:
3668c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3669683b57b4STrond Myklebust out_eio:
3670683b57b4STrond Myklebust 	status = -EIO;
3671683b57b4STrond Myklebust 	goto out;
3672683b57b4STrond Myklebust }
3673683b57b4STrond Myklebust 
36741da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
36751da177e4SLinus Torvalds {
36768687b63aSAl Viro 	__be32 *p;
36771da177e4SLinus Torvalds 	int status = 0;
36781da177e4SLinus Torvalds 
36791da177e4SLinus Torvalds 	*res = 0;
36801da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
36811da177e4SLinus Torvalds 		return -EIO;
36821da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3683c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3684c0eae66eSBenny Halevy 		if (unlikely(!p))
3685c0eae66eSBenny Halevy 			goto out_overflow;
3686cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
36871da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
36881da177e4SLinus Torvalds 	}
36893110ff80SHarvey Harrison 	dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
36901da177e4SLinus Torvalds 	return status;
3691c0eae66eSBenny Halevy out_overflow:
3692c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3693c0eae66eSBenny Halevy 	return -EIO;
36941da177e4SLinus Torvalds }
36951da177e4SLinus Torvalds 
36961da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
36971da177e4SLinus Torvalds {
36988687b63aSAl Viro 	__be32 *p;
36991da177e4SLinus Torvalds 	int status = 0;
37001da177e4SLinus Torvalds 
37011da177e4SLinus Torvalds 	*maxlink = 1;
37021da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
37031da177e4SLinus Torvalds 		return -EIO;
37041da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3705c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3706c0eae66eSBenny Halevy 		if (unlikely(!p))
3707c0eae66eSBenny Halevy 			goto out_overflow;
3708cccddf4fSBenny Halevy 		*maxlink = be32_to_cpup(p);
37091da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
37101da177e4SLinus Torvalds 	}
37113110ff80SHarvey Harrison 	dprintk("%s: maxlink=%u\n", __func__, *maxlink);
37121da177e4SLinus Torvalds 	return status;
3713c0eae66eSBenny Halevy out_overflow:
3714c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3715c0eae66eSBenny Halevy 	return -EIO;
37161da177e4SLinus Torvalds }
37171da177e4SLinus Torvalds 
37181da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
37191da177e4SLinus Torvalds {
37208687b63aSAl Viro 	__be32 *p;
37211da177e4SLinus Torvalds 	int status = 0;
37221da177e4SLinus Torvalds 
37231da177e4SLinus Torvalds 	*maxname = 1024;
37241da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
37251da177e4SLinus Torvalds 		return -EIO;
37261da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3727c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3728c0eae66eSBenny Halevy 		if (unlikely(!p))
3729c0eae66eSBenny Halevy 			goto out_overflow;
3730cccddf4fSBenny Halevy 		*maxname = be32_to_cpup(p);
37311da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
37321da177e4SLinus Torvalds 	}
37333110ff80SHarvey Harrison 	dprintk("%s: maxname=%u\n", __func__, *maxname);
37341da177e4SLinus Torvalds 	return status;
3735c0eae66eSBenny Halevy out_overflow:
3736c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3737c0eae66eSBenny Halevy 	return -EIO;
37381da177e4SLinus Torvalds }
37391da177e4SLinus Torvalds 
37401da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
37411da177e4SLinus Torvalds {
37428687b63aSAl Viro 	__be32 *p;
37431da177e4SLinus Torvalds 	int status = 0;
37441da177e4SLinus Torvalds 
37451da177e4SLinus Torvalds 	*res = 1024;
37461da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
37471da177e4SLinus Torvalds 		return -EIO;
37481da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
37491da177e4SLinus Torvalds 		uint64_t maxread;
3750c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3751c0eae66eSBenny Halevy 		if (unlikely(!p))
3752c0eae66eSBenny Halevy 			goto out_overflow;
3753cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxread);
37541da177e4SLinus Torvalds 		if (maxread > 0x7FFFFFFF)
37551da177e4SLinus Torvalds 			maxread = 0x7FFFFFFF;
37561da177e4SLinus Torvalds 		*res = (uint32_t)maxread;
37571da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
37581da177e4SLinus Torvalds 	}
37593110ff80SHarvey Harrison 	dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
37601da177e4SLinus Torvalds 	return status;
3761c0eae66eSBenny Halevy out_overflow:
3762c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3763c0eae66eSBenny Halevy 	return -EIO;
37641da177e4SLinus Torvalds }
37651da177e4SLinus Torvalds 
37661da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
37671da177e4SLinus Torvalds {
37688687b63aSAl Viro 	__be32 *p;
37691da177e4SLinus Torvalds 	int status = 0;
37701da177e4SLinus Torvalds 
37711da177e4SLinus Torvalds 	*res = 1024;
37721da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
37731da177e4SLinus Torvalds 		return -EIO;
37741da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
37751da177e4SLinus Torvalds 		uint64_t maxwrite;
3776c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3777c0eae66eSBenny Halevy 		if (unlikely(!p))
3778c0eae66eSBenny Halevy 			goto out_overflow;
3779cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxwrite);
37801da177e4SLinus Torvalds 		if (maxwrite > 0x7FFFFFFF)
37811da177e4SLinus Torvalds 			maxwrite = 0x7FFFFFFF;
37821da177e4SLinus Torvalds 		*res = (uint32_t)maxwrite;
37831da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
37841da177e4SLinus Torvalds 	}
37853110ff80SHarvey Harrison 	dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
37861da177e4SLinus Torvalds 	return status;
3787c0eae66eSBenny Halevy out_overflow:
3788c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3789c0eae66eSBenny Halevy 	return -EIO;
37901da177e4SLinus Torvalds }
37911da177e4SLinus Torvalds 
3792bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
37931da177e4SLinus Torvalds {
3794bca79478STrond Myklebust 	uint32_t tmp;
37958687b63aSAl Viro 	__be32 *p;
3796409924e4STrond Myklebust 	int ret = 0;
37971da177e4SLinus Torvalds 
37981da177e4SLinus Torvalds 	*mode = 0;
37991da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
38001da177e4SLinus Torvalds 		return -EIO;
38011da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3802c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3803c0eae66eSBenny Halevy 		if (unlikely(!p))
3804c0eae66eSBenny Halevy 			goto out_overflow;
3805cccddf4fSBenny Halevy 		tmp = be32_to_cpup(p);
3806bca79478STrond Myklebust 		*mode = tmp & ~S_IFMT;
38071da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_MODE;
3808409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_MODE;
38091da177e4SLinus Torvalds 	}
38103110ff80SHarvey Harrison 	dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3811409924e4STrond Myklebust 	return ret;
3812c0eae66eSBenny Halevy out_overflow:
3813c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3814c0eae66eSBenny Halevy 	return -EIO;
38151da177e4SLinus Torvalds }
38161da177e4SLinus Torvalds 
38171da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
38181da177e4SLinus Torvalds {
38198687b63aSAl Viro 	__be32 *p;
3820409924e4STrond Myklebust 	int ret = 0;
38211da177e4SLinus Torvalds 
38221da177e4SLinus Torvalds 	*nlink = 1;
38231da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
38241da177e4SLinus Torvalds 		return -EIO;
38251da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3826c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3827c0eae66eSBenny Halevy 		if (unlikely(!p))
3828c0eae66eSBenny Halevy 			goto out_overflow;
3829cccddf4fSBenny Halevy 		*nlink = be32_to_cpup(p);
38301da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3831409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_NLINK;
38321da177e4SLinus Torvalds 	}
38333110ff80SHarvey Harrison 	dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3834409924e4STrond Myklebust 	return ret;
3835c0eae66eSBenny Halevy out_overflow:
3836c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3837c0eae66eSBenny Halevy 	return -EIO;
38381da177e4SLinus Torvalds }
38391da177e4SLinus Torvalds 
384080e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
38416926afd1STrond Myklebust 		const struct nfs_server *server, uint32_t *uid,
38426926afd1STrond Myklebust 		struct nfs4_string *owner_name)
38431da177e4SLinus Torvalds {
38448687b63aSAl Viro 	uint32_t len;
38458687b63aSAl Viro 	__be32 *p;
3846409924e4STrond Myklebust 	int ret = 0;
38471da177e4SLinus Torvalds 
38481da177e4SLinus Torvalds 	*uid = -2;
38491da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
38501da177e4SLinus Torvalds 		return -EIO;
38511da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3852c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3853c0eae66eSBenny Halevy 		if (unlikely(!p))
3854c0eae66eSBenny Halevy 			goto out_overflow;
3855cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
3856c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
3857c0eae66eSBenny Halevy 		if (unlikely(!p))
3858c0eae66eSBenny Halevy 			goto out_overflow;
38596926afd1STrond Myklebust 		if (owner_name != NULL) {
38606926afd1STrond Myklebust 			owner_name->data = kmemdup(p, len, GFP_NOWAIT);
38616926afd1STrond Myklebust 			if (owner_name->data != NULL) {
38626926afd1STrond Myklebust 				owner_name->len = len;
38636926afd1STrond Myklebust 				ret = NFS_ATTR_FATTR_OWNER_NAME;
38646926afd1STrond Myklebust 			}
386580e52aceSTrond Myklebust 		} else if (len < XDR_MAX_NETOBJ) {
3866e4fd72a1STrond Myklebust 			if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3867409924e4STrond Myklebust 				ret = NFS_ATTR_FATTR_OWNER;
3868409924e4STrond Myklebust 			else
38691da177e4SLinus Torvalds 				dprintk("%s: nfs_map_name_to_uid failed!\n",
38703110ff80SHarvey Harrison 						__func__);
38711da177e4SLinus Torvalds 		} else
3872fe82a183SChuck Lever 			dprintk("%s: name too long (%u)!\n",
38733110ff80SHarvey Harrison 					__func__, len);
38741da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_OWNER;
38751da177e4SLinus Torvalds 	}
38763110ff80SHarvey Harrison 	dprintk("%s: uid=%d\n", __func__, (int)*uid);
3877409924e4STrond Myklebust 	return ret;
3878c0eae66eSBenny Halevy out_overflow:
3879c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3880c0eae66eSBenny Halevy 	return -EIO;
38811da177e4SLinus Torvalds }
38821da177e4SLinus Torvalds 
388380e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
38846926afd1STrond Myklebust 		const struct nfs_server *server, uint32_t *gid,
38856926afd1STrond Myklebust 		struct nfs4_string *group_name)
38861da177e4SLinus Torvalds {
38878687b63aSAl Viro 	uint32_t len;
38888687b63aSAl Viro 	__be32 *p;
3889409924e4STrond Myklebust 	int ret = 0;
38901da177e4SLinus Torvalds 
38911da177e4SLinus Torvalds 	*gid = -2;
38921da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
38931da177e4SLinus Torvalds 		return -EIO;
38941da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3895c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3896c0eae66eSBenny Halevy 		if (unlikely(!p))
3897c0eae66eSBenny Halevy 			goto out_overflow;
3898cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
3899c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
3900c0eae66eSBenny Halevy 		if (unlikely(!p))
3901c0eae66eSBenny Halevy 			goto out_overflow;
39026926afd1STrond Myklebust 		if (group_name != NULL) {
39036926afd1STrond Myklebust 			group_name->data = kmemdup(p, len, GFP_NOWAIT);
39046926afd1STrond Myklebust 			if (group_name->data != NULL) {
39056926afd1STrond Myklebust 				group_name->len = len;
39066926afd1STrond Myklebust 				ret = NFS_ATTR_FATTR_GROUP_NAME;
39076926afd1STrond Myklebust 			}
390880e52aceSTrond Myklebust 		} else if (len < XDR_MAX_NETOBJ) {
3909e4fd72a1STrond Myklebust 			if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3910409924e4STrond Myklebust 				ret = NFS_ATTR_FATTR_GROUP;
3911409924e4STrond Myklebust 			else
39121da177e4SLinus Torvalds 				dprintk("%s: nfs_map_group_to_gid failed!\n",
39133110ff80SHarvey Harrison 						__func__);
39141da177e4SLinus Torvalds 		} else
3915fe82a183SChuck Lever 			dprintk("%s: name too long (%u)!\n",
39163110ff80SHarvey Harrison 					__func__, len);
39171da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
39181da177e4SLinus Torvalds 	}
39193110ff80SHarvey Harrison 	dprintk("%s: gid=%d\n", __func__, (int)*gid);
3920409924e4STrond Myklebust 	return ret;
3921c0eae66eSBenny Halevy out_overflow:
3922c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3923c0eae66eSBenny Halevy 	return -EIO;
39241da177e4SLinus Torvalds }
39251da177e4SLinus Torvalds 
39261da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
39271da177e4SLinus Torvalds {
39288687b63aSAl Viro 	uint32_t major = 0, minor = 0;
39298687b63aSAl Viro 	__be32 *p;
3930409924e4STrond Myklebust 	int ret = 0;
39311da177e4SLinus Torvalds 
39321da177e4SLinus Torvalds 	*rdev = MKDEV(0,0);
39331da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
39341da177e4SLinus Torvalds 		return -EIO;
39351da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
39361da177e4SLinus Torvalds 		dev_t tmp;
39371da177e4SLinus Torvalds 
3938c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3939c0eae66eSBenny Halevy 		if (unlikely(!p))
3940c0eae66eSBenny Halevy 			goto out_overflow;
39416f723f77SBenny Halevy 		major = be32_to_cpup(p++);
3942cccddf4fSBenny Halevy 		minor = be32_to_cpup(p);
39431da177e4SLinus Torvalds 		tmp = MKDEV(major, minor);
39441da177e4SLinus Torvalds 		if (MAJOR(tmp) == major && MINOR(tmp) == minor)
39451da177e4SLinus Torvalds 			*rdev = tmp;
39461da177e4SLinus Torvalds 		bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3947409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_RDEV;
39481da177e4SLinus Torvalds 	}
39493110ff80SHarvey Harrison 	dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3950409924e4STrond Myklebust 	return ret;
3951c0eae66eSBenny Halevy out_overflow:
3952c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3953c0eae66eSBenny Halevy 	return -EIO;
39541da177e4SLinus Torvalds }
39551da177e4SLinus Torvalds 
39561da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
39571da177e4SLinus Torvalds {
39588687b63aSAl Viro 	__be32 *p;
39591da177e4SLinus Torvalds 	int status = 0;
39601da177e4SLinus Torvalds 
39611da177e4SLinus Torvalds 	*res = 0;
39621da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
39631da177e4SLinus Torvalds 		return -EIO;
39641da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3965c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3966c0eae66eSBenny Halevy 		if (unlikely(!p))
3967c0eae66eSBenny Halevy 			goto out_overflow;
3968cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
39691da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
39701da177e4SLinus Torvalds 	}
39713110ff80SHarvey Harrison 	dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
39721da177e4SLinus Torvalds 	return status;
3973c0eae66eSBenny Halevy out_overflow:
3974c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3975c0eae66eSBenny Halevy 	return -EIO;
39761da177e4SLinus Torvalds }
39771da177e4SLinus Torvalds 
39781da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
39791da177e4SLinus Torvalds {
39808687b63aSAl Viro 	__be32 *p;
39811da177e4SLinus Torvalds 	int status = 0;
39821da177e4SLinus Torvalds 
39831da177e4SLinus Torvalds 	*res = 0;
39841da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
39851da177e4SLinus Torvalds 		return -EIO;
39861da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3987c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3988c0eae66eSBenny Halevy 		if (unlikely(!p))
3989c0eae66eSBenny Halevy 			goto out_overflow;
3990cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
39911da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
39921da177e4SLinus Torvalds 	}
39933110ff80SHarvey Harrison 	dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
39941da177e4SLinus Torvalds 	return status;
3995c0eae66eSBenny Halevy out_overflow:
3996c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3997c0eae66eSBenny Halevy 	return -EIO;
39981da177e4SLinus Torvalds }
39991da177e4SLinus Torvalds 
40001da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40011da177e4SLinus Torvalds {
40028687b63aSAl Viro 	__be32 *p;
40031da177e4SLinus Torvalds 	int status = 0;
40041da177e4SLinus Torvalds 
40051da177e4SLinus Torvalds 	*res = 0;
40061da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
40071da177e4SLinus Torvalds 		return -EIO;
40081da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4009c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4010c0eae66eSBenny Halevy 		if (unlikely(!p))
4011c0eae66eSBenny Halevy 			goto out_overflow;
4012cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40131da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
40141da177e4SLinus Torvalds 	}
40153110ff80SHarvey Harrison 	dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
40161da177e4SLinus Torvalds 	return status;
4017c0eae66eSBenny Halevy out_overflow:
4018c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4019c0eae66eSBenny Halevy 	return -EIO;
40201da177e4SLinus Torvalds }
40211da177e4SLinus Torvalds 
40221da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
40231da177e4SLinus Torvalds {
40248687b63aSAl Viro 	__be32 *p;
4025409924e4STrond Myklebust 	int ret = 0;
40261da177e4SLinus Torvalds 
40271da177e4SLinus Torvalds 	*used = 0;
40281da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
40291da177e4SLinus Torvalds 		return -EIO;
40301da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4031c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4032c0eae66eSBenny Halevy 		if (unlikely(!p))
4033c0eae66eSBenny Halevy 			goto out_overflow;
4034cccddf4fSBenny Halevy 		xdr_decode_hyper(p, used);
40351da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4036409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SPACE_USED;
40371da177e4SLinus Torvalds 	}
40383110ff80SHarvey Harrison 	dprintk("%s: space used=%Lu\n", __func__,
40391da177e4SLinus Torvalds 			(unsigned long long)*used);
4040409924e4STrond Myklebust 	return ret;
4041c0eae66eSBenny Halevy out_overflow:
4042c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4043c0eae66eSBenny Halevy 	return -EIO;
40441da177e4SLinus Torvalds }
40451da177e4SLinus Torvalds 
40461da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
40471da177e4SLinus Torvalds {
40488687b63aSAl Viro 	__be32 *p;
40491da177e4SLinus Torvalds 	uint64_t sec;
40501da177e4SLinus Torvalds 	uint32_t nsec;
40511da177e4SLinus Torvalds 
4052c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
4053c0eae66eSBenny Halevy 	if (unlikely(!p))
4054c0eae66eSBenny Halevy 		goto out_overflow;
40553ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &sec);
4056cccddf4fSBenny Halevy 	nsec = be32_to_cpup(p);
40571da177e4SLinus Torvalds 	time->tv_sec = (time_t)sec;
40581da177e4SLinus Torvalds 	time->tv_nsec = (long)nsec;
40591da177e4SLinus Torvalds 	return 0;
4060c0eae66eSBenny Halevy out_overflow:
4061c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4062c0eae66eSBenny Halevy 	return -EIO;
40631da177e4SLinus Torvalds }
40641da177e4SLinus Torvalds 
40651da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
40661da177e4SLinus Torvalds {
40671da177e4SLinus Torvalds 	int status = 0;
40681da177e4SLinus Torvalds 
40691da177e4SLinus Torvalds 	time->tv_sec = 0;
40701da177e4SLinus Torvalds 	time->tv_nsec = 0;
40711da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
40721da177e4SLinus Torvalds 		return -EIO;
40731da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
40741da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4075409924e4STrond Myklebust 		if (status == 0)
4076409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_ATIME;
40771da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
40781da177e4SLinus Torvalds 	}
40793110ff80SHarvey Harrison 	dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
40801da177e4SLinus Torvalds 	return status;
40811da177e4SLinus Torvalds }
40821da177e4SLinus Torvalds 
40831da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
40841da177e4SLinus Torvalds {
40851da177e4SLinus Torvalds 	int status = 0;
40861da177e4SLinus Torvalds 
40871da177e4SLinus Torvalds 	time->tv_sec = 0;
40881da177e4SLinus Torvalds 	time->tv_nsec = 0;
40891da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
40901da177e4SLinus Torvalds 		return -EIO;
40911da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
40921da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4093409924e4STrond Myklebust 		if (status == 0)
4094409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_CTIME;
40951da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
40961da177e4SLinus Torvalds 	}
40973110ff80SHarvey Harrison 	dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
40981da177e4SLinus Torvalds 	return status;
40991da177e4SLinus Torvalds }
41001da177e4SLinus Torvalds 
410155b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
410255b6e774SRicardo Labiaga 				  struct timespec *time)
410355b6e774SRicardo Labiaga {
410455b6e774SRicardo Labiaga 	int status = 0;
410555b6e774SRicardo Labiaga 
410655b6e774SRicardo Labiaga 	time->tv_sec = 0;
410755b6e774SRicardo Labiaga 	time->tv_nsec = 0;
410855b6e774SRicardo Labiaga 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
410955b6e774SRicardo Labiaga 		return -EIO;
411055b6e774SRicardo Labiaga 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
411155b6e774SRicardo Labiaga 		status = decode_attr_time(xdr, time);
411255b6e774SRicardo Labiaga 		bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
411355b6e774SRicardo Labiaga 	}
411455b6e774SRicardo Labiaga 	dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
411555b6e774SRicardo Labiaga 		(long)time->tv_nsec);
411655b6e774SRicardo Labiaga 	return status;
411755b6e774SRicardo Labiaga }
411855b6e774SRicardo Labiaga 
41191da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
41201da177e4SLinus Torvalds {
41211da177e4SLinus Torvalds 	int status = 0;
41221da177e4SLinus Torvalds 
41231da177e4SLinus Torvalds 	time->tv_sec = 0;
41241da177e4SLinus Torvalds 	time->tv_nsec = 0;
41251da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
41261da177e4SLinus Torvalds 		return -EIO;
41271da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
41281da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4129409924e4STrond Myklebust 		if (status == 0)
4130409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_MTIME;
41311da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
41321da177e4SLinus Torvalds 	}
41333110ff80SHarvey Harrison 	dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
41341da177e4SLinus Torvalds 	return status;
41351da177e4SLinus Torvalds }
41361da177e4SLinus Torvalds 
41378687b63aSAl Viro static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
41381da177e4SLinus Torvalds {
41391da177e4SLinus Torvalds 	unsigned int attrwords = XDR_QUADLEN(attrlen);
41401da177e4SLinus Torvalds 	unsigned int nwords = xdr->p - savep;
41411da177e4SLinus Torvalds 
41421da177e4SLinus Torvalds 	if (unlikely(attrwords != nwords)) {
4143fe82a183SChuck Lever 		dprintk("%s: server returned incorrect attribute length: "
4144fe82a183SChuck Lever 			"%u %c %u\n",
41453110ff80SHarvey Harrison 				__func__,
41461da177e4SLinus Torvalds 				attrwords << 2,
41471da177e4SLinus Torvalds 				(attrwords < nwords) ? '<' : '>',
41481da177e4SLinus Torvalds 				nwords << 2);
41491da177e4SLinus Torvalds 		return -EIO;
41501da177e4SLinus Torvalds 	}
41511da177e4SLinus Torvalds 	return 0;
41521da177e4SLinus Torvalds }
41531da177e4SLinus Torvalds 
41541da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
41551da177e4SLinus Torvalds {
41568687b63aSAl Viro 	__be32 *p;
41571da177e4SLinus Torvalds 
4158c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
4159c0eae66eSBenny Halevy 	if (unlikely(!p))
4160c0eae66eSBenny Halevy 		goto out_overflow;
41616f723f77SBenny Halevy 	cinfo->atomic = be32_to_cpup(p++);
41623ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &cinfo->before);
4163cccddf4fSBenny Halevy 	xdr_decode_hyper(p, &cinfo->after);
41641da177e4SLinus Torvalds 	return 0;
4165c0eae66eSBenny Halevy out_overflow:
4166c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4167c0eae66eSBenny Halevy 	return -EIO;
41681da177e4SLinus Torvalds }
41691da177e4SLinus Torvalds 
41701da177e4SLinus Torvalds static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
41711da177e4SLinus Torvalds {
41728687b63aSAl Viro 	__be32 *p;
41731da177e4SLinus Torvalds 	uint32_t supp, acc;
41741da177e4SLinus Torvalds 	int status;
41751da177e4SLinus Torvalds 
41761da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_ACCESS);
41771da177e4SLinus Torvalds 	if (status)
41781da177e4SLinus Torvalds 		return status;
4179c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
4180c0eae66eSBenny Halevy 	if (unlikely(!p))
4181c0eae66eSBenny Halevy 		goto out_overflow;
41826f723f77SBenny Halevy 	supp = be32_to_cpup(p++);
4183cccddf4fSBenny Halevy 	acc = be32_to_cpup(p);
41841da177e4SLinus Torvalds 	access->supported = supp;
41851da177e4SLinus Torvalds 	access->access = acc;
41861da177e4SLinus Torvalds 	return 0;
4187c0eae66eSBenny Halevy out_overflow:
4188c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4189c0eae66eSBenny Halevy 	return -EIO;
41901da177e4SLinus Torvalds }
41911da177e4SLinus Torvalds 
419207d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
41931da177e4SLinus Torvalds {
41948687b63aSAl Viro 	__be32 *p;
419507d30434SBenny Halevy 
419607d30434SBenny Halevy 	p = xdr_inline_decode(xdr, len);
419707d30434SBenny Halevy 	if (likely(p)) {
419807d30434SBenny Halevy 		memcpy(buf, p, len);
419907d30434SBenny Halevy 		return 0;
420007d30434SBenny Halevy 	}
420107d30434SBenny Halevy 	print_overflow_msg(__func__, xdr);
420207d30434SBenny Halevy 	return -EIO;
420307d30434SBenny Halevy }
420407d30434SBenny Halevy 
420507d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
420607d30434SBenny Halevy {
420707d30434SBenny Halevy 	return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
42081da177e4SLinus Torvalds }
42091da177e4SLinus Torvalds 
42101da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
42111da177e4SLinus Torvalds {
42121da177e4SLinus Torvalds 	int status;
42131da177e4SLinus Torvalds 
42141da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CLOSE);
4215c1d51931STrond Myklebust 	if (status != -EIO)
4216c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
421707d30434SBenny Halevy 	if (!status)
421807d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
42191da177e4SLinus Torvalds 	return status;
42201da177e4SLinus Torvalds }
42211da177e4SLinus Torvalds 
4222db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4223db942bbdSBenny Halevy {
4224db942bbdSBenny Halevy 	return decode_opaque_fixed(xdr, verifier, 8);
42251da177e4SLinus Torvalds }
42261da177e4SLinus Torvalds 
42271da177e4SLinus Torvalds static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
42281da177e4SLinus Torvalds {
42291da177e4SLinus Torvalds 	int status;
42301da177e4SLinus Torvalds 
42311da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_COMMIT);
4232db942bbdSBenny Halevy 	if (!status)
4233db942bbdSBenny Halevy 		status = decode_verifier(xdr, res->verf->verifier);
42341da177e4SLinus Torvalds 	return status;
42351da177e4SLinus Torvalds }
42361da177e4SLinus Torvalds 
42371da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
42381da177e4SLinus Torvalds {
42398687b63aSAl Viro 	__be32 *p;
42401da177e4SLinus Torvalds 	uint32_t bmlen;
42411da177e4SLinus Torvalds 	int status;
42421da177e4SLinus Torvalds 
42431da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CREATE);
42441da177e4SLinus Torvalds 	if (status)
42451da177e4SLinus Torvalds 		return status;
42461da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, cinfo)))
42471da177e4SLinus Torvalds 		return status;
4248c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4249c0eae66eSBenny Halevy 	if (unlikely(!p))
4250c0eae66eSBenny Halevy 		goto out_overflow;
4251cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
4252c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
4253c0eae66eSBenny Halevy 	if (likely(p))
42541da177e4SLinus Torvalds 		return 0;
4255c0eae66eSBenny Halevy out_overflow:
4256c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4257c0eae66eSBenny Halevy 	return -EIO;
42581da177e4SLinus Torvalds }
42591da177e4SLinus Torvalds 
42601da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
42611da177e4SLinus Torvalds {
42628687b63aSAl Viro 	__be32 *savep;
4263dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
42641da177e4SLinus Torvalds 	int status;
42651da177e4SLinus Torvalds 
42661da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
42671da177e4SLinus Torvalds 		goto xdr_error;
42681da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
42691da177e4SLinus Torvalds 		goto xdr_error;
42701da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
42711da177e4SLinus Torvalds 		goto xdr_error;
42721da177e4SLinus Torvalds 	if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
42731da177e4SLinus Torvalds 		goto xdr_error;
42741da177e4SLinus Torvalds 	if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
42751da177e4SLinus Torvalds 		goto xdr_error;
42761da177e4SLinus Torvalds 	if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
42771da177e4SLinus Torvalds 		goto xdr_error;
42781da177e4SLinus Torvalds 	if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
42791da177e4SLinus Torvalds 		goto xdr_error;
42801da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
42811da177e4SLinus Torvalds xdr_error:
42823110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
42831da177e4SLinus Torvalds 	return status;
42841da177e4SLinus Torvalds }
42851da177e4SLinus Torvalds 
42861da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
42871da177e4SLinus Torvalds {
42888687b63aSAl Viro 	__be32 *savep;
4289dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
42901da177e4SLinus Torvalds 	int status;
42911da177e4SLinus Torvalds 
42921da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
42931da177e4SLinus Torvalds 		goto xdr_error;
42941da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
42951da177e4SLinus Torvalds 		goto xdr_error;
42961da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
42971da177e4SLinus Torvalds 		goto xdr_error;
42981da177e4SLinus Torvalds 
42991da177e4SLinus Torvalds 	if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
43001da177e4SLinus Torvalds 		goto xdr_error;
43011da177e4SLinus Torvalds 	if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
43021da177e4SLinus Torvalds 		goto xdr_error;
43031da177e4SLinus Torvalds 	if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
43041da177e4SLinus Torvalds 		goto xdr_error;
43051da177e4SLinus Torvalds 	if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
43061da177e4SLinus Torvalds 		goto xdr_error;
43071da177e4SLinus Torvalds 	if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
43081da177e4SLinus Torvalds 		goto xdr_error;
43091da177e4SLinus Torvalds 	if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
43101da177e4SLinus Torvalds 		goto xdr_error;
43111da177e4SLinus Torvalds 
43121da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
43131da177e4SLinus Torvalds xdr_error:
43143110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
43151da177e4SLinus Torvalds 	return status;
43161da177e4SLinus Torvalds }
43171da177e4SLinus Torvalds 
43181da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
43191da177e4SLinus Torvalds {
43208687b63aSAl Viro 	__be32 *savep;
4321dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
43221da177e4SLinus Torvalds 	int status;
43231da177e4SLinus Torvalds 
43241da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
43251da177e4SLinus Torvalds 		goto xdr_error;
43261da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
43271da177e4SLinus Torvalds 		goto xdr_error;
43281da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
43291da177e4SLinus Torvalds 		goto xdr_error;
43301da177e4SLinus Torvalds 
43311da177e4SLinus Torvalds 	if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
43321da177e4SLinus Torvalds 		goto xdr_error;
43331da177e4SLinus Torvalds 	if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 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 
4342ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4343ae42c70aSBryan Schumaker 		struct nfs_fattr *fattr, struct nfs_fh *fh,
43448b7e3f49STrond Myklebust 		struct nfs4_fs_locations *fs_loc,
43456926afd1STrond Myklebust 		const struct nfs_server *server)
43461da177e4SLinus Torvalds {
4347bca79478STrond Myklebust 	int status;
4348bca79478STrond Myklebust 	umode_t fmode = 0;
4349ae42c70aSBryan Schumaker 	uint32_t type;
4350ee7b75fcSTrond Myklebust 	int32_t err;
43511da177e4SLinus Torvalds 
4352f26c7a78STrond Myklebust 	status = decode_attr_type(xdr, bitmap, &type);
4353f26c7a78STrond Myklebust 	if (status < 0)
43541da177e4SLinus Torvalds 		goto xdr_error;
4355409924e4STrond Myklebust 	fattr->mode = 0;
4356409924e4STrond Myklebust 	if (status != 0) {
4357409924e4STrond Myklebust 		fattr->mode |= nfs_type2fmt[type];
4358409924e4STrond Myklebust 		fattr->valid |= status;
4359409924e4STrond Myklebust 	}
43601da177e4SLinus Torvalds 
4361f26c7a78STrond Myklebust 	status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4362f26c7a78STrond Myklebust 	if (status < 0)
43631da177e4SLinus Torvalds 		goto xdr_error;
4364409924e4STrond Myklebust 	fattr->valid |= status;
4365f26c7a78STrond Myklebust 
4366f26c7a78STrond Myklebust 	status = decode_attr_size(xdr, bitmap, &fattr->size);
4367f26c7a78STrond Myklebust 	if (status < 0)
43681da177e4SLinus Torvalds 		goto xdr_error;
4369409924e4STrond Myklebust 	fattr->valid |= status;
4370f26c7a78STrond Myklebust 
4371f26c7a78STrond Myklebust 	status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4372f26c7a78STrond Myklebust 	if (status < 0)
43731da177e4SLinus Torvalds 		goto xdr_error;
4374409924e4STrond Myklebust 	fattr->valid |= status;
4375f26c7a78STrond Myklebust 
4376ee7b75fcSTrond Myklebust 	err = 0;
4377ee7b75fcSTrond Myklebust 	status = decode_attr_error(xdr, bitmap, &err);
4378ae42c70aSBryan Schumaker 	if (status < 0)
4379ae42c70aSBryan Schumaker 		goto xdr_error;
4380ee7b75fcSTrond Myklebust 	if (err == -NFS4ERR_WRONGSEC)
4381ee7b75fcSTrond Myklebust 		nfs_fixup_secinfo_attributes(fattr, fh);
4382ae42c70aSBryan Schumaker 
4383ae42c70aSBryan Schumaker 	status = decode_attr_filehandle(xdr, bitmap, fh);
4384ae42c70aSBryan Schumaker 	if (status < 0)
4385ae42c70aSBryan Schumaker 		goto xdr_error;
4386ae42c70aSBryan Schumaker 
4387f26c7a78STrond Myklebust 	status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4388f26c7a78STrond Myklebust 	if (status < 0)
43891da177e4SLinus Torvalds 		goto xdr_error;
4390409924e4STrond Myklebust 	fattr->valid |= status;
4391f26c7a78STrond Myklebust 
43928b7e3f49STrond Myklebust 	status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4393f26c7a78STrond Myklebust 	if (status < 0)
4394683b57b4STrond Myklebust 		goto xdr_error;
4395409924e4STrond Myklebust 	fattr->valid |= status;
4396f26c7a78STrond Myklebust 
4397f26c7a78STrond Myklebust 	status = decode_attr_mode(xdr, bitmap, &fmode);
4398f26c7a78STrond Myklebust 	if (status < 0)
43991da177e4SLinus Torvalds 		goto xdr_error;
4400409924e4STrond Myklebust 	if (status != 0) {
44011da177e4SLinus Torvalds 		fattr->mode |= fmode;
4402409924e4STrond Myklebust 		fattr->valid |= status;
4403409924e4STrond Myklebust 	}
4404f26c7a78STrond Myklebust 
4405f26c7a78STrond Myklebust 	status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4406f26c7a78STrond Myklebust 	if (status < 0)
44071da177e4SLinus Torvalds 		goto xdr_error;
4408409924e4STrond Myklebust 	fattr->valid |= status;
4409f26c7a78STrond Myklebust 
44106926afd1STrond Myklebust 	status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4411f26c7a78STrond Myklebust 	if (status < 0)
44121da177e4SLinus Torvalds 		goto xdr_error;
4413409924e4STrond Myklebust 	fattr->valid |= status;
4414f26c7a78STrond Myklebust 
44156926afd1STrond Myklebust 	status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4416f26c7a78STrond Myklebust 	if (status < 0)
44171da177e4SLinus Torvalds 		goto xdr_error;
4418409924e4STrond Myklebust 	fattr->valid |= status;
4419f26c7a78STrond Myklebust 
4420f26c7a78STrond Myklebust 	status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4421f26c7a78STrond Myklebust 	if (status < 0)
44221da177e4SLinus Torvalds 		goto xdr_error;
4423409924e4STrond Myklebust 	fattr->valid |= status;
4424f26c7a78STrond Myklebust 
4425f26c7a78STrond Myklebust 	status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4426f26c7a78STrond Myklebust 	if (status < 0)
44271da177e4SLinus Torvalds 		goto xdr_error;
4428409924e4STrond Myklebust 	fattr->valid |= status;
4429f26c7a78STrond Myklebust 
4430f26c7a78STrond Myklebust 	status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4431f26c7a78STrond Myklebust 	if (status < 0)
44321da177e4SLinus Torvalds 		goto xdr_error;
4433409924e4STrond Myklebust 	fattr->valid |= status;
4434f26c7a78STrond Myklebust 
4435f26c7a78STrond Myklebust 	status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4436f26c7a78STrond Myklebust 	if (status < 0)
44371da177e4SLinus Torvalds 		goto xdr_error;
4438409924e4STrond Myklebust 	fattr->valid |= status;
4439f26c7a78STrond Myklebust 
4440f26c7a78STrond Myklebust 	status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4441f26c7a78STrond Myklebust 	if (status < 0)
44421da177e4SLinus Torvalds 		goto xdr_error;
4443409924e4STrond Myklebust 	fattr->valid |= status;
4444f26c7a78STrond Myklebust 
444528331a46STrond Myklebust 	status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4446f26c7a78STrond Myklebust 	if (status < 0)
444799baf625SManoj Naik 		goto xdr_error;
4448409924e4STrond Myklebust 	fattr->valid |= status;
4449f26c7a78STrond Myklebust 
4450ae42c70aSBryan Schumaker xdr_error:
4451ae42c70aSBryan Schumaker 	dprintk("%s: xdr returned %d\n", __func__, -status);
4452ae42c70aSBryan Schumaker 	return status;
4453ae42c70aSBryan Schumaker }
4454ae42c70aSBryan Schumaker 
4455ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
44568b7e3f49STrond Myklebust 		struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
44578b7e3f49STrond Myklebust 		const struct nfs_server *server)
4458ae42c70aSBryan Schumaker {
4459ae42c70aSBryan Schumaker 	__be32 *savep;
4460ae42c70aSBryan Schumaker 	uint32_t attrlen,
4461dae100c2SFred Isaman 		 bitmap[3] = {0};
4462ae42c70aSBryan Schumaker 	int status;
4463ae42c70aSBryan Schumaker 
4464ae42c70aSBryan Schumaker 	status = decode_op_hdr(xdr, OP_GETATTR);
4465ae42c70aSBryan Schumaker 	if (status < 0)
4466ae42c70aSBryan Schumaker 		goto xdr_error;
4467ae42c70aSBryan Schumaker 
4468ae42c70aSBryan Schumaker 	status = decode_attr_bitmap(xdr, bitmap);
4469ae42c70aSBryan Schumaker 	if (status < 0)
4470ae42c70aSBryan Schumaker 		goto xdr_error;
4471ae42c70aSBryan Schumaker 
4472ae42c70aSBryan Schumaker 	status = decode_attr_length(xdr, &attrlen, &savep);
4473ae42c70aSBryan Schumaker 	if (status < 0)
4474ae42c70aSBryan Schumaker 		goto xdr_error;
4475ae42c70aSBryan Schumaker 
44768b7e3f49STrond Myklebust 	status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
4477ae42c70aSBryan Schumaker 	if (status < 0)
4478ae42c70aSBryan Schumaker 		goto xdr_error;
4479ae42c70aSBryan Schumaker 
4480f26c7a78STrond Myklebust 	status = verify_attr_len(xdr, savep, attrlen);
44811da177e4SLinus Torvalds xdr_error:
44823110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d\n", __func__, -status);
44831da177e4SLinus Torvalds 	return status;
44841da177e4SLinus Torvalds }
44851da177e4SLinus Torvalds 
4486ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
44876926afd1STrond Myklebust 		const struct nfs_server *server)
4488ae42c70aSBryan Schumaker {
44898b7e3f49STrond Myklebust 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
4490ae42c70aSBryan Schumaker }
44911da177e4SLinus Torvalds 
4492504913fbSAndy Adamson /*
4493504913fbSAndy Adamson  * Decode potentially multiple layout types. Currently we only support
4494504913fbSAndy Adamson  * one layout driver per file system.
4495504913fbSAndy Adamson  */
4496504913fbSAndy Adamson static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4497504913fbSAndy Adamson 					 uint32_t *layouttype)
4498504913fbSAndy Adamson {
4499504913fbSAndy Adamson 	uint32_t *p;
4500504913fbSAndy Adamson 	int num;
4501504913fbSAndy Adamson 
4502504913fbSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
4503504913fbSAndy Adamson 	if (unlikely(!p))
4504504913fbSAndy Adamson 		goto out_overflow;
4505504913fbSAndy Adamson 	num = be32_to_cpup(p);
4506504913fbSAndy Adamson 
4507504913fbSAndy Adamson 	/* pNFS is not supported by the underlying file system */
4508504913fbSAndy Adamson 	if (num == 0) {
4509504913fbSAndy Adamson 		*layouttype = 0;
4510504913fbSAndy Adamson 		return 0;
4511504913fbSAndy Adamson 	}
4512504913fbSAndy Adamson 	if (num > 1)
4513a030889aSWeston Andros Adamson 		printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4514a030889aSWeston Andros Adamson 			"drivers per filesystem not supported\n", __func__);
4515504913fbSAndy Adamson 
4516504913fbSAndy Adamson 	/* Decode and set first layout type, move xdr->p past unused types */
4517504913fbSAndy Adamson 	p = xdr_inline_decode(xdr, num * 4);
4518504913fbSAndy Adamson 	if (unlikely(!p))
4519504913fbSAndy Adamson 		goto out_overflow;
4520504913fbSAndy Adamson 	*layouttype = be32_to_cpup(p);
4521504913fbSAndy Adamson 	return 0;
4522504913fbSAndy Adamson out_overflow:
4523504913fbSAndy Adamson 	print_overflow_msg(__func__, xdr);
4524504913fbSAndy Adamson 	return -EIO;
4525504913fbSAndy Adamson }
4526504913fbSAndy Adamson 
4527504913fbSAndy Adamson /*
4528504913fbSAndy Adamson  * The type of file system exported.
4529504913fbSAndy Adamson  * Note we must ensure that layouttype is set in any non-error case.
4530504913fbSAndy Adamson  */
4531504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4532504913fbSAndy Adamson 				uint32_t *layouttype)
4533504913fbSAndy Adamson {
4534504913fbSAndy Adamson 	int status = 0;
4535504913fbSAndy Adamson 
4536504913fbSAndy Adamson 	dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4537504913fbSAndy Adamson 	if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4538504913fbSAndy Adamson 		return -EIO;
4539504913fbSAndy Adamson 	if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4540504913fbSAndy Adamson 		status = decode_first_pnfs_layout_type(xdr, layouttype);
4541504913fbSAndy Adamson 		bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4542504913fbSAndy Adamson 	} else
4543504913fbSAndy Adamson 		*layouttype = 0;
4544504913fbSAndy Adamson 	return status;
4545504913fbSAndy Adamson }
4546504913fbSAndy Adamson 
4547dae100c2SFred Isaman /*
4548dae100c2SFred Isaman  * The prefered block size for layout directed io
4549dae100c2SFred Isaman  */
4550dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4551dae100c2SFred Isaman 				      uint32_t *res)
4552dae100c2SFred Isaman {
4553dae100c2SFred Isaman 	__be32 *p;
4554dae100c2SFred Isaman 
4555dae100c2SFred Isaman 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4556dae100c2SFred Isaman 	*res = 0;
4557dae100c2SFred Isaman 	if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4558dae100c2SFred Isaman 		p = xdr_inline_decode(xdr, 4);
4559dae100c2SFred Isaman 		if (unlikely(!p)) {
4560dae100c2SFred Isaman 			print_overflow_msg(__func__, xdr);
4561dae100c2SFred Isaman 			return -EIO;
4562dae100c2SFred Isaman 		}
4563dae100c2SFred Isaman 		*res = be32_to_cpup(p);
4564dae100c2SFred Isaman 		bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4565dae100c2SFred Isaman 	}
4566dae100c2SFred Isaman 	return 0;
4567dae100c2SFred Isaman }
4568dae100c2SFred Isaman 
45691da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
45701da177e4SLinus Torvalds {
45718687b63aSAl Viro 	__be32 *savep;
4572dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3];
45731da177e4SLinus Torvalds 	int status;
45741da177e4SLinus Torvalds 
45751da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
45761da177e4SLinus Torvalds 		goto xdr_error;
45771da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
45781da177e4SLinus Torvalds 		goto xdr_error;
45791da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
45801da177e4SLinus Torvalds 		goto xdr_error;
45811da177e4SLinus Torvalds 
45821da177e4SLinus Torvalds 	fsinfo->rtmult = fsinfo->wtmult = 512;	/* ??? */
45831da177e4SLinus Torvalds 
45841da177e4SLinus Torvalds 	if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
45851da177e4SLinus Torvalds 		goto xdr_error;
45861da177e4SLinus Torvalds 	if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
45871da177e4SLinus Torvalds 		goto xdr_error;
45881da177e4SLinus Torvalds 	if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
45891da177e4SLinus Torvalds 		goto xdr_error;
45901da177e4SLinus Torvalds 	fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
45911da177e4SLinus Torvalds 	if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
45921da177e4SLinus Torvalds 		goto xdr_error;
45931da177e4SLinus Torvalds 	fsinfo->wtpref = fsinfo->wtmax;
459455b6e774SRicardo Labiaga 	status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
459555b6e774SRicardo Labiaga 	if (status != 0)
459655b6e774SRicardo Labiaga 		goto xdr_error;
4597504913fbSAndy Adamson 	status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4598504913fbSAndy Adamson 	if (status != 0)
4599504913fbSAndy Adamson 		goto xdr_error;
4600dae100c2SFred Isaman 	status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4601dae100c2SFred Isaman 	if (status)
4602dae100c2SFred Isaman 		goto xdr_error;
46031da177e4SLinus Torvalds 
46041da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
46051da177e4SLinus Torvalds xdr_error:
46063110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
46071da177e4SLinus Torvalds 	return status;
46081da177e4SLinus Torvalds }
46091da177e4SLinus Torvalds 
46101da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
46111da177e4SLinus Torvalds {
46128687b63aSAl Viro 	__be32 *p;
46131da177e4SLinus Torvalds 	uint32_t len;
46141da177e4SLinus Torvalds 	int status;
46151da177e4SLinus Torvalds 
46169936781dSTrond Myklebust 	/* Zero handle first to allow comparisons */
46179936781dSTrond Myklebust 	memset(fh, 0, sizeof(*fh));
46189936781dSTrond Myklebust 
46191da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_GETFH);
46201da177e4SLinus Torvalds 	if (status)
46211da177e4SLinus Torvalds 		return status;
46221da177e4SLinus Torvalds 
4623c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4624c0eae66eSBenny Halevy 	if (unlikely(!p))
4625c0eae66eSBenny Halevy 		goto out_overflow;
4626cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
46271da177e4SLinus Torvalds 	if (len > NFS4_FHSIZE)
46281da177e4SLinus Torvalds 		return -EIO;
46291da177e4SLinus Torvalds 	fh->size = len;
4630c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, len);
4631c0eae66eSBenny Halevy 	if (unlikely(!p))
4632c0eae66eSBenny Halevy 		goto out_overflow;
463399398d06SBenny Halevy 	memcpy(fh->data, p, len);
46341da177e4SLinus Torvalds 	return 0;
4635c0eae66eSBenny Halevy out_overflow:
4636c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4637c0eae66eSBenny Halevy 	return -EIO;
46381da177e4SLinus Torvalds }
46391da177e4SLinus Torvalds 
46401da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
46411da177e4SLinus Torvalds {
46421da177e4SLinus Torvalds 	int status;
46431da177e4SLinus Torvalds 
46441da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LINK);
46451da177e4SLinus Torvalds 	if (status)
46461da177e4SLinus Torvalds 		return status;
46471da177e4SLinus Torvalds 	return decode_change_info(xdr, cinfo);
46481da177e4SLinus Torvalds }
46491da177e4SLinus Torvalds 
46501da177e4SLinus Torvalds /*
46511da177e4SLinus Torvalds  * We create the owner, so we know a proper owner.id length is 4.
46521da177e4SLinus Torvalds  */
4653911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
46541da177e4SLinus Torvalds {
4655911d1aafSTrond Myklebust 	uint64_t offset, length, clientid;
46568687b63aSAl Viro 	__be32 *p;
4657911d1aafSTrond Myklebust 	uint32_t namelen, type;
46581da177e4SLinus Torvalds 
4659babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4660c0eae66eSBenny Halevy 	if (unlikely(!p))
4661c0eae66eSBenny Halevy 		goto out_overflow;
4662babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
46633ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &length);
4664babddc72SBryan Schumaker 	type = be32_to_cpup(p++); /* 4 byte read */
4665babddc72SBryan Schumaker 	if (fl != NULL) { /* manipulate file lock */
4666911d1aafSTrond Myklebust 		fl->fl_start = (loff_t)offset;
4667911d1aafSTrond Myklebust 		fl->fl_end = fl->fl_start + (loff_t)length - 1;
4668911d1aafSTrond Myklebust 		if (length == ~(uint64_t)0)
4669911d1aafSTrond Myklebust 			fl->fl_end = OFFSET_MAX;
4670911d1aafSTrond Myklebust 		fl->fl_type = F_WRLCK;
4671911d1aafSTrond Myklebust 		if (type & 1)
4672911d1aafSTrond Myklebust 			fl->fl_type = F_RDLCK;
4673911d1aafSTrond Myklebust 		fl->fl_pid = 0;
4674911d1aafSTrond Myklebust 	}
4675babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4676babddc72SBryan Schumaker 	namelen = be32_to_cpup(p); /* read 4 bytes */  /* have read all 32 bytes now */
4677babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, namelen); /* variable size field */
4678c0eae66eSBenny Halevy 	if (likely(p))
46791da177e4SLinus Torvalds 		return -NFS4ERR_DENIED;
4680c0eae66eSBenny Halevy out_overflow:
4681c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4682c0eae66eSBenny Halevy 	return -EIO;
46831da177e4SLinus Torvalds }
46841da177e4SLinus Torvalds 
4685911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
46861da177e4SLinus Torvalds {
46871da177e4SLinus Torvalds 	int status;
46881da177e4SLinus Torvalds 
46891da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCK);
4690c1d51931STrond Myklebust 	if (status == -EIO)
4691c1d51931STrond Myklebust 		goto out;
46921da177e4SLinus Torvalds 	if (status == 0) {
469307d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
469407d30434SBenny Halevy 		if (unlikely(status))
469507d30434SBenny Halevy 			goto out;
46961da177e4SLinus Torvalds 	} else if (status == -NFS4ERR_DENIED)
4697c1d51931STrond Myklebust 		status = decode_lock_denied(xdr, NULL);
4698c1d51931STrond Myklebust 	if (res->open_seqid != NULL)
4699c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->open_seqid);
4700c1d51931STrond Myklebust 	nfs_increment_lock_seqid(status, res->lock_seqid);
4701c1d51931STrond Myklebust out:
47021da177e4SLinus Torvalds 	return status;
47031da177e4SLinus Torvalds }
47041da177e4SLinus Torvalds 
4705911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
47061da177e4SLinus Torvalds {
47071da177e4SLinus Torvalds 	int status;
47081da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKT);
47091da177e4SLinus Torvalds 	if (status == -NFS4ERR_DENIED)
4710911d1aafSTrond Myklebust 		return decode_lock_denied(xdr, res->denied);
47111da177e4SLinus Torvalds 	return status;
47121da177e4SLinus Torvalds }
47131da177e4SLinus Torvalds 
4714911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
47151da177e4SLinus Torvalds {
47161da177e4SLinus Torvalds 	int status;
47171da177e4SLinus Torvalds 
47181da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKU);
4719c1d51931STrond Myklebust 	if (status != -EIO)
4720c1d51931STrond Myklebust 		nfs_increment_lock_seqid(status, res->seqid);
472107d30434SBenny Halevy 	if (status == 0)
472207d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
47231da177e4SLinus Torvalds 	return status;
47241da177e4SLinus Torvalds }
47251da177e4SLinus Torvalds 
4726d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr)
4727d3c7b7ccSTrond Myklebust {
4728d3c7b7ccSTrond Myklebust 	return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4729d3c7b7ccSTrond Myklebust }
4730d3c7b7ccSTrond Myklebust 
47311da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr)
47321da177e4SLinus Torvalds {
47331da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_LOOKUP);
47341da177e4SLinus Torvalds }
47351da177e4SLinus Torvalds 
47361da177e4SLinus Torvalds /* This is too sick! */
47371da177e4SLinus Torvalds static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
47381da177e4SLinus Torvalds {
47398687b63aSAl Viro 	__be32 *p;
47401da177e4SLinus Torvalds 	uint32_t limit_type, nblocks, blocksize;
47411da177e4SLinus Torvalds 
4742c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
4743c0eae66eSBenny Halevy 	if (unlikely(!p))
4744c0eae66eSBenny Halevy 		goto out_overflow;
47456f723f77SBenny Halevy 	limit_type = be32_to_cpup(p++);
47461da177e4SLinus Torvalds 	switch (limit_type) {
47471da177e4SLinus Torvalds 	case 1:
4748cccddf4fSBenny Halevy 		xdr_decode_hyper(p, maxsize);
47491da177e4SLinus Torvalds 		break;
47501da177e4SLinus Torvalds 	case 2:
47516f723f77SBenny Halevy 		nblocks = be32_to_cpup(p++);
4752cccddf4fSBenny Halevy 		blocksize = be32_to_cpup(p);
47531da177e4SLinus Torvalds 		*maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
47541da177e4SLinus Torvalds 	}
47551da177e4SLinus Torvalds 	return 0;
4756c0eae66eSBenny Halevy out_overflow:
4757c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4758c0eae66eSBenny Halevy 	return -EIO;
47591da177e4SLinus Torvalds }
47601da177e4SLinus Torvalds 
47611da177e4SLinus Torvalds static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
47621da177e4SLinus Torvalds {
47638687b63aSAl Viro 	__be32 *p;
47641da177e4SLinus Torvalds 	uint32_t delegation_type;
476507d30434SBenny Halevy 	int status;
47661da177e4SLinus Torvalds 
4767c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4768c0eae66eSBenny Halevy 	if (unlikely(!p))
4769c0eae66eSBenny Halevy 		goto out_overflow;
4770cccddf4fSBenny Halevy 	delegation_type = be32_to_cpup(p);
47711da177e4SLinus Torvalds 	if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
47721da177e4SLinus Torvalds 		res->delegation_type = 0;
47731da177e4SLinus Torvalds 		return 0;
47741da177e4SLinus Torvalds 	}
477507d30434SBenny Halevy 	status = decode_stateid(xdr, &res->delegation);
477607d30434SBenny Halevy 	if (unlikely(status))
477707d30434SBenny Halevy 		return status;
4778c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4779c0eae66eSBenny Halevy 	if (unlikely(!p))
4780c0eae66eSBenny Halevy 		goto out_overflow;
4781cccddf4fSBenny Halevy 	res->do_recall = be32_to_cpup(p);
478205d564feSAndy Adamson 
47831da177e4SLinus Torvalds 	switch (delegation_type) {
47841da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_READ:
47851da177e4SLinus Torvalds 		res->delegation_type = FMODE_READ;
47861da177e4SLinus Torvalds 		break;
47871da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_WRITE:
47881da177e4SLinus Torvalds 		res->delegation_type = FMODE_WRITE|FMODE_READ;
47891da177e4SLinus Torvalds 		if (decode_space_limit(xdr, &res->maxsize) < 0)
47901da177e4SLinus Torvalds 				return -EIO;
47911da177e4SLinus Torvalds 	}
47927539bbabSDavid Howells 	return decode_ace(xdr, NULL, res->server->nfs_client);
4793c0eae66eSBenny Halevy out_overflow:
4794c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4795c0eae66eSBenny Halevy 	return -EIO;
47961da177e4SLinus Torvalds }
47971da177e4SLinus Torvalds 
47981da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
47991da177e4SLinus Torvalds {
48008687b63aSAl Viro 	__be32 *p;
4801aa53ed54SJeff Layton 	uint32_t savewords, bmlen, i;
48021da177e4SLinus Torvalds 	int status;
48031da177e4SLinus Torvalds 
48041da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN);
4805c1d51931STrond Myklebust 	if (status != -EIO)
4806c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
480707d30434SBenny Halevy 	if (!status)
480807d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
480907d30434SBenny Halevy 	if (unlikely(status))
48101da177e4SLinus Torvalds 		return status;
48111da177e4SLinus Torvalds 
48121da177e4SLinus Torvalds 	decode_change_info(xdr, &res->cinfo);
48131da177e4SLinus Torvalds 
4814c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
4815c0eae66eSBenny Halevy 	if (unlikely(!p))
4816c0eae66eSBenny Halevy 		goto out_overflow;
48176f723f77SBenny Halevy 	res->rflags = be32_to_cpup(p++);
4818cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
48191da177e4SLinus Torvalds 	if (bmlen > 10)
48201da177e4SLinus Torvalds 		goto xdr_error;
48211da177e4SLinus Torvalds 
4822c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
4823c0eae66eSBenny Halevy 	if (unlikely(!p))
4824c0eae66eSBenny Halevy 		goto out_overflow;
4825aa53ed54SJeff Layton 	savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4826aa53ed54SJeff Layton 	for (i = 0; i < savewords; ++i)
48276f723f77SBenny Halevy 		res->attrset[i] = be32_to_cpup(p++);
4828aa53ed54SJeff Layton 	for (; i < NFS4_BITMAP_SIZE; i++)
4829aa53ed54SJeff Layton 		res->attrset[i] = 0;
4830aa53ed54SJeff Layton 
48311da177e4SLinus Torvalds 	return decode_delegation(xdr, res);
48321da177e4SLinus Torvalds xdr_error:
48333110ff80SHarvey Harrison 	dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
48341da177e4SLinus Torvalds 	return -EIO;
4835c0eae66eSBenny Halevy out_overflow:
4836c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4837c0eae66eSBenny Halevy 	return -EIO;
48381da177e4SLinus Torvalds }
48391da177e4SLinus Torvalds 
48401da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
48411da177e4SLinus Torvalds {
48421da177e4SLinus Torvalds 	int status;
48431da177e4SLinus Torvalds 
48441da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
4845c1d51931STrond Myklebust 	if (status != -EIO)
4846c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
484707d30434SBenny Halevy 	if (!status)
484807d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
48491da177e4SLinus Torvalds 	return status;
48501da177e4SLinus Torvalds }
48511da177e4SLinus Torvalds 
48521da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
48531da177e4SLinus Torvalds {
48541da177e4SLinus Torvalds 	int status;
48551da177e4SLinus Torvalds 
48561da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
4857c1d51931STrond Myklebust 	if (status != -EIO)
4858c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
485907d30434SBenny Halevy 	if (!status)
486007d30434SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
48611da177e4SLinus Torvalds 	return status;
48621da177e4SLinus Torvalds }
48631da177e4SLinus Torvalds 
48641da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr)
48651da177e4SLinus Torvalds {
48661da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTFH);
48671da177e4SLinus Torvalds }
48681da177e4SLinus Torvalds 
48691da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr)
48701da177e4SLinus Torvalds {
48711da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTROOTFH);
48721da177e4SLinus Torvalds }
48731da177e4SLinus Torvalds 
48741da177e4SLinus Torvalds static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
48751da177e4SLinus Torvalds {
48761da177e4SLinus Torvalds 	struct kvec *iov = req->rq_rcv_buf.head;
48778687b63aSAl Viro 	__be32 *p;
48781da177e4SLinus Torvalds 	uint32_t count, eof, recvd, hdrlen;
48791da177e4SLinus Torvalds 	int status;
48801da177e4SLinus Torvalds 
48811da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READ);
48821da177e4SLinus Torvalds 	if (status)
48831da177e4SLinus Torvalds 		return status;
4884c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
4885c0eae66eSBenny Halevy 	if (unlikely(!p))
4886c0eae66eSBenny Halevy 		goto out_overflow;
48876f723f77SBenny Halevy 	eof = be32_to_cpup(p++);
4888cccddf4fSBenny Halevy 	count = be32_to_cpup(p);
48898111f373SChuck Lever 	hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
48901da177e4SLinus Torvalds 	recvd = req->rq_rcv_buf.len - hdrlen;
48911da177e4SLinus Torvalds 	if (count > recvd) {
4892fe82a183SChuck Lever 		dprintk("NFS: server cheating in read reply: "
48931da177e4SLinus Torvalds 				"count %u > recvd %u\n", count, recvd);
48941da177e4SLinus Torvalds 		count = recvd;
48951da177e4SLinus Torvalds 		eof = 0;
48961da177e4SLinus Torvalds 	}
48971da177e4SLinus Torvalds 	xdr_read_pages(xdr, count);
48981da177e4SLinus Torvalds 	res->eof = eof;
48991da177e4SLinus Torvalds 	res->count = count;
49001da177e4SLinus Torvalds 	return 0;
4901c0eae66eSBenny Halevy out_overflow:
4902c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4903c0eae66eSBenny Halevy 	return -EIO;
49041da177e4SLinus Torvalds }
49051da177e4SLinus Torvalds 
49061da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
49071da177e4SLinus Torvalds {
49081da177e4SLinus Torvalds 	struct xdr_buf	*rcvbuf = &req->rq_rcv_buf;
49091da177e4SLinus Torvalds 	struct kvec	*iov = rcvbuf->head;
4910bcecff77SChuck Lever 	size_t		hdrlen;
4911bcecff77SChuck Lever 	u32		recvd, pglen = rcvbuf->page_len;
4912bcecff77SChuck Lever 	int		status;
49131da177e4SLinus Torvalds 
49141da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READDIR);
4915db942bbdSBenny Halevy 	if (!status)
4916db942bbdSBenny Halevy 		status = decode_verifier(xdr, readdir->verifier.data);
4917db942bbdSBenny Halevy 	if (unlikely(status))
49181da177e4SLinus Torvalds 		return status;
491944109241SFred Isaman 	dprintk("%s: verifier = %08x:%08x\n",
492044109241SFred Isaman 			__func__,
4921eadf4598STrond Myklebust 			((u32 *)readdir->verifier.data)[0],
4922eadf4598STrond Myklebust 			((u32 *)readdir->verifier.data)[1]);
4923eadf4598STrond Myklebust 
49241da177e4SLinus Torvalds 
4925db942bbdSBenny Halevy 	hdrlen = (char *) xdr->p - (char *) iov->iov_base;
49261da177e4SLinus Torvalds 	recvd = rcvbuf->len - hdrlen;
49271da177e4SLinus Torvalds 	if (pglen > recvd)
49281da177e4SLinus Torvalds 		pglen = recvd;
49291da177e4SLinus Torvalds 	xdr_read_pages(xdr, pglen);
49301da177e4SLinus Torvalds 
49317bda2cdfSJeff Layton 
4932ac396128STrond Myklebust 	return pglen;
49331da177e4SLinus Torvalds }
49341da177e4SLinus Torvalds 
49351da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
49361da177e4SLinus Torvalds {
49371da177e4SLinus Torvalds 	struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
49381da177e4SLinus Torvalds 	struct kvec *iov = rcvbuf->head;
4939bcecff77SChuck Lever 	size_t hdrlen;
4940bcecff77SChuck Lever 	u32 len, recvd;
49418687b63aSAl Viro 	__be32 *p;
49421da177e4SLinus Torvalds 	int status;
49431da177e4SLinus Torvalds 
49441da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READLINK);
49451da177e4SLinus Torvalds 	if (status)
49461da177e4SLinus Torvalds 		return status;
49471da177e4SLinus Torvalds 
49481da177e4SLinus Torvalds 	/* Convert length of symlink */
4949c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4950c0eae66eSBenny Halevy 	if (unlikely(!p))
4951c0eae66eSBenny Halevy 		goto out_overflow;
4952cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
49531da177e4SLinus Torvalds 	if (len >= rcvbuf->page_len || len <= 0) {
4954fe82a183SChuck Lever 		dprintk("nfs: server returned giant symlink!\n");
49551da177e4SLinus Torvalds 		return -ENAMETOOLONG;
49561da177e4SLinus Torvalds 	}
49571da177e4SLinus Torvalds 	hdrlen = (char *) xdr->p - (char *) iov->iov_base;
49581da177e4SLinus Torvalds 	recvd = req->rq_rcv_buf.len - hdrlen;
49591da177e4SLinus Torvalds 	if (recvd < len) {
4960fe82a183SChuck Lever 		dprintk("NFS: server cheating in readlink reply: "
49611da177e4SLinus Torvalds 				"count %u > recvd %u\n", len, recvd);
49621da177e4SLinus Torvalds 		return -EIO;
49631da177e4SLinus Torvalds 	}
49641da177e4SLinus Torvalds 	xdr_read_pages(xdr, len);
49651da177e4SLinus Torvalds 	/*
49661da177e4SLinus Torvalds 	 * The XDR encode routine has set things up so that
49671da177e4SLinus Torvalds 	 * the link text will be copied directly into the
49681da177e4SLinus Torvalds 	 * buffer.  We just have to do overflow-checking,
49691da177e4SLinus Torvalds 	 * and and null-terminate the text (the VFS expects
49701da177e4SLinus Torvalds 	 * null-termination).
49711da177e4SLinus Torvalds 	 */
4972b4687da7SChuck Lever 	xdr_terminate_string(rcvbuf, len);
49731da177e4SLinus Torvalds 	return 0;
4974c0eae66eSBenny Halevy out_overflow:
4975c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4976c0eae66eSBenny Halevy 	return -EIO;
49771da177e4SLinus Torvalds }
49781da177e4SLinus Torvalds 
49791da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
49801da177e4SLinus Torvalds {
49811da177e4SLinus Torvalds 	int status;
49821da177e4SLinus Torvalds 
49831da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_REMOVE);
49841da177e4SLinus Torvalds 	if (status)
49851da177e4SLinus Torvalds 		goto out;
49861da177e4SLinus Torvalds 	status = decode_change_info(xdr, cinfo);
49871da177e4SLinus Torvalds out:
49881da177e4SLinus Torvalds 	return status;
49891da177e4SLinus Torvalds }
49901da177e4SLinus Torvalds 
49911da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
49921da177e4SLinus Torvalds 	      struct nfs4_change_info *new_cinfo)
49931da177e4SLinus Torvalds {
49941da177e4SLinus Torvalds 	int status;
49951da177e4SLinus Torvalds 
49961da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_RENAME);
49971da177e4SLinus Torvalds 	if (status)
49981da177e4SLinus Torvalds 		goto out;
49991da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, old_cinfo)))
50001da177e4SLinus Torvalds 		goto out;
50011da177e4SLinus Torvalds 	status = decode_change_info(xdr, new_cinfo);
50021da177e4SLinus Torvalds out:
50031da177e4SLinus Torvalds 	return status;
50041da177e4SLinus Torvalds }
50051da177e4SLinus Torvalds 
50061da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr)
50071da177e4SLinus Torvalds {
50081da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_RENEW);
50091da177e4SLinus Torvalds }
50101da177e4SLinus Torvalds 
501156ae19f3STrond Myklebust static int
501256ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr)
501356ae19f3STrond Myklebust {
501456ae19f3STrond Myklebust 	return decode_op_hdr(xdr, OP_RESTOREFH);
501556ae19f3STrond Myklebust }
501656ae19f3STrond Myklebust 
5017029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5018bf118a34SAndy Adamson 			 struct nfs_getaclres *res)
5019029d105eSJ. Bruce Fields {
5020bf118a34SAndy Adamson 	__be32 *savep, *bm_p;
5021029d105eSJ. Bruce Fields 	uint32_t attrlen,
5022dae100c2SFred Isaman 		 bitmap[3] = {0};
5023029d105eSJ. Bruce Fields 	struct kvec *iov = req->rq_rcv_buf.head;
5024029d105eSJ. Bruce Fields 	int status;
5025029d105eSJ. Bruce Fields 
5026bf118a34SAndy Adamson 	res->acl_len = 0;
5027029d105eSJ. Bruce Fields 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5028029d105eSJ. Bruce Fields 		goto out;
5029bf118a34SAndy Adamson 	bm_p = xdr->p;
5030029d105eSJ. Bruce Fields 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5031029d105eSJ. Bruce Fields 		goto out;
5032029d105eSJ. Bruce Fields 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5033029d105eSJ. Bruce Fields 		goto out;
5034029d105eSJ. Bruce Fields 
5035029d105eSJ. Bruce Fields 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5036029d105eSJ. Bruce Fields 		return -EIO;
5037029d105eSJ. Bruce Fields 	if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5038bcecff77SChuck Lever 		size_t hdrlen;
5039bcecff77SChuck Lever 		u32 recvd;
5040029d105eSJ. Bruce Fields 
5041bf118a34SAndy Adamson 		/* The bitmap (xdr len + bitmaps) and the attr xdr len words
5042bf118a34SAndy Adamson 		 * are stored with the acl data to handle the problem of
5043bf118a34SAndy Adamson 		 * variable length bitmaps.*/
5044bf118a34SAndy Adamson 		xdr->p = bm_p;
5045bf118a34SAndy Adamson 		res->acl_data_offset = be32_to_cpup(bm_p) + 2;
5046bf118a34SAndy Adamson 		res->acl_data_offset <<= 2;
5047bf118a34SAndy Adamson 
5048029d105eSJ. Bruce Fields 		/* We ignore &savep and don't do consistency checks on
5049029d105eSJ. Bruce Fields 		 * the attr length.  Let userspace figure it out.... */
5050029d105eSJ. Bruce Fields 		hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
5051bf118a34SAndy Adamson 		attrlen += res->acl_data_offset;
5052029d105eSJ. Bruce Fields 		recvd = req->rq_rcv_buf.len - hdrlen;
5053029d105eSJ. Bruce Fields 		if (attrlen > recvd) {
5054bf118a34SAndy Adamson 			if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
5055bf118a34SAndy Adamson 				/* getxattr interface called with a NULL buf */
5056bf118a34SAndy Adamson 				res->acl_len = attrlen;
5057bf118a34SAndy Adamson 				goto out;
5058bf118a34SAndy Adamson 			}
5059bf118a34SAndy Adamson 			dprintk("NFS: acl reply: attrlen %u > recvd %u\n",
5060029d105eSJ. Bruce Fields 					attrlen, recvd);
5061029d105eSJ. Bruce Fields 			return -EINVAL;
5062029d105eSJ. Bruce Fields 		}
5063029d105eSJ. Bruce Fields 		xdr_read_pages(xdr, attrlen);
5064bf118a34SAndy Adamson 		res->acl_len = attrlen;
50658c233cf9SJ. Bruce Fields 	} else
50668c233cf9SJ. Bruce Fields 		status = -EOPNOTSUPP;
5067029d105eSJ. Bruce Fields 
5068029d105eSJ. Bruce Fields out:
5069029d105eSJ. Bruce Fields 	return status;
5070029d105eSJ. Bruce Fields }
5071029d105eSJ. Bruce Fields 
50721da177e4SLinus Torvalds static int
50731da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr)
50741da177e4SLinus Torvalds {
50751da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SAVEFH);
50761da177e4SLinus Torvalds }
50771da177e4SLinus Torvalds 
50789e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr)
50791da177e4SLinus Torvalds {
50808687b63aSAl Viro 	__be32 *p;
50811da177e4SLinus Torvalds 	uint32_t bmlen;
50821da177e4SLinus Torvalds 	int status;
50831da177e4SLinus Torvalds 
50841da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_SETATTR);
50851da177e4SLinus Torvalds 	if (status)
50861da177e4SLinus Torvalds 		return status;
5087c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5088c0eae66eSBenny Halevy 	if (unlikely(!p))
5089c0eae66eSBenny Halevy 		goto out_overflow;
5090cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
5091c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
5092c0eae66eSBenny Halevy 	if (likely(p))
50931da177e4SLinus Torvalds 		return 0;
5094c0eae66eSBenny Halevy out_overflow:
5095c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5096c0eae66eSBenny Halevy 	return -EIO;
50971da177e4SLinus Torvalds }
50981da177e4SLinus Torvalds 
5099bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
51001da177e4SLinus Torvalds {
51018687b63aSAl Viro 	__be32 *p;
51021da177e4SLinus Torvalds 	uint32_t opnum;
51031da177e4SLinus Torvalds 	int32_t nfserr;
51041da177e4SLinus Torvalds 
5105c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5106c0eae66eSBenny Halevy 	if (unlikely(!p))
5107c0eae66eSBenny Halevy 		goto out_overflow;
51086f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
51091da177e4SLinus Torvalds 	if (opnum != OP_SETCLIENTID) {
5110fe82a183SChuck Lever 		dprintk("nfs: decode_setclientid: Server returned operation"
51111da177e4SLinus Torvalds 			" %d\n", opnum);
51121da177e4SLinus Torvalds 		return -EIO;
51131da177e4SLinus Torvalds 	}
5114cccddf4fSBenny Halevy 	nfserr = be32_to_cpup(p);
51151da177e4SLinus Torvalds 	if (nfserr == NFS_OK) {
5116c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5117c0eae66eSBenny Halevy 		if (unlikely(!p))
5118c0eae66eSBenny Halevy 			goto out_overflow;
5119bb8b27e5STrond Myklebust 		p = xdr_decode_hyper(p, &res->clientid);
5120bb8b27e5STrond Myklebust 		memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
51211da177e4SLinus Torvalds 	} else if (nfserr == NFSERR_CLID_INUSE) {
51221da177e4SLinus Torvalds 		uint32_t len;
51231da177e4SLinus Torvalds 
51241da177e4SLinus Torvalds 		/* skip netid string */
5125c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5126c0eae66eSBenny Halevy 		if (unlikely(!p))
5127c0eae66eSBenny Halevy 			goto out_overflow;
5128cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5129c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5130c0eae66eSBenny Halevy 		if (unlikely(!p))
5131c0eae66eSBenny Halevy 			goto out_overflow;
51321da177e4SLinus Torvalds 
51331da177e4SLinus Torvalds 		/* skip uaddr string */
5134c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5135c0eae66eSBenny Halevy 		if (unlikely(!p))
5136c0eae66eSBenny Halevy 			goto out_overflow;
5137cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5138c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5139c0eae66eSBenny Halevy 		if (unlikely(!p))
5140c0eae66eSBenny Halevy 			goto out_overflow;
51411da177e4SLinus Torvalds 		return -NFSERR_CLID_INUSE;
51421da177e4SLinus Torvalds 	} else
5143856dff3dSBenny Halevy 		return nfs4_stat_to_errno(nfserr);
51441da177e4SLinus Torvalds 
51451da177e4SLinus Torvalds 	return 0;
5146c0eae66eSBenny Halevy out_overflow:
5147c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5148c0eae66eSBenny Halevy 	return -EIO;
51491da177e4SLinus Torvalds }
51501da177e4SLinus Torvalds 
51511da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr)
51521da177e4SLinus Torvalds {
51531da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
51541da177e4SLinus Torvalds }
51551da177e4SLinus Torvalds 
51561da177e4SLinus Torvalds static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
51571da177e4SLinus Torvalds {
51588687b63aSAl Viro 	__be32 *p;
51591da177e4SLinus Torvalds 	int status;
51601da177e4SLinus Torvalds 
51611da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_WRITE);
51621da177e4SLinus Torvalds 	if (status)
51631da177e4SLinus Torvalds 		return status;
51641da177e4SLinus Torvalds 
5165c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 16);
5166c0eae66eSBenny Halevy 	if (unlikely(!p))
5167c0eae66eSBenny Halevy 		goto out_overflow;
51686f723f77SBenny Halevy 	res->count = be32_to_cpup(p++);
51696f723f77SBenny Halevy 	res->verf->committed = be32_to_cpup(p++);
517099398d06SBenny Halevy 	memcpy(res->verf->verifier, p, 8);
51711da177e4SLinus Torvalds 	return 0;
5172c0eae66eSBenny Halevy out_overflow:
5173c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5174c0eae66eSBenny Halevy 	return -EIO;
51751da177e4SLinus Torvalds }
51761da177e4SLinus Torvalds 
51771da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr)
51781da177e4SLinus Torvalds {
51791da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_DELEGRETURN);
51801da177e4SLinus Torvalds }
51811da177e4SLinus Torvalds 
51825a5ea0d4SBryan Schumaker static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
51835a5ea0d4SBryan Schumaker {
51845a5ea0d4SBryan Schumaker 	__be32 *p;
51855a5ea0d4SBryan Schumaker 
51865a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
51875a5ea0d4SBryan Schumaker 	if (unlikely(!p))
51885a5ea0d4SBryan Schumaker 		goto out_overflow;
51895a5ea0d4SBryan Schumaker 	flavor->gss.sec_oid4.len = be32_to_cpup(p);
51905a5ea0d4SBryan Schumaker 	if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
51915a5ea0d4SBryan Schumaker 		goto out_err;
51925a5ea0d4SBryan Schumaker 
51935a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
51945a5ea0d4SBryan Schumaker 	if (unlikely(!p))
51955a5ea0d4SBryan Schumaker 		goto out_overflow;
51965a5ea0d4SBryan Schumaker 	memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
51975a5ea0d4SBryan Schumaker 
51985a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 8);
51995a5ea0d4SBryan Schumaker 	if (unlikely(!p))
52005a5ea0d4SBryan Schumaker 		goto out_overflow;
52015a5ea0d4SBryan Schumaker 	flavor->gss.qop4 = be32_to_cpup(p++);
52025a5ea0d4SBryan Schumaker 	flavor->gss.service = be32_to_cpup(p);
52035a5ea0d4SBryan Schumaker 
52045a5ea0d4SBryan Schumaker 	return 0;
52055a5ea0d4SBryan Schumaker 
52065a5ea0d4SBryan Schumaker out_overflow:
52075a5ea0d4SBryan Schumaker 	print_overflow_msg(__func__, xdr);
52085a5ea0d4SBryan Schumaker 	return -EIO;
52095a5ea0d4SBryan Schumaker out_err:
52105a5ea0d4SBryan Schumaker 	return -EINVAL;
52115a5ea0d4SBryan Schumaker }
52125a5ea0d4SBryan Schumaker 
52135a5ea0d4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
52145a5ea0d4SBryan Schumaker {
52155a5ea0d4SBryan Schumaker 	struct nfs4_secinfo_flavor *sec_flavor;
52165a5ea0d4SBryan Schumaker 	int status;
52175a5ea0d4SBryan Schumaker 	__be32 *p;
5218c3dfc280SBryan Schumaker 	int i, num_flavors;
52195a5ea0d4SBryan Schumaker 
52205a5ea0d4SBryan Schumaker 	status = decode_op_hdr(xdr, OP_SECINFO);
5221613e901eSBryan Schumaker 	if (status)
5222613e901eSBryan Schumaker 		goto out;
52235a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
52245a5ea0d4SBryan Schumaker 	if (unlikely(!p))
52255a5ea0d4SBryan Schumaker 		goto out_overflow;
52265a5ea0d4SBryan Schumaker 
5227c3dfc280SBryan Schumaker 	res->flavors->num_flavors = 0;
5228c3dfc280SBryan Schumaker 	num_flavors = be32_to_cpup(p);
5229c3dfc280SBryan Schumaker 
5230c3dfc280SBryan Schumaker 	for (i = 0; i < num_flavors; i++) {
52315a5ea0d4SBryan Schumaker 		sec_flavor = &res->flavors->flavors[i];
5232c3dfc280SBryan Schumaker 		if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
52335a5ea0d4SBryan Schumaker 			break;
52345a5ea0d4SBryan Schumaker 
52355a5ea0d4SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
52365a5ea0d4SBryan Schumaker 		if (unlikely(!p))
52375a5ea0d4SBryan Schumaker 			goto out_overflow;
52385a5ea0d4SBryan Schumaker 		sec_flavor->flavor = be32_to_cpup(p);
52395a5ea0d4SBryan Schumaker 
52405a5ea0d4SBryan Schumaker 		if (sec_flavor->flavor == RPC_AUTH_GSS) {
5241613e901eSBryan Schumaker 			status = decode_secinfo_gss(xdr, sec_flavor);
5242613e901eSBryan Schumaker 			if (status)
5243613e901eSBryan Schumaker 				goto out;
52445a5ea0d4SBryan Schumaker 		}
5245c3dfc280SBryan Schumaker 		res->flavors->num_flavors++;
52465a5ea0d4SBryan Schumaker 	}
52475a5ea0d4SBryan Schumaker 
5248613e901eSBryan Schumaker out:
5249613e901eSBryan Schumaker 	return status;
52505a5ea0d4SBryan Schumaker out_overflow:
52515a5ea0d4SBryan Schumaker 	print_overflow_msg(__func__, xdr);
52525a5ea0d4SBryan Schumaker 	return -EIO;
52535a5ea0d4SBryan Schumaker }
52545a5ea0d4SBryan Schumaker 
525599fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
525699fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr,
525799fe60d0SBenny Halevy 			      struct nfs41_exchange_id_res *res)
525899fe60d0SBenny Halevy {
525999fe60d0SBenny Halevy 	__be32 *p;
526099fe60d0SBenny Halevy 	uint32_t dummy;
52612460ba57SBenny Halevy 	char *dummy_str;
526299fe60d0SBenny Halevy 	int status;
526399fe60d0SBenny Halevy 	struct nfs_client *clp = res->client;
52647d2ed9acSWeston Andros Adamson 	uint32_t impl_id_count;
526599fe60d0SBenny Halevy 
526699fe60d0SBenny Halevy 	status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
526799fe60d0SBenny Halevy 	if (status)
526899fe60d0SBenny Halevy 		return status;
526999fe60d0SBenny Halevy 
5270c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5271c0eae66eSBenny Halevy 	if (unlikely(!p))
5272c0eae66eSBenny Halevy 		goto out_overflow;
5273114f64b5SAndy Adamson 	xdr_decode_hyper(p, &clp->cl_clientid);
5274c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
5275c0eae66eSBenny Halevy 	if (unlikely(!p))
5276c0eae66eSBenny Halevy 		goto out_overflow;
52776f723f77SBenny Halevy 	clp->cl_seqid = be32_to_cpup(p++);
52786f723f77SBenny Halevy 	clp->cl_exchange_flags = be32_to_cpup(p++);
527999fe60d0SBenny Halevy 
528099fe60d0SBenny Halevy 	/* We ask for SP4_NONE */
5281cccddf4fSBenny Halevy 	dummy = be32_to_cpup(p);
528299fe60d0SBenny Halevy 	if (dummy != SP4_NONE)
528399fe60d0SBenny Halevy 		return -EIO;
528499fe60d0SBenny Halevy 
528599fe60d0SBenny Halevy 	/* Throw away minor_id */
5286c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5287c0eae66eSBenny Halevy 	if (unlikely(!p))
5288c0eae66eSBenny Halevy 		goto out_overflow;
528999fe60d0SBenny Halevy 
529099fe60d0SBenny Halevy 	/* Throw away Major id */
52912460ba57SBenny Halevy 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
52922460ba57SBenny Halevy 	if (unlikely(status))
52932460ba57SBenny Halevy 		return status;
529499fe60d0SBenny Halevy 
529578fe0f41SWeston Andros Adamson 	/* Save server_scope */
52962460ba57SBenny Halevy 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
52972460ba57SBenny Halevy 	if (unlikely(status))
52982460ba57SBenny Halevy 		return status;
529999fe60d0SBenny Halevy 
530078fe0f41SWeston Andros Adamson 	if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
530178fe0f41SWeston Andros Adamson 		return -EIO;
530278fe0f41SWeston Andros Adamson 
530378fe0f41SWeston Andros Adamson 	memcpy(res->server_scope->server_scope, dummy_str, dummy);
530478fe0f41SWeston Andros Adamson 	res->server_scope->server_scope_sz = dummy;
530578fe0f41SWeston Andros Adamson 
53067d2ed9acSWeston Andros Adamson 	/* Implementation Id */
53077d2ed9acSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4);
53087d2ed9acSWeston Andros Adamson 	if (unlikely(!p))
53097d2ed9acSWeston Andros Adamson 		goto out_overflow;
53107d2ed9acSWeston Andros Adamson 	impl_id_count = be32_to_cpup(p++);
53117d2ed9acSWeston Andros Adamson 
53127d2ed9acSWeston Andros Adamson 	if (impl_id_count) {
53137d2ed9acSWeston Andros Adamson 		/* nii_domain */
53142460ba57SBenny Halevy 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
53152460ba57SBenny Halevy 		if (unlikely(status))
53162460ba57SBenny Halevy 			return status;
53177d2ed9acSWeston Andros Adamson 		if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
53187d2ed9acSWeston Andros Adamson 			return -EIO;
53197d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->domain, dummy_str, dummy);
532099fe60d0SBenny Halevy 
53217d2ed9acSWeston Andros Adamson 		/* nii_name */
53227d2ed9acSWeston Andros Adamson 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
53237d2ed9acSWeston Andros Adamson 		if (unlikely(status))
53247d2ed9acSWeston Andros Adamson 			return status;
53257d2ed9acSWeston Andros Adamson 		if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
53267d2ed9acSWeston Andros Adamson 			return -EIO;
53277d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->name, dummy_str, dummy);
53287d2ed9acSWeston Andros Adamson 
53297d2ed9acSWeston Andros Adamson 		/* nii_date */
53307d2ed9acSWeston Andros Adamson 		p = xdr_inline_decode(xdr, 12);
53317d2ed9acSWeston Andros Adamson 		if (unlikely(!p))
53327d2ed9acSWeston Andros Adamson 			goto out_overflow;
53337d2ed9acSWeston Andros Adamson 		p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
53347d2ed9acSWeston Andros Adamson 		res->impl_id->date.nseconds = be32_to_cpup(p);
53357d2ed9acSWeston Andros Adamson 
53367d2ed9acSWeston Andros Adamson 		/* if there's more than one entry, ignore the rest */
53377d2ed9acSWeston Andros Adamson 	}
533899fe60d0SBenny Halevy 	return 0;
5339c0eae66eSBenny Halevy out_overflow:
5340c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5341c0eae66eSBenny Halevy 	return -EIO;
534299fe60d0SBenny Halevy }
5343fc931582SAndy Adamson 
5344fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr,
5345fc931582SAndy Adamson 			     struct nfs4_channel_attrs *attrs)
5346fc931582SAndy Adamson {
5347fc931582SAndy Adamson 	__be32 *p;
5348c9c30dd5SBenny Halevy 	u32 nr_attrs, val;
5349fc931582SAndy Adamson 
5350c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 28);
5351c0eae66eSBenny Halevy 	if (unlikely(!p))
5352c0eae66eSBenny Halevy 		goto out_overflow;
5353c9c30dd5SBenny Halevy 	val = be32_to_cpup(p++);	/* headerpadsz */
5354c9c30dd5SBenny Halevy 	if (val)
5355c9c30dd5SBenny Halevy 		return -EINVAL;		/* no support for header padding yet */
53566f723f77SBenny Halevy 	attrs->max_rqst_sz = be32_to_cpup(p++);
53576f723f77SBenny Halevy 	attrs->max_resp_sz = be32_to_cpup(p++);
53586f723f77SBenny Halevy 	attrs->max_resp_sz_cached = be32_to_cpup(p++);
53596f723f77SBenny Halevy 	attrs->max_ops = be32_to_cpup(p++);
53606f723f77SBenny Halevy 	attrs->max_reqs = be32_to_cpup(p++);
5361cccddf4fSBenny Halevy 	nr_attrs = be32_to_cpup(p);
5362fc931582SAndy Adamson 	if (unlikely(nr_attrs > 1)) {
5363a030889aSWeston Andros Adamson 		printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5364a030889aSWeston Andros Adamson 			"count %u\n", __func__, nr_attrs);
5365fc931582SAndy Adamson 		return -EINVAL;
5366fc931582SAndy Adamson 	}
5367c0eae66eSBenny Halevy 	if (nr_attrs == 1) {
5368c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5369c0eae66eSBenny Halevy 		if (unlikely(!p))
5370c0eae66eSBenny Halevy 			goto out_overflow;
5371c0eae66eSBenny Halevy 	}
5372fc931582SAndy Adamson 	return 0;
5373c0eae66eSBenny Halevy out_overflow:
5374c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5375c0eae66eSBenny Halevy 	return -EIO;
5376fc931582SAndy Adamson }
5377fc931582SAndy Adamson 
5378e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5379e78291e4SBenny Halevy {
5380e78291e4SBenny Halevy 	return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5381fc931582SAndy Adamson }
5382fc931582SAndy Adamson 
5383fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr,
5384fc931582SAndy Adamson 				 struct nfs41_create_session_res *res)
5385fc931582SAndy Adamson {
5386fc931582SAndy Adamson 	__be32 *p;
5387fc931582SAndy Adamson 	int status;
5388fc931582SAndy Adamson 	struct nfs_client *clp = res->client;
5389fc931582SAndy Adamson 	struct nfs4_session *session = clp->cl_session;
5390fc931582SAndy Adamson 
5391fc931582SAndy Adamson 	status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5392e78291e4SBenny Halevy 	if (!status)
5393e78291e4SBenny Halevy 		status = decode_sessionid(xdr, &session->sess_id);
5394e78291e4SBenny Halevy 	if (unlikely(status))
5395fc931582SAndy Adamson 		return status;
5396fc931582SAndy Adamson 
5397fc931582SAndy Adamson 	/* seqid, flags */
5398c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5399c0eae66eSBenny Halevy 	if (unlikely(!p))
5400c0eae66eSBenny Halevy 		goto out_overflow;
54016f723f77SBenny Halevy 	clp->cl_seqid = be32_to_cpup(p++);
5402cccddf4fSBenny Halevy 	session->flags = be32_to_cpup(p);
5403fc931582SAndy Adamson 
5404fc931582SAndy Adamson 	/* Channel attributes */
5405fc931582SAndy Adamson 	status = decode_chan_attrs(xdr, &session->fc_attrs);
5406fc931582SAndy Adamson 	if (!status)
5407fc931582SAndy Adamson 		status = decode_chan_attrs(xdr, &session->bc_attrs);
5408fc931582SAndy Adamson 	return status;
5409c0eae66eSBenny Halevy out_overflow:
5410c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5411c0eae66eSBenny Halevy 	return -EIO;
5412fc931582SAndy Adamson }
54130f3e66c6SAndy Adamson 
54140f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
54150f3e66c6SAndy Adamson {
54160f3e66c6SAndy Adamson 	return decode_op_hdr(xdr, OP_DESTROY_SESSION);
54170f3e66c6SAndy Adamson }
541818019753SRicardo Labiaga 
541918019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
542018019753SRicardo Labiaga {
542118019753SRicardo Labiaga 	return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
542218019753SRicardo Labiaga }
542399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
542499fe60d0SBenny Halevy 
54259b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr,
54269b7b9fccSAndy Adamson 			   struct nfs4_sequence_res *res,
54279b7b9fccSAndy Adamson 			   struct rpc_rqst *rqstp)
54289b7b9fccSAndy Adamson {
54299b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
5430fc01cea9SAndy Adamson 	struct nfs4_sessionid id;
5431fc01cea9SAndy Adamson 	u32 dummy;
5432fc01cea9SAndy Adamson 	int status;
5433fc01cea9SAndy Adamson 	__be32 *p;
5434fc01cea9SAndy Adamson 
54359b7b9fccSAndy Adamson 	if (!res->sr_session)
54369b7b9fccSAndy Adamson 		return 0;
54379b7b9fccSAndy Adamson 
5438fc01cea9SAndy Adamson 	status = decode_op_hdr(xdr, OP_SEQUENCE);
5439e78291e4SBenny Halevy 	if (!status)
5440e78291e4SBenny Halevy 		status = decode_sessionid(xdr, &id);
5441e78291e4SBenny Halevy 	if (unlikely(status))
5442fc01cea9SAndy Adamson 		goto out_err;
54439b7b9fccSAndy Adamson 
5444fc01cea9SAndy Adamson 	/*
5445fc01cea9SAndy Adamson 	 * If the server returns different values for sessionID, slotID or
5446fc01cea9SAndy Adamson 	 * sequence number, the server is looney tunes.
5447fc01cea9SAndy Adamson 	 */
5448fdcb4577STrond Myklebust 	status = -EREMOTEIO;
5449fc01cea9SAndy Adamson 
5450fc01cea9SAndy Adamson 	if (memcmp(id.data, res->sr_session->sess_id.data,
5451fc01cea9SAndy Adamson 		   NFS4_MAX_SESSIONID_LEN)) {
5452fc01cea9SAndy Adamson 		dprintk("%s Invalid session id\n", __func__);
5453fc01cea9SAndy Adamson 		goto out_err;
5454fc01cea9SAndy Adamson 	}
5455e78291e4SBenny Halevy 
5456c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
5457c0eae66eSBenny Halevy 	if (unlikely(!p))
5458c0eae66eSBenny Halevy 		goto out_overflow;
5459e78291e4SBenny Halevy 
5460fc01cea9SAndy Adamson 	/* seqid */
54616f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5462dfb4f309SBenny Halevy 	if (dummy != res->sr_slot->seq_nr) {
5463fc01cea9SAndy Adamson 		dprintk("%s Invalid sequence number\n", __func__);
5464fc01cea9SAndy Adamson 		goto out_err;
5465fc01cea9SAndy Adamson 	}
5466fc01cea9SAndy Adamson 	/* slot id */
54676f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5468dfb4f309SBenny Halevy 	if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
5469fc01cea9SAndy Adamson 		dprintk("%s Invalid slot id\n", __func__);
5470fc01cea9SAndy Adamson 		goto out_err;
5471fc01cea9SAndy Adamson 	}
5472fc01cea9SAndy Adamson 	/* highest slot id - currently not processed */
54736f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5474fc01cea9SAndy Adamson 	/* target highest slot id - currently not processed */
54756f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
54760629e370SAlexandros Batsakis 	/* result flags */
54770629e370SAlexandros Batsakis 	res->sr_status_flags = be32_to_cpup(p);
5478fc01cea9SAndy Adamson 	status = 0;
5479fc01cea9SAndy Adamson out_err:
5480fc01cea9SAndy Adamson 	res->sr_status = status;
5481fc01cea9SAndy Adamson 	return status;
5482c0eae66eSBenny Halevy out_overflow:
5483c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5484c0eae66eSBenny Halevy 	status = -EIO;
5485c0eae66eSBenny Halevy 	goto out_err;
5486fc01cea9SAndy Adamson #else  /* CONFIG_NFS_V4_1 */
54879b7b9fccSAndy Adamson 	return 0;
5488fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
54899b7b9fccSAndy Adamson }
54909b7b9fccSAndy Adamson 
5491b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1)
54927f11d8d3SAndy Adamson /*
54937f11d8d3SAndy Adamson  * TODO: Need to handle case when EOF != true;
54947f11d8d3SAndy Adamson  */
54957f11d8d3SAndy Adamson static int decode_getdevicelist(struct xdr_stream *xdr,
54967f11d8d3SAndy Adamson 				struct pnfs_devicelist *res)
54977f11d8d3SAndy Adamson {
54987f11d8d3SAndy Adamson 	__be32 *p;
54997f11d8d3SAndy Adamson 	int status, i;
55007f11d8d3SAndy Adamson 	struct nfs_writeverf verftemp;
55017f11d8d3SAndy Adamson 
55027f11d8d3SAndy Adamson 	status = decode_op_hdr(xdr, OP_GETDEVICELIST);
55037f11d8d3SAndy Adamson 	if (status)
55047f11d8d3SAndy Adamson 		return status;
55057f11d8d3SAndy Adamson 
55067f11d8d3SAndy Adamson 	p = xdr_inline_decode(xdr, 8 + 8 + 4);
55077f11d8d3SAndy Adamson 	if (unlikely(!p))
55087f11d8d3SAndy Adamson 		goto out_overflow;
55097f11d8d3SAndy Adamson 
55107f11d8d3SAndy Adamson 	/* TODO: Skip cookie for now */
55117f11d8d3SAndy Adamson 	p += 2;
55127f11d8d3SAndy Adamson 
55137f11d8d3SAndy Adamson 	/* Read verifier */
55147f11d8d3SAndy Adamson 	p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8);
55157f11d8d3SAndy Adamson 
55167f11d8d3SAndy Adamson 	res->num_devs = be32_to_cpup(p);
55177f11d8d3SAndy Adamson 
55187f11d8d3SAndy Adamson 	dprintk("%s: num_dev %d\n", __func__, res->num_devs);
55197f11d8d3SAndy Adamson 
55207f11d8d3SAndy Adamson 	if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
5521a030889aSWeston Andros Adamson 		printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
55227f11d8d3SAndy Adamson 				__func__, res->num_devs);
55237f11d8d3SAndy Adamson 		return -EIO;
55247f11d8d3SAndy Adamson 	}
55257f11d8d3SAndy Adamson 
55267f11d8d3SAndy Adamson 	p = xdr_inline_decode(xdr,
55277f11d8d3SAndy Adamson 			      res->num_devs * NFS4_DEVICEID4_SIZE + 4);
55287f11d8d3SAndy Adamson 	if (unlikely(!p))
55297f11d8d3SAndy Adamson 		goto out_overflow;
55307f11d8d3SAndy Adamson 	for (i = 0; i < res->num_devs; i++)
55317f11d8d3SAndy Adamson 		p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
55327f11d8d3SAndy Adamson 					    NFS4_DEVICEID4_SIZE);
55337f11d8d3SAndy Adamson 	res->eof = be32_to_cpup(p);
55347f11d8d3SAndy Adamson 	return 0;
55357f11d8d3SAndy Adamson out_overflow:
55367f11d8d3SAndy Adamson 	print_overflow_msg(__func__, xdr);
55377f11d8d3SAndy Adamson 	return -EIO;
55387f11d8d3SAndy Adamson }
5539b1f69b75SAndy Adamson 
5540b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr,
5541b1f69b75SAndy Adamson 				struct pnfs_device *pdev)
5542b1f69b75SAndy Adamson {
5543b1f69b75SAndy Adamson 	__be32 *p;
5544b1f69b75SAndy Adamson 	uint32_t len, type;
5545b1f69b75SAndy Adamson 	int status;
5546b1f69b75SAndy Adamson 
5547b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5548b1f69b75SAndy Adamson 	if (status) {
5549b1f69b75SAndy Adamson 		if (status == -ETOOSMALL) {
5550b1f69b75SAndy Adamson 			p = xdr_inline_decode(xdr, 4);
5551b1f69b75SAndy Adamson 			if (unlikely(!p))
5552b1f69b75SAndy Adamson 				goto out_overflow;
5553b1f69b75SAndy Adamson 			pdev->mincount = be32_to_cpup(p);
5554b1f69b75SAndy Adamson 			dprintk("%s: Min count too small. mincnt = %u\n",
5555b1f69b75SAndy Adamson 				__func__, pdev->mincount);
5556b1f69b75SAndy Adamson 		}
5557b1f69b75SAndy Adamson 		return status;
5558b1f69b75SAndy Adamson 	}
5559b1f69b75SAndy Adamson 
5560b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 8);
5561b1f69b75SAndy Adamson 	if (unlikely(!p))
5562b1f69b75SAndy Adamson 		goto out_overflow;
5563b1f69b75SAndy Adamson 	type = be32_to_cpup(p++);
5564b1f69b75SAndy Adamson 	if (type != pdev->layout_type) {
5565b1f69b75SAndy Adamson 		dprintk("%s: layout mismatch req: %u pdev: %u\n",
5566b1f69b75SAndy Adamson 			__func__, pdev->layout_type, type);
5567b1f69b75SAndy Adamson 		return -EINVAL;
5568b1f69b75SAndy Adamson 	}
5569b1f69b75SAndy Adamson 	/*
5570b1f69b75SAndy Adamson 	 * Get the length of the opaque device_addr4. xdr_read_pages places
5571b1f69b75SAndy Adamson 	 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5572b1f69b75SAndy Adamson 	 * and places the remaining xdr data in xdr_buf->tail
5573b1f69b75SAndy Adamson 	 */
5574b1f69b75SAndy Adamson 	pdev->mincount = be32_to_cpup(p);
5575b1f69b75SAndy Adamson 	xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5576b1f69b75SAndy Adamson 
5577b1f69b75SAndy Adamson 	/* Parse notification bitmap, verifying that it is zero. */
5578b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 4);
5579b1f69b75SAndy Adamson 	if (unlikely(!p))
5580b1f69b75SAndy Adamson 		goto out_overflow;
5581b1f69b75SAndy Adamson 	len = be32_to_cpup(p);
5582b1f69b75SAndy Adamson 	if (len) {
5583ead00597SChuck Lever 		uint32_t i;
5584b1f69b75SAndy Adamson 
5585b1f69b75SAndy Adamson 		p = xdr_inline_decode(xdr, 4 * len);
5586b1f69b75SAndy Adamson 		if (unlikely(!p))
5587b1f69b75SAndy Adamson 			goto out_overflow;
5588b1f69b75SAndy Adamson 		for (i = 0; i < len; i++, p++) {
5589b1f69b75SAndy Adamson 			if (be32_to_cpup(p)) {
5590b1f69b75SAndy Adamson 				dprintk("%s: notifications not supported\n",
5591b1f69b75SAndy Adamson 					__func__);
5592b1f69b75SAndy Adamson 				return -EIO;
5593b1f69b75SAndy Adamson 			}
5594b1f69b75SAndy Adamson 		}
5595b1f69b75SAndy Adamson 	}
5596b1f69b75SAndy Adamson 	return 0;
5597b1f69b75SAndy Adamson out_overflow:
5598b1f69b75SAndy Adamson 	print_overflow_msg(__func__, xdr);
5599b1f69b75SAndy Adamson 	return -EIO;
5600b1f69b75SAndy Adamson }
5601b1f69b75SAndy Adamson 
5602b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5603b1f69b75SAndy Adamson 			    struct nfs4_layoutget_res *res)
5604b1f69b75SAndy Adamson {
5605b1f69b75SAndy Adamson 	__be32 *p;
5606b1f69b75SAndy Adamson 	int status;
5607b1f69b75SAndy Adamson 	u32 layout_count;
560835124a09SWeston Andros Adamson 	struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
560935124a09SWeston Andros Adamson 	struct kvec *iov = rcvbuf->head;
561035124a09SWeston Andros Adamson 	u32 hdrlen, recvd;
5611b1f69b75SAndy Adamson 
5612b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTGET);
5613b1f69b75SAndy Adamson 	if (status)
5614b1f69b75SAndy Adamson 		return status;
5615b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5616b1f69b75SAndy Adamson 	if (unlikely(!p))
5617b1f69b75SAndy Adamson 		goto out_overflow;
5618b1f69b75SAndy Adamson 	res->return_on_close = be32_to_cpup(p++);
5619b1f69b75SAndy Adamson 	p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5620b1f69b75SAndy Adamson 	layout_count = be32_to_cpup(p);
5621b1f69b75SAndy Adamson 	if (!layout_count) {
5622b1f69b75SAndy Adamson 		dprintk("%s: server responded with empty layout array\n",
5623b1f69b75SAndy Adamson 			__func__);
5624b1f69b75SAndy Adamson 		return -EINVAL;
5625b1f69b75SAndy Adamson 	}
5626b1f69b75SAndy Adamson 
562735124a09SWeston Andros Adamson 	p = xdr_inline_decode(xdr, 28);
5628b1f69b75SAndy Adamson 	if (unlikely(!p))
5629b1f69b75SAndy Adamson 		goto out_overflow;
5630b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.offset);
5631b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.length);
5632b1f69b75SAndy Adamson 	res->range.iomode = be32_to_cpup(p++);
5633b1f69b75SAndy Adamson 	res->type = be32_to_cpup(p++);
563435124a09SWeston Andros Adamson 	res->layoutp->len = be32_to_cpup(p);
5635b1f69b75SAndy Adamson 
5636b1f69b75SAndy Adamson 	dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5637b1f69b75SAndy Adamson 		__func__,
5638b1f69b75SAndy Adamson 		(unsigned long)res->range.offset,
5639b1f69b75SAndy Adamson 		(unsigned long)res->range.length,
5640b1f69b75SAndy Adamson 		res->range.iomode,
5641b1f69b75SAndy Adamson 		res->type,
564235124a09SWeston Andros Adamson 		res->layoutp->len);
5643b1f69b75SAndy Adamson 
564435124a09SWeston Andros Adamson 	hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
564535124a09SWeston Andros Adamson 	recvd = req->rq_rcv_buf.len - hdrlen;
564635124a09SWeston Andros Adamson 	if (res->layoutp->len > recvd) {
564735124a09SWeston Andros Adamson 		dprintk("NFS: server cheating in layoutget reply: "
564835124a09SWeston Andros Adamson 				"layout len %u > recvd %u\n",
564935124a09SWeston Andros Adamson 				res->layoutp->len, recvd);
565035124a09SWeston Andros Adamson 		return -EINVAL;
565135124a09SWeston Andros Adamson 	}
565235124a09SWeston Andros Adamson 
565335124a09SWeston Andros Adamson 	xdr_read_pages(xdr, res->layoutp->len);
5654b1f69b75SAndy Adamson 
5655b1f69b75SAndy Adamson 	if (layout_count > 1) {
5656b1f69b75SAndy Adamson 		/* We only handle a length one array at the moment.  Any
5657b1f69b75SAndy Adamson 		 * further entries are just ignored.  Note that this means
5658b1f69b75SAndy Adamson 		 * the client may see a response that is less than the
5659b1f69b75SAndy Adamson 		 * minimum it requested.
5660b1f69b75SAndy Adamson 		 */
5661b1f69b75SAndy Adamson 		dprintk("%s: server responded with %d layouts, dropping tail\n",
5662b1f69b75SAndy Adamson 			__func__, layout_count);
5663b1f69b75SAndy Adamson 	}
5664b1f69b75SAndy Adamson 
5665b1f69b75SAndy Adamson 	return 0;
5666b1f69b75SAndy Adamson out_overflow:
5667b1f69b75SAndy Adamson 	print_overflow_msg(__func__, xdr);
5668b1f69b75SAndy Adamson 	return -EIO;
5669b1f69b75SAndy Adamson }
5670863a3c6cSAndy Adamson 
5671cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr,
5672cbe82603SBenny Halevy 			       struct nfs4_layoutreturn_res *res)
5673cbe82603SBenny Halevy {
5674cbe82603SBenny Halevy 	__be32 *p;
5675cbe82603SBenny Halevy 	int status;
5676cbe82603SBenny Halevy 
5677cbe82603SBenny Halevy 	status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5678cbe82603SBenny Halevy 	if (status)
5679cbe82603SBenny Halevy 		return status;
5680cbe82603SBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5681cbe82603SBenny Halevy 	if (unlikely(!p))
5682cbe82603SBenny Halevy 		goto out_overflow;
5683cbe82603SBenny Halevy 	res->lrs_present = be32_to_cpup(p);
5684cbe82603SBenny Halevy 	if (res->lrs_present)
5685cbe82603SBenny Halevy 		status = decode_stateid(xdr, &res->stateid);
5686cbe82603SBenny Halevy 	return status;
5687cbe82603SBenny Halevy out_overflow:
5688cbe82603SBenny Halevy 	print_overflow_msg(__func__, xdr);
5689cbe82603SBenny Halevy 	return -EIO;
5690cbe82603SBenny Halevy }
5691cbe82603SBenny Halevy 
5692863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr,
5693863a3c6cSAndy Adamson 			       struct rpc_rqst *req,
5694863a3c6cSAndy Adamson 			       struct nfs4_layoutcommit_res *res)
5695863a3c6cSAndy Adamson {
5696863a3c6cSAndy Adamson 	__be32 *p;
5697863a3c6cSAndy Adamson 	__u32 sizechanged;
5698863a3c6cSAndy Adamson 	int status;
5699863a3c6cSAndy Adamson 
5700863a3c6cSAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5701db29c089SAndy Adamson 	res->status = status;
5702863a3c6cSAndy Adamson 	if (status)
5703863a3c6cSAndy Adamson 		return status;
5704863a3c6cSAndy Adamson 
5705863a3c6cSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
5706863a3c6cSAndy Adamson 	if (unlikely(!p))
5707863a3c6cSAndy Adamson 		goto out_overflow;
5708863a3c6cSAndy Adamson 	sizechanged = be32_to_cpup(p);
5709863a3c6cSAndy Adamson 
5710863a3c6cSAndy Adamson 	if (sizechanged) {
5711863a3c6cSAndy Adamson 		/* throw away new size */
5712863a3c6cSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
5713863a3c6cSAndy Adamson 		if (unlikely(!p))
5714863a3c6cSAndy Adamson 			goto out_overflow;
5715863a3c6cSAndy Adamson 	}
5716863a3c6cSAndy Adamson 	return 0;
5717863a3c6cSAndy Adamson out_overflow:
5718863a3c6cSAndy Adamson 	print_overflow_msg(__func__, xdr);
5719863a3c6cSAndy Adamson 	return -EIO;
5720863a3c6cSAndy Adamson }
57217d974794SBryan Schumaker 
57227d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr,
57237d974794SBryan Schumaker 			       struct nfs41_test_stateid_res *res)
57247d974794SBryan Schumaker {
57257d974794SBryan Schumaker 	__be32 *p;
57267d974794SBryan Schumaker 	int status;
57277d974794SBryan Schumaker 	int num_res;
57287d974794SBryan Schumaker 
57297d974794SBryan Schumaker 	status = decode_op_hdr(xdr, OP_TEST_STATEID);
57307d974794SBryan Schumaker 	if (status)
57317d974794SBryan Schumaker 		return status;
57327d974794SBryan Schumaker 
57337d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
57347d974794SBryan Schumaker 	if (unlikely(!p))
57357d974794SBryan Schumaker 		goto out_overflow;
57367d974794SBryan Schumaker 	num_res = be32_to_cpup(p++);
57377d974794SBryan Schumaker 	if (num_res != 1)
57387d974794SBryan Schumaker 		goto out;
57397d974794SBryan Schumaker 
57407d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
57417d974794SBryan Schumaker 	if (unlikely(!p))
57427d974794SBryan Schumaker 		goto out_overflow;
57437d974794SBryan Schumaker 	res->status = be32_to_cpup(p++);
57441cab0652SBryan Schumaker 
57451cab0652SBryan Schumaker 	return status;
57467d974794SBryan Schumaker out_overflow:
57477d974794SBryan Schumaker 	print_overflow_msg(__func__, xdr);
57487d974794SBryan Schumaker out:
57497d974794SBryan Schumaker 	return -EIO;
57507d974794SBryan Schumaker }
57519aeda35fSBryan Schumaker 
57529aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr,
57539aeda35fSBryan Schumaker 			       struct nfs41_free_stateid_res *res)
57549aeda35fSBryan Schumaker {
57559aeda35fSBryan Schumaker 	__be32 *p;
57569aeda35fSBryan Schumaker 	int status;
57579aeda35fSBryan Schumaker 
57589aeda35fSBryan Schumaker 	status = decode_op_hdr(xdr, OP_FREE_STATEID);
57599aeda35fSBryan Schumaker 	if (status)
57609aeda35fSBryan Schumaker 		return status;
57619aeda35fSBryan Schumaker 
57629aeda35fSBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
57639aeda35fSBryan Schumaker 	if (unlikely(!p))
57649aeda35fSBryan Schumaker 		goto out_overflow;
57659aeda35fSBryan Schumaker 	res->status = be32_to_cpup(p++);
57669aeda35fSBryan Schumaker 	return res->status;
57679aeda35fSBryan Schumaker out_overflow:
57689aeda35fSBryan Schumaker 	print_overflow_msg(__func__, xdr);
57699aeda35fSBryan Schumaker 	return -EIO;
57709aeda35fSBryan Schumaker }
5771b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
5772b1f69b75SAndy Adamson 
57731da177e4SLinus Torvalds /*
577449c2559eSBenny Halevy  * END OF "GENERIC" DECODE ROUTINES.
577549c2559eSBenny Halevy  */
577649c2559eSBenny Halevy 
577749c2559eSBenny Halevy /*
57781da177e4SLinus Torvalds  * Decode OPEN_DOWNGRADE response
57791da177e4SLinus Torvalds  */
5780bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5781bf269551SChuck Lever 				       struct xdr_stream *xdr,
5782bf269551SChuck Lever 				       struct nfs_closeres *res)
57831da177e4SLinus Torvalds {
57841da177e4SLinus Torvalds 	struct compound_hdr hdr;
57851da177e4SLinus Torvalds 	int status;
57861da177e4SLinus Torvalds 
5787bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
57881da177e4SLinus Torvalds 	if (status)
57891da177e4SLinus Torvalds 		goto out;
5790bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
57919b7b9fccSAndy Adamson 	if (status)
57929b7b9fccSAndy Adamson 		goto out;
5793bf269551SChuck Lever 	status = decode_putfh(xdr);
57941da177e4SLinus Torvalds 	if (status)
57951da177e4SLinus Torvalds 		goto out;
5796bf269551SChuck Lever 	status = decode_open_downgrade(xdr, res);
5797516a6af6STrond Myklebust 	if (status != 0)
5798516a6af6STrond Myklebust 		goto out;
57996926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
58001da177e4SLinus Torvalds out:
58011da177e4SLinus Torvalds 	return status;
58021da177e4SLinus Torvalds }
58031da177e4SLinus Torvalds 
58041da177e4SLinus Torvalds /*
58051da177e4SLinus Torvalds  * Decode ACCESS response
58061da177e4SLinus Torvalds  */
5807bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5808bf269551SChuck Lever 			       struct nfs4_accessres *res)
58091da177e4SLinus Torvalds {
58101da177e4SLinus Torvalds 	struct compound_hdr hdr;
58111da177e4SLinus Torvalds 	int status;
58121da177e4SLinus Torvalds 
5813bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
58149b7b9fccSAndy Adamson 	if (status)
58159b7b9fccSAndy Adamson 		goto out;
5816bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
58179b7b9fccSAndy Adamson 	if (status)
58181da177e4SLinus Torvalds 		goto out;
5819bf269551SChuck Lever 	status = decode_putfh(xdr);
582076b32999STrond Myklebust 	if (status != 0)
582176b32999STrond Myklebust 		goto out;
5822bf269551SChuck Lever 	status = decode_access(xdr, res);
582376b32999STrond Myklebust 	if (status != 0)
582476b32999STrond Myklebust 		goto out;
58256926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
58261da177e4SLinus Torvalds out:
58271da177e4SLinus Torvalds 	return status;
58281da177e4SLinus Torvalds }
58291da177e4SLinus Torvalds 
58301da177e4SLinus Torvalds /*
58311da177e4SLinus Torvalds  * Decode LOOKUP response
58321da177e4SLinus Torvalds  */
5833bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5834bf269551SChuck Lever 			       struct nfs4_lookup_res *res)
58351da177e4SLinus Torvalds {
58361da177e4SLinus Torvalds 	struct compound_hdr hdr;
58371da177e4SLinus Torvalds 	int status;
58381da177e4SLinus Torvalds 
5839bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
58409b7b9fccSAndy Adamson 	if (status)
58419b7b9fccSAndy Adamson 		goto out;
5842bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
58439b7b9fccSAndy Adamson 	if (status)
58441da177e4SLinus Torvalds 		goto out;
5845bf269551SChuck Lever 	status = decode_putfh(xdr);
5846bf269551SChuck Lever 	if (status)
58471da177e4SLinus Torvalds 		goto out;
5848bf269551SChuck Lever 	status = decode_lookup(xdr);
5849bf269551SChuck Lever 	if (status)
58501da177e4SLinus Torvalds 		goto out;
5851bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
5852bf269551SChuck Lever 	if (status)
58531da177e4SLinus Torvalds 		goto out;
58546926afd1STrond Myklebust 	status = decode_getfattr(xdr, res->fattr, res->server);
58551da177e4SLinus Torvalds out:
58561da177e4SLinus Torvalds 	return status;
58571da177e4SLinus Torvalds }
58581da177e4SLinus Torvalds 
58591da177e4SLinus Torvalds /*
58601da177e4SLinus Torvalds  * Decode LOOKUP_ROOT response
58611da177e4SLinus Torvalds  */
5862bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5863bf269551SChuck Lever 				    struct xdr_stream *xdr,
5864bf269551SChuck Lever 				    struct nfs4_lookup_res *res)
58651da177e4SLinus Torvalds {
58661da177e4SLinus Torvalds 	struct compound_hdr hdr;
58671da177e4SLinus Torvalds 	int status;
58681da177e4SLinus Torvalds 
5869bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
58709b7b9fccSAndy Adamson 	if (status)
58719b7b9fccSAndy Adamson 		goto out;
5872bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
58739b7b9fccSAndy Adamson 	if (status)
58741da177e4SLinus Torvalds 		goto out;
5875bf269551SChuck Lever 	status = decode_putrootfh(xdr);
5876bf269551SChuck Lever 	if (status)
58771da177e4SLinus Torvalds 		goto out;
5878bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
5879bf269551SChuck Lever 	if (status == 0)
58806926afd1STrond Myklebust 		status = decode_getfattr(xdr, res->fattr, res->server);
58811da177e4SLinus Torvalds out:
58821da177e4SLinus Torvalds 	return status;
58831da177e4SLinus Torvalds }
58841da177e4SLinus Torvalds 
58851da177e4SLinus Torvalds /*
58861da177e4SLinus Torvalds  * Decode REMOVE response
58871da177e4SLinus Torvalds  */
5888bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5889bf269551SChuck Lever 			       struct nfs_removeres *res)
58901da177e4SLinus Torvalds {
58911da177e4SLinus Torvalds 	struct compound_hdr hdr;
58921da177e4SLinus Torvalds 	int status;
58931da177e4SLinus Torvalds 
5894bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
58959b7b9fccSAndy Adamson 	if (status)
58969b7b9fccSAndy Adamson 		goto out;
5897bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
58989b7b9fccSAndy Adamson 	if (status)
58991da177e4SLinus Torvalds 		goto out;
5900bf269551SChuck Lever 	status = decode_putfh(xdr);
5901bf269551SChuck Lever 	if (status)
590216e42959STrond Myklebust 		goto out;
5903bf269551SChuck Lever 	status = decode_remove(xdr, &res->cinfo);
5904bf269551SChuck Lever 	if (status)
590516e42959STrond Myklebust 		goto out;
59066926afd1STrond Myklebust 	decode_getfattr(xdr, res->dir_attr, res->server);
59071da177e4SLinus Torvalds out:
59081da177e4SLinus Torvalds 	return status;
59091da177e4SLinus Torvalds }
59101da177e4SLinus Torvalds 
59111da177e4SLinus Torvalds /*
59121da177e4SLinus Torvalds  * Decode RENAME response
59131da177e4SLinus Torvalds  */
5914bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5915bf269551SChuck Lever 			       struct nfs_renameres *res)
59161da177e4SLinus Torvalds {
59171da177e4SLinus Torvalds 	struct compound_hdr hdr;
59181da177e4SLinus Torvalds 	int status;
59191da177e4SLinus Torvalds 
5920bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
59219b7b9fccSAndy Adamson 	if (status)
59229b7b9fccSAndy Adamson 		goto out;
5923bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
59249b7b9fccSAndy Adamson 	if (status)
59251da177e4SLinus Torvalds 		goto out;
5926bf269551SChuck Lever 	status = decode_putfh(xdr);
5927bf269551SChuck Lever 	if (status)
59281da177e4SLinus Torvalds 		goto out;
5929bf269551SChuck Lever 	status = decode_savefh(xdr);
5930bf269551SChuck Lever 	if (status)
59311da177e4SLinus Torvalds 		goto out;
5932bf269551SChuck Lever 	status = decode_putfh(xdr);
5933bf269551SChuck Lever 	if (status)
59341da177e4SLinus Torvalds 		goto out;
5935bf269551SChuck Lever 	status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5936bf269551SChuck Lever 	if (status)
59376caf2c82STrond Myklebust 		goto out;
59386caf2c82STrond Myklebust 	/* Current FH is target directory */
59396926afd1STrond Myklebust 	if (decode_getfattr(xdr, res->new_fattr, res->server))
59406caf2c82STrond Myklebust 		goto out;
5941bf269551SChuck Lever 	status = decode_restorefh(xdr);
5942bf269551SChuck Lever 	if (status)
59436caf2c82STrond Myklebust 		goto out;
59446926afd1STrond Myklebust 	decode_getfattr(xdr, res->old_fattr, res->server);
59451da177e4SLinus Torvalds out:
59461da177e4SLinus Torvalds 	return status;
59471da177e4SLinus Torvalds }
59481da177e4SLinus Torvalds 
59491da177e4SLinus Torvalds /*
59501da177e4SLinus Torvalds  * Decode LINK response
59511da177e4SLinus Torvalds  */
5952bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5953bf269551SChuck Lever 			     struct nfs4_link_res *res)
59541da177e4SLinus Torvalds {
59551da177e4SLinus Torvalds 	struct compound_hdr hdr;
59561da177e4SLinus Torvalds 	int status;
59571da177e4SLinus Torvalds 
5958bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
59599b7b9fccSAndy Adamson 	if (status)
59609b7b9fccSAndy Adamson 		goto out;
5961bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
59629b7b9fccSAndy Adamson 	if (status)
59631da177e4SLinus Torvalds 		goto out;
5964bf269551SChuck Lever 	status = decode_putfh(xdr);
5965bf269551SChuck Lever 	if (status)
59661da177e4SLinus Torvalds 		goto out;
5967bf269551SChuck Lever 	status = decode_savefh(xdr);
5968bf269551SChuck Lever 	if (status)
59691da177e4SLinus Torvalds 		goto out;
5970bf269551SChuck Lever 	status = decode_putfh(xdr);
5971bf269551SChuck Lever 	if (status)
59721da177e4SLinus Torvalds 		goto out;
5973bf269551SChuck Lever 	status = decode_link(xdr, &res->cinfo);
5974bf269551SChuck Lever 	if (status)
597591ba2eeeSTrond Myklebust 		goto out;
597691ba2eeeSTrond Myklebust 	/*
597791ba2eeeSTrond Myklebust 	 * Note order: OP_LINK leaves the directory as the current
597891ba2eeeSTrond Myklebust 	 *             filehandle.
597991ba2eeeSTrond Myklebust 	 */
59806926afd1STrond Myklebust 	if (decode_getfattr(xdr, res->dir_attr, res->server))
598191ba2eeeSTrond Myklebust 		goto out;
5982bf269551SChuck Lever 	status = decode_restorefh(xdr);
5983bf269551SChuck Lever 	if (status)
598491ba2eeeSTrond Myklebust 		goto out;
59856926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
59861da177e4SLinus Torvalds out:
59871da177e4SLinus Torvalds 	return status;
59881da177e4SLinus Torvalds }
59891da177e4SLinus Torvalds 
59901da177e4SLinus Torvalds /*
59911da177e4SLinus Torvalds  * Decode CREATE response
59921da177e4SLinus Torvalds  */
5993bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5994bf269551SChuck Lever 			       struct nfs4_create_res *res)
59951da177e4SLinus Torvalds {
59961da177e4SLinus Torvalds 	struct compound_hdr hdr;
59971da177e4SLinus Torvalds 	int status;
59981da177e4SLinus Torvalds 
5999bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
60009b7b9fccSAndy Adamson 	if (status)
60019b7b9fccSAndy Adamson 		goto out;
6002bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
60039b7b9fccSAndy Adamson 	if (status)
60041da177e4SLinus Torvalds 		goto out;
6005bf269551SChuck Lever 	status = decode_putfh(xdr);
6006bf269551SChuck Lever 	if (status)
60071da177e4SLinus Torvalds 		goto out;
6008bf269551SChuck Lever 	status = decode_savefh(xdr);
6009bf269551SChuck Lever 	if (status)
601056ae19f3STrond Myklebust 		goto out;
6011bf269551SChuck Lever 	status = decode_create(xdr, &res->dir_cinfo);
6012bf269551SChuck Lever 	if (status)
60131da177e4SLinus Torvalds 		goto out;
6014bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6015bf269551SChuck Lever 	if (status)
60161da177e4SLinus Torvalds 		goto out;
60176926afd1STrond Myklebust 	if (decode_getfattr(xdr, res->fattr, res->server))
601856ae19f3STrond Myklebust 		goto out;
6019bf269551SChuck Lever 	status = decode_restorefh(xdr);
6020bf269551SChuck Lever 	if (status)
602156ae19f3STrond Myklebust 		goto out;
60226926afd1STrond Myklebust 	decode_getfattr(xdr, res->dir_fattr, res->server);
60231da177e4SLinus Torvalds out:
60241da177e4SLinus Torvalds 	return status;
60251da177e4SLinus Torvalds }
60261da177e4SLinus Torvalds 
60271da177e4SLinus Torvalds /*
60281da177e4SLinus Torvalds  * Decode SYMLINK response
60291da177e4SLinus Torvalds  */
6030bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6031bf269551SChuck Lever 				struct nfs4_create_res *res)
60321da177e4SLinus Torvalds {
6033bf269551SChuck Lever 	return nfs4_xdr_dec_create(rqstp, xdr, res);
60341da177e4SLinus Torvalds }
60351da177e4SLinus Torvalds 
60361da177e4SLinus Torvalds /*
60371da177e4SLinus Torvalds  * Decode GETATTR response
60381da177e4SLinus Torvalds  */
6039bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6040bf269551SChuck Lever 				struct nfs4_getattr_res *res)
60411da177e4SLinus Torvalds {
60421da177e4SLinus Torvalds 	struct compound_hdr hdr;
60431da177e4SLinus Torvalds 	int status;
60441da177e4SLinus Torvalds 
6045bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
60461da177e4SLinus Torvalds 	if (status)
60471da177e4SLinus Torvalds 		goto out;
6048bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
60499b7b9fccSAndy Adamson 	if (status)
60509b7b9fccSAndy Adamson 		goto out;
6051bf269551SChuck Lever 	status = decode_putfh(xdr);
60521da177e4SLinus Torvalds 	if (status)
60531da177e4SLinus Torvalds 		goto out;
60546926afd1STrond Myklebust 	status = decode_getfattr(xdr, res->fattr, res->server);
60551da177e4SLinus Torvalds out:
60561da177e4SLinus Torvalds 	return status;
60571da177e4SLinus Torvalds }
60581da177e4SLinus Torvalds 
605923ec6965SJ. Bruce Fields /*
606023ec6965SJ. Bruce Fields  * Encode an SETACL request
606123ec6965SJ. Bruce Fields  */
60629f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
60639f06c719SChuck Lever 				struct nfs_setaclargs *args)
606423ec6965SJ. Bruce Fields {
606523ec6965SJ. Bruce Fields 	struct compound_hdr hdr = {
606666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
606723ec6965SJ. Bruce Fields 	};
606823ec6965SJ. Bruce Fields 
60699f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
60709f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
60719f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
60729f06c719SChuck Lever 	encode_setacl(xdr, args, &hdr);
6073d017931cSAndy Adamson 	encode_nops(&hdr);
607423ec6965SJ. Bruce Fields }
607505d564feSAndy Adamson 
607623ec6965SJ. Bruce Fields /*
607723ec6965SJ. Bruce Fields  * Decode SETACL response
607823ec6965SJ. Bruce Fields  */
607923ec6965SJ. Bruce Fields static int
6080bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
608173c403a9SBenny Halevy 		    struct nfs_setaclres *res)
608223ec6965SJ. Bruce Fields {
608323ec6965SJ. Bruce Fields 	struct compound_hdr hdr;
608423ec6965SJ. Bruce Fields 	int status;
608523ec6965SJ. Bruce Fields 
6086bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
608723ec6965SJ. Bruce Fields 	if (status)
608823ec6965SJ. Bruce Fields 		goto out;
6089bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
60909b7b9fccSAndy Adamson 	if (status)
60919b7b9fccSAndy Adamson 		goto out;
6092bf269551SChuck Lever 	status = decode_putfh(xdr);
609323ec6965SJ. Bruce Fields 	if (status)
609423ec6965SJ. Bruce Fields 		goto out;
6095bf269551SChuck Lever 	status = decode_setattr(xdr);
609623ec6965SJ. Bruce Fields out:
609723ec6965SJ. Bruce Fields 	return status;
609823ec6965SJ. Bruce Fields }
60991da177e4SLinus Torvalds 
61001da177e4SLinus Torvalds /*
6101029d105eSJ. Bruce Fields  * Decode GETACL response
6102029d105eSJ. Bruce Fields  */
6103029d105eSJ. Bruce Fields static int
6104bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6105663c79b3SBenny Halevy 		    struct nfs_getaclres *res)
6106029d105eSJ. Bruce Fields {
6107029d105eSJ. Bruce Fields 	struct compound_hdr hdr;
6108029d105eSJ. Bruce Fields 	int status;
6109029d105eSJ. Bruce Fields 
6110bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6111029d105eSJ. Bruce Fields 	if (status)
6112029d105eSJ. 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);
6117029d105eSJ. Bruce Fields 	if (status)
6118029d105eSJ. Bruce Fields 		goto out;
6119bf118a34SAndy Adamson 	status = decode_getacl(xdr, rqstp, res);
6120029d105eSJ. Bruce Fields 
6121029d105eSJ. Bruce Fields out:
6122029d105eSJ. Bruce Fields 	return status;
6123029d105eSJ. Bruce Fields }
6124029d105eSJ. Bruce Fields 
6125029d105eSJ. Bruce Fields /*
61261da177e4SLinus Torvalds  * Decode CLOSE response
61271da177e4SLinus Torvalds  */
6128bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6129bf269551SChuck Lever 			      struct nfs_closeres *res)
61301da177e4SLinus Torvalds {
61311da177e4SLinus Torvalds 	struct compound_hdr hdr;
61321da177e4SLinus Torvalds 	int status;
61331da177e4SLinus Torvalds 
6134bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61351da177e4SLinus Torvalds 	if (status)
61361da177e4SLinus Torvalds 		goto out;
6137bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61389b7b9fccSAndy Adamson 	if (status)
61399b7b9fccSAndy Adamson 		goto out;
6140bf269551SChuck Lever 	status = decode_putfh(xdr);
61411da177e4SLinus Torvalds 	if (status)
61421da177e4SLinus Torvalds 		goto out;
6143bf269551SChuck Lever 	status = decode_close(xdr, res);
6144516a6af6STrond Myklebust 	if (status != 0)
6145516a6af6STrond Myklebust 		goto out;
6146516a6af6STrond Myklebust 	/*
6147516a6af6STrond Myklebust 	 * Note: Server may do delete on close for this file
6148516a6af6STrond Myklebust 	 * 	in which case the getattr call will fail with
6149516a6af6STrond Myklebust 	 * 	an ESTALE error. Shouldn't be a problem,
6150516a6af6STrond Myklebust 	 * 	though, since fattr->valid will remain unset.
6151516a6af6STrond Myklebust 	 */
61526926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
61531da177e4SLinus Torvalds out:
61541da177e4SLinus Torvalds 	return status;
61551da177e4SLinus Torvalds }
61561da177e4SLinus Torvalds 
61571da177e4SLinus Torvalds /*
61581da177e4SLinus Torvalds  * Decode OPEN response
61591da177e4SLinus Torvalds  */
6160bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6161bf269551SChuck Lever 			     struct nfs_openres *res)
61621da177e4SLinus Torvalds {
61631da177e4SLinus Torvalds 	struct compound_hdr hdr;
61641da177e4SLinus Torvalds 	int status;
61651da177e4SLinus Torvalds 
6166bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61671da177e4SLinus Torvalds 	if (status)
61681da177e4SLinus Torvalds 		goto out;
6169bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61709b7b9fccSAndy Adamson 	if (status)
61719b7b9fccSAndy Adamson 		goto out;
6172bf269551SChuck Lever 	status = decode_putfh(xdr);
61731da177e4SLinus Torvalds 	if (status)
61741da177e4SLinus Torvalds 		goto out;
6175bf269551SChuck Lever 	status = decode_savefh(xdr);
617656ae19f3STrond Myklebust 	if (status)
617756ae19f3STrond Myklebust 		goto out;
6178bf269551SChuck Lever 	status = decode_open(xdr, res);
61791da177e4SLinus Torvalds 	if (status)
61801da177e4SLinus Torvalds 		goto out;
6181bf269551SChuck Lever 	if (decode_getfh(xdr, &res->fh) != 0)
61821da177e4SLinus Torvalds 		goto out;
61836926afd1STrond Myklebust 	if (decode_getfattr(xdr, res->f_attr, res->server) != 0)
618456ae19f3STrond Myklebust 		goto out;
6185bf269551SChuck Lever 	if (decode_restorefh(xdr) != 0)
618656ae19f3STrond Myklebust 		goto out;
61876926afd1STrond Myklebust 	decode_getfattr(xdr, res->dir_attr, res->server);
61881da177e4SLinus Torvalds out:
61891da177e4SLinus Torvalds 	return status;
61901da177e4SLinus Torvalds }
61911da177e4SLinus Torvalds 
61921da177e4SLinus Torvalds /*
61931da177e4SLinus Torvalds  * Decode OPEN_CONFIRM response
61941da177e4SLinus Torvalds  */
6195bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6196bf269551SChuck Lever 				     struct xdr_stream *xdr,
6197bf269551SChuck Lever 				     struct nfs_open_confirmres *res)
61981da177e4SLinus Torvalds {
61991da177e4SLinus Torvalds 	struct compound_hdr hdr;
62001da177e4SLinus Torvalds 	int status;
62011da177e4SLinus Torvalds 
6202bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62031da177e4SLinus Torvalds 	if (status)
62041da177e4SLinus Torvalds 		goto out;
6205bf269551SChuck Lever 	status = decode_putfh(xdr);
62061da177e4SLinus Torvalds 	if (status)
62071da177e4SLinus Torvalds 		goto out;
6208bf269551SChuck Lever 	status = decode_open_confirm(xdr, res);
62091da177e4SLinus Torvalds out:
62101da177e4SLinus Torvalds 	return status;
62111da177e4SLinus Torvalds }
62121da177e4SLinus Torvalds 
62131da177e4SLinus Torvalds /*
62141da177e4SLinus Torvalds  * Decode OPEN response
62151da177e4SLinus Torvalds  */
6216bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6217bf269551SChuck Lever 				    struct xdr_stream *xdr,
6218bf269551SChuck Lever 				    struct nfs_openres *res)
62191da177e4SLinus Torvalds {
62201da177e4SLinus Torvalds 	struct compound_hdr hdr;
62211da177e4SLinus Torvalds 	int status;
62221da177e4SLinus Torvalds 
6223bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62241da177e4SLinus Torvalds 	if (status)
62251da177e4SLinus Torvalds 		goto out;
6226bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62279b7b9fccSAndy Adamson 	if (status)
62289b7b9fccSAndy Adamson 		goto out;
6229bf269551SChuck Lever 	status = decode_putfh(xdr);
62301da177e4SLinus Torvalds 	if (status)
62311da177e4SLinus Torvalds 		goto out;
6232bf269551SChuck Lever 	status = decode_open(xdr, res);
6233864472e9STrond Myklebust 	if (status)
6234864472e9STrond Myklebust 		goto out;
62356926afd1STrond Myklebust 	decode_getfattr(xdr, res->f_attr, res->server);
62361da177e4SLinus Torvalds out:
62371da177e4SLinus Torvalds 	return status;
62381da177e4SLinus Torvalds }
62391da177e4SLinus Torvalds 
62401da177e4SLinus Torvalds /*
62411da177e4SLinus Torvalds  * Decode SETATTR response
62421da177e4SLinus Torvalds  */
6243bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6244bf269551SChuck Lever 				struct xdr_stream *xdr,
6245bf269551SChuck Lever 				struct nfs_setattrres *res)
62461da177e4SLinus Torvalds {
62471da177e4SLinus Torvalds 	struct compound_hdr hdr;
62481da177e4SLinus Torvalds 	int status;
62491da177e4SLinus Torvalds 
6250bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62511da177e4SLinus Torvalds 	if (status)
62521da177e4SLinus Torvalds 		goto out;
6253bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62549b7b9fccSAndy Adamson 	if (status)
62559b7b9fccSAndy Adamson 		goto out;
6256bf269551SChuck Lever 	status = decode_putfh(xdr);
62571da177e4SLinus Torvalds 	if (status)
62581da177e4SLinus Torvalds 		goto out;
6259bf269551SChuck Lever 	status = decode_setattr(xdr);
62601da177e4SLinus Torvalds 	if (status)
62611da177e4SLinus Torvalds 		goto out;
62626926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
62631da177e4SLinus Torvalds out:
62641da177e4SLinus Torvalds 	return status;
62651da177e4SLinus Torvalds }
62661da177e4SLinus Torvalds 
62671da177e4SLinus Torvalds /*
62681da177e4SLinus Torvalds  * Decode LOCK response
62691da177e4SLinus Torvalds  */
6270bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6271bf269551SChuck Lever 			     struct nfs_lock_res *res)
62721da177e4SLinus Torvalds {
62731da177e4SLinus Torvalds 	struct compound_hdr hdr;
62741da177e4SLinus Torvalds 	int status;
62751da177e4SLinus Torvalds 
6276bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62771da177e4SLinus Torvalds 	if (status)
62781da177e4SLinus Torvalds 		goto out;
6279bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62809b7b9fccSAndy Adamson 	if (status)
62819b7b9fccSAndy Adamson 		goto out;
6282bf269551SChuck Lever 	status = decode_putfh(xdr);
62831da177e4SLinus Torvalds 	if (status)
62841da177e4SLinus Torvalds 		goto out;
6285bf269551SChuck Lever 	status = decode_lock(xdr, res);
62861da177e4SLinus Torvalds out:
62871da177e4SLinus Torvalds 	return status;
62881da177e4SLinus Torvalds }
62891da177e4SLinus Torvalds 
62901da177e4SLinus Torvalds /*
62911da177e4SLinus Torvalds  * Decode LOCKT response
62921da177e4SLinus Torvalds  */
6293bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6294bf269551SChuck Lever 			      struct nfs_lockt_res *res)
62951da177e4SLinus Torvalds {
62961da177e4SLinus Torvalds 	struct compound_hdr hdr;
62971da177e4SLinus Torvalds 	int status;
62981da177e4SLinus Torvalds 
6299bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63001da177e4SLinus Torvalds 	if (status)
63011da177e4SLinus Torvalds 		goto out;
6302bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63039b7b9fccSAndy Adamson 	if (status)
63049b7b9fccSAndy Adamson 		goto out;
6305bf269551SChuck Lever 	status = decode_putfh(xdr);
63061da177e4SLinus Torvalds 	if (status)
63071da177e4SLinus Torvalds 		goto out;
6308bf269551SChuck Lever 	status = decode_lockt(xdr, res);
63091da177e4SLinus Torvalds out:
63101da177e4SLinus Torvalds 	return status;
63111da177e4SLinus Torvalds }
63121da177e4SLinus Torvalds 
63131da177e4SLinus Torvalds /*
63141da177e4SLinus Torvalds  * Decode LOCKU response
63151da177e4SLinus Torvalds  */
6316bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6317bf269551SChuck Lever 			      struct nfs_locku_res *res)
63181da177e4SLinus Torvalds {
63191da177e4SLinus Torvalds 	struct compound_hdr hdr;
63201da177e4SLinus Torvalds 	int status;
63211da177e4SLinus Torvalds 
6322bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63231da177e4SLinus Torvalds 	if (status)
63241da177e4SLinus Torvalds 		goto out;
6325bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63269b7b9fccSAndy Adamson 	if (status)
63279b7b9fccSAndy Adamson 		goto out;
6328bf269551SChuck Lever 	status = decode_putfh(xdr);
63291da177e4SLinus Torvalds 	if (status)
63301da177e4SLinus Torvalds 		goto out;
6331bf269551SChuck Lever 	status = decode_locku(xdr, res);
63321da177e4SLinus Torvalds out:
63331da177e4SLinus Torvalds 	return status;
63341da177e4SLinus Torvalds }
63351da177e4SLinus Torvalds 
6336bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6337bf269551SChuck Lever 					  struct xdr_stream *xdr, void *dummy)
6338d3c7b7ccSTrond Myklebust {
6339d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr;
6340d3c7b7ccSTrond Myklebust 	int status;
6341d3c7b7ccSTrond Myklebust 
6342bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6343d3c7b7ccSTrond Myklebust 	if (!status)
6344bf269551SChuck Lever 		status = decode_release_lockowner(xdr);
6345d3c7b7ccSTrond Myklebust 	return status;
6346d3c7b7ccSTrond Myklebust }
6347d3c7b7ccSTrond Myklebust 
63481da177e4SLinus Torvalds /*
63491da177e4SLinus Torvalds  * Decode READLINK response
63501da177e4SLinus Torvalds  */
6351bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6352bf269551SChuck Lever 				 struct xdr_stream *xdr,
6353f50c7000SBenny Halevy 				 struct nfs4_readlink_res *res)
63541da177e4SLinus Torvalds {
63551da177e4SLinus Torvalds 	struct compound_hdr hdr;
63561da177e4SLinus Torvalds 	int status;
63571da177e4SLinus Torvalds 
6358bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63591da177e4SLinus Torvalds 	if (status)
63601da177e4SLinus Torvalds 		goto out;
6361bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63629b7b9fccSAndy Adamson 	if (status)
63639b7b9fccSAndy Adamson 		goto out;
6364bf269551SChuck Lever 	status = decode_putfh(xdr);
63651da177e4SLinus Torvalds 	if (status)
63661da177e4SLinus Torvalds 		goto out;
6367bf269551SChuck Lever 	status = decode_readlink(xdr, rqstp);
63681da177e4SLinus Torvalds out:
63691da177e4SLinus Torvalds 	return status;
63701da177e4SLinus Torvalds }
63711da177e4SLinus Torvalds 
63721da177e4SLinus Torvalds /*
63731da177e4SLinus Torvalds  * Decode READDIR response
63741da177e4SLinus Torvalds  */
6375bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6376bf269551SChuck Lever 				struct nfs4_readdir_res *res)
63771da177e4SLinus Torvalds {
63781da177e4SLinus Torvalds 	struct compound_hdr hdr;
63791da177e4SLinus Torvalds 	int status;
63801da177e4SLinus Torvalds 
6381bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63821da177e4SLinus Torvalds 	if (status)
63831da177e4SLinus Torvalds 		goto out;
6384bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63859b7b9fccSAndy Adamson 	if (status)
63869b7b9fccSAndy Adamson 		goto out;
6387bf269551SChuck Lever 	status = decode_putfh(xdr);
63881da177e4SLinus Torvalds 	if (status)
63891da177e4SLinus Torvalds 		goto out;
6390bf269551SChuck Lever 	status = decode_readdir(xdr, rqstp, res);
63911da177e4SLinus Torvalds out:
63921da177e4SLinus Torvalds 	return status;
63931da177e4SLinus Torvalds }
63941da177e4SLinus Torvalds 
63951da177e4SLinus Torvalds /*
63961da177e4SLinus Torvalds  * Decode Read response
63971da177e4SLinus Torvalds  */
6398bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6399bf269551SChuck Lever 			     struct nfs_readres *res)
64001da177e4SLinus Torvalds {
64011da177e4SLinus Torvalds 	struct compound_hdr hdr;
64021da177e4SLinus Torvalds 	int status;
64031da177e4SLinus Torvalds 
6404bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64051da177e4SLinus Torvalds 	if (status)
64061da177e4SLinus Torvalds 		goto out;
6407bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64089b7b9fccSAndy Adamson 	if (status)
64099b7b9fccSAndy Adamson 		goto out;
6410bf269551SChuck Lever 	status = decode_putfh(xdr);
64111da177e4SLinus Torvalds 	if (status)
64121da177e4SLinus Torvalds 		goto out;
6413bf269551SChuck Lever 	status = decode_read(xdr, rqstp, res);
64141da177e4SLinus Torvalds 	if (!status)
64151da177e4SLinus Torvalds 		status = res->count;
64161da177e4SLinus Torvalds out:
64171da177e4SLinus Torvalds 	return status;
64181da177e4SLinus Torvalds }
64191da177e4SLinus Torvalds 
64201da177e4SLinus Torvalds /*
64211da177e4SLinus Torvalds  * Decode WRITE response
64221da177e4SLinus Torvalds  */
6423bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6424bf269551SChuck Lever 			      struct nfs_writeres *res)
64251da177e4SLinus Torvalds {
64261da177e4SLinus Torvalds 	struct compound_hdr hdr;
64271da177e4SLinus Torvalds 	int status;
64281da177e4SLinus Torvalds 
6429bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64301da177e4SLinus Torvalds 	if (status)
64311da177e4SLinus Torvalds 		goto out;
6432bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64339b7b9fccSAndy Adamson 	if (status)
64349b7b9fccSAndy Adamson 		goto out;
6435bf269551SChuck Lever 	status = decode_putfh(xdr);
64361da177e4SLinus Torvalds 	if (status)
64371da177e4SLinus Torvalds 		goto out;
6438bf269551SChuck Lever 	status = decode_write(xdr, res);
64394f9838c7STrond Myklebust 	if (status)
64404f9838c7STrond Myklebust 		goto out;
64417ffd1064SFred Isaman 	if (res->fattr)
64426926afd1STrond Myklebust 		decode_getfattr(xdr, res->fattr, res->server);
64431da177e4SLinus Torvalds 	if (!status)
64441da177e4SLinus Torvalds 		status = res->count;
64451da177e4SLinus Torvalds out:
64461da177e4SLinus Torvalds 	return status;
64471da177e4SLinus Torvalds }
64481da177e4SLinus Torvalds 
64491da177e4SLinus Torvalds /*
64501da177e4SLinus Torvalds  * Decode COMMIT response
64511da177e4SLinus Torvalds  */
6452bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6453bf269551SChuck Lever 			       struct nfs_writeres *res)
64541da177e4SLinus Torvalds {
64551da177e4SLinus Torvalds 	struct compound_hdr hdr;
64561da177e4SLinus Torvalds 	int status;
64571da177e4SLinus Torvalds 
6458bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64591da177e4SLinus Torvalds 	if (status)
64601da177e4SLinus Torvalds 		goto out;
6461bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64629b7b9fccSAndy Adamson 	if (status)
64639b7b9fccSAndy Adamson 		goto out;
6464bf269551SChuck Lever 	status = decode_putfh(xdr);
64651da177e4SLinus Torvalds 	if (status)
64661da177e4SLinus Torvalds 		goto out;
6467bf269551SChuck Lever 	status = decode_commit(xdr, res);
64684f9838c7STrond Myklebust 	if (status)
64694f9838c7STrond Myklebust 		goto out;
6470988b6dceSFred Isaman 	if (res->fattr)
64716926afd1STrond Myklebust 		decode_getfattr(xdr, res->fattr, res->server);
64721da177e4SLinus Torvalds out:
64731da177e4SLinus Torvalds 	return status;
64741da177e4SLinus Torvalds }
64751da177e4SLinus Torvalds 
64761da177e4SLinus Torvalds /*
64778b173218SRicardo Labiaga  * Decode FSINFO response
64781da177e4SLinus Torvalds  */
6479bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
64803dda5e43SBenny Halevy 			       struct nfs4_fsinfo_res *res)
64811da177e4SLinus Torvalds {
64821da177e4SLinus Torvalds 	struct compound_hdr hdr;
64831da177e4SLinus Torvalds 	int status;
64841da177e4SLinus Torvalds 
6485bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64861da177e4SLinus Torvalds 	if (!status)
6487bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
64889b7b9fccSAndy Adamson 	if (!status)
6489bf269551SChuck Lever 		status = decode_putfh(xdr);
64901da177e4SLinus Torvalds 	if (!status)
6491bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->fsinfo);
64921da177e4SLinus Torvalds 	return status;
64931da177e4SLinus Torvalds }
64941da177e4SLinus Torvalds 
64951da177e4SLinus Torvalds /*
64968b173218SRicardo Labiaga  * Decode PATHCONF response
64971da177e4SLinus Torvalds  */
6498bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6499d45b2989SBenny Halevy 				 struct nfs4_pathconf_res *res)
65001da177e4SLinus Torvalds {
65011da177e4SLinus Torvalds 	struct compound_hdr hdr;
65021da177e4SLinus Torvalds 	int status;
65031da177e4SLinus Torvalds 
6504bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65051da177e4SLinus Torvalds 	if (!status)
6506bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
65079b7b9fccSAndy Adamson 	if (!status)
6508bf269551SChuck Lever 		status = decode_putfh(xdr);
65091da177e4SLinus Torvalds 	if (!status)
6510bf269551SChuck Lever 		status = decode_pathconf(xdr, res->pathconf);
65111da177e4SLinus Torvalds 	return status;
65121da177e4SLinus Torvalds }
65131da177e4SLinus Torvalds 
65141da177e4SLinus Torvalds /*
65158b173218SRicardo Labiaga  * Decode STATFS response
65161da177e4SLinus Torvalds  */
6517bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
651824ad148aSBenny Halevy 			       struct nfs4_statfs_res *res)
65191da177e4SLinus Torvalds {
65201da177e4SLinus Torvalds 	struct compound_hdr hdr;
65211da177e4SLinus Torvalds 	int status;
65221da177e4SLinus Torvalds 
6523bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65241da177e4SLinus Torvalds 	if (!status)
6525bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
65269b7b9fccSAndy Adamson 	if (!status)
6527bf269551SChuck Lever 		status = decode_putfh(xdr);
65281da177e4SLinus Torvalds 	if (!status)
6529bf269551SChuck Lever 		status = decode_statfs(xdr, res->fsstat);
65301da177e4SLinus Torvalds 	return status;
65311da177e4SLinus Torvalds }
65321da177e4SLinus Torvalds 
65331da177e4SLinus Torvalds /*
65348b173218SRicardo Labiaga  * Decode GETATTR_BITMAP response
65351da177e4SLinus Torvalds  */
6536bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6537bf269551SChuck Lever 				    struct xdr_stream *xdr,
6538bf269551SChuck Lever 				    struct nfs4_server_caps_res *res)
65391da177e4SLinus Torvalds {
65401da177e4SLinus Torvalds 	struct compound_hdr hdr;
65411da177e4SLinus Torvalds 	int status;
65421da177e4SLinus Torvalds 
6543bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65449b7b9fccSAndy Adamson 	if (status)
65459b7b9fccSAndy Adamson 		goto out;
6546bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
65479b7b9fccSAndy Adamson 	if (status)
65481da177e4SLinus Torvalds 		goto out;
6549bf269551SChuck Lever 	status = decode_putfh(xdr);
6550bf269551SChuck Lever 	if (status)
65511da177e4SLinus Torvalds 		goto out;
6552bf269551SChuck Lever 	status = decode_server_caps(xdr, res);
65531da177e4SLinus Torvalds out:
65541da177e4SLinus Torvalds 	return status;
65551da177e4SLinus Torvalds }
65561da177e4SLinus Torvalds 
65571da177e4SLinus Torvalds /*
65581da177e4SLinus Torvalds  * Decode RENEW response
65591da177e4SLinus Torvalds  */
6560bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6561bf269551SChuck Lever 			      void *__unused)
65621da177e4SLinus Torvalds {
65631da177e4SLinus Torvalds 	struct compound_hdr hdr;
65641da177e4SLinus Torvalds 	int status;
65651da177e4SLinus Torvalds 
6566bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65671da177e4SLinus Torvalds 	if (!status)
6568bf269551SChuck Lever 		status = decode_renew(xdr);
65691da177e4SLinus Torvalds 	return status;
65701da177e4SLinus Torvalds }
65711da177e4SLinus Torvalds 
65721da177e4SLinus Torvalds /*
65738b173218SRicardo Labiaga  * Decode SETCLIENTID response
65741da177e4SLinus Torvalds  */
6575bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6576bf269551SChuck Lever 				    struct xdr_stream *xdr,
6577bb8b27e5STrond Myklebust 				    struct nfs4_setclientid_res *res)
65781da177e4SLinus Torvalds {
65791da177e4SLinus Torvalds 	struct compound_hdr hdr;
65801da177e4SLinus Torvalds 	int status;
65811da177e4SLinus Torvalds 
6582bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65831da177e4SLinus Torvalds 	if (!status)
6584bf269551SChuck Lever 		status = decode_setclientid(xdr, res);
65851da177e4SLinus Torvalds 	return status;
65861da177e4SLinus Torvalds }
65871da177e4SLinus Torvalds 
65881da177e4SLinus Torvalds /*
65898b173218SRicardo Labiaga  * Decode SETCLIENTID_CONFIRM response
65901da177e4SLinus Torvalds  */
6591bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6592bf269551SChuck Lever 					    struct xdr_stream *xdr,
6593bf269551SChuck Lever 					    struct nfs_fsinfo *fsinfo)
65941da177e4SLinus Torvalds {
65951da177e4SLinus Torvalds 	struct compound_hdr hdr;
65961da177e4SLinus Torvalds 	int status;
65971da177e4SLinus Torvalds 
6598bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65991da177e4SLinus Torvalds 	if (!status)
6600bf269551SChuck Lever 		status = decode_setclientid_confirm(xdr);
66011da177e4SLinus Torvalds 	if (!status)
6602bf269551SChuck Lever 		status = decode_putrootfh(xdr);
66031da177e4SLinus Torvalds 	if (!status)
6604bf269551SChuck Lever 		status = decode_fsinfo(xdr, fsinfo);
66051da177e4SLinus Torvalds 	return status;
66061da177e4SLinus Torvalds }
66071da177e4SLinus Torvalds 
66081da177e4SLinus Torvalds /*
66098b173218SRicardo Labiaga  * Decode DELEGRETURN response
66101da177e4SLinus Torvalds  */
6611bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6612bf269551SChuck Lever 				    struct xdr_stream *xdr,
6613bf269551SChuck Lever 				    struct nfs4_delegreturnres *res)
66141da177e4SLinus Torvalds {
66151da177e4SLinus Torvalds 	struct compound_hdr hdr;
66161da177e4SLinus Torvalds 	int status;
66171da177e4SLinus Torvalds 
6618bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66199b7b9fccSAndy Adamson 	if (status)
66209b7b9fccSAndy Adamson 		goto out;
6621bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66229b7b9fccSAndy Adamson 	if (status)
6623fa178f29STrond Myklebust 		goto out;
6624bf269551SChuck Lever 	status = decode_putfh(xdr);
6625fa178f29STrond Myklebust 	if (status != 0)
6626fa178f29STrond Myklebust 		goto out;
6627bf269551SChuck Lever 	status = decode_delegreturn(xdr);
6628556ae3bbSJeff Layton 	if (status != 0)
6629556ae3bbSJeff Layton 		goto out;
66306926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
6631fa178f29STrond Myklebust out:
66321da177e4SLinus Torvalds 	return status;
66331da177e4SLinus Torvalds }
66341da177e4SLinus Torvalds 
6635683b57b4STrond Myklebust /*
66368b173218SRicardo Labiaga  * Decode FS_LOCATIONS response
6637683b57b4STrond Myklebust  */
6638bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6639bf269551SChuck Lever 				     struct xdr_stream *xdr,
664022958463SBenny Halevy 				     struct nfs4_fs_locations_res *res)
6641683b57b4STrond Myklebust {
6642683b57b4STrond Myklebust 	struct compound_hdr hdr;
6643683b57b4STrond Myklebust 	int status;
6644683b57b4STrond Myklebust 
6645bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66469b7b9fccSAndy Adamson 	if (status)
66479b7b9fccSAndy Adamson 		goto out;
6648bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
66499b7b9fccSAndy Adamson 	if (status)
6650683b57b4STrond Myklebust 		goto out;
6651bf269551SChuck Lever 	status = decode_putfh(xdr);
6652bf269551SChuck Lever 	if (status)
6653683b57b4STrond Myklebust 		goto out;
6654bf269551SChuck Lever 	status = decode_lookup(xdr);
6655bf269551SChuck Lever 	if (status)
6656683b57b4STrond Myklebust 		goto out;
6657bf269551SChuck Lever 	xdr_enter_page(xdr, PAGE_SIZE);
66588b7e3f49STrond Myklebust 	status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
66598b7e3f49STrond Myklebust 					 NULL, res->fs_locations,
66606926afd1STrond Myklebust 					 res->fs_locations->server);
6661683b57b4STrond Myklebust out:
6662683b57b4STrond Myklebust 	return status;
6663683b57b4STrond Myklebust }
6664683b57b4STrond Myklebust 
66655a5ea0d4SBryan Schumaker /*
66665a5ea0d4SBryan Schumaker  * Decode SECINFO response
66675a5ea0d4SBryan Schumaker  */
66685a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
66695a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
66705a5ea0d4SBryan Schumaker 				struct nfs4_secinfo_res *res)
66715a5ea0d4SBryan Schumaker {
66725a5ea0d4SBryan Schumaker 	struct compound_hdr hdr;
66735a5ea0d4SBryan Schumaker 	int status;
66745a5ea0d4SBryan Schumaker 
66755a5ea0d4SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
66765a5ea0d4SBryan Schumaker 	if (status)
66775a5ea0d4SBryan Schumaker 		goto out;
66785a5ea0d4SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66795a5ea0d4SBryan Schumaker 	if (status)
66805a5ea0d4SBryan Schumaker 		goto out;
66815a5ea0d4SBryan Schumaker 	status = decode_putfh(xdr);
66825a5ea0d4SBryan Schumaker 	if (status)
66835a5ea0d4SBryan Schumaker 		goto out;
66845a5ea0d4SBryan Schumaker 	status = decode_secinfo(xdr, res);
66855a5ea0d4SBryan Schumaker out:
66865a5ea0d4SBryan Schumaker 	return status;
66875a5ea0d4SBryan Schumaker }
66885a5ea0d4SBryan Schumaker 
668999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
669099fe60d0SBenny Halevy /*
66918b173218SRicardo Labiaga  * Decode EXCHANGE_ID response
669299fe60d0SBenny Halevy  */
6693bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6694bf269551SChuck Lever 				    struct xdr_stream *xdr,
669599fe60d0SBenny Halevy 				    void *res)
669699fe60d0SBenny Halevy {
669799fe60d0SBenny Halevy 	struct compound_hdr hdr;
669899fe60d0SBenny Halevy 	int status;
669999fe60d0SBenny Halevy 
6700bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
670199fe60d0SBenny Halevy 	if (!status)
6702bf269551SChuck Lever 		status = decode_exchange_id(xdr, res);
670399fe60d0SBenny Halevy 	return status;
670499fe60d0SBenny Halevy }
67052050f0ccSAndy Adamson 
67062050f0ccSAndy Adamson /*
67078b173218SRicardo Labiaga  * Decode CREATE_SESSION response
6708fc931582SAndy Adamson  */
6709bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6710bf269551SChuck Lever 				       struct xdr_stream *xdr,
6711fc931582SAndy Adamson 				       struct nfs41_create_session_res *res)
6712fc931582SAndy Adamson {
6713fc931582SAndy Adamson 	struct compound_hdr hdr;
6714fc931582SAndy Adamson 	int status;
6715fc931582SAndy Adamson 
6716bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6717fc931582SAndy Adamson 	if (!status)
6718bf269551SChuck Lever 		status = decode_create_session(xdr, res);
6719fc931582SAndy Adamson 	return status;
6720fc931582SAndy Adamson }
6721fc931582SAndy Adamson 
6722fc931582SAndy Adamson /*
67238b173218SRicardo Labiaga  * Decode DESTROY_SESSION response
67240f3e66c6SAndy Adamson  */
6725bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6726bf269551SChuck Lever 					struct xdr_stream *xdr,
6727bf269551SChuck Lever 					void *res)
67280f3e66c6SAndy Adamson {
67290f3e66c6SAndy Adamson 	struct compound_hdr hdr;
67300f3e66c6SAndy Adamson 	int status;
67310f3e66c6SAndy Adamson 
6732bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67330f3e66c6SAndy Adamson 	if (!status)
6734bf269551SChuck Lever 		status = decode_destroy_session(xdr, res);
67350f3e66c6SAndy Adamson 	return status;
67360f3e66c6SAndy Adamson }
67370f3e66c6SAndy Adamson 
67380f3e66c6SAndy Adamson /*
67398b173218SRicardo Labiaga  * Decode SEQUENCE response
6740fc01cea9SAndy Adamson  */
6741bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6742bf269551SChuck Lever 				 struct xdr_stream *xdr,
6743fc01cea9SAndy Adamson 				 struct nfs4_sequence_res *res)
6744fc01cea9SAndy Adamson {
6745fc01cea9SAndy Adamson 	struct compound_hdr hdr;
6746fc01cea9SAndy Adamson 	int status;
6747fc01cea9SAndy Adamson 
6748bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6749fc01cea9SAndy Adamson 	if (!status)
6750bf269551SChuck Lever 		status = decode_sequence(xdr, res, rqstp);
6751fc01cea9SAndy Adamson 	return status;
6752fc01cea9SAndy Adamson }
6753fc01cea9SAndy Adamson 
6754fc01cea9SAndy Adamson /*
67558b173218SRicardo Labiaga  * Decode GET_LEASE_TIME response
67562050f0ccSAndy Adamson  */
6757bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6758bf269551SChuck Lever 				       struct xdr_stream *xdr,
67592050f0ccSAndy Adamson 				       struct nfs4_get_lease_time_res *res)
67602050f0ccSAndy Adamson {
67612050f0ccSAndy Adamson 	struct compound_hdr hdr;
67622050f0ccSAndy Adamson 	int status;
67632050f0ccSAndy Adamson 
6764bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67652050f0ccSAndy Adamson 	if (!status)
6766bf269551SChuck Lever 		status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
67672050f0ccSAndy Adamson 	if (!status)
6768bf269551SChuck Lever 		status = decode_putrootfh(xdr);
67692050f0ccSAndy Adamson 	if (!status)
6770bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->lr_fsinfo);
67712050f0ccSAndy Adamson 	return status;
67722050f0ccSAndy Adamson }
677318019753SRicardo Labiaga 
677418019753SRicardo Labiaga /*
677518019753SRicardo Labiaga  * Decode RECLAIM_COMPLETE response
677618019753SRicardo Labiaga  */
6777bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6778bf269551SChuck Lever 					 struct xdr_stream *xdr,
677918019753SRicardo Labiaga 					 struct nfs41_reclaim_complete_res *res)
678018019753SRicardo Labiaga {
678118019753SRicardo Labiaga 	struct compound_hdr hdr;
678218019753SRicardo Labiaga 	int status;
678318019753SRicardo Labiaga 
6784bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
678518019753SRicardo Labiaga 	if (!status)
6786bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, rqstp);
678718019753SRicardo Labiaga 	if (!status)
6788bf269551SChuck Lever 		status = decode_reclaim_complete(xdr, (void *)NULL);
678918019753SRicardo Labiaga 	return status;
679018019753SRicardo Labiaga }
6791b1f69b75SAndy Adamson 
6792b1f69b75SAndy Adamson /*
67937f11d8d3SAndy Adamson  * Decode GETDEVICELIST response
67947f11d8d3SAndy Adamson  */
67957f11d8d3SAndy Adamson static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
67967f11d8d3SAndy Adamson 				      struct xdr_stream *xdr,
67977f11d8d3SAndy Adamson 				      struct nfs4_getdevicelist_res *res)
67987f11d8d3SAndy Adamson {
67997f11d8d3SAndy Adamson 	struct compound_hdr hdr;
68007f11d8d3SAndy Adamson 	int status;
68017f11d8d3SAndy Adamson 
68027f11d8d3SAndy Adamson 	dprintk("encoding getdevicelist!\n");
68037f11d8d3SAndy Adamson 
68047f11d8d3SAndy Adamson 	status = decode_compound_hdr(xdr, &hdr);
68057f11d8d3SAndy Adamson 	if (status != 0)
68067f11d8d3SAndy Adamson 		goto out;
68077f11d8d3SAndy Adamson 	status = decode_sequence(xdr, &res->seq_res, rqstp);
68087f11d8d3SAndy Adamson 	if (status != 0)
68097f11d8d3SAndy Adamson 		goto out;
68107f11d8d3SAndy Adamson 	status = decode_putfh(xdr);
68117f11d8d3SAndy Adamson 	if (status != 0)
68127f11d8d3SAndy Adamson 		goto out;
68137f11d8d3SAndy Adamson 	status = decode_getdevicelist(xdr, res->devlist);
68147f11d8d3SAndy Adamson out:
68157f11d8d3SAndy Adamson 	return status;
68167f11d8d3SAndy Adamson }
68177f11d8d3SAndy Adamson 
68187f11d8d3SAndy Adamson /*
6819b1f69b75SAndy Adamson  * Decode GETDEVINFO response
6820b1f69b75SAndy Adamson  */
6821bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6822bf269551SChuck Lever 				      struct xdr_stream *xdr,
6823b1f69b75SAndy Adamson 				      struct nfs4_getdeviceinfo_res *res)
6824b1f69b75SAndy Adamson {
6825b1f69b75SAndy Adamson 	struct compound_hdr hdr;
6826b1f69b75SAndy Adamson 	int status;
6827b1f69b75SAndy Adamson 
6828bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6829b1f69b75SAndy Adamson 	if (status != 0)
6830b1f69b75SAndy Adamson 		goto out;
6831bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6832b1f69b75SAndy Adamson 	if (status != 0)
6833b1f69b75SAndy Adamson 		goto out;
6834bf269551SChuck Lever 	status = decode_getdeviceinfo(xdr, res->pdev);
6835b1f69b75SAndy Adamson out:
6836b1f69b75SAndy Adamson 	return status;
6837b1f69b75SAndy Adamson }
6838b1f69b75SAndy Adamson 
6839b1f69b75SAndy Adamson /*
6840b1f69b75SAndy Adamson  * Decode LAYOUTGET response
6841b1f69b75SAndy Adamson  */
6842bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6843bf269551SChuck Lever 				  struct xdr_stream *xdr,
6844b1f69b75SAndy Adamson 				  struct nfs4_layoutget_res *res)
6845b1f69b75SAndy Adamson {
6846b1f69b75SAndy Adamson 	struct compound_hdr hdr;
6847b1f69b75SAndy Adamson 	int status;
6848b1f69b75SAndy Adamson 
6849bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6850b1f69b75SAndy Adamson 	if (status)
6851b1f69b75SAndy Adamson 		goto out;
6852bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6853b1f69b75SAndy Adamson 	if (status)
6854b1f69b75SAndy Adamson 		goto out;
6855bf269551SChuck Lever 	status = decode_putfh(xdr);
6856b1f69b75SAndy Adamson 	if (status)
6857b1f69b75SAndy Adamson 		goto out;
6858bf269551SChuck Lever 	status = decode_layoutget(xdr, rqstp, res);
6859b1f69b75SAndy Adamson out:
6860b1f69b75SAndy Adamson 	return status;
6861b1f69b75SAndy Adamson }
6862863a3c6cSAndy Adamson 
6863863a3c6cSAndy Adamson /*
6864cbe82603SBenny Halevy  * Decode LAYOUTRETURN response
6865cbe82603SBenny Halevy  */
6866cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6867cbe82603SBenny Halevy 				     struct xdr_stream *xdr,
6868cbe82603SBenny Halevy 				     struct nfs4_layoutreturn_res *res)
6869cbe82603SBenny Halevy {
6870cbe82603SBenny Halevy 	struct compound_hdr hdr;
6871cbe82603SBenny Halevy 	int status;
6872cbe82603SBenny Halevy 
6873cbe82603SBenny Halevy 	status = decode_compound_hdr(xdr, &hdr);
6874cbe82603SBenny Halevy 	if (status)
6875cbe82603SBenny Halevy 		goto out;
6876cbe82603SBenny Halevy 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6877cbe82603SBenny Halevy 	if (status)
6878cbe82603SBenny Halevy 		goto out;
6879cbe82603SBenny Halevy 	status = decode_putfh(xdr);
6880cbe82603SBenny Halevy 	if (status)
6881cbe82603SBenny Halevy 		goto out;
6882cbe82603SBenny Halevy 	status = decode_layoutreturn(xdr, res);
6883cbe82603SBenny Halevy out:
6884cbe82603SBenny Halevy 	return status;
6885cbe82603SBenny Halevy }
6886cbe82603SBenny Halevy 
6887cbe82603SBenny Halevy /*
6888863a3c6cSAndy Adamson  * Decode LAYOUTCOMMIT response
6889863a3c6cSAndy Adamson  */
6890863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6891863a3c6cSAndy Adamson 				     struct xdr_stream *xdr,
6892863a3c6cSAndy Adamson 				     struct nfs4_layoutcommit_res *res)
6893863a3c6cSAndy Adamson {
6894863a3c6cSAndy Adamson 	struct compound_hdr hdr;
6895863a3c6cSAndy Adamson 	int status;
6896863a3c6cSAndy Adamson 
6897863a3c6cSAndy Adamson 	status = decode_compound_hdr(xdr, &hdr);
6898863a3c6cSAndy Adamson 	if (status)
6899863a3c6cSAndy Adamson 		goto out;
6900863a3c6cSAndy Adamson 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6901863a3c6cSAndy Adamson 	if (status)
6902863a3c6cSAndy Adamson 		goto out;
6903863a3c6cSAndy Adamson 	status = decode_putfh(xdr);
6904863a3c6cSAndy Adamson 	if (status)
6905863a3c6cSAndy Adamson 		goto out;
6906863a3c6cSAndy Adamson 	status = decode_layoutcommit(xdr, rqstp, res);
6907863a3c6cSAndy Adamson 	if (status)
6908863a3c6cSAndy Adamson 		goto out;
69096926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
6910863a3c6cSAndy Adamson out:
6911863a3c6cSAndy Adamson 	return status;
6912863a3c6cSAndy Adamson }
6913fca78d6dSBryan Schumaker 
6914fca78d6dSBryan Schumaker /*
6915fca78d6dSBryan Schumaker  * Decode SECINFO_NO_NAME response
6916fca78d6dSBryan Schumaker  */
6917fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6918fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
6919fca78d6dSBryan Schumaker 					struct nfs4_secinfo_res *res)
6920fca78d6dSBryan Schumaker {
6921fca78d6dSBryan Schumaker 	struct compound_hdr hdr;
6922fca78d6dSBryan Schumaker 	int status;
6923fca78d6dSBryan Schumaker 
6924fca78d6dSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
6925fca78d6dSBryan Schumaker 	if (status)
6926fca78d6dSBryan Schumaker 		goto out;
6927fca78d6dSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6928fca78d6dSBryan Schumaker 	if (status)
6929fca78d6dSBryan Schumaker 		goto out;
6930fca78d6dSBryan Schumaker 	status = decode_putrootfh(xdr);
6931fca78d6dSBryan Schumaker 	if (status)
6932fca78d6dSBryan Schumaker 		goto out;
6933fca78d6dSBryan Schumaker 	status = decode_secinfo(xdr, res);
6934fca78d6dSBryan Schumaker out:
6935fca78d6dSBryan Schumaker 	return status;
6936fca78d6dSBryan Schumaker }
69377d974794SBryan Schumaker 
69387d974794SBryan Schumaker /*
69397d974794SBryan Schumaker  * Decode TEST_STATEID response
69407d974794SBryan Schumaker  */
69417d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
69427d974794SBryan Schumaker 				     struct xdr_stream *xdr,
69437d974794SBryan Schumaker 				     struct nfs41_test_stateid_res *res)
69447d974794SBryan Schumaker {
69457d974794SBryan Schumaker 	struct compound_hdr hdr;
69467d974794SBryan Schumaker 	int status;
69477d974794SBryan Schumaker 
69487d974794SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
69497d974794SBryan Schumaker 	if (status)
69507d974794SBryan Schumaker 		goto out;
69517d974794SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
69527d974794SBryan Schumaker 	if (status)
69537d974794SBryan Schumaker 		goto out;
69547d974794SBryan Schumaker 	status = decode_test_stateid(xdr, res);
69557d974794SBryan Schumaker out:
69567d974794SBryan Schumaker 	return status;
69577d974794SBryan Schumaker }
69589aeda35fSBryan Schumaker 
69599aeda35fSBryan Schumaker /*
69609aeda35fSBryan Schumaker  * Decode FREE_STATEID response
69619aeda35fSBryan Schumaker  */
69629aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
69639aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
69649aeda35fSBryan Schumaker 				     struct nfs41_free_stateid_res *res)
69659aeda35fSBryan Schumaker {
69669aeda35fSBryan Schumaker 	struct compound_hdr hdr;
69679aeda35fSBryan Schumaker 	int status;
69689aeda35fSBryan Schumaker 
69699aeda35fSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
69709aeda35fSBryan Schumaker 	if (status)
69719aeda35fSBryan Schumaker 		goto out;
69729aeda35fSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
69739aeda35fSBryan Schumaker 	if (status)
69749aeda35fSBryan Schumaker 		goto out;
69759aeda35fSBryan Schumaker 	status = decode_free_stateid(xdr, res);
69769aeda35fSBryan Schumaker out:
69779aeda35fSBryan Schumaker 	return status;
69789aeda35fSBryan Schumaker }
697999fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
698099fe60d0SBenny Halevy 
6981573c4e1eSChuck Lever /**
6982573c4e1eSChuck Lever  * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6983573c4e1eSChuck Lever  *                      the local page cache.
6984573c4e1eSChuck Lever  * @xdr: XDR stream where entry resides
6985573c4e1eSChuck Lever  * @entry: buffer to fill in with entry data
6986573c4e1eSChuck Lever  * @plus: boolean indicating whether this should be a readdirplus entry
6987573c4e1eSChuck Lever  *
6988573c4e1eSChuck Lever  * Returns zero if successful, otherwise a negative errno value is
6989573c4e1eSChuck Lever  * returned.
6990573c4e1eSChuck Lever  *
6991573c4e1eSChuck Lever  * This function is not invoked during READDIR reply decoding, but
6992573c4e1eSChuck Lever  * rather whenever an application invokes the getdents(2) system call
6993573c4e1eSChuck Lever  * on a directory already in our cache.
6994573c4e1eSChuck Lever  */
6995573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6996573c4e1eSChuck Lever 		       int plus)
69971da177e4SLinus Torvalds {
6998dae100c2SFred Isaman 	uint32_t bitmap[3] = {0};
69991da177e4SLinus Torvalds 	uint32_t len;
7000babddc72SBryan Schumaker 	__be32 *p = xdr_inline_decode(xdr, 4);
7001babddc72SBryan Schumaker 	if (unlikely(!p))
7002babddc72SBryan Schumaker 		goto out_overflow;
7003c08e76d0SChuck Lever 	if (*p == xdr_zero) {
7004babddc72SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
7005babddc72SBryan Schumaker 		if (unlikely(!p))
7006babddc72SBryan Schumaker 			goto out_overflow;
7007c08e76d0SChuck Lever 		if (*p == xdr_zero)
7008573c4e1eSChuck Lever 			return -EAGAIN;
70091da177e4SLinus Torvalds 		entry->eof = 1;
7010573c4e1eSChuck Lever 		return -EBADCOOKIE;
70111da177e4SLinus Torvalds 	}
70121da177e4SLinus Torvalds 
7013babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 12);
7014babddc72SBryan Schumaker 	if (unlikely(!p))
7015babddc72SBryan Schumaker 		goto out_overflow;
70161da177e4SLinus Torvalds 	entry->prev_cookie = entry->cookie;
70171da177e4SLinus Torvalds 	p = xdr_decode_hyper(p, &entry->cookie);
7018c08e76d0SChuck Lever 	entry->len = be32_to_cpup(p);
7019babddc72SBryan Schumaker 
70209af8c222STrond Myklebust 	p = xdr_inline_decode(xdr, entry->len);
7021babddc72SBryan Schumaker 	if (unlikely(!p))
7022babddc72SBryan Schumaker 		goto out_overflow;
70231da177e4SLinus Torvalds 	entry->name = (const char *) p;
70241da177e4SLinus Torvalds 
70251da177e4SLinus Torvalds 	/*
70261da177e4SLinus Torvalds 	 * In case the server doesn't return an inode number,
70271da177e4SLinus Torvalds 	 * we fake one here.  (We don't use inode number 0,
70281da177e4SLinus Torvalds 	 * since glibc seems to choke on it...)
70291da177e4SLinus Torvalds 	 */
70301da177e4SLinus Torvalds 	entry->ino = 1;
70314f082222STrond Myklebust 	entry->fattr->valid = 0;
70321da177e4SLinus Torvalds 
70339af8c222STrond Myklebust 	if (decode_attr_bitmap(xdr, bitmap) < 0)
7034babddc72SBryan Schumaker 		goto out_overflow;
70359af8c222STrond Myklebust 
70369af8c222STrond Myklebust 	if (decode_attr_length(xdr, &len, &p) < 0)
7037babddc72SBryan Schumaker 		goto out_overflow;
70389af8c222STrond Myklebust 
7039573c4e1eSChuck Lever 	if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
70408b7e3f49STrond Myklebust 				  NULL, entry->server) < 0)
7041babddc72SBryan Schumaker 		goto out_overflow;
704228331a46STrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
704328331a46STrond Myklebust 		entry->ino = entry->fattr->mounted_on_fileid;
704428331a46STrond Myklebust 	else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
704582f2e547SBryan Schumaker 		entry->ino = entry->fattr->fileid;
70469af8c222STrond Myklebust 
70470b26a0bfSTrond Myklebust 	entry->d_type = DT_UNKNOWN;
70480b26a0bfSTrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
70490b26a0bfSTrond Myklebust 		entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
70500b26a0bfSTrond Myklebust 
7051573c4e1eSChuck Lever 	return 0;
7052babddc72SBryan Schumaker 
7053babddc72SBryan Schumaker out_overflow:
7054babddc72SBryan Schumaker 	print_overflow_msg(__func__, xdr);
7055573c4e1eSChuck Lever 	return -EAGAIN;
70561da177e4SLinus Torvalds }
70571da177e4SLinus Torvalds 
70581da177e4SLinus Torvalds /*
70591da177e4SLinus Torvalds  * We need to translate between nfs status return values and
70601da177e4SLinus Torvalds  * the local errno values which may not be the same.
70611da177e4SLinus Torvalds  */
70621da177e4SLinus Torvalds static struct {
70631da177e4SLinus Torvalds 	int stat;
70641da177e4SLinus Torvalds 	int errno;
70651da177e4SLinus Torvalds } nfs_errtbl[] = {
70661da177e4SLinus Torvalds 	{ NFS4_OK,		0		},
7067856dff3dSBenny Halevy 	{ NFS4ERR_PERM,		-EPERM		},
7068856dff3dSBenny Halevy 	{ NFS4ERR_NOENT,	-ENOENT		},
7069856dff3dSBenny Halevy 	{ NFS4ERR_IO,		-errno_NFSERR_IO},
7070856dff3dSBenny Halevy 	{ NFS4ERR_NXIO,		-ENXIO		},
7071856dff3dSBenny Halevy 	{ NFS4ERR_ACCESS,	-EACCES		},
7072856dff3dSBenny Halevy 	{ NFS4ERR_EXIST,	-EEXIST		},
7073856dff3dSBenny Halevy 	{ NFS4ERR_XDEV,		-EXDEV		},
7074856dff3dSBenny Halevy 	{ NFS4ERR_NOTDIR,	-ENOTDIR	},
7075856dff3dSBenny Halevy 	{ NFS4ERR_ISDIR,	-EISDIR		},
7076856dff3dSBenny Halevy 	{ NFS4ERR_INVAL,	-EINVAL		},
7077856dff3dSBenny Halevy 	{ NFS4ERR_FBIG,		-EFBIG		},
7078856dff3dSBenny Halevy 	{ NFS4ERR_NOSPC,	-ENOSPC		},
7079856dff3dSBenny Halevy 	{ NFS4ERR_ROFS,		-EROFS		},
7080856dff3dSBenny Halevy 	{ NFS4ERR_MLINK,	-EMLINK		},
7081856dff3dSBenny Halevy 	{ NFS4ERR_NAMETOOLONG,	-ENAMETOOLONG	},
7082856dff3dSBenny Halevy 	{ NFS4ERR_NOTEMPTY,	-ENOTEMPTY	},
7083856dff3dSBenny Halevy 	{ NFS4ERR_DQUOT,	-EDQUOT		},
7084856dff3dSBenny Halevy 	{ NFS4ERR_STALE,	-ESTALE		},
7085856dff3dSBenny Halevy 	{ NFS4ERR_BADHANDLE,	-EBADHANDLE	},
7086856dff3dSBenny Halevy 	{ NFS4ERR_BAD_COOKIE,	-EBADCOOKIE	},
7087856dff3dSBenny Halevy 	{ NFS4ERR_NOTSUPP,	-ENOTSUPP	},
7088856dff3dSBenny Halevy 	{ NFS4ERR_TOOSMALL,	-ETOOSMALL	},
7089fdcb4577STrond Myklebust 	{ NFS4ERR_SERVERFAULT,	-EREMOTEIO	},
7090856dff3dSBenny Halevy 	{ NFS4ERR_BADTYPE,	-EBADTYPE	},
7091856dff3dSBenny Halevy 	{ NFS4ERR_LOCKED,	-EAGAIN		},
7092856dff3dSBenny Halevy 	{ NFS4ERR_SYMLINK,	-ELOOP		},
7093856dff3dSBenny Halevy 	{ NFS4ERR_OP_ILLEGAL,	-EOPNOTSUPP	},
7094856dff3dSBenny Halevy 	{ NFS4ERR_DEADLOCK,	-EDEADLK	},
7095856dff3dSBenny Halevy 	{ -1,			-EIO		}
70961da177e4SLinus Torvalds };
70971da177e4SLinus Torvalds 
70981da177e4SLinus Torvalds /*
70991da177e4SLinus Torvalds  * Convert an NFS error code to a local one.
71001da177e4SLinus Torvalds  * This one is used jointly by NFSv2 and NFSv3.
71011da177e4SLinus Torvalds  */
71021da177e4SLinus Torvalds static int
71030a8ea437SDavid Howells nfs4_stat_to_errno(int stat)
71041da177e4SLinus Torvalds {
71051da177e4SLinus Torvalds 	int i;
71061da177e4SLinus Torvalds 	for (i = 0; nfs_errtbl[i].stat != -1; i++) {
71071da177e4SLinus Torvalds 		if (nfs_errtbl[i].stat == stat)
71081da177e4SLinus Torvalds 			return nfs_errtbl[i].errno;
71091da177e4SLinus Torvalds 	}
71101da177e4SLinus Torvalds 	if (stat <= 10000 || stat > 10100) {
71111da177e4SLinus Torvalds 		/* The server is looney tunes. */
7112fdcb4577STrond Myklebust 		return -EREMOTEIO;
71131da177e4SLinus Torvalds 	}
71141da177e4SLinus Torvalds 	/* If we cannot translate the error, the recovery routines should
71151da177e4SLinus Torvalds 	 * handle it.
71161da177e4SLinus Torvalds 	 * Note: remaining NFSv4 error codes have values > 10000, so should
71171da177e4SLinus Torvalds 	 * not conflict with native Linux error codes.
71181da177e4SLinus Torvalds 	 */
7119856dff3dSBenny Halevy 	return -stat;
71201da177e4SLinus Torvalds }
71211da177e4SLinus Torvalds 
71221da177e4SLinus Torvalds #define PROC(proc, argtype, restype)				\
71231da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = {					\
71241da177e4SLinus Torvalds 	.p_proc   = NFSPROC4_COMPOUND,				\
71259f06c719SChuck Lever 	.p_encode = (kxdreproc_t)nfs4_xdr_##argtype,		\
7126bf269551SChuck Lever 	.p_decode = (kxdrdproc_t)nfs4_xdr_##restype,		\
71272bea90d4SChuck Lever 	.p_arglen = NFS4_##argtype##_sz,			\
71282bea90d4SChuck Lever 	.p_replen = NFS4_##restype##_sz,			\
7129cc0175c1SChuck Lever 	.p_statidx = NFSPROC4_CLNT_##proc,			\
7130cc0175c1SChuck Lever 	.p_name   = #proc,					\
71311da177e4SLinus Torvalds }
71321da177e4SLinus Torvalds 
71331da177e4SLinus Torvalds struct rpc_procinfo	nfs4_procedures[] = {
71341da177e4SLinus Torvalds 	PROC(READ,		enc_read,		dec_read),
71351da177e4SLinus Torvalds 	PROC(WRITE,		enc_write,		dec_write),
71361da177e4SLinus Torvalds 	PROC(COMMIT,		enc_commit,		dec_commit),
71371da177e4SLinus Torvalds 	PROC(OPEN,		enc_open,		dec_open),
71381da177e4SLinus Torvalds 	PROC(OPEN_CONFIRM,	enc_open_confirm,	dec_open_confirm),
71391da177e4SLinus Torvalds 	PROC(OPEN_NOATTR,	enc_open_noattr,	dec_open_noattr),
71401da177e4SLinus Torvalds 	PROC(OPEN_DOWNGRADE,	enc_open_downgrade,	dec_open_downgrade),
71411da177e4SLinus Torvalds 	PROC(CLOSE,		enc_close,		dec_close),
71421da177e4SLinus Torvalds 	PROC(SETATTR,		enc_setattr,		dec_setattr),
71431da177e4SLinus Torvalds 	PROC(FSINFO,		enc_fsinfo,		dec_fsinfo),
71441da177e4SLinus Torvalds 	PROC(RENEW,		enc_renew,		dec_renew),
71451da177e4SLinus Torvalds 	PROC(SETCLIENTID,	enc_setclientid,	dec_setclientid),
71461da177e4SLinus Torvalds 	PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
71471da177e4SLinus Torvalds 	PROC(LOCK,		enc_lock,		dec_lock),
71481da177e4SLinus Torvalds 	PROC(LOCKT,		enc_lockt,		dec_lockt),
71491da177e4SLinus Torvalds 	PROC(LOCKU,		enc_locku,		dec_locku),
71501da177e4SLinus Torvalds 	PROC(ACCESS,		enc_access,		dec_access),
71511da177e4SLinus Torvalds 	PROC(GETATTR,		enc_getattr,		dec_getattr),
71521da177e4SLinus Torvalds 	PROC(LOOKUP,		enc_lookup,		dec_lookup),
71531da177e4SLinus Torvalds 	PROC(LOOKUP_ROOT,	enc_lookup_root,	dec_lookup_root),
71541da177e4SLinus Torvalds 	PROC(REMOVE,		enc_remove,		dec_remove),
71551da177e4SLinus Torvalds 	PROC(RENAME,		enc_rename,		dec_rename),
71561da177e4SLinus Torvalds 	PROC(LINK,		enc_link,		dec_link),
71571da177e4SLinus Torvalds 	PROC(SYMLINK,		enc_symlink,		dec_symlink),
71581da177e4SLinus Torvalds 	PROC(CREATE,		enc_create,		dec_create),
71591da177e4SLinus Torvalds 	PROC(PATHCONF,		enc_pathconf,		dec_pathconf),
71601da177e4SLinus Torvalds 	PROC(STATFS,		enc_statfs,		dec_statfs),
71611da177e4SLinus Torvalds 	PROC(READLINK,		enc_readlink,		dec_readlink),
71621da177e4SLinus Torvalds 	PROC(READDIR,		enc_readdir,		dec_readdir),
71631da177e4SLinus Torvalds 	PROC(SERVER_CAPS,	enc_server_caps,	dec_server_caps),
71641da177e4SLinus Torvalds 	PROC(DELEGRETURN,	enc_delegreturn,	dec_delegreturn),
7165029d105eSJ. Bruce Fields 	PROC(GETACL,		enc_getacl,		dec_getacl),
716623ec6965SJ. Bruce Fields 	PROC(SETACL,		enc_setacl,		dec_setacl),
7167683b57b4STrond Myklebust 	PROC(FS_LOCATIONS,	enc_fs_locations,	dec_fs_locations),
7168d3c7b7ccSTrond Myklebust 	PROC(RELEASE_LOCKOWNER,	enc_release_lockowner,	dec_release_lockowner),
71695a5ea0d4SBryan Schumaker 	PROC(SECINFO,		enc_secinfo,		dec_secinfo),
717099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
717199fe60d0SBenny Halevy 	PROC(EXCHANGE_ID,	enc_exchange_id,	dec_exchange_id),
7172fc931582SAndy Adamson 	PROC(CREATE_SESSION,	enc_create_session,	dec_create_session),
71730f3e66c6SAndy Adamson 	PROC(DESTROY_SESSION,	enc_destroy_session,	dec_destroy_session),
7174fc01cea9SAndy Adamson 	PROC(SEQUENCE,		enc_sequence,		dec_sequence),
71752050f0ccSAndy Adamson 	PROC(GET_LEASE_TIME,	enc_get_lease_time,	dec_get_lease_time),
717618019753SRicardo Labiaga 	PROC(RECLAIM_COMPLETE,	enc_reclaim_complete,	dec_reclaim_complete),
7177b1f69b75SAndy Adamson 	PROC(GETDEVICEINFO,	enc_getdeviceinfo,	dec_getdeviceinfo),
7178b1f69b75SAndy Adamson 	PROC(LAYOUTGET,		enc_layoutget,		dec_layoutget),
7179863a3c6cSAndy Adamson 	PROC(LAYOUTCOMMIT,	enc_layoutcommit,	dec_layoutcommit),
7180cbe82603SBenny Halevy 	PROC(LAYOUTRETURN,	enc_layoutreturn,	dec_layoutreturn),
7181fca78d6dSBryan Schumaker 	PROC(SECINFO_NO_NAME,	enc_secinfo_no_name,	dec_secinfo_no_name),
71827d974794SBryan Schumaker 	PROC(TEST_STATEID,	enc_test_stateid,	dec_test_stateid),
71839aeda35fSBryan Schumaker 	PROC(FREE_STATEID,	enc_free_stateid,	dec_free_stateid),
71847f11d8d3SAndy Adamson 	PROC(GETDEVICELIST,	enc_getdevicelist,	dec_getdevicelist),
718599fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
71861da177e4SLinus Torvalds };
71871da177e4SLinus Torvalds 
7188a613fa16STrond Myklebust const struct rpc_version nfs_version4 = {
71891da177e4SLinus Torvalds 	.number			= 4,
7190e8c96f8cSTobias Klauser 	.nrprocs		= ARRAY_SIZE(nfs4_procedures),
71911da177e4SLinus Torvalds 	.procs			= nfs4_procedures
71921da177e4SLinus Torvalds };
71931da177e4SLinus Torvalds 
71941da177e4SLinus Torvalds /*
71951da177e4SLinus Torvalds  * Local variables:
71961da177e4SLinus Torvalds  *  c-basic-offset: 8
71971da177e4SLinus Torvalds  * End:
71981da177e4SLinus Torvalds  */
7199