xref: /openbmc/linux/fs/nfs/nfs4xdr.c (revision 2e18d4d8)
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>
55f092075dSChuck Lever 
564ce79717STrond Myklebust #include "nfs4_fs.h"
574882ef72SAlexandros Batsakis #include "internal.h"
5840c64c26SAnna Schumaker #include "nfs4idmap.h"
5976e697baSTrond Myklebust #include "nfs4session.h"
60b1f69b75SAndy Adamson #include "pnfs.h"
61f092075dSChuck Lever #include "netns.h"
621da177e4SLinus Torvalds 
631da177e4SLinus Torvalds #define NFSDBG_FACILITY		NFSDBG_XDR
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */
661da177e4SLinus Torvalds #define errno_NFSERR_IO		EIO
671da177e4SLinus Torvalds 
680a8ea437SDavid Howells static int nfs4_stat_to_errno(int);
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
711da177e4SLinus Torvalds #ifdef DEBUG
721da177e4SLinus Torvalds #define NFS4_MAXTAGLEN		20
731da177e4SLinus Torvalds #else
741da177e4SLinus Torvalds #define NFS4_MAXTAGLEN		0
751da177e4SLinus Torvalds #endif
761da177e4SLinus Torvalds 
771da177e4SLinus Torvalds /* lock,open owner id:
789f958ab8STrond Myklebust  * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT  >> 2)
791da177e4SLinus Torvalds  */
8095b72eb0STrond Myklebust #define open_owner_id_maxsz	(1 + 2 + 1 + 1 + 2)
81d035c36cSTrond Myklebust #define lock_owner_id_maxsz	(1 + 1 + 4)
829104a55dSTrond Myklebust #define decode_lockowner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
831da177e4SLinus Torvalds #define compound_encode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
841da177e4SLinus Torvalds #define compound_decode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
851da177e4SLinus Torvalds #define op_encode_hdr_maxsz	(1)
861da177e4SLinus Torvalds #define op_decode_hdr_maxsz	(2)
879104a55dSTrond Myklebust #define encode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
889104a55dSTrond Myklebust #define decode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
899104a55dSTrond Myklebust #define encode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
909104a55dSTrond Myklebust #define decode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
911da177e4SLinus Torvalds #define encode_putfh_maxsz	(op_encode_hdr_maxsz + 1 + \
921da177e4SLinus Torvalds 				(NFS4_FHSIZE >> 2))
931da177e4SLinus Torvalds #define decode_putfh_maxsz	(op_decode_hdr_maxsz)
941da177e4SLinus Torvalds #define encode_putrootfh_maxsz	(op_encode_hdr_maxsz)
951da177e4SLinus Torvalds #define decode_putrootfh_maxsz	(op_decode_hdr_maxsz)
961da177e4SLinus Torvalds #define encode_getfh_maxsz      (op_encode_hdr_maxsz)
971da177e4SLinus Torvalds #define decode_getfh_maxsz      (op_decode_hdr_maxsz + 1 + \
981da177e4SLinus Torvalds 				((3+NFS4_FHSIZE) >> 2))
99e5012d1fSAndy Adamson #define nfs4_fattr_bitmap_maxsz 4
10096928206SJ. Bruce Fields #define encode_getattr_maxsz    (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
1011da177e4SLinus Torvalds #define nfs4_name_maxsz		(1 + ((3 + NFS4_MAXNAMLEN) >> 2))
1021da177e4SLinus Torvalds #define nfs4_path_maxsz		(1 + ((3 + NFS4_MAXPATHLEN) >> 2))
103bd625ba8STrond Myklebust #define nfs4_owner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
104bd625ba8STrond Myklebust #define nfs4_group_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
105aa9c2669SDavid Quigley #ifdef CONFIG_NFS_V4_SECURITY_LABEL
106aa9c2669SDavid Quigley /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
107aa9c2669SDavid Quigley #define	nfs4_label_maxsz	(4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
108aa9c2669SDavid Quigley #else
109aa9c2669SDavid Quigley #define	nfs4_label_maxsz	0
110aa9c2669SDavid Quigley #endif
11188034c3dSAndy Adamson /* We support only one layout type per file system */
11288034c3dSAndy Adamson #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
11396928206SJ. Bruce Fields /* This is based on getfattr, which uses the most attributes: */
11496928206SJ. Bruce Fields #define nfs4_fattr_value_maxsz	(1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
11588034c3dSAndy Adamson 				3 + 3 + 3 + nfs4_owner_maxsz + \
116aa9c2669SDavid Quigley 				nfs4_group_maxsz + nfs4_label_maxsz + \
117aa9c2669SDavid Quigley 				 decode_mdsthreshold_maxsz))
11896928206SJ. Bruce Fields #define nfs4_fattr_maxsz	(nfs4_fattr_bitmap_maxsz + \
11996928206SJ. Bruce Fields 				nfs4_fattr_value_maxsz)
12096928206SJ. Bruce Fields #define decode_getattr_maxsz    (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
1219104a55dSTrond Myklebust #define encode_attrs_maxsz	(nfs4_fattr_bitmap_maxsz + \
1229104a55dSTrond Myklebust 				 1 + 2 + 1 + \
1239104a55dSTrond Myklebust 				nfs4_owner_maxsz + \
1249104a55dSTrond Myklebust 				nfs4_group_maxsz + \
125aa9c2669SDavid Quigley 				nfs4_label_maxsz + \
1269104a55dSTrond Myklebust 				4 + 4)
1271da177e4SLinus Torvalds #define encode_savefh_maxsz     (op_encode_hdr_maxsz)
1281da177e4SLinus Torvalds #define decode_savefh_maxsz     (op_decode_hdr_maxsz)
12956ae19f3STrond Myklebust #define encode_restorefh_maxsz  (op_encode_hdr_maxsz)
13056ae19f3STrond Myklebust #define decode_restorefh_maxsz  (op_decode_hdr_maxsz)
1312f42b5d0SFred Isaman #define encode_fsinfo_maxsz	(encode_getattr_maxsz)
132dae100c2SFred Isaman /* The 5 accounts for the PNFS attributes, and assumes that at most three
133dae100c2SFred Isaman  * layout types will be returned.
134dae100c2SFred Isaman  */
135dae100c2SFred Isaman #define decode_fsinfo_maxsz	(op_decode_hdr_maxsz + \
136dae100c2SFred Isaman 				 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
1371da177e4SLinus Torvalds #define encode_renew_maxsz	(op_encode_hdr_maxsz + 3)
1381da177e4SLinus Torvalds #define decode_renew_maxsz	(op_decode_hdr_maxsz)
1391da177e4SLinus Torvalds #define encode_setclientid_maxsz \
1401da177e4SLinus Torvalds 				(op_encode_hdr_maxsz + \
141cc38bac3SChuck Lever 				XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
142b8fb2f59SJeff Layton 				/* client name */ \
143b8fb2f59SJeff Layton 				1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
144cc38bac3SChuck Lever 				1 /* sc_prog */ + \
1456dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
1466dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
147cc38bac3SChuck Lever 				1) /* sc_cb_ident */
1481da177e4SLinus Torvalds #define decode_setclientid_maxsz \
1491da177e4SLinus Torvalds 				(op_decode_hdr_maxsz + \
1506dd3436bSChuck Lever 				2 /* clientid */ + \
1516dd3436bSChuck Lever 				XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
1526dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
1536dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
1541da177e4SLinus Torvalds #define encode_setclientid_confirm_maxsz \
1551da177e4SLinus Torvalds 				(op_encode_hdr_maxsz + \
1561da177e4SLinus Torvalds 				3 + (NFS4_VERIFIER_SIZE >> 2))
1571da177e4SLinus Torvalds #define decode_setclientid_confirm_maxsz \
1581da177e4SLinus Torvalds 				(op_decode_hdr_maxsz)
159e6889620STrond Myklebust #define encode_lookup_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
160e6889620STrond Myklebust #define decode_lookup_maxsz	(op_decode_hdr_maxsz)
1612cebf828STrond Myklebust #define encode_share_access_maxsz \
1622cebf828STrond Myklebust 				(2)
1634882ef72SAlexandros Batsakis #define encode_createmode_maxsz	(1 + encode_attrs_maxsz + encode_verifier_maxsz)
1642cebf828STrond Myklebust #define encode_opentype_maxsz	(1 + encode_createmode_maxsz)
1652cebf828STrond Myklebust #define encode_claim_null_maxsz	(1 + nfs4_name_maxsz)
1662cebf828STrond Myklebust #define encode_open_maxsz	(op_encode_hdr_maxsz + \
1672cebf828STrond Myklebust 				2 + encode_share_access_maxsz + 2 + \
1682cebf828STrond Myklebust 				open_owner_id_maxsz + \
1692cebf828STrond Myklebust 				encode_opentype_maxsz + \
1702cebf828STrond Myklebust 				encode_claim_null_maxsz)
1712cebf828STrond Myklebust #define decode_ace_maxsz	(3 + nfs4_owner_maxsz)
1729104a55dSTrond Myklebust #define decode_delegation_maxsz	(1 + decode_stateid_maxsz + 1 + \
1732cebf828STrond Myklebust 				decode_ace_maxsz)
1742cebf828STrond Myklebust #define decode_change_info_maxsz	(5)
1752cebf828STrond Myklebust #define decode_open_maxsz	(op_decode_hdr_maxsz + \
1769104a55dSTrond Myklebust 				decode_stateid_maxsz + \
1772cebf828STrond Myklebust 				decode_change_info_maxsz + 1 + \
1782cebf828STrond Myklebust 				nfs4_fattr_bitmap_maxsz + \
1792cebf828STrond Myklebust 				decode_delegation_maxsz)
1809104a55dSTrond Myklebust #define encode_open_confirm_maxsz \
1819104a55dSTrond Myklebust 				(op_encode_hdr_maxsz + \
1829104a55dSTrond Myklebust 				 encode_stateid_maxsz + 1)
1839104a55dSTrond Myklebust #define decode_open_confirm_maxsz \
1849104a55dSTrond Myklebust 				(op_decode_hdr_maxsz + \
1859104a55dSTrond Myklebust 				 decode_stateid_maxsz)
1869104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \
1879104a55dSTrond Myklebust 				(op_encode_hdr_maxsz + \
1889104a55dSTrond Myklebust 				 encode_stateid_maxsz + 1 + \
1899104a55dSTrond Myklebust 				 encode_share_access_maxsz)
1909104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \
1919104a55dSTrond Myklebust 				(op_decode_hdr_maxsz + \
1929104a55dSTrond Myklebust 				 decode_stateid_maxsz)
1939104a55dSTrond Myklebust #define encode_close_maxsz	(op_encode_hdr_maxsz + \
1949104a55dSTrond Myklebust 				 1 + encode_stateid_maxsz)
1959104a55dSTrond Myklebust #define decode_close_maxsz	(op_decode_hdr_maxsz + \
1969104a55dSTrond Myklebust 				 decode_stateid_maxsz)
1979104a55dSTrond Myklebust #define encode_setattr_maxsz	(op_encode_hdr_maxsz + \
1989104a55dSTrond Myklebust 				 encode_stateid_maxsz + \
1999104a55dSTrond Myklebust 				 encode_attrs_maxsz)
2009104a55dSTrond Myklebust #define decode_setattr_maxsz	(op_decode_hdr_maxsz + \
2019104a55dSTrond Myklebust 				 nfs4_fattr_bitmap_maxsz)
2029104a55dSTrond Myklebust #define encode_read_maxsz	(op_encode_hdr_maxsz + \
2039104a55dSTrond Myklebust 				 encode_stateid_maxsz + 3)
2049104a55dSTrond Myklebust #define decode_read_maxsz	(op_decode_hdr_maxsz + 2)
2059104a55dSTrond Myklebust #define encode_readdir_maxsz	(op_encode_hdr_maxsz + \
206aa9c2669SDavid Quigley 				 2 + encode_verifier_maxsz + 5 + \
207aa9c2669SDavid Quigley 				nfs4_label_maxsz)
2089104a55dSTrond Myklebust #define decode_readdir_maxsz	(op_decode_hdr_maxsz + \
209a7697f6fSChuck Lever 				 decode_verifier_maxsz)
2109104a55dSTrond Myklebust #define encode_readlink_maxsz	(op_encode_hdr_maxsz)
2119104a55dSTrond Myklebust #define decode_readlink_maxsz	(op_decode_hdr_maxsz + 1)
2129104a55dSTrond Myklebust #define encode_write_maxsz	(op_encode_hdr_maxsz + \
2139104a55dSTrond Myklebust 				 encode_stateid_maxsz + 4)
2149104a55dSTrond Myklebust #define decode_write_maxsz	(op_decode_hdr_maxsz + \
2159104a55dSTrond Myklebust 				 2 + decode_verifier_maxsz)
2169104a55dSTrond Myklebust #define encode_commit_maxsz	(op_encode_hdr_maxsz + 3)
2179104a55dSTrond Myklebust #define decode_commit_maxsz	(op_decode_hdr_maxsz + \
2189104a55dSTrond Myklebust 				 decode_verifier_maxsz)
2191da177e4SLinus Torvalds #define encode_remove_maxsz	(op_encode_hdr_maxsz + \
2201da177e4SLinus Torvalds 				nfs4_name_maxsz)
2216ce18391SBenny Halevy #define decode_remove_maxsz	(op_decode_hdr_maxsz + \
2226ce18391SBenny Halevy 				 decode_change_info_maxsz)
2231da177e4SLinus Torvalds #define encode_rename_maxsz	(op_encode_hdr_maxsz + \
2241da177e4SLinus Torvalds 				2 * nfs4_name_maxsz)
2256ce18391SBenny Halevy #define decode_rename_maxsz	(op_decode_hdr_maxsz + \
2266ce18391SBenny Halevy 				 decode_change_info_maxsz + \
2276ce18391SBenny Halevy 				 decode_change_info_maxsz)
2281da177e4SLinus Torvalds #define encode_link_maxsz	(op_encode_hdr_maxsz + \
2291da177e4SLinus Torvalds 				nfs4_name_maxsz)
2306ce18391SBenny Halevy #define decode_link_maxsz	(op_decode_hdr_maxsz + decode_change_info_maxsz)
231daccbdedSTrond Myklebust #define encode_lockowner_maxsz	(7)
2329104a55dSTrond Myklebust #define encode_lock_maxsz	(op_encode_hdr_maxsz + \
2339104a55dSTrond Myklebust 				 7 + \
234daccbdedSTrond Myklebust 				 1 + encode_stateid_maxsz + 1 + \
235daccbdedSTrond Myklebust 				 encode_lockowner_maxsz)
2369104a55dSTrond Myklebust #define decode_lock_denied_maxsz \
2379104a55dSTrond Myklebust 				(8 + decode_lockowner_maxsz)
2389104a55dSTrond Myklebust #define decode_lock_maxsz	(op_decode_hdr_maxsz + \
2399104a55dSTrond Myklebust 				 decode_lock_denied_maxsz)
240daccbdedSTrond Myklebust #define encode_lockt_maxsz	(op_encode_hdr_maxsz + 5 + \
241daccbdedSTrond Myklebust 				encode_lockowner_maxsz)
2429104a55dSTrond Myklebust #define decode_lockt_maxsz	(op_decode_hdr_maxsz + \
2439104a55dSTrond Myklebust 				 decode_lock_denied_maxsz)
2449104a55dSTrond Myklebust #define encode_locku_maxsz	(op_encode_hdr_maxsz + 3 + \
2459104a55dSTrond Myklebust 				 encode_stateid_maxsz + \
2469104a55dSTrond Myklebust 				 4)
2479104a55dSTrond Myklebust #define decode_locku_maxsz	(op_decode_hdr_maxsz + \
2489104a55dSTrond Myklebust 				 decode_stateid_maxsz)
249d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \
250d3c7b7ccSTrond Myklebust 				(op_encode_hdr_maxsz + \
251d3c7b7ccSTrond Myklebust 				 encode_lockowner_maxsz)
252d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \
253d3c7b7ccSTrond Myklebust 				(op_decode_hdr_maxsz)
2549104a55dSTrond Myklebust #define encode_access_maxsz	(op_encode_hdr_maxsz + 1)
2559104a55dSTrond Myklebust #define decode_access_maxsz	(op_decode_hdr_maxsz + 2)
2561da177e4SLinus Torvalds #define encode_symlink_maxsz	(op_encode_hdr_maxsz + \
2571da177e4SLinus Torvalds 				1 + nfs4_name_maxsz + \
25894a6d753SChuck Lever 				1 + \
25996928206SJ. Bruce Fields 				nfs4_fattr_maxsz)
2601da177e4SLinus Torvalds #define decode_symlink_maxsz	(op_decode_hdr_maxsz + 8)
2611da177e4SLinus Torvalds #define encode_create_maxsz	(op_encode_hdr_maxsz + \
2629104a55dSTrond Myklebust 				1 + 2 + nfs4_name_maxsz + \
2639104a55dSTrond Myklebust 				encode_attrs_maxsz)
2642cebf828STrond Myklebust #define decode_create_maxsz	(op_decode_hdr_maxsz + \
2652cebf828STrond Myklebust 				decode_change_info_maxsz + \
2662cebf828STrond Myklebust 				nfs4_fattr_bitmap_maxsz)
2679104a55dSTrond Myklebust #define encode_statfs_maxsz	(encode_getattr_maxsz)
2689104a55dSTrond Myklebust #define decode_statfs_maxsz	(decode_getattr_maxsz)
2691da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
2701da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
2719104a55dSTrond Myklebust #define encode_getacl_maxsz	(encode_getattr_maxsz)
2729104a55dSTrond Myklebust #define decode_getacl_maxsz	(op_decode_hdr_maxsz + \
2739104a55dSTrond Myklebust 				 nfs4_fattr_bitmap_maxsz + 1)
2749104a55dSTrond Myklebust #define encode_setacl_maxsz	(op_encode_hdr_maxsz + \
2759104a55dSTrond Myklebust 				 encode_stateid_maxsz + 3)
2769104a55dSTrond Myklebust #define decode_setacl_maxsz	(decode_setattr_maxsz)
277e6889620STrond Myklebust #define encode_fs_locations_maxsz \
278e6889620STrond Myklebust 				(encode_getattr_maxsz)
279e6889620STrond Myklebust #define decode_fs_locations_maxsz \
280e6889620STrond Myklebust 				(0)
2815a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
2821650add2SBryan Schumaker #define decode_secinfo_maxsz	(op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
2839b7b9fccSAndy Adamson 
2849b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
285fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64)
286d751f748SJim Rees #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
287d751f748SJim Rees 			 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
288fc931582SAndy Adamson 
28999fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
29099fe60d0SBenny Halevy 				encode_verifier_maxsz + \
29199fe60d0SBenny Halevy 				1 /* co_ownerid.len */ + \
292b8fb2f59SJeff Layton 				/* eia_clientowner */ \
293b8fb2f59SJeff Layton 				1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
29499fe60d0SBenny Halevy 				1 /* flags */ + \
29599fe60d0SBenny Halevy 				1 /* spa_how */ + \
2962031cd1aSWeston Andros Adamson 				/* max is SP4_MACH_CRED (for now) */ + \
2972031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
2982031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
299db8ac8baSWeston Andros Adamson 				1 /* implementation id array of size 1 */ + \
300db8ac8baSWeston Andros Adamson 				1 /* nii_domain */ + \
301db8ac8baSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
302db8ac8baSWeston Andros Adamson 				1 /* nii_name */ + \
303d751f748SJim Rees 				XDR_QUADLEN(IMPL_NAME_LIMIT) + \
304db8ac8baSWeston Andros Adamson 				3 /* nii_date */)
30599fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
30699fe60d0SBenny Halevy 				2 /* eir_clientid */ + \
30799fe60d0SBenny Halevy 				1 /* eir_sequenceid */ + \
30899fe60d0SBenny Halevy 				1 /* eir_flags */ + \
30999fe60d0SBenny Halevy 				1 /* spr_how */ + \
3102031cd1aSWeston Andros Adamson 				  /* max is SP4_MACH_CRED (for now) */ + \
3112031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
3122031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
31399fe60d0SBenny Halevy 				2 /* eir_server_owner.so_minor_id */ + \
31499fe60d0SBenny Halevy 				/* eir_server_owner.so_major_id<> */ \
31599fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
31699fe60d0SBenny Halevy 				/* eir_server_scope<> */ \
31799fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
31899fe60d0SBenny Halevy 				1 /* eir_server_impl_id array length */ + \
3197d2ed9acSWeston Andros Adamson 				1 /* nii_domain */ + \
3207d2ed9acSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
3217d2ed9acSWeston Andros Adamson 				1 /* nii_name */ + \
3227d2ed9acSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
3237d2ed9acSWeston Andros Adamson 				3 /* nii_date */)
324fc931582SAndy Adamson #define encode_channel_attrs_maxsz  (6 + 1 /* ca_rdma_ird.len (0) */)
325fc931582SAndy Adamson #define decode_channel_attrs_maxsz  (6 + \
326fc931582SAndy Adamson 				     1 /* ca_rdma_ird.len */ + \
327fc931582SAndy Adamson 				     1 /* ca_rdma_ird */)
328fc931582SAndy Adamson #define encode_create_session_maxsz  (op_encode_hdr_maxsz + \
329fc931582SAndy Adamson 				     2 /* csa_clientid */ + \
330fc931582SAndy Adamson 				     1 /* csa_sequence */ + \
331fc931582SAndy Adamson 				     1 /* csa_flags */ + \
332fc931582SAndy Adamson 				     encode_channel_attrs_maxsz + \
333fc931582SAndy Adamson 				     encode_channel_attrs_maxsz + \
334fc931582SAndy Adamson 				     1 /* csa_cb_program */ + \
335fc931582SAndy Adamson 				     1 /* csa_sec_parms.len (1) */ + \
336fc931582SAndy Adamson 				     1 /* cb_secflavor (AUTH_SYS) */ + \
337fc931582SAndy Adamson 				     1 /* stamp */ + \
338fc931582SAndy Adamson 				     1 /* machinename.len */ + \
339fc931582SAndy Adamson 				     XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
340fc931582SAndy Adamson 				     1 /* uid */ + \
341fc931582SAndy Adamson 				     1 /* gid */ + \
342fc931582SAndy Adamson 				     1 /* gids.len (0) */)
343fc931582SAndy Adamson #define decode_create_session_maxsz  (op_decode_hdr_maxsz +	\
344fc931582SAndy Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
345fc931582SAndy Adamson 				     1 /* csr_sequence */ + \
346fc931582SAndy Adamson 				     1 /* csr_flags */ + \
347fc931582SAndy Adamson 				     decode_channel_attrs_maxsz + \
348fc931582SAndy Adamson 				     decode_channel_attrs_maxsz)
3497c44f1aeSWeston Andros Adamson #define encode_bind_conn_to_session_maxsz  (op_encode_hdr_maxsz + \
3507c44f1aeSWeston Andros Adamson 				     /* bctsa_sessid */ \
3517c44f1aeSWeston Andros Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
3527c44f1aeSWeston Andros Adamson 				     1 /* bctsa_dir */ + \
3537c44f1aeSWeston Andros Adamson 				     1 /* bctsa_use_conn_in_rdma_mode */)
3547c44f1aeSWeston Andros Adamson #define decode_bind_conn_to_session_maxsz  (op_decode_hdr_maxsz +	\
3557c44f1aeSWeston Andros Adamson 				     /* bctsr_sessid */ \
3567c44f1aeSWeston Andros Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
3577c44f1aeSWeston Andros Adamson 				     1 /* bctsr_dir */ + \
3587c44f1aeSWeston Andros Adamson 				     1 /* bctsr_use_conn_in_rdma_mode */)
3590f3e66c6SAndy Adamson #define encode_destroy_session_maxsz    (op_encode_hdr_maxsz + 4)
3600f3e66c6SAndy Adamson #define decode_destroy_session_maxsz    (op_decode_hdr_maxsz)
36166245539STrond Myklebust #define encode_destroy_clientid_maxsz   (op_encode_hdr_maxsz + 2)
36266245539STrond Myklebust #define decode_destroy_clientid_maxsz   (op_decode_hdr_maxsz)
363fc01cea9SAndy Adamson #define encode_sequence_maxsz	(op_encode_hdr_maxsz + \
364fc01cea9SAndy Adamson 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
365fc01cea9SAndy Adamson #define decode_sequence_maxsz	(op_decode_hdr_maxsz + \
366fc01cea9SAndy Adamson 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
36718019753SRicardo Labiaga #define encode_reclaim_complete_maxsz	(op_encode_hdr_maxsz + 4)
36818019753SRicardo Labiaga #define decode_reclaim_complete_maxsz	(op_decode_hdr_maxsz + 4)
36984c9dee3SChristoph Hellwig #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
37084c9dee3SChristoph Hellwig 				XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
37184c9dee3SChristoph Hellwig 				1 /* layout type */ + \
37284c9dee3SChristoph Hellwig 				1 /* maxcount */ + \
37384c9dee3SChristoph Hellwig 				1 /* bitmap size */ + \
37484c9dee3SChristoph Hellwig 				1 /* notification bitmap length */ + \
37584c9dee3SChristoph Hellwig 				1 /* notification bitmap, word 0 */)
376b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
377b1f69b75SAndy Adamson 				1 /* layout type */ + \
378b1f69b75SAndy Adamson 				1 /* opaque devaddr4 length */ + \
379b1f69b75SAndy Adamson 				  /* devaddr4 payload is read into page */ \
380b1f69b75SAndy Adamson 				1 /* notification bitmap length */ + \
38184c9dee3SChristoph Hellwig 				1 /* notification bitmap, word 0 */)
382b1f69b75SAndy Adamson #define encode_layoutget_maxsz	(op_encode_hdr_maxsz + 10 + \
383b1f69b75SAndy Adamson 				encode_stateid_maxsz)
384b1f69b75SAndy Adamson #define decode_layoutget_maxsz	(op_decode_hdr_maxsz + 8 + \
385b1f69b75SAndy Adamson 				decode_stateid_maxsz + \
386b1f69b75SAndy Adamson 				XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
387863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
388863a3c6cSAndy Adamson 				2 /* offset */ + \
389863a3c6cSAndy Adamson 				2 /* length */ + \
390863a3c6cSAndy Adamson 				1 /* reclaim */ + \
391863a3c6cSAndy Adamson 				encode_stateid_maxsz + \
392863a3c6cSAndy Adamson 				1 /* new offset (true) */ + \
393863a3c6cSAndy Adamson 				2 /* last byte written */ + \
394863a3c6cSAndy Adamson 				1 /* nt_timechanged (false) */ + \
395863a3c6cSAndy Adamson 				1 /* layoutupdate4 layout type */ + \
3965f919c9fSChristoph Hellwig 				1 /* layoutupdate4 opaqueue len */)
3975f919c9fSChristoph Hellwig 				  /* the actual content of layoutupdate4 should
3985f919c9fSChristoph Hellwig 				     be allocated by drivers and spliced in
3995f919c9fSChristoph Hellwig 				     using xdr_write_pages */
400863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
401cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
402cbe82603SBenny Halevy 				encode_stateid_maxsz + \
4036669cb8bSTrond Myklebust 				1 + \
4046669cb8bSTrond Myklebust 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
405cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
406cbe82603SBenny Halevy 				1 + decode_stateid_maxsz)
407fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
408fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
4097d974794SBryan Schumaker #define encode_test_stateid_maxsz	(op_encode_hdr_maxsz + 2 + \
4107d974794SBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
4117d974794SBryan Schumaker #define decode_test_stateid_maxsz	(op_decode_hdr_maxsz + 2 + 1)
4129aeda35fSBryan Schumaker #define encode_free_stateid_maxsz	(op_encode_hdr_maxsz + 1 + \
4139aeda35fSBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
4149f79fb48SAndy Adamson #define decode_free_stateid_maxsz	(op_decode_hdr_maxsz)
4159b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */
4169b7b9fccSAndy Adamson #define encode_sequence_maxsz	0
4179b7b9fccSAndy Adamson #define decode_sequence_maxsz	0
4189b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
4199b7b9fccSAndy Adamson 
4201da177e4SLinus Torvalds #define NFS4_enc_compound_sz	(1024)  /* XXX: large enough? */
4211da177e4SLinus Torvalds #define NFS4_dec_compound_sz	(1024)  /* XXX: large enough? */
4221da177e4SLinus Torvalds #define NFS4_enc_read_sz	(compound_encode_hdr_maxsz + \
4239b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4241da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4259104a55dSTrond Myklebust 				encode_read_maxsz)
4261da177e4SLinus Torvalds #define NFS4_dec_read_sz	(compound_decode_hdr_maxsz + \
4279b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4281da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4299104a55dSTrond Myklebust 				decode_read_maxsz)
4301da177e4SLinus Torvalds #define NFS4_enc_readlink_sz	(compound_encode_hdr_maxsz + \
4319b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4321da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4339104a55dSTrond Myklebust 				encode_readlink_maxsz)
4341da177e4SLinus Torvalds #define NFS4_dec_readlink_sz	(compound_decode_hdr_maxsz + \
4359b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4361da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4379104a55dSTrond Myklebust 				decode_readlink_maxsz)
4381da177e4SLinus Torvalds #define NFS4_enc_readdir_sz	(compound_encode_hdr_maxsz + \
4399b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4401da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4419104a55dSTrond Myklebust 				encode_readdir_maxsz)
4421da177e4SLinus Torvalds #define NFS4_dec_readdir_sz	(compound_decode_hdr_maxsz + \
4439b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4441da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4459104a55dSTrond Myklebust 				decode_readdir_maxsz)
4461da177e4SLinus Torvalds #define NFS4_enc_write_sz	(compound_encode_hdr_maxsz + \
4479b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4481da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4499104a55dSTrond Myklebust 				encode_write_maxsz + \
4504f9838c7STrond Myklebust 				encode_getattr_maxsz)
4511da177e4SLinus Torvalds #define NFS4_dec_write_sz	(compound_decode_hdr_maxsz + \
4529b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4531da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4549104a55dSTrond Myklebust 				decode_write_maxsz + \
4554f9838c7STrond Myklebust 				decode_getattr_maxsz)
4561da177e4SLinus Torvalds #define NFS4_enc_commit_sz	(compound_encode_hdr_maxsz + \
4579b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4581da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4598582715eSTrond Myklebust 				encode_commit_maxsz)
4601da177e4SLinus Torvalds #define NFS4_dec_commit_sz	(compound_decode_hdr_maxsz + \
4619b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4621da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4638582715eSTrond Myklebust 				decode_commit_maxsz)
4641da177e4SLinus Torvalds #define NFS4_enc_open_sz        (compound_encode_hdr_maxsz + \
4659b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4661da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4672cebf828STrond Myklebust 				encode_open_maxsz + \
4686168f62cSWeston Andros Adamson 				encode_access_maxsz + \
4692cebf828STrond Myklebust 				encode_getfh_maxsz + \
4702cebf828STrond Myklebust 				encode_getattr_maxsz)
4711da177e4SLinus Torvalds #define NFS4_dec_open_sz        (compound_decode_hdr_maxsz + \
4729b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4731da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4742cebf828STrond Myklebust 				decode_open_maxsz + \
4756168f62cSWeston Andros Adamson 				decode_access_maxsz + \
4762cebf828STrond Myklebust 				decode_getfh_maxsz + \
4772cebf828STrond Myklebust 				decode_getattr_maxsz)
4781da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \
4791da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
4801da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
4819104a55dSTrond Myklebust 				 encode_open_confirm_maxsz)
4829104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \
4839104a55dSTrond Myklebust 				(compound_decode_hdr_maxsz + \
4841da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
4859104a55dSTrond Myklebust 				 decode_open_confirm_maxsz)
4861da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz	(compound_encode_hdr_maxsz + \
4879b7b9fccSAndy Adamson 					encode_sequence_maxsz + \
4881da177e4SLinus Torvalds 					encode_putfh_maxsz + \
4892cebf828STrond Myklebust 					encode_open_maxsz + \
4906168f62cSWeston Andros Adamson 					encode_access_maxsz + \
4912cebf828STrond Myklebust 					encode_getattr_maxsz)
4921da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz	(compound_decode_hdr_maxsz + \
4939b7b9fccSAndy Adamson 					decode_sequence_maxsz + \
4941da177e4SLinus Torvalds 					decode_putfh_maxsz + \
4952cebf828STrond Myklebust 					decode_open_maxsz + \
4966168f62cSWeston Andros Adamson 					decode_access_maxsz + \
4972cebf828STrond Myklebust 					decode_getattr_maxsz)
4981da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \
4991da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
5009b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5011da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
5029104a55dSTrond Myklebust 				 encode_open_downgrade_maxsz + \
503516a6af6STrond Myklebust 				 encode_getattr_maxsz)
5041da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \
5051da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
5069b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5071da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
5089104a55dSTrond Myklebust 				 decode_open_downgrade_maxsz + \
509516a6af6STrond Myklebust 				 decode_getattr_maxsz)
5101da177e4SLinus Torvalds #define NFS4_enc_close_sz	(compound_encode_hdr_maxsz + \
5119b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5121da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
5139104a55dSTrond Myklebust 				 encode_close_maxsz + \
514516a6af6STrond Myklebust 				 encode_getattr_maxsz)
5151da177e4SLinus Torvalds #define NFS4_dec_close_sz	(compound_decode_hdr_maxsz + \
5169b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5171da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
5189104a55dSTrond Myklebust 				 decode_close_maxsz + \
519516a6af6STrond Myklebust 				 decode_getattr_maxsz)
5201da177e4SLinus Torvalds #define NFS4_enc_setattr_sz	(compound_encode_hdr_maxsz + \
5219b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5221da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
5239104a55dSTrond Myklebust 				 encode_setattr_maxsz + \
5241da177e4SLinus Torvalds 				 encode_getattr_maxsz)
5251da177e4SLinus Torvalds #define NFS4_dec_setattr_sz	(compound_decode_hdr_maxsz + \
5269b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5271da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
5289104a55dSTrond Myklebust 				 decode_setattr_maxsz + \
5299104a55dSTrond Myklebust 				 decode_getattr_maxsz)
5301da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz	(compound_encode_hdr_maxsz + \
5319b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5321da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5331da177e4SLinus Torvalds 				encode_fsinfo_maxsz)
5341da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz	(compound_decode_hdr_maxsz + \
5359b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5361da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5371da177e4SLinus Torvalds 				decode_fsinfo_maxsz)
5381da177e4SLinus Torvalds #define NFS4_enc_renew_sz	(compound_encode_hdr_maxsz + \
5391da177e4SLinus Torvalds 				encode_renew_maxsz)
5401da177e4SLinus Torvalds #define NFS4_dec_renew_sz	(compound_decode_hdr_maxsz + \
5411da177e4SLinus Torvalds 				decode_renew_maxsz)
5421da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz	(compound_encode_hdr_maxsz + \
5431da177e4SLinus Torvalds 				encode_setclientid_maxsz)
5441da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz	(compound_decode_hdr_maxsz + \
5451da177e4SLinus Torvalds 				decode_setclientid_maxsz)
5461da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \
5471da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
54883ca7f5aSChuck Lever 				encode_setclientid_confirm_maxsz)
5491da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \
5501da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
55183ca7f5aSChuck Lever 				decode_setclientid_confirm_maxsz)
5521da177e4SLinus Torvalds #define NFS4_enc_lock_sz        (compound_encode_hdr_maxsz + \
5539b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5541da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5559104a55dSTrond Myklebust 				encode_lock_maxsz)
5561da177e4SLinus Torvalds #define NFS4_dec_lock_sz        (compound_decode_hdr_maxsz + \
5579b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5581da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5599104a55dSTrond Myklebust 				decode_lock_maxsz)
5601da177e4SLinus Torvalds #define NFS4_enc_lockt_sz       (compound_encode_hdr_maxsz + \
5619b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5621da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5639104a55dSTrond Myklebust 				encode_lockt_maxsz)
5649104a55dSTrond Myklebust #define NFS4_dec_lockt_sz       (compound_decode_hdr_maxsz + \
5659b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5669104a55dSTrond Myklebust 				 decode_putfh_maxsz + \
5679104a55dSTrond Myklebust 				 decode_lockt_maxsz)
5681da177e4SLinus Torvalds #define NFS4_enc_locku_sz       (compound_encode_hdr_maxsz + \
5699b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5701da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5719104a55dSTrond Myklebust 				encode_locku_maxsz)
5721da177e4SLinus Torvalds #define NFS4_dec_locku_sz       (compound_decode_hdr_maxsz + \
5739b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5741da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5759104a55dSTrond Myklebust 				decode_locku_maxsz)
576d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \
577d3c7b7ccSTrond Myklebust 				(compound_encode_hdr_maxsz + \
578d3c7b7ccSTrond Myklebust 				 encode_lockowner_maxsz)
579d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \
580d3c7b7ccSTrond Myklebust 				(compound_decode_hdr_maxsz + \
581d3c7b7ccSTrond Myklebust 				 decode_lockowner_maxsz)
5821da177e4SLinus Torvalds #define NFS4_enc_access_sz	(compound_encode_hdr_maxsz + \
5839b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5841da177e4SLinus Torvalds 				encode_putfh_maxsz + \
58576b32999STrond Myklebust 				encode_access_maxsz + \
58676b32999STrond Myklebust 				encode_getattr_maxsz)
5871da177e4SLinus Torvalds #define NFS4_dec_access_sz	(compound_decode_hdr_maxsz + \
5889b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5891da177e4SLinus Torvalds 				decode_putfh_maxsz + \
59076b32999STrond Myklebust 				decode_access_maxsz + \
59176b32999STrond Myklebust 				decode_getattr_maxsz)
5921da177e4SLinus Torvalds #define NFS4_enc_getattr_sz	(compound_encode_hdr_maxsz + \
5939b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5941da177e4SLinus Torvalds 				encode_putfh_maxsz + \
59544c99933SChuck Lever 				encode_getattr_maxsz + \
59644c99933SChuck Lever 				encode_renew_maxsz)
5971da177e4SLinus Torvalds #define NFS4_dec_getattr_sz	(compound_decode_hdr_maxsz + \
5989b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5991da177e4SLinus Torvalds 				decode_putfh_maxsz + \
60044c99933SChuck Lever 				decode_getattr_maxsz + \
60144c99933SChuck Lever 				decode_renew_maxsz)
6021da177e4SLinus Torvalds #define NFS4_enc_lookup_sz	(compound_encode_hdr_maxsz + \
6039b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6041da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6051da177e4SLinus Torvalds 				encode_lookup_maxsz + \
6061da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6071da177e4SLinus Torvalds 				encode_getfh_maxsz)
6081da177e4SLinus Torvalds #define NFS4_dec_lookup_sz	(compound_decode_hdr_maxsz + \
6099b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6101da177e4SLinus Torvalds 				decode_putfh_maxsz + \
611e6889620STrond Myklebust 				decode_lookup_maxsz + \
6121da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6131da177e4SLinus Torvalds 				decode_getfh_maxsz)
6141da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
6159b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6161da177e4SLinus Torvalds 				encode_putrootfh_maxsz + \
6171da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6181da177e4SLinus Torvalds 				encode_getfh_maxsz)
6191da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
6209b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6211da177e4SLinus Torvalds 				decode_putrootfh_maxsz + \
6221da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6231da177e4SLinus Torvalds 				decode_getfh_maxsz)
6241da177e4SLinus Torvalds #define NFS4_enc_remove_sz	(compound_encode_hdr_maxsz + \
6259b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6261da177e4SLinus Torvalds 				encode_putfh_maxsz + \
627778d2817STrond Myklebust 				encode_remove_maxsz)
6281da177e4SLinus Torvalds #define NFS4_dec_remove_sz	(compound_decode_hdr_maxsz + \
6299b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6301da177e4SLinus Torvalds 				decode_putfh_maxsz + \
631778d2817STrond Myklebust 				decode_remove_maxsz)
6321da177e4SLinus Torvalds #define NFS4_enc_rename_sz	(compound_encode_hdr_maxsz + \
6339b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6341da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6351da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6361da177e4SLinus Torvalds 				encode_putfh_maxsz + \
637778d2817STrond Myklebust 				encode_rename_maxsz)
6381da177e4SLinus Torvalds #define NFS4_dec_rename_sz	(compound_decode_hdr_maxsz + \
6399b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6401da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6411da177e4SLinus Torvalds 				decode_savefh_maxsz + \
6421da177e4SLinus Torvalds 				decode_putfh_maxsz + \
643778d2817STrond Myklebust 				decode_rename_maxsz)
6441da177e4SLinus Torvalds #define NFS4_enc_link_sz	(compound_encode_hdr_maxsz + \
6459b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6461da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6471da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6481da177e4SLinus Torvalds 				encode_putfh_maxsz + \
64991ba2eeeSTrond Myklebust 				encode_link_maxsz + \
65091ba2eeeSTrond Myklebust 				encode_restorefh_maxsz + \
651a9f6991bSTrond Myklebust 				encode_getattr_maxsz)
6521da177e4SLinus Torvalds #define NFS4_dec_link_sz	(compound_decode_hdr_maxsz + \
6539b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6541da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6551da177e4SLinus Torvalds 				decode_savefh_maxsz + \
6561da177e4SLinus Torvalds 				decode_putfh_maxsz + \
65791ba2eeeSTrond Myklebust 				decode_link_maxsz + \
65891ba2eeeSTrond Myklebust 				decode_restorefh_maxsz + \
65991ba2eeeSTrond Myklebust 				decode_getattr_maxsz)
6601da177e4SLinus Torvalds #define NFS4_enc_symlink_sz	(compound_encode_hdr_maxsz + \
6619b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6621da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6631da177e4SLinus Torvalds 				encode_symlink_maxsz + \
6641da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6651da177e4SLinus Torvalds 				encode_getfh_maxsz)
6661da177e4SLinus Torvalds #define NFS4_dec_symlink_sz	(compound_decode_hdr_maxsz + \
6679b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6681da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6691da177e4SLinus Torvalds 				decode_symlink_maxsz + \
6701da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6711da177e4SLinus Torvalds 				decode_getfh_maxsz)
6721da177e4SLinus Torvalds #define NFS4_enc_create_sz	(compound_encode_hdr_maxsz + \
6739b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6741da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6751da177e4SLinus Torvalds 				encode_create_maxsz + \
67656ae19f3STrond Myklebust 				encode_getfh_maxsz + \
67756ae19f3STrond Myklebust 				encode_getattr_maxsz)
6781da177e4SLinus Torvalds #define NFS4_dec_create_sz	(compound_decode_hdr_maxsz + \
6799b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6801da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6811da177e4SLinus Torvalds 				decode_create_maxsz + \
68256ae19f3STrond Myklebust 				decode_getfh_maxsz + \
68356ae19f3STrond Myklebust 				decode_getattr_maxsz)
6841da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz	(compound_encode_hdr_maxsz + \
6859b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6861da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6871da177e4SLinus Torvalds 				encode_getattr_maxsz)
6881da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz	(compound_decode_hdr_maxsz + \
6899b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6901da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6911da177e4SLinus Torvalds 				decode_getattr_maxsz)
6921da177e4SLinus Torvalds #define NFS4_enc_statfs_sz	(compound_encode_hdr_maxsz + \
6939b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6941da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6959104a55dSTrond Myklebust 				encode_statfs_maxsz)
6961da177e4SLinus Torvalds #define NFS4_dec_statfs_sz	(compound_decode_hdr_maxsz + \
6979b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6981da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6999104a55dSTrond Myklebust 				decode_statfs_maxsz)
7001da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
7019b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
702ab91f264STrond Myklebust 				encode_putfh_maxsz + \
7031da177e4SLinus Torvalds 				encode_getattr_maxsz)
7041da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
7059b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
706ab91f264STrond Myklebust 				decode_putfh_maxsz + \
7071da177e4SLinus Torvalds 				decode_getattr_maxsz)
7081da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz	(compound_encode_hdr_maxsz + \
7099b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
7101da177e4SLinus Torvalds 				encode_putfh_maxsz + \
711fa178f29STrond Myklebust 				encode_delegreturn_maxsz + \
712fa178f29STrond Myklebust 				encode_getattr_maxsz)
7131da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
7149b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
715fa178f29STrond Myklebust 				decode_delegreturn_maxsz + \
716fa178f29STrond Myklebust 				decode_getattr_maxsz)
717029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz	(compound_encode_hdr_maxsz + \
7189b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
719029d105eSJ. Bruce Fields 				encode_putfh_maxsz + \
7209104a55dSTrond Myklebust 				encode_getacl_maxsz)
721029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz	(compound_decode_hdr_maxsz + \
7229b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
723029d105eSJ. Bruce Fields 				decode_putfh_maxsz + \
7249104a55dSTrond Myklebust 				decode_getacl_maxsz)
72523ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz	(compound_encode_hdr_maxsz + \
7269b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
72723ec6965SJ. Bruce Fields 				encode_putfh_maxsz + \
7289104a55dSTrond Myklebust 				encode_setacl_maxsz)
72923ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz	(compound_decode_hdr_maxsz + \
7309b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
73123ec6965SJ. Bruce Fields 				decode_putfh_maxsz + \
7329104a55dSTrond Myklebust 				decode_setacl_maxsz)
733683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \
734683b57b4STrond Myklebust 				(compound_encode_hdr_maxsz + \
7359b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
736683b57b4STrond Myklebust 				 encode_putfh_maxsz + \
737e6889620STrond Myklebust 				 encode_lookup_maxsz + \
738b03d735bSChuck Lever 				 encode_fs_locations_maxsz + \
739b03d735bSChuck Lever 				 encode_renew_maxsz)
740683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \
741683b57b4STrond Myklebust 				(compound_decode_hdr_maxsz + \
7429b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
743683b57b4STrond Myklebust 				 decode_putfh_maxsz + \
744e6889620STrond Myklebust 				 decode_lookup_maxsz + \
745b03d735bSChuck Lever 				 decode_fs_locations_maxsz + \
746b03d735bSChuck Lever 				 decode_renew_maxsz)
7475a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz 	(compound_encode_hdr_maxsz + \
7485a5ea0d4SBryan Schumaker 				encode_sequence_maxsz + \
7495a5ea0d4SBryan Schumaker 				encode_putfh_maxsz + \
7505a5ea0d4SBryan Schumaker 				encode_secinfo_maxsz)
7515a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz	(compound_decode_hdr_maxsz + \
7525a5ea0d4SBryan Schumaker 				decode_sequence_maxsz + \
7535a5ea0d4SBryan Schumaker 				decode_putfh_maxsz + \
7545a5ea0d4SBryan Schumaker 				decode_secinfo_maxsz)
75544c99933SChuck Lever #define NFS4_enc_fsid_present_sz \
75644c99933SChuck Lever 				(compound_encode_hdr_maxsz + \
75744c99933SChuck Lever 				 encode_sequence_maxsz + \
75844c99933SChuck Lever 				 encode_putfh_maxsz + \
75944c99933SChuck Lever 				 encode_getfh_maxsz + \
76044c99933SChuck Lever 				 encode_renew_maxsz)
76144c99933SChuck Lever #define NFS4_dec_fsid_present_sz \
76244c99933SChuck Lever 				(compound_decode_hdr_maxsz + \
76344c99933SChuck Lever 				 decode_sequence_maxsz + \
76444c99933SChuck Lever 				 decode_putfh_maxsz + \
76544c99933SChuck Lever 				 decode_getfh_maxsz + \
76644c99933SChuck Lever 				 decode_renew_maxsz)
76799fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
7687c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \
7697c44f1aeSWeston Andros Adamson 				(compound_encode_hdr_maxsz + \
7707c44f1aeSWeston Andros Adamson 				 encode_bind_conn_to_session_maxsz)
7717c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \
7727c44f1aeSWeston Andros Adamson 				(compound_decode_hdr_maxsz + \
7737c44f1aeSWeston Andros Adamson 				 decode_bind_conn_to_session_maxsz)
77499fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \
77599fe60d0SBenny Halevy 				(compound_encode_hdr_maxsz + \
77699fe60d0SBenny Halevy 				 encode_exchange_id_maxsz)
77799fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \
77899fe60d0SBenny Halevy 				(compound_decode_hdr_maxsz + \
77999fe60d0SBenny Halevy 				 decode_exchange_id_maxsz)
780fc931582SAndy Adamson #define NFS4_enc_create_session_sz \
781fc931582SAndy Adamson 				(compound_encode_hdr_maxsz + \
782fc931582SAndy Adamson 				 encode_create_session_maxsz)
783fc931582SAndy Adamson #define NFS4_dec_create_session_sz \
784fc931582SAndy Adamson 				(compound_decode_hdr_maxsz + \
785fc931582SAndy Adamson 				 decode_create_session_maxsz)
7860f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz	(compound_encode_hdr_maxsz + \
7870f3e66c6SAndy Adamson 					 encode_destroy_session_maxsz)
7880f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz	(compound_decode_hdr_maxsz + \
7890f3e66c6SAndy Adamson 					 decode_destroy_session_maxsz)
79066245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz	(compound_encode_hdr_maxsz + \
79166245539STrond Myklebust 					 encode_destroy_clientid_maxsz)
79266245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz	(compound_decode_hdr_maxsz + \
79366245539STrond Myklebust 					 decode_destroy_clientid_maxsz)
794fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \
795fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
796fc01cea9SAndy Adamson 				 encode_sequence_maxsz)
797fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \
798fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
799fc01cea9SAndy Adamson 				 decode_sequence_maxsz)
8002050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz	(compound_encode_hdr_maxsz + \
8012050f0ccSAndy Adamson 					 encode_sequence_maxsz + \
8022050f0ccSAndy Adamson 					 encode_putrootfh_maxsz + \
8032050f0ccSAndy Adamson 					 encode_fsinfo_maxsz)
8042050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz	(compound_decode_hdr_maxsz + \
8052050f0ccSAndy Adamson 					 decode_sequence_maxsz + \
8062050f0ccSAndy Adamson 					 decode_putrootfh_maxsz + \
8072050f0ccSAndy Adamson 					 decode_fsinfo_maxsz)
80818019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz	(compound_encode_hdr_maxsz + \
80918019753SRicardo Labiaga 					 encode_sequence_maxsz + \
81018019753SRicardo Labiaga 					 encode_reclaim_complete_maxsz)
81118019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz	(compound_decode_hdr_maxsz + \
81218019753SRicardo Labiaga 					 decode_sequence_maxsz + \
81318019753SRicardo Labiaga 					 decode_reclaim_complete_maxsz)
814b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz +    \
815b1f69b75SAndy Adamson 				encode_sequence_maxsz +\
816b1f69b75SAndy Adamson 				encode_getdeviceinfo_maxsz)
817b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz +    \
818b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
819b1f69b75SAndy Adamson 				decode_getdeviceinfo_maxsz)
820b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz	(compound_encode_hdr_maxsz + \
821b1f69b75SAndy Adamson 				encode_sequence_maxsz + \
822b1f69b75SAndy Adamson 				encode_putfh_maxsz +        \
823b1f69b75SAndy Adamson 				encode_layoutget_maxsz)
824b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz	(compound_decode_hdr_maxsz + \
825b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
826b1f69b75SAndy Adamson 				decode_putfh_maxsz +        \
827b1f69b75SAndy Adamson 				decode_layoutget_maxsz)
828863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
829863a3c6cSAndy Adamson 				encode_sequence_maxsz +\
830863a3c6cSAndy Adamson 				encode_putfh_maxsz + \
831863a3c6cSAndy Adamson 				encode_layoutcommit_maxsz + \
832863a3c6cSAndy Adamson 				encode_getattr_maxsz)
833863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
834863a3c6cSAndy Adamson 				decode_sequence_maxsz + \
835863a3c6cSAndy Adamson 				decode_putfh_maxsz + \
836863a3c6cSAndy Adamson 				decode_layoutcommit_maxsz + \
837863a3c6cSAndy Adamson 				decode_getattr_maxsz)
838cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
839cbe82603SBenny Halevy 				encode_sequence_maxsz + \
840cbe82603SBenny Halevy 				encode_putfh_maxsz + \
841cbe82603SBenny Halevy 				encode_layoutreturn_maxsz)
842cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
843cbe82603SBenny Halevy 				decode_sequence_maxsz + \
844cbe82603SBenny Halevy 				decode_putfh_maxsz + \
845cbe82603SBenny Halevy 				decode_layoutreturn_maxsz)
846fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz	(compound_encode_hdr_maxsz + \
847fca78d6dSBryan Schumaker 					encode_sequence_maxsz + \
848fca78d6dSBryan Schumaker 					encode_putrootfh_maxsz +\
849fca78d6dSBryan Schumaker 					encode_secinfo_no_name_maxsz)
850fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz	(compound_decode_hdr_maxsz + \
851fca78d6dSBryan Schumaker 					decode_sequence_maxsz + \
852fca78d6dSBryan Schumaker 					decode_putrootfh_maxsz + \
853fca78d6dSBryan Schumaker 					decode_secinfo_no_name_maxsz)
8547d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz	(compound_encode_hdr_maxsz + \
8557d974794SBryan Schumaker 					 encode_sequence_maxsz + \
8567d974794SBryan Schumaker 					 encode_test_stateid_maxsz)
8577d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz	(compound_decode_hdr_maxsz + \
8587d974794SBryan Schumaker 					 decode_sequence_maxsz + \
8597d974794SBryan Schumaker 					 decode_test_stateid_maxsz)
8609aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz	(compound_encode_hdr_maxsz + \
8619aeda35fSBryan Schumaker 					 encode_sequence_maxsz + \
8629aeda35fSBryan Schumaker 					 encode_free_stateid_maxsz)
8639aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz	(compound_decode_hdr_maxsz + \
8649aeda35fSBryan Schumaker 					 decode_sequence_maxsz + \
8659aeda35fSBryan Schumaker 					 decode_free_stateid_maxsz)
8662449ea2eSAlexandros Batsakis 
8672449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
8682449ea2eSAlexandros Batsakis 				      compound_encode_hdr_maxsz +
8692449ea2eSAlexandros Batsakis 				      encode_sequence_maxsz +
8702449ea2eSAlexandros Batsakis 				      encode_putfh_maxsz +
8712449ea2eSAlexandros Batsakis 				      encode_getattr_maxsz) *
8722449ea2eSAlexandros Batsakis 				     XDR_UNIT);
8732449ea2eSAlexandros Batsakis 
8742449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
8752449ea2eSAlexandros Batsakis 				     compound_decode_hdr_maxsz +
8762449ea2eSAlexandros Batsakis 				     decode_sequence_maxsz +
8772449ea2eSAlexandros Batsakis 				     decode_putfh_maxsz) *
8782449ea2eSAlexandros Batsakis 				    XDR_UNIT);
879f1c097beSAndy Adamson 
880f1c097beSAndy Adamson const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
881f1c097beSAndy Adamson 					   compound_decode_hdr_maxsz +
882f1c097beSAndy Adamson 					   decode_sequence_maxsz) *
883f1c097beSAndy Adamson 					  XDR_UNIT);
884f1c097beSAndy Adamson EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
88599fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
8861da177e4SLinus Torvalds 
887bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = {
888bca79478STrond Myklebust 	[NF4BAD] = 0,
889bca79478STrond Myklebust 	[NF4REG] = S_IFREG,
890bca79478STrond Myklebust 	[NF4DIR] = S_IFDIR,
891bca79478STrond Myklebust 	[NF4BLK] = S_IFBLK,
892bca79478STrond Myklebust 	[NF4CHR] = S_IFCHR,
893bca79478STrond Myklebust 	[NF4LNK] = S_IFLNK,
894bca79478STrond Myklebust 	[NF4SOCK] = S_IFSOCK,
895bca79478STrond Myklebust 	[NF4FIFO] = S_IFIFO,
896bca79478STrond Myklebust 	[NF4ATTRDIR] = 0,
897bca79478STrond Myklebust 	[NF4NAMEDATTR] = 0,
8981da177e4SLinus Torvalds };
8991da177e4SLinus Torvalds 
9001da177e4SLinus Torvalds struct compound_hdr {
9011da177e4SLinus Torvalds 	int32_t		status;
9021da177e4SLinus Torvalds 	uint32_t	nops;
903d017931cSAndy Adamson 	__be32 *	nops_p;
9041da177e4SLinus Torvalds 	uint32_t	taglen;
9051da177e4SLinus Torvalds 	char *		tag;
9060c4e8c18SBenny Halevy 	uint32_t	replen;		/* expected reply words */
90766cc0429SBenny Halevy 	u32		minorversion;
9081da177e4SLinus Torvalds };
9091da177e4SLinus Torvalds 
91013c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
91113c65ce9SBenny Halevy {
91213c65ce9SBenny Halevy 	__be32 *p = xdr_reserve_space(xdr, nbytes);
91313c65ce9SBenny Halevy 	BUG_ON(!p);
91413c65ce9SBenny Halevy 	return p;
91513c65ce9SBenny Halevy }
9161da177e4SLinus Torvalds 
917cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
918cb17e556STrond Myklebust {
919cb17e556STrond Myklebust 	__be32 *p;
920cb17e556STrond Myklebust 
921cb17e556STrond Myklebust 	p = xdr_reserve_space(xdr, len);
922cb17e556STrond Myklebust 	xdr_encode_opaque_fixed(p, buf, len);
923cb17e556STrond Myklebust }
924cb17e556STrond Myklebust 
9251da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
9261da177e4SLinus Torvalds {
9278687b63aSAl Viro 	__be32 *p;
9281da177e4SLinus Torvalds 
9296fdfb0bcSTrond Myklebust 	p = reserve_space(xdr, 4 + len);
9301da177e4SLinus Torvalds 	xdr_encode_opaque(p, str, len);
9311da177e4SLinus Torvalds }
9321da177e4SLinus Torvalds 
9334ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n)
9344ade9821STrond Myklebust {
9354ade9821STrond Myklebust 	__be32 *p;
9364ade9821STrond Myklebust 
9374ade9821STrond Myklebust 	p = reserve_space(xdr, 4);
9384ade9821STrond Myklebust 	*p = cpu_to_be32(n);
9394ade9821STrond Myklebust }
9404ade9821STrond Myklebust 
941ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n)
942ff2eb681STrond Myklebust {
943ff2eb681STrond Myklebust 	__be32 *p;
944ff2eb681STrond Myklebust 
945ff2eb681STrond Myklebust 	p = reserve_space(xdr, 8);
946ff2eb681STrond Myklebust 	xdr_encode_hyper(p, n);
947ff2eb681STrond Myklebust }
948ff2eb681STrond Myklebust 
9494ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr,
9504ade9821STrond Myklebust 		const struct nfs_seqid *seqid)
9514ade9821STrond Myklebust {
952a6796419STrond Myklebust 	if (seqid != NULL)
9534ade9821STrond Myklebust 		encode_uint32(xdr, seqid->sequence->counter);
954a6796419STrond Myklebust 	else
955a6796419STrond Myklebust 		encode_uint32(xdr, 0);
9564ade9821STrond Myklebust }
9574ade9821STrond Myklebust 
9580c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr,
9590c4e8c18SBenny Halevy 				struct rpc_rqst *req,
9600c4e8c18SBenny Halevy 				struct compound_hdr *hdr)
9611da177e4SLinus Torvalds {
9628687b63aSAl Viro 	__be32 *p;
963a17c2153STrond Myklebust 	struct rpc_auth *auth = req->rq_cred->cr_auth;
9640c4e8c18SBenny Halevy 
9650c4e8c18SBenny Halevy 	/* initialize running count of expected bytes in reply.
9660c4e8c18SBenny Halevy 	 * NOTE: the replied tag SHOULD be the same is the one sent,
9670c4e8c18SBenny Halevy 	 * but this is not required as a MUST for the server to do so. */
9680c4e8c18SBenny Halevy 	hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
9691da177e4SLinus Torvalds 
9707fc38846STrond Myklebust 	WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
9716fdfb0bcSTrond Myklebust 	encode_string(xdr, hdr->taglen, hdr->tag);
9726fdfb0bcSTrond Myklebust 	p = reserve_space(xdr, 8);
973e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(hdr->minorversion);
974d017931cSAndy Adamson 	hdr->nops_p = p;
97534558513SBenny Halevy 	*p = cpu_to_be32(hdr->nops);
976d017931cSAndy Adamson }
977d017931cSAndy Adamson 
978ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
979ab19b481STrond Myklebust 		uint32_t replen,
980ab19b481STrond Myklebust 		struct compound_hdr *hdr)
981ab19b481STrond Myklebust {
982ab19b481STrond Myklebust 	encode_uint32(xdr, op);
983ab19b481STrond Myklebust 	hdr->nops++;
984ab19b481STrond Myklebust 	hdr->replen += replen;
985ab19b481STrond Myklebust }
986ab19b481STrond Myklebust 
987d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr)
988d017931cSAndy Adamson {
9897fc38846STrond Myklebust 	WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
990d017931cSAndy Adamson 	*hdr->nops_p = htonl(hdr->nops);
9911da177e4SLinus Torvalds }
9921da177e4SLinus Torvalds 
993ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
994ea9d23f5STrond Myklebust {
9952d2f24adSTrond Myklebust 	encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
996ea9d23f5STrond Myklebust }
997ea9d23f5STrond Myklebust 
9981da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
9991da177e4SLinus Torvalds {
1000cb17e556STrond Myklebust 	encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
10011da177e4SLinus Torvalds }
10021da177e4SLinus Torvalds 
1003aa9c2669SDavid Quigley static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1004aa9c2669SDavid Quigley 				const struct nfs4_label *label,
10055334c5bdSKinglong Mee 				const struct nfs_server *server,
10065334c5bdSKinglong Mee 				bool excl_check)
10071da177e4SLinus Torvalds {
10081da177e4SLinus Torvalds 	char owner_name[IDMAP_NAMESZ];
10091da177e4SLinus Torvalds 	char owner_group[IDMAP_NAMESZ];
10101da177e4SLinus Torvalds 	int owner_namelen = 0;
10111da177e4SLinus Torvalds 	int owner_grouplen = 0;
10128687b63aSAl Viro 	__be32 *p;
1013d7067b2dSTrond Myklebust 	unsigned i;
1014d7067b2dSTrond Myklebust 	uint32_t len = 0;
1015d7067b2dSTrond Myklebust 	uint32_t bmval_len;
1016d7067b2dSTrond Myklebust 	uint32_t bmval[3] = { 0 };
10171da177e4SLinus Torvalds 
10181da177e4SLinus Torvalds 	/*
10191da177e4SLinus Torvalds 	 * We reserve enough space to write the entire attribute buffer at once.
10201da177e4SLinus Torvalds 	 * In the worst-case, this would be
1021a09df2caSDavid Quigley 	 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1022a09df2caSDavid Quigley 	 * = 40 bytes, plus any contribution from variable-length fields
102323ec6965SJ. Bruce Fields 	 *            such as owner/group.
10241da177e4SLinus Torvalds 	 */
1025d7067b2dSTrond Myklebust 	if (iap->ia_valid & ATTR_SIZE) {
1026d7067b2dSTrond Myklebust 		bmval[0] |= FATTR4_WORD0_SIZE;
10271da177e4SLinus Torvalds 		len += 8;
1028d7067b2dSTrond Myklebust 	}
1029d7067b2dSTrond Myklebust 	if (iap->ia_valid & ATTR_MODE) {
1030d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_MODE;
10311da177e4SLinus Torvalds 		len += 4;
1032d7067b2dSTrond Myklebust 	}
10331da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_UID) {
1034e4fd72a1STrond Myklebust 		owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
10351da177e4SLinus Torvalds 		if (owner_namelen < 0) {
1036fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve uid %d to string\n",
1037e5782076SEric W. Biederman 					from_kuid(&init_user_ns, iap->ia_uid));
10381da177e4SLinus Torvalds 			/* XXX */
10391da177e4SLinus Torvalds 			strcpy(owner_name, "nobody");
10401da177e4SLinus Torvalds 			owner_namelen = sizeof("nobody") - 1;
10411da177e4SLinus Torvalds 			/* goto out; */
10421da177e4SLinus Torvalds 		}
1043d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_OWNER;
10441da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
10451da177e4SLinus Torvalds 	}
10461da177e4SLinus Torvalds 	if (iap->ia_valid & ATTR_GID) {
1047e4fd72a1STrond Myklebust 		owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
10481da177e4SLinus Torvalds 		if (owner_grouplen < 0) {
1049fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve gid %d to string\n",
1050e5782076SEric W. Biederman 					from_kgid(&init_user_ns, iap->ia_gid));
10511da177e4SLinus Torvalds 			strcpy(owner_group, "nobody");
10521da177e4SLinus Torvalds 			owner_grouplen = sizeof("nobody") - 1;
10531da177e4SLinus Torvalds 			/* goto out; */
10541da177e4SLinus Torvalds 		}
1055d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
10561da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
10571da177e4SLinus Torvalds 	}
1058d7067b2dSTrond Myklebust 	if (iap->ia_valid & ATTR_ATIME_SET) {
1059d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
10601da177e4SLinus Torvalds 		len += 16;
1061d7067b2dSTrond Myklebust 	} else if (iap->ia_valid & ATTR_ATIME) {
1062d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
10631da177e4SLinus Torvalds 		len += 4;
1064d7067b2dSTrond Myklebust 	}
1065d7067b2dSTrond Myklebust 	if (iap->ia_valid & ATTR_MTIME_SET) {
1066d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
10671da177e4SLinus Torvalds 		len += 16;
1068d7067b2dSTrond Myklebust 	} else if (iap->ia_valid & ATTR_MTIME) {
1069d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
10701da177e4SLinus Torvalds 		len += 4;
1071d7067b2dSTrond Myklebust 	}
10725334c5bdSKinglong Mee 
10735334c5bdSKinglong Mee 	if (excl_check) {
10745334c5bdSKinglong Mee 		const u32 *excl_bmval = server->exclcreat_bitmask;
10755334c5bdSKinglong Mee 		bmval[0] &= excl_bmval[0];
10765334c5bdSKinglong Mee 		bmval[1] &= excl_bmval[1];
10775334c5bdSKinglong Mee 		bmval[2] &= excl_bmval[2];
10785334c5bdSKinglong Mee 
10795334c5bdSKinglong Mee 		if (!(excl_bmval[2] & FATTR4_WORD2_SECURITY_LABEL))
10805334c5bdSKinglong Mee 			label = NULL;
10815334c5bdSKinglong Mee 	}
10825334c5bdSKinglong Mee 
1083b4a2cf76STrond Myklebust 	if (label) {
1084b4a2cf76STrond Myklebust 		len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1085d7067b2dSTrond Myklebust 		bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1086d7067b2dSTrond Myklebust 	}
1087d7067b2dSTrond Myklebust 
1088d7067b2dSTrond Myklebust 	if (bmval[2] != 0)
1089b4a2cf76STrond Myklebust 		bmval_len = 3;
1090d7067b2dSTrond Myklebust 	else if (bmval[1] != 0)
1091d7067b2dSTrond Myklebust 		bmval_len = 2;
1092d7067b2dSTrond Myklebust 	else
1093d7067b2dSTrond Myklebust 		bmval_len = 1;
1094b4a2cf76STrond Myklebust 
1095d7067b2dSTrond Myklebust 	p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
10961da177e4SLinus Torvalds 
1097b4a2cf76STrond Myklebust 	*p++ = cpu_to_be32(bmval_len);
1098d7067b2dSTrond Myklebust 	for (i = 0; i < bmval_len; i++)
1099d7067b2dSTrond Myklebust 		*p++ = cpu_to_be32(bmval[i]);
1100d7067b2dSTrond Myklebust 	*p++ = cpu_to_be32(len);
11011da177e4SLinus Torvalds 
1102d7067b2dSTrond Myklebust 	if (bmval[0] & FATTR4_WORD0_SIZE)
1103b95be5a9SBenny Halevy 		p = xdr_encode_hyper(p, iap->ia_size);
1104d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_MODE)
1105e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1106d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_OWNER)
1107811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_name, owner_namelen);
1108d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1109811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1110d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
11111da177e4SLinus Torvalds 		if (iap->ia_valid & ATTR_ATIME_SET) {
1112e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1113042ad0b3SBryan Schumaker 			p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1114d3f6baaaSTrond Myklebust 			*p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1115d7067b2dSTrond Myklebust 		} else
1116e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
11171da177e4SLinus Torvalds 	}
1118d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
11191da177e4SLinus Torvalds 		if (iap->ia_valid & ATTR_MTIME_SET) {
1120e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1121042ad0b3SBryan Schumaker 			p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1122e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1123d7067b2dSTrond Myklebust 		} else
1124e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
11251da177e4SLinus Torvalds 	}
1126d7067b2dSTrond Myklebust 	if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
1127aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->lfs);
1128aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->pi);
1129aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->len);
1130aa9c2669SDavid Quigley 		p = xdr_encode_opaque_fixed(p, label->label, label->len);
1131aa9c2669SDavid Quigley 	}
11321da177e4SLinus Torvalds 
11331da177e4SLinus Torvalds /* out: */
11341da177e4SLinus Torvalds }
11351da177e4SLinus Torvalds 
1136cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
11371da177e4SLinus Torvalds {
1138475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1139475d4ba0STrond Myklebust 	encode_uint32(xdr, access);
11401da177e4SLinus Torvalds }
11411da177e4SLinus Torvalds 
1142cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
11431da177e4SLinus Torvalds {
1144ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
11454ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
1146566fcec6STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
11471da177e4SLinus Torvalds }
11481da177e4SLinus Torvalds 
11490b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
11501da177e4SLinus Torvalds {
11518687b63aSAl Viro 	__be32 *p;
11521da177e4SLinus Torvalds 
1153475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1154475d4ba0STrond Myklebust 	p = reserve_space(xdr, 12);
1155b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
115634558513SBenny Halevy 	*p = cpu_to_be32(args->count);
11571da177e4SLinus Torvalds }
11581da177e4SLinus Torvalds 
1159cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
11601da177e4SLinus Torvalds {
11618687b63aSAl Viro 	__be32 *p;
11621da177e4SLinus Torvalds 
1163475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1164475d4ba0STrond Myklebust 	encode_uint32(xdr, create->ftype);
11651da177e4SLinus Torvalds 
11661da177e4SLinus Torvalds 	switch (create->ftype) {
11671da177e4SLinus Torvalds 	case NF4LNK:
116813c65ce9SBenny Halevy 		p = reserve_space(xdr, 4);
116934558513SBenny Halevy 		*p = cpu_to_be32(create->u.symlink.len);
11702fcc213aSChuck Lever 		xdr_write_pages(xdr, create->u.symlink.pages, 0,
11712fcc213aSChuck Lever 				create->u.symlink.len);
11722fcc213aSChuck Lever 		xdr->buf->flags |= XDRBUF_WRITE;
11731da177e4SLinus Torvalds 		break;
11741da177e4SLinus Torvalds 
11751da177e4SLinus Torvalds 	case NF4BLK: case NF4CHR:
117613c65ce9SBenny Halevy 		p = reserve_space(xdr, 8);
1177e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(create->u.device.specdata1);
117834558513SBenny Halevy 		*p = cpu_to_be32(create->u.device.specdata2);
11791da177e4SLinus Torvalds 		break;
11801da177e4SLinus Torvalds 
11811da177e4SLinus Torvalds 	default:
11821da177e4SLinus Torvalds 		break;
11831da177e4SLinus Torvalds 	}
11841da177e4SLinus Torvalds 
1185811652bdSBenny Halevy 	encode_string(xdr, create->name->len, create->name->name);
11865334c5bdSKinglong Mee 	encode_attrs(xdr, create->attrs, create->label, create->server, false);
11871da177e4SLinus Torvalds }
11881da177e4SLinus Torvalds 
1189cf8cdbe5SAndy Adamson static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
11901da177e4SLinus Torvalds {
11918687b63aSAl Viro 	__be32 *p;
11921da177e4SLinus Torvalds 
1193475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1194475d4ba0STrond Myklebust 	p = reserve_space(xdr, 8);
1195e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
119634558513SBenny Halevy 	*p = cpu_to_be32(bitmap);
11971da177e4SLinus Torvalds }
11981da177e4SLinus Torvalds 
1199cf8cdbe5SAndy Adamson static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
12001da177e4SLinus Torvalds {
12018687b63aSAl Viro 	__be32 *p;
12021da177e4SLinus Torvalds 
1203475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1204475d4ba0STrond Myklebust 	p = reserve_space(xdr, 12);
1205e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(2);
1206e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(bm0);
120734558513SBenny Halevy 	*p = cpu_to_be32(bm1);
12081da177e4SLinus Torvalds }
12091da177e4SLinus Torvalds 
1210dae100c2SFred Isaman static void
1211dae100c2SFred Isaman encode_getattr_three(struct xdr_stream *xdr,
1212dae100c2SFred Isaman 		     uint32_t bm0, uint32_t bm1, uint32_t bm2,
1213dae100c2SFred Isaman 		     struct compound_hdr *hdr)
1214dae100c2SFred Isaman {
1215dae100c2SFred Isaman 	__be32 *p;
1216dae100c2SFred Isaman 
1217ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1218dae100c2SFred Isaman 	if (bm2) {
1219dae100c2SFred Isaman 		p = reserve_space(xdr, 16);
1220dae100c2SFred Isaman 		*p++ = cpu_to_be32(3);
1221dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm0);
1222dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm1);
1223dae100c2SFred Isaman 		*p = cpu_to_be32(bm2);
1224dae100c2SFred Isaman 	} else if (bm1) {
1225dae100c2SFred Isaman 		p = reserve_space(xdr, 12);
1226dae100c2SFred Isaman 		*p++ = cpu_to_be32(2);
1227dae100c2SFred Isaman 		*p++ = cpu_to_be32(bm0);
1228dae100c2SFred Isaman 		*p = cpu_to_be32(bm1);
1229dae100c2SFred Isaman 	} else {
1230dae100c2SFred Isaman 		p = reserve_space(xdr, 8);
1231dae100c2SFred Isaman 		*p++ = cpu_to_be32(1);
1232dae100c2SFred Isaman 		*p = cpu_to_be32(bm0);
1233dae100c2SFred Isaman 	}
1234dae100c2SFred Isaman }
1235dae100c2SFred Isaman 
1236cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
12371da177e4SLinus Torvalds {
1238a09df2caSDavid Quigley 	encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1239a09df2caSDavid Quigley 			   bitmask[1] & nfs4_fattr_bitmap[1],
1240a09df2caSDavid Quigley 			   bitmask[2] & nfs4_fattr_bitmap[2],
1241a09df2caSDavid Quigley 			   hdr);
12421da177e4SLinus Torvalds }
12431da177e4SLinus Torvalds 
124488034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
12451549210fSTrond Myklebust 				 const u32 *open_bitmap,
124688034c3dSAndy Adamson 				 struct compound_hdr *hdr)
124788034c3dSAndy Adamson {
124888034c3dSAndy Adamson 	encode_getattr_three(xdr,
12491549210fSTrond Myklebust 			     bitmask[0] & open_bitmap[0],
12501549210fSTrond Myklebust 			     bitmask[1] & open_bitmap[1],
12511549210fSTrond Myklebust 			     bitmask[2] & open_bitmap[2],
125288034c3dSAndy Adamson 			     hdr);
125388034c3dSAndy Adamson }
125488034c3dSAndy Adamson 
1255cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
12561da177e4SLinus Torvalds {
1257dae100c2SFred Isaman 	encode_getattr_three(xdr,
1258dae100c2SFred Isaman 			     bitmask[0] & nfs4_fsinfo_bitmap[0],
1259dae100c2SFred Isaman 			     bitmask[1] & nfs4_fsinfo_bitmap[1],
1260dae100c2SFred Isaman 			     bitmask[2] & nfs4_fsinfo_bitmap[2],
1261dae100c2SFred Isaman 			     hdr);
12621da177e4SLinus Torvalds }
12631da177e4SLinus Torvalds 
1264cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1265830b8e33SManoj Naik {
1266cf8cdbe5SAndy Adamson 	encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1267cf8cdbe5SAndy Adamson 			   bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1268830b8e33SManoj Naik }
1269830b8e33SManoj Naik 
1270cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
12711da177e4SLinus Torvalds {
1272ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
12731da177e4SLinus Torvalds }
12741da177e4SLinus Torvalds 
1275cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
12761da177e4SLinus Torvalds {
1277ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
12786fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
12791da177e4SLinus Torvalds }
12801da177e4SLinus Torvalds 
1281911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block)
1282911d1aafSTrond Myklebust {
1283f44106e2SJeff Layton 	if (fl->fl_type == F_RDLCK)
1284911d1aafSTrond Myklebust 		return block ? NFS4_READW_LT : NFS4_READ_LT;
1285911d1aafSTrond Myklebust 	return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1286911d1aafSTrond Myklebust }
1287911d1aafSTrond Myklebust 
1288911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1289911d1aafSTrond Myklebust {
1290911d1aafSTrond Myklebust 	if (fl->fl_end == OFFSET_MAX)
1291911d1aafSTrond Myklebust 		return ~(uint64_t)0;
1292911d1aafSTrond Myklebust 	return fl->fl_end - fl->fl_start + 1;
1293911d1aafSTrond Myklebust }
1294911d1aafSTrond Myklebust 
1295daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1296daccbdedSTrond Myklebust {
1297daccbdedSTrond Myklebust 	__be32 *p;
1298daccbdedSTrond Myklebust 
1299d035c36cSTrond Myklebust 	p = reserve_space(xdr, 32);
1300daccbdedSTrond Myklebust 	p = xdr_encode_hyper(p, lowner->clientid);
1301d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(20);
1302daccbdedSTrond Myklebust 	p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1303d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(lowner->s_dev);
1304daccbdedSTrond Myklebust 	xdr_encode_hyper(p, lowner->id);
1305daccbdedSTrond Myklebust }
1306daccbdedSTrond Myklebust 
13071da177e4SLinus Torvalds /*
13081da177e4SLinus Torvalds  * opcode,type,reclaim,offset,length,new_lock_owner = 32
13091da177e4SLinus Torvalds  * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
13101da177e4SLinus Torvalds  */
1311cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
13121da177e4SLinus Torvalds {
13138687b63aSAl Viro 	__be32 *p;
13141da177e4SLinus Torvalds 
1315475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1316475d4ba0STrond Myklebust 	p = reserve_space(xdr, 28);
1317e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1318e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->reclaim);
1319b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1320b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
132134558513SBenny Halevy 	*p = cpu_to_be32(args->new_lock_owner);
1322911d1aafSTrond Myklebust 	if (args->new_lock_owner){
13234ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->open_seqid);
1324425c1d4eSTrond Myklebust 		encode_nfs4_stateid(xdr, &args->open_stateid);
13254ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->lock_seqid);
1326daccbdedSTrond Myklebust 		encode_lockowner(xdr, &args->lock_owner);
13271da177e4SLinus Torvalds 	}
13281da177e4SLinus Torvalds 	else {
1329425c1d4eSTrond Myklebust 		encode_nfs4_stateid(xdr, &args->lock_stateid);
13304ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->lock_seqid);
13311da177e4SLinus Torvalds 	}
13321da177e4SLinus Torvalds }
13331da177e4SLinus Torvalds 
1334cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
13351da177e4SLinus Torvalds {
13368687b63aSAl Viro 	__be32 *p;
13371da177e4SLinus Torvalds 
1338475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1339475d4ba0STrond Myklebust 	p = reserve_space(xdr, 20);
1340e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1341b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1342b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1343daccbdedSTrond Myklebust 	encode_lockowner(xdr, &args->lock_owner);
13441da177e4SLinus Torvalds }
13451da177e4SLinus Torvalds 
1346cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
13471da177e4SLinus Torvalds {
13488687b63aSAl Viro 	__be32 *p;
13491da177e4SLinus Torvalds 
1350475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1351475d4ba0STrond Myklebust 	encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
13524ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, args->seqid);
1353425c1d4eSTrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
1354ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 16);
1355b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
135634558513SBenny Halevy 	xdr_encode_hyper(p, nfs4_lock_length(args->fl));
13571da177e4SLinus Torvalds }
13581da177e4SLinus Torvalds 
1359d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1360d3c7b7ccSTrond Myklebust {
1361ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1362d3c7b7ccSTrond Myklebust 	encode_lockowner(xdr, lowner);
1363d3c7b7ccSTrond Myklebust }
1364d3c7b7ccSTrond Myklebust 
1365cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
13661da177e4SLinus Torvalds {
1367ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
13686fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
13691da177e4SLinus Torvalds }
13701da177e4SLinus Torvalds 
13716ae37339STrond Myklebust static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
13721da177e4SLinus Torvalds {
13738687b63aSAl Viro 	__be32 *p;
13741da177e4SLinus Torvalds 
137513c65ce9SBenny Halevy 	p = reserve_space(xdr, 8);
13766ae37339STrond Myklebust 	*p++ = cpu_to_be32(share_access);
137734558513SBenny Halevy 	*p = cpu_to_be32(0);		/* for linux, share_deny = 0 always */
13781da177e4SLinus Torvalds }
13791da177e4SLinus Torvalds 
13801da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
13811da177e4SLinus Torvalds {
13828687b63aSAl Viro 	__be32 *p;
13831da177e4SLinus Torvalds  /*
13841da177e4SLinus Torvalds  * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
13851da177e4SLinus Torvalds  * owner 4 = 32
13861da177e4SLinus Torvalds  */
13874ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
13886ae37339STrond Myklebust 	encode_share_access(xdr, arg->share_access);
138995b72eb0STrond Myklebust 	p = reserve_space(xdr, 36);
1390b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, arg->clientid);
139195b72eb0STrond Myklebust 	*p++ = cpu_to_be32(24);
139293f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, "open id:", 8);
1393d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(arg->server->s_dev);
139495b72eb0STrond Myklebust 	*p++ = cpu_to_be32(arg->id.uniquifier);
139595b72eb0STrond Myklebust 	xdr_encode_hyper(p, arg->id.create_time);
13961da177e4SLinus Torvalds }
13971da177e4SLinus Torvalds 
13981da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
13991da177e4SLinus Torvalds {
14008687b63aSAl Viro 	__be32 *p;
14011da177e4SLinus Torvalds 
140213c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
1403549b19ccSTrond Myklebust 	switch(arg->createmode) {
1404549b19ccSTrond Myklebust 	case NFS4_CREATE_UNCHECKED:
140534558513SBenny Halevy 		*p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
14065334c5bdSKinglong Mee 		encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false);
14071da177e4SLinus Torvalds 		break;
1408549b19ccSTrond Myklebust 	case NFS4_CREATE_GUARDED:
14094882ef72SAlexandros Batsakis 		*p = cpu_to_be32(NFS4_CREATE_GUARDED);
14105334c5bdSKinglong Mee 		encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false);
1411549b19ccSTrond Myklebust 		break;
1412549b19ccSTrond Myklebust 	case NFS4_CREATE_EXCLUSIVE:
1413549b19ccSTrond Myklebust 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1414549b19ccSTrond Myklebust 		encode_nfs4_verifier(xdr, &arg->u.verifier);
1415549b19ccSTrond Myklebust 		break;
1416549b19ccSTrond Myklebust 	case NFS4_CREATE_EXCLUSIVE4_1:
14174882ef72SAlexandros Batsakis 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
14184882ef72SAlexandros Batsakis 		encode_nfs4_verifier(xdr, &arg->u.verifier);
14195334c5bdSKinglong Mee 		encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, true);
14204882ef72SAlexandros Batsakis 	}
14214882ef72SAlexandros Batsakis }
14221da177e4SLinus Torvalds 
14231da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14241da177e4SLinus Torvalds {
14258687b63aSAl Viro 	__be32 *p;
14261da177e4SLinus Torvalds 
142713c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14281da177e4SLinus Torvalds 	switch (arg->open_flags & O_CREAT) {
14291da177e4SLinus Torvalds 	case 0:
143034558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_NOCREATE);
14311da177e4SLinus Torvalds 		break;
14321da177e4SLinus Torvalds 	default:
143334558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_CREATE);
14341da177e4SLinus Torvalds 		encode_createmode(xdr, arg);
14351da177e4SLinus Torvalds 	}
14361da177e4SLinus Torvalds }
14371da177e4SLinus Torvalds 
1438bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
14391da177e4SLinus Torvalds {
14408687b63aSAl Viro 	__be32 *p;
14411da177e4SLinus Torvalds 
144213c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14431da177e4SLinus Torvalds 	switch (delegation_type) {
14441da177e4SLinus Torvalds 	case 0:
144534558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
14461da177e4SLinus Torvalds 		break;
14471da177e4SLinus Torvalds 	case FMODE_READ:
144834558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
14491da177e4SLinus Torvalds 		break;
14501da177e4SLinus Torvalds 	case FMODE_WRITE|FMODE_READ:
145134558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
14521da177e4SLinus Torvalds 		break;
14531da177e4SLinus Torvalds 	default:
14541da177e4SLinus Torvalds 		BUG();
14551da177e4SLinus Torvalds 	}
14561da177e4SLinus Torvalds }
14571da177e4SLinus Torvalds 
14581da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
14591da177e4SLinus Torvalds {
14608687b63aSAl Viro 	__be32 *p;
14611da177e4SLinus Torvalds 
146213c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
146334558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
14641da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14651da177e4SLinus Torvalds }
14661da177e4SLinus Torvalds 
1467bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
14681da177e4SLinus Torvalds {
14698687b63aSAl Viro 	__be32 *p;
14701da177e4SLinus Torvalds 
147113c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
147234558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
14731da177e4SLinus Torvalds 	encode_delegation_type(xdr, type);
14741da177e4SLinus Torvalds }
14751da177e4SLinus Torvalds 
14761da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
14771da177e4SLinus Torvalds {
14788687b63aSAl Viro 	__be32 *p;
14791da177e4SLinus Torvalds 
1480ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 4);
1481ea9d23f5STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1482ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
14831da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14841da177e4SLinus Torvalds }
14851da177e4SLinus Torvalds 
1486d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr)
1487d9fc6619STrond Myklebust {
1488d9fc6619STrond Myklebust 	__be32 *p;
1489d9fc6619STrond Myklebust 
1490d9fc6619STrond Myklebust 	p = reserve_space(xdr, 4);
1491d9fc6619STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1492d9fc6619STrond Myklebust }
1493d9fc6619STrond Myklebust 
1494d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1495d9fc6619STrond Myklebust {
1496d9fc6619STrond Myklebust 	__be32 *p;
1497d9fc6619STrond Myklebust 
1498d9fc6619STrond Myklebust 	p = reserve_space(xdr, 4);
1499d9fc6619STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1500d9fc6619STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
1501d9fc6619STrond Myklebust }
1502d9fc6619STrond Myklebust 
1503cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
15041da177e4SLinus Torvalds {
1505ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
15061da177e4SLinus Torvalds 	encode_openhdr(xdr, arg);
15071da177e4SLinus Torvalds 	encode_opentype(xdr, arg);
15081da177e4SLinus Torvalds 	switch (arg->claim) {
15091da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_NULL:
15101da177e4SLinus Torvalds 		encode_claim_null(xdr, arg->name);
15111da177e4SLinus Torvalds 		break;
15121da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_PREVIOUS:
15131da177e4SLinus Torvalds 		encode_claim_previous(xdr, arg->u.delegation_type);
15141da177e4SLinus Torvalds 		break;
15151da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_DELEGATE_CUR:
15161da177e4SLinus Torvalds 		encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
15171da177e4SLinus Torvalds 		break;
1518d9fc6619STrond Myklebust 	case NFS4_OPEN_CLAIM_FH:
1519d9fc6619STrond Myklebust 		encode_claim_fh(xdr);
1520d9fc6619STrond Myklebust 		break;
1521d9fc6619STrond Myklebust 	case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1522d9fc6619STrond Myklebust 		encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1523d9fc6619STrond Myklebust 		break;
15241da177e4SLinus Torvalds 	default:
15251da177e4SLinus Torvalds 		BUG();
15261da177e4SLinus Torvalds 	}
15271da177e4SLinus Torvalds }
15281da177e4SLinus Torvalds 
1529cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
15301da177e4SLinus Torvalds {
1531ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1532ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, arg->stateid);
15334ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
15341da177e4SLinus Torvalds }
15351da177e4SLinus Torvalds 
1536cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
15371da177e4SLinus Torvalds {
1538ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1539566fcec6STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
15404ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
15416ae37339STrond Myklebust 	encode_share_access(xdr, arg->share_access);
15421da177e4SLinus Torvalds }
15431da177e4SLinus Torvalds 
1544cf8cdbe5SAndy Adamson static void
1545d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
15461da177e4SLinus Torvalds {
1547ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
15486fdfb0bcSTrond Myklebust 	encode_string(xdr, fh->size, fh->data);
15491da177e4SLinus Torvalds }
15501da177e4SLinus Torvalds 
1551cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
15521da177e4SLinus Torvalds {
1553ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
15541da177e4SLinus Torvalds }
15551da177e4SLinus Torvalds 
15563c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
15573c6b899cSAnna Schumaker 			struct compound_hdr *hdr)
15581da177e4SLinus Torvalds {
15598687b63aSAl Viro 	__be32 *p;
15601da177e4SLinus Torvalds 
1561ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
15629b206149STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
15631da177e4SLinus Torvalds 
156413c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1565b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
156634558513SBenny Halevy 	*p = cpu_to_be32(args->count);
15671da177e4SLinus Torvalds }
15681da177e4SLinus Torvalds 
1569cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
15701da177e4SLinus Torvalds {
1571aa9c2669SDavid Quigley 	uint32_t attrs[3] = {
157228331a46STrond Myklebust 		FATTR4_WORD0_RDATTR_ERROR,
157328331a46STrond Myklebust 		FATTR4_WORD1_MOUNTED_ON_FILEID,
157428331a46STrond Myklebust 	};
15756f7a35bdSTrond Myklebust 	uint32_t dircount = readdir->count >> 1;
1576cd93710eSChuck Lever 	__be32 *p, verf[2];
1577d204c5d2STrond Myklebust 	uint32_t attrlen = 0;
1578d204c5d2STrond Myklebust 	unsigned int i;
15791da177e4SLinus Torvalds 
158082f2e547SBryan Schumaker 	if (readdir->plus) {
158182f2e547SBryan Schumaker 		attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
158228331a46STrond Myklebust 			FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
158382f2e547SBryan Schumaker 		attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
158482f2e547SBryan Schumaker 			FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
158582f2e547SBryan Schumaker 			FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
158682f2e547SBryan Schumaker 			FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1587d204c5d2STrond Myklebust 		attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
15886f7a35bdSTrond Myklebust 		dircount >>= 1;
158982f2e547SBryan Schumaker 	}
159028331a46STrond Myklebust 	/* Use mounted_on_fileid only if the server supports it */
159128331a46STrond Myklebust 	if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
159228331a46STrond Myklebust 		attrs[0] |= FATTR4_WORD0_FILEID;
1593d204c5d2STrond Myklebust 	for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1594d204c5d2STrond Myklebust 		attrs[i] &= readdir->bitmask[i];
1595d204c5d2STrond Myklebust 		if (attrs[i] != 0)
1596d204c5d2STrond Myklebust 			attrlen = i+1;
1597d204c5d2STrond Myklebust 	}
15986f7a35bdSTrond Myklebust 
1599475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1600ff2eb681STrond Myklebust 	encode_uint64(xdr, readdir->cookie);
1601cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, &readdir->verifier);
1602d204c5d2STrond Myklebust 	p = reserve_space(xdr, 12 + (attrlen << 2));
16036f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(dircount);
16046f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(readdir->count);
1605d204c5d2STrond Myklebust 	*p++ = cpu_to_be32(attrlen);
1606d204c5d2STrond Myklebust 	for (i = 0; i < attrlen; i++)
1607d204c5d2STrond Myklebust 		*p++ = cpu_to_be32(attrs[i]);
1608cd93710eSChuck Lever 	memcpy(verf, readdir->verifier.data, sizeof(verf));
1609aa9c2669SDavid Quigley 
1610aa9c2669SDavid Quigley 	dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
161144109241SFred Isaman 			__func__,
1612eadf4598STrond Myklebust 			(unsigned long long)readdir->cookie,
1613cd93710eSChuck Lever 			verf[0], verf[1],
1614eadf4598STrond Myklebust 			attrs[0] & readdir->bitmask[0],
1615aa9c2669SDavid Quigley 			attrs[1] & readdir->bitmask[1],
1616aa9c2669SDavid Quigley 			attrs[2] & readdir->bitmask[2]);
16171da177e4SLinus Torvalds }
16181da177e4SLinus Torvalds 
1619cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
16201da177e4SLinus Torvalds {
1621ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
16221da177e4SLinus Torvalds }
16231da177e4SLinus Torvalds 
1624cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
16251da177e4SLinus Torvalds {
1626ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
16276fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
16281da177e4SLinus Torvalds }
16291da177e4SLinus Torvalds 
1630cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
16311da177e4SLinus Torvalds {
1632ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1633811652bdSBenny Halevy 	encode_string(xdr, oldname->len, oldname->name);
1634811652bdSBenny Halevy 	encode_string(xdr, newname->len, newname->name);
16351da177e4SLinus Torvalds }
16361da177e4SLinus Torvalds 
1637bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1638bb4dae5eSChuck Lever 			 struct compound_hdr *hdr)
16391da177e4SLinus Torvalds {
1640475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1641ff2eb681STrond Myklebust 	encode_uint64(xdr, clid);
16421da177e4SLinus Torvalds }
16431da177e4SLinus Torvalds 
1644cf8cdbe5SAndy Adamson static void
1645d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
164656ae19f3STrond Myklebust {
1647ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
164856ae19f3STrond Myklebust }
164956ae19f3STrond Myklebust 
16509f06c719SChuck Lever static void
1651d017931cSAndy Adamson encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
165223ec6965SJ. Bruce Fields {
16538687b63aSAl Viro 	__be32 *p;
165423ec6965SJ. Bruce Fields 
1655ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1656ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &zero_stateid);
165713c65ce9SBenny Halevy 	p = reserve_space(xdr, 2*4);
1658e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
165934558513SBenny Halevy 	*p = cpu_to_be32(FATTR4_WORD0_ACL);
166013c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
166134558513SBenny Halevy 	*p = cpu_to_be32(arg->acl_len);
16628fbcf237SAndreas Gruenbacher 	xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
166323ec6965SJ. Bruce Fields }
166423ec6965SJ. Bruce Fields 
1665cf8cdbe5SAndy Adamson static void
1666d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
16671da177e4SLinus Torvalds {
1668ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
16691da177e4SLinus Torvalds }
16701da177e4SLinus Torvalds 
1671cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
16721da177e4SLinus Torvalds {
1673ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1674ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
16755334c5bdSKinglong Mee 	encode_attrs(xdr, arg->iap, arg->label, server, false);
16761da177e4SLinus Torvalds }
16771da177e4SLinus Torvalds 
1678cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
16791da177e4SLinus Torvalds {
16808687b63aSAl Viro 	__be32 *p;
16811da177e4SLinus Torvalds 
168270019514STrond Myklebust 	encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1683cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, setclientid->sc_verifier);
16841da177e4SLinus Torvalds 
16853a6bb738SJeff Layton 	encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
16863a6bb738SJeff Layton 			setclientid->sc_clnt->cl_owner_id);
168713c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
168834558513SBenny Halevy 	*p = cpu_to_be32(setclientid->sc_prog);
16891da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
16901da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
169113c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
16923a6bb738SJeff Layton 	*p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
16931da177e4SLinus Torvalds }
16941da177e4SLinus Torvalds 
1695bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
16961da177e4SLinus Torvalds {
1697475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1698475d4ba0STrond Myklebust 			decode_setclientid_confirm_maxsz, hdr);
1699ff2eb681STrond Myklebust 	encode_uint64(xdr, arg->clientid);
1700cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, &arg->confirm);
17011da177e4SLinus Torvalds }
17021da177e4SLinus Torvalds 
17033c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
17043c6b899cSAnna Schumaker 			 struct compound_hdr *hdr)
17051da177e4SLinus Torvalds {
17068687b63aSAl Viro 	__be32 *p;
17071da177e4SLinus Torvalds 
1708ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
17099b206149STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
17101da177e4SLinus Torvalds 
171113c65ce9SBenny Halevy 	p = reserve_space(xdr, 16);
1712b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
1713e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->stable);
171434558513SBenny Halevy 	*p = cpu_to_be32(args->count);
17151da177e4SLinus Torvalds 
17161da177e4SLinus Torvalds 	xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
17171da177e4SLinus Torvalds }
17181da177e4SLinus Torvalds 
1719cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
17201da177e4SLinus Torvalds {
1721ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1722ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
17231da177e4SLinus Torvalds }
17249b7b9fccSAndy Adamson 
17255a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
17265a5ea0d4SBryan Schumaker {
1727ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
17286fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
17295a5ea0d4SBryan Schumaker }
17305a5ea0d4SBryan Schumaker 
173199fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
17329b7b9fccSAndy Adamson /* NFSv4.1 operations */
17337c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr,
173471a097c6STrond Myklebust 				   struct nfs41_bind_conn_to_session_args *args,
17357c44f1aeSWeston Andros Adamson 				   struct compound_hdr *hdr)
17367c44f1aeSWeston Andros Adamson {
17377c44f1aeSWeston Andros Adamson 	__be32 *p;
17387c44f1aeSWeston Andros Adamson 
17397c44f1aeSWeston Andros Adamson 	encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
17407c44f1aeSWeston Andros Adamson 		decode_bind_conn_to_session_maxsz, hdr);
174171a097c6STrond Myklebust 	encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
17427c44f1aeSWeston Andros Adamson 	p = xdr_reserve_space(xdr, 8);
174371a097c6STrond Myklebust 	*p++ = cpu_to_be32(args->dir);
174471a097c6STrond Myklebust 	*p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
17457c44f1aeSWeston Andros Adamson }
17467c44f1aeSWeston Andros Adamson 
17472031cd1aSWeston Andros Adamson static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
17482031cd1aSWeston Andros Adamson {
17492031cd1aSWeston Andros Adamson 	unsigned int i;
17502031cd1aSWeston Andros Adamson 	encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
17512031cd1aSWeston Andros Adamson 	for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
17522031cd1aSWeston Andros Adamson 		encode_uint32(xdr, op_map->u.words[i]);
17532031cd1aSWeston Andros Adamson }
17542031cd1aSWeston Andros Adamson 
175599fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr,
175699fe60d0SBenny Halevy 			       struct nfs41_exchange_id_args *args,
175799fe60d0SBenny Halevy 			       struct compound_hdr *hdr)
175899fe60d0SBenny Halevy {
175999fe60d0SBenny Halevy 	__be32 *p;
1760d751f748SJim Rees 	char impl_name[IMPL_NAME_LIMIT];
1761db8ac8baSWeston Andros Adamson 	int len = 0;
176299fe60d0SBenny Halevy 
176370019514STrond Myklebust 	encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1764cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, args->verifier);
176599fe60d0SBenny Halevy 
17663a6bb738SJeff Layton 	encode_string(xdr, strlen(args->client->cl_owner_id),
17673a6bb738SJeff Layton 			args->client->cl_owner_id);
176899fe60d0SBenny Halevy 
17692031cd1aSWeston Andros Adamson 	encode_uint32(xdr, args->flags);
17702031cd1aSWeston Andros Adamson 	encode_uint32(xdr, args->state_protect.how);
17712031cd1aSWeston Andros Adamson 
17722031cd1aSWeston Andros Adamson 	switch (args->state_protect.how) {
17732031cd1aSWeston Andros Adamson 	case SP4_NONE:
17742031cd1aSWeston Andros Adamson 		break;
17752031cd1aSWeston Andros Adamson 	case SP4_MACH_CRED:
17762031cd1aSWeston Andros Adamson 		encode_op_map(xdr, &args->state_protect.enforce);
17772031cd1aSWeston Andros Adamson 		encode_op_map(xdr, &args->state_protect.allow);
17782031cd1aSWeston Andros Adamson 		break;
17792031cd1aSWeston Andros Adamson 	default:
17802031cd1aSWeston Andros Adamson 		WARN_ON_ONCE(1);
17812031cd1aSWeston Andros Adamson 		break;
17822031cd1aSWeston Andros Adamson 	}
1783db8ac8baSWeston Andros Adamson 
1784db8ac8baSWeston Andros Adamson 	if (send_implementation_id &&
1785db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1786db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1787d751f748SJim Rees 		<= sizeof(impl_name) + 1)
1788db8ac8baSWeston Andros Adamson 		len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1789db8ac8baSWeston Andros Adamson 			       utsname()->sysname, utsname()->release,
1790db8ac8baSWeston Andros Adamson 			       utsname()->version, utsname()->machine);
1791db8ac8baSWeston Andros Adamson 
1792db8ac8baSWeston Andros Adamson 	if (len > 0) {
17932031cd1aSWeston Andros Adamson 		encode_uint32(xdr, 1);	/* implementation id array length=1 */
1794db8ac8baSWeston Andros Adamson 
1795db8ac8baSWeston Andros Adamson 		encode_string(xdr,
1796db8ac8baSWeston Andros Adamson 			sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1797db8ac8baSWeston Andros Adamson 			CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1798db8ac8baSWeston Andros Adamson 		encode_string(xdr, len, impl_name);
1799db8ac8baSWeston Andros Adamson 		/* just send zeros for nii_date - the date is in nii_name */
1800db8ac8baSWeston Andros Adamson 		p = reserve_space(xdr, 12);
1801db8ac8baSWeston Andros Adamson 		p = xdr_encode_hyper(p, 0);
1802db8ac8baSWeston Andros Adamson 		*p = cpu_to_be32(0);
1803db8ac8baSWeston Andros Adamson 	} else
18042031cd1aSWeston Andros Adamson 		encode_uint32(xdr, 0);	/* implementation id array length=0 */
180599fe60d0SBenny Halevy }
1806fc931582SAndy Adamson 
1807fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr,
1808fc931582SAndy Adamson 				  struct nfs41_create_session_args *args,
1809fc931582SAndy Adamson 				  struct compound_hdr *hdr)
1810fc931582SAndy Adamson {
1811fc931582SAndy Adamson 	__be32 *p;
1812fc931582SAndy Adamson 	struct nfs_client *clp = args->client;
181389f0ff38STrond Myklebust 	struct rpc_clnt *clnt = clp->cl_rpcclient;
1814f092075dSChuck Lever 	struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
18158e0d46e1SMike Sager 	u32 max_resp_sz_cached;
18168e0d46e1SMike Sager 
18178e0d46e1SMike Sager 	/*
18188e0d46e1SMike Sager 	 * Assumes OPEN is the biggest non-idempotent compound.
18198e0d46e1SMike Sager 	 * 2 is the verifier.
18208e0d46e1SMike Sager 	 */
18218e0d46e1SMike Sager 	max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
18228e0d46e1SMike Sager 			      RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1823fc931582SAndy Adamson 
1824475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
182589f0ff38STrond Myklebust 	p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
182679969dd1STrond Myklebust 	p = xdr_encode_hyper(p, args->clientid);
182779969dd1STrond Myklebust 	*p++ = cpu_to_be32(args->seqid);			/*Sequence id */
1828e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->flags);			/*flags */
1829fc931582SAndy Adamson 
1830fc931582SAndy Adamson 	/* Fore Channel */
1831c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1832e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz);	/* max req size */
1833e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_resp_sz);	/* max resp size */
18348e0d46e1SMike Sager 	*p++ = cpu_to_be32(max_resp_sz_cached);		/* Max resp sz cached */
1835e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_ops);	/* max operations */
1836e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_reqs);	/* max requests */
1837e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1838fc931582SAndy Adamson 
1839fc931582SAndy Adamson 	/* Back Channel */
1840c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1841e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz);	/* max req size */
1842e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz);	/* max resp size */
1843e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached);	/* Max resp sz cached */
1844e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_ops);	/* max operations */
1845e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_reqs);	/* max requests */
1846e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1847fc931582SAndy Adamson 
1848e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->cb_program);		/* cb_program */
1849e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
1850e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(RPC_AUTH_UNIX);			/* auth_sys */
1851fc931582SAndy Adamson 
1852fc931582SAndy Adamson 	/* authsys_parms rfc1831 */
185317f26b12STrond Myklebust 	*p++ = cpu_to_be32(nn->boot_time.tv_nsec);	/* stamp */
185489f0ff38STrond Myklebust 	p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
1855e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* UID */
1856e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* GID */
185734558513SBenny Halevy 	*p = cpu_to_be32(0);				/* No more gids */
1858fc931582SAndy Adamson }
18590f3e66c6SAndy Adamson 
18600f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr,
18610f3e66c6SAndy Adamson 				   struct nfs4_session *session,
18620f3e66c6SAndy Adamson 				   struct compound_hdr *hdr)
18630f3e66c6SAndy Adamson {
1864475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1865475d4ba0STrond Myklebust 	encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
18660f3e66c6SAndy Adamson }
186718019753SRicardo Labiaga 
186866245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr,
186966245539STrond Myklebust 				   uint64_t clientid,
187066245539STrond Myklebust 				   struct compound_hdr *hdr)
187166245539STrond Myklebust {
187266245539STrond Myklebust 	encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
187366245539STrond Myklebust 	encode_uint64(xdr, clientid);
187466245539STrond Myklebust }
187566245539STrond Myklebust 
187618019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr,
187718019753SRicardo Labiaga 				    struct nfs41_reclaim_complete_args *args,
187818019753SRicardo Labiaga 				    struct compound_hdr *hdr)
187918019753SRicardo Labiaga {
1880475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1881475d4ba0STrond Myklebust 	encode_uint32(xdr, args->one_fs);
188218019753SRicardo Labiaga }
188399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
188499fe60d0SBenny Halevy 
18859b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr,
18869b7b9fccSAndy Adamson 			    const struct nfs4_sequence_args *args,
18879b7b9fccSAndy Adamson 			    struct compound_hdr *hdr)
18889b7b9fccSAndy Adamson {
18899b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
18902b2fa717STrond Myklebust 	struct nfs4_session *session;
1891fc01cea9SAndy Adamson 	struct nfs4_slot_table *tp;
18922b2fa717STrond Myklebust 	struct nfs4_slot *slot = args->sa_slot;
1893fc01cea9SAndy Adamson 	__be32 *p;
18949b7b9fccSAndy Adamson 
18952b2fa717STrond Myklebust 	tp = slot->table;
18962b2fa717STrond Myklebust 	session = tp->session;
18973bd2384aSChuck Lever 	if (!session)
18983bd2384aSChuck Lever 		return;
1899fc01cea9SAndy Adamson 
1900475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1901fc01cea9SAndy Adamson 
1902fc01cea9SAndy Adamson 	/*
1903fc01cea9SAndy Adamson 	 * Sessionid + seqid + slotid + max slotid + cache_this
1904fc01cea9SAndy Adamson 	 */
1905fc01cea9SAndy Adamson 	dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1906fc01cea9SAndy Adamson 		"max_slotid=%d cache_this=%d\n",
1907fc01cea9SAndy Adamson 		__func__,
1908fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[0],
1909fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[1],
1910fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[2],
1911fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[3],
19122b2fa717STrond Myklebust 		slot->seq_nr, slot->slot_nr,
1913fc01cea9SAndy Adamson 		tp->highest_used_slotid, args->sa_cache_this);
1914475d4ba0STrond Myklebust 	p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
191593f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1916e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(slot->seq_nr);
19172b2fa717STrond Myklebust 	*p++ = cpu_to_be32(slot->slot_nr);
1918e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(tp->highest_used_slotid);
191934558513SBenny Halevy 	*p = cpu_to_be32(args->sa_cache_this);
19209b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
19219b7b9fccSAndy Adamson }
19229b7b9fccSAndy Adamson 
1923b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1
1924b1f69b75SAndy Adamson static void
1925b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr,
1926b1f69b75SAndy Adamson 		     const struct nfs4_getdeviceinfo_args *args,
1927b1f69b75SAndy Adamson 		     struct compound_hdr *hdr)
1928b1f69b75SAndy Adamson {
1929b1f69b75SAndy Adamson 	__be32 *p;
1930b1f69b75SAndy Adamson 
1931475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
193284c9dee3SChristoph Hellwig 	p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
1933b1f69b75SAndy Adamson 	p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1934b1f69b75SAndy Adamson 				    NFS4_DEVICEID4_SIZE);
1935b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->pdev->layout_type);
1936f1c097beSAndy Adamson 	*p++ = cpu_to_be32(args->pdev->maxcount);	/* gdia_maxcount */
193784c9dee3SChristoph Hellwig 
193884c9dee3SChristoph Hellwig 	p = reserve_space(xdr, 4 + 4);
193984c9dee3SChristoph Hellwig 	*p++ = cpu_to_be32(1);			/* bitmap length */
19404e590803STrond Myklebust 	*p++ = cpu_to_be32(args->notify_types);
1941b1f69b75SAndy Adamson }
1942b1f69b75SAndy Adamson 
1943b1f69b75SAndy Adamson static void
1944b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr,
1945b1f69b75SAndy Adamson 		      const struct nfs4_layoutget_args *args,
1946b1f69b75SAndy Adamson 		      struct compound_hdr *hdr)
1947b1f69b75SAndy Adamson {
1948b1f69b75SAndy Adamson 	__be32 *p;
1949b1f69b75SAndy Adamson 
1950475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1951475d4ba0STrond Myklebust 	p = reserve_space(xdr, 36);
1952b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(0);     /* Signal layout available */
1953b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->type);
1954b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->range.iomode);
1955b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.offset);
1956b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.length);
1957b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->minlength);
1958ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
1959475d4ba0STrond Myklebust 	encode_uint32(xdr, args->maxcount);
1960b1f69b75SAndy Adamson 
1961b1f69b75SAndy Adamson 	dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1962b1f69b75SAndy Adamson 		__func__,
1963b1f69b75SAndy Adamson 		args->type,
1964b1f69b75SAndy Adamson 		args->range.iomode,
1965b1f69b75SAndy Adamson 		(unsigned long)args->range.offset,
1966b1f69b75SAndy Adamson 		(unsigned long)args->range.length,
1967b1f69b75SAndy Adamson 		args->maxcount);
1968b1f69b75SAndy Adamson }
1969863a3c6cSAndy Adamson 
1970863a3c6cSAndy Adamson static int
1971863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr,
1972ac7db726SBenny Halevy 		    struct inode *inode,
19735f919c9fSChristoph Hellwig 		    struct nfs4_layoutcommit_args *args,
1974863a3c6cSAndy Adamson 		    struct compound_hdr *hdr)
1975863a3c6cSAndy Adamson {
1976863a3c6cSAndy Adamson 	__be32 *p;
1977863a3c6cSAndy Adamson 
1978863a3c6cSAndy Adamson 	dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1979863a3c6cSAndy Adamson 		NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1980863a3c6cSAndy Adamson 
1981475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1982475d4ba0STrond Myklebust 	p = reserve_space(xdr, 20);
1983863a3c6cSAndy Adamson 	/* Only whole file layouts */
1984863a3c6cSAndy Adamson 	p = xdr_encode_hyper(p, 0); /* offset */
19853557c6c3SPeng Tao 	p = xdr_encode_hyper(p, args->lastbytewritten + 1);	/* length */
1986ea9d23f5STrond Myklebust 	*p = cpu_to_be32(0); /* reclaim */
1987ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
19882e18d4d8STrond Myklebust 	if (args->lastbytewritten != U64_MAX) {
1989ea9d23f5STrond Myklebust 		p = reserve_space(xdr, 20);
1990863a3c6cSAndy Adamson 		*p++ = cpu_to_be32(1); /* newoffset = TRUE */
1991863a3c6cSAndy Adamson 		p = xdr_encode_hyper(p, args->lastbytewritten);
19922e18d4d8STrond Myklebust 	} else {
19932e18d4d8STrond Myklebust 		p = reserve_space(xdr, 12);
19942e18d4d8STrond Myklebust 		*p++ = cpu_to_be32(0); /* newoffset = FALSE */
19952e18d4d8STrond Myklebust 	}
1996863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1997863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1998ac7db726SBenny Halevy 
19995f919c9fSChristoph Hellwig 	if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
2000ac7db726SBenny Halevy 		NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2001ac7db726SBenny Halevy 			NFS_I(inode)->layout, xdr, args);
20025f919c9fSChristoph Hellwig 	} else {
20035f919c9fSChristoph Hellwig 		encode_uint32(xdr, args->layoutupdate_len);
20045f919c9fSChristoph Hellwig 		if (args->layoutupdate_pages) {
20055f919c9fSChristoph Hellwig 			xdr_write_pages(xdr, args->layoutupdate_pages, 0,
20065f919c9fSChristoph Hellwig 					args->layoutupdate_len);
20075f919c9fSChristoph Hellwig 		}
20085f919c9fSChristoph Hellwig 	}
2009863a3c6cSAndy Adamson 
2010863a3c6cSAndy Adamson 	return 0;
2011863a3c6cSAndy Adamson }
2012cbe82603SBenny Halevy 
2013cbe82603SBenny Halevy static void
2014cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr,
2015cbe82603SBenny Halevy 		    const struct nfs4_layoutreturn_args *args,
2016cbe82603SBenny Halevy 		    struct compound_hdr *hdr)
2017cbe82603SBenny Halevy {
2018cbe82603SBenny Halevy 	__be32 *p;
2019cbe82603SBenny Halevy 
2020475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2021475d4ba0STrond Myklebust 	p = reserve_space(xdr, 16);
2022cbe82603SBenny Halevy 	*p++ = cpu_to_be32(0);		/* reclaim. always 0 for now */
2023cbe82603SBenny Halevy 	*p++ = cpu_to_be32(args->layout_type);
202415eb67c1SPeng Tao 	*p++ = cpu_to_be32(args->range.iomode);
2025cbe82603SBenny Halevy 	*p = cpu_to_be32(RETURN_FILE);
2026ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 16);
202715eb67c1SPeng Tao 	p = xdr_encode_hyper(p, args->range.offset);
202815eb67c1SPeng Tao 	p = xdr_encode_hyper(p, args->range.length);
2029cbe82603SBenny Halevy 	spin_lock(&args->inode->i_lock);
2030ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
2031cbe82603SBenny Halevy 	spin_unlock(&args->inode->i_lock);
203204a55549SAndy Adamson 	if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
203304a55549SAndy Adamson 		NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
203404a55549SAndy Adamson 			NFS_I(args->inode)->layout, xdr, args);
2035475d4ba0STrond Myklebust 	} else
2036475d4ba0STrond Myklebust 		encode_uint32(xdr, 0);
2037cbe82603SBenny Halevy }
2038fca78d6dSBryan Schumaker 
2039fca78d6dSBryan Schumaker static int
2040fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr,
2041fca78d6dSBryan Schumaker 		       const struct nfs41_secinfo_no_name_args *args,
2042fca78d6dSBryan Schumaker 		       struct compound_hdr *hdr)
2043fca78d6dSBryan Schumaker {
2044475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2045475d4ba0STrond Myklebust 	encode_uint32(xdr, args->style);
2046fca78d6dSBryan Schumaker 	return 0;
2047fca78d6dSBryan Schumaker }
20487d974794SBryan Schumaker 
20497d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr,
20507d974794SBryan Schumaker 				struct nfs41_test_stateid_args *args,
20517d974794SBryan Schumaker 				struct compound_hdr *hdr)
20527d974794SBryan Schumaker {
2053475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2054475d4ba0STrond Myklebust 	encode_uint32(xdr, 1);
2055ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, args->stateid);
20567d974794SBryan Schumaker }
20579aeda35fSBryan Schumaker 
20589aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr,
20599aeda35fSBryan Schumaker 				struct nfs41_free_stateid_args *args,
20609aeda35fSBryan Schumaker 				struct compound_hdr *hdr)
20619aeda35fSBryan Schumaker {
2062ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
20637c1d5faeSTrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
20649aeda35fSBryan Schumaker }
2065b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
2066b1f69b75SAndy Adamson 
20671da177e4SLinus Torvalds /*
20681da177e4SLinus Torvalds  * END OF "GENERIC" ENCODE ROUTINES.
20691da177e4SLinus Torvalds  */
20701da177e4SLinus Torvalds 
207166cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
207266cc0429SBenny Halevy {
207366cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1)
20743bd2384aSChuck Lever 	struct nfs4_session *session = args->sa_slot->table->session;
20753bd2384aSChuck Lever 	if (session)
20763bd2384aSChuck Lever 		return session->clp->cl_mvops->minor_version;
207766cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
207866cc0429SBenny Halevy 	return 0;
207966cc0429SBenny Halevy }
208066cc0429SBenny Halevy 
20811da177e4SLinus Torvalds /*
20821da177e4SLinus Torvalds  * Encode an ACCESS request
20831da177e4SLinus Torvalds  */
20849f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
20859f06c719SChuck Lever 				const struct nfs4_accessargs *args)
20861da177e4SLinus Torvalds {
20871da177e4SLinus Torvalds 	struct compound_hdr hdr = {
208866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
20891da177e4SLinus Torvalds 	};
20901da177e4SLinus Torvalds 
20919f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
20929f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
20939f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
20949f06c719SChuck Lever 	encode_access(xdr, args->access, &hdr);
20959f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2096d017931cSAndy Adamson 	encode_nops(&hdr);
20971da177e4SLinus Torvalds }
20981da177e4SLinus Torvalds 
20991da177e4SLinus Torvalds /*
21001da177e4SLinus Torvalds  * Encode LOOKUP request
21011da177e4SLinus Torvalds  */
21029f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
21039f06c719SChuck Lever 				const struct nfs4_lookup_arg *args)
21041da177e4SLinus Torvalds {
21051da177e4SLinus Torvalds 	struct compound_hdr hdr = {
210666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21071da177e4SLinus Torvalds 	};
21081da177e4SLinus Torvalds 
21099f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21109f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21119f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
21129f06c719SChuck Lever 	encode_lookup(xdr, args->name, &hdr);
21139f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21149f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2115d017931cSAndy Adamson 	encode_nops(&hdr);
21161da177e4SLinus Torvalds }
21171da177e4SLinus Torvalds 
21181da177e4SLinus Torvalds /*
21191da177e4SLinus Torvalds  * Encode LOOKUP_ROOT request
21201da177e4SLinus Torvalds  */
21219f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
21229f06c719SChuck Lever 				     struct xdr_stream *xdr,
21239f06c719SChuck Lever 				     const struct nfs4_lookup_root_arg *args)
21241da177e4SLinus Torvalds {
21251da177e4SLinus Torvalds 	struct compound_hdr hdr = {
212666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21271da177e4SLinus Torvalds 	};
21281da177e4SLinus Torvalds 
21299f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21309f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21319f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
21329f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21339f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2134d017931cSAndy Adamson 	encode_nops(&hdr);
21351da177e4SLinus Torvalds }
21361da177e4SLinus Torvalds 
21371da177e4SLinus Torvalds /*
21381da177e4SLinus Torvalds  * Encode REMOVE request
21391da177e4SLinus Torvalds  */
21409f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
21419f06c719SChuck Lever 				const struct nfs_removeargs *args)
21421da177e4SLinus Torvalds {
21431da177e4SLinus Torvalds 	struct compound_hdr hdr = {
214466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21451da177e4SLinus Torvalds 	};
21461da177e4SLinus Torvalds 
21479f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21489f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21499f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21509f06c719SChuck Lever 	encode_remove(xdr, &args->name, &hdr);
2151d017931cSAndy Adamson 	encode_nops(&hdr);
21521da177e4SLinus Torvalds }
21531da177e4SLinus Torvalds 
21541da177e4SLinus Torvalds /*
21551da177e4SLinus Torvalds  * Encode RENAME request
21561da177e4SLinus Torvalds  */
21579f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
21589f06c719SChuck Lever 				const struct nfs_renameargs *args)
21591da177e4SLinus Torvalds {
21601da177e4SLinus Torvalds 	struct compound_hdr hdr = {
216166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21621da177e4SLinus Torvalds 	};
21631da177e4SLinus Torvalds 
21649f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21659f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21669f06c719SChuck Lever 	encode_putfh(xdr, args->old_dir, &hdr);
21679f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
21689f06c719SChuck Lever 	encode_putfh(xdr, args->new_dir, &hdr);
21699f06c719SChuck Lever 	encode_rename(xdr, args->old_name, args->new_name, &hdr);
2170d017931cSAndy Adamson 	encode_nops(&hdr);
21711da177e4SLinus Torvalds }
21721da177e4SLinus Torvalds 
21731da177e4SLinus Torvalds /*
21741da177e4SLinus Torvalds  * Encode LINK request
21751da177e4SLinus Torvalds  */
21769f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
21779f06c719SChuck Lever 			     const struct nfs4_link_arg *args)
21781da177e4SLinus Torvalds {
21791da177e4SLinus Torvalds 	struct compound_hdr hdr = {
218066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21811da177e4SLinus Torvalds 	};
21821da177e4SLinus Torvalds 
21839f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21849f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21859f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21869f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
21879f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
21889f06c719SChuck Lever 	encode_link(xdr, args->name, &hdr);
21899f06c719SChuck Lever 	encode_restorefh(xdr, &hdr);
21909f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2191d017931cSAndy Adamson 	encode_nops(&hdr);
21921da177e4SLinus Torvalds }
21931da177e4SLinus Torvalds 
21941da177e4SLinus Torvalds /*
21951da177e4SLinus Torvalds  * Encode CREATE request
21961da177e4SLinus Torvalds  */
21979f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
21989f06c719SChuck Lever 				const struct nfs4_create_arg *args)
21991da177e4SLinus Torvalds {
22001da177e4SLinus Torvalds 	struct compound_hdr hdr = {
220166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22021da177e4SLinus Torvalds 	};
22031da177e4SLinus Torvalds 
22049f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22059f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22069f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
22079f06c719SChuck Lever 	encode_create(xdr, args, &hdr);
22089f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
22099f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2210d017931cSAndy Adamson 	encode_nops(&hdr);
22111da177e4SLinus Torvalds }
22121da177e4SLinus Torvalds 
22131da177e4SLinus Torvalds /*
22141da177e4SLinus Torvalds  * Encode SYMLINK request
22151da177e4SLinus Torvalds  */
22169f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
22179f06c719SChuck Lever 				 const struct nfs4_create_arg *args)
22181da177e4SLinus Torvalds {
22199f06c719SChuck Lever 	nfs4_xdr_enc_create(req, xdr, args);
22201da177e4SLinus Torvalds }
22211da177e4SLinus Torvalds 
22221da177e4SLinus Torvalds /*
22231da177e4SLinus Torvalds  * Encode GETATTR request
22241da177e4SLinus Torvalds  */
22259f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
22269f06c719SChuck Lever 				 const struct nfs4_getattr_arg *args)
22271da177e4SLinus Torvalds {
22281da177e4SLinus Torvalds 	struct compound_hdr hdr = {
222966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22301da177e4SLinus Torvalds 	};
22311da177e4SLinus Torvalds 
22329f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22339f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22349f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22359f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2236d017931cSAndy Adamson 	encode_nops(&hdr);
22371da177e4SLinus Torvalds }
22381da177e4SLinus Torvalds 
22391da177e4SLinus Torvalds /*
22401da177e4SLinus Torvalds  * Encode a CLOSE request
22411da177e4SLinus Torvalds  */
22429f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
22439f06c719SChuck Lever 			       struct nfs_closeargs *args)
22441da177e4SLinus Torvalds {
22451da177e4SLinus Torvalds 	struct compound_hdr hdr = {
224666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22471da177e4SLinus Torvalds 	};
22481da177e4SLinus Torvalds 
22499f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22509f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22519f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22529f06c719SChuck Lever 	encode_close(xdr, args, &hdr);
22539f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2254d017931cSAndy Adamson 	encode_nops(&hdr);
22551da177e4SLinus Torvalds }
22561da177e4SLinus Torvalds 
22571da177e4SLinus Torvalds /*
22581da177e4SLinus Torvalds  * Encode an OPEN request
22591da177e4SLinus Torvalds  */
22609f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
22619f06c719SChuck Lever 			      struct nfs_openargs *args)
22621da177e4SLinus Torvalds {
22631da177e4SLinus Torvalds 	struct compound_hdr hdr = {
226466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22651da177e4SLinus Torvalds 	};
22661da177e4SLinus Torvalds 
22679f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22689f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22699f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22709f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
22719f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
2272ae2bb032SWeston Andros Adamson 	if (args->access)
22736168f62cSWeston Andros Adamson 		encode_access(xdr, args->access, &hdr);
22741549210fSTrond Myklebust 	encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2275d017931cSAndy Adamson 	encode_nops(&hdr);
22761da177e4SLinus Torvalds }
22771da177e4SLinus Torvalds 
22781da177e4SLinus Torvalds /*
22791da177e4SLinus Torvalds  * Encode an OPEN_CONFIRM request
22801da177e4SLinus Torvalds  */
22819f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
22829f06c719SChuck Lever 				      struct xdr_stream *xdr,
22839f06c719SChuck Lever 				      struct nfs_open_confirmargs *args)
22841da177e4SLinus Torvalds {
22851da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2286d017931cSAndy Adamson 		.nops   = 0,
22871da177e4SLinus Torvalds 	};
22881da177e4SLinus Torvalds 
22899f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22909f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22919f06c719SChuck Lever 	encode_open_confirm(xdr, args, &hdr);
2292d017931cSAndy Adamson 	encode_nops(&hdr);
22931da177e4SLinus Torvalds }
22941da177e4SLinus Torvalds 
22951da177e4SLinus Torvalds /*
22961da177e4SLinus Torvalds  * Encode an OPEN request with no attributes.
22971da177e4SLinus Torvalds  */
22989f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
22999f06c719SChuck Lever 				     struct xdr_stream *xdr,
23009f06c719SChuck Lever 				     struct nfs_openargs *args)
23011da177e4SLinus Torvalds {
23021da177e4SLinus Torvalds 	struct compound_hdr hdr = {
230366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23041da177e4SLinus Torvalds 	};
23051da177e4SLinus Torvalds 
23069f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23079f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23089f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23099f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
2310ae2bb032SWeston Andros Adamson 	if (args->access)
23116168f62cSWeston Andros Adamson 		encode_access(xdr, args->access, &hdr);
2312e23008ecSAndy Adamson 	encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2313d017931cSAndy Adamson 	encode_nops(&hdr);
23141da177e4SLinus Torvalds }
23151da177e4SLinus Torvalds 
23161da177e4SLinus Torvalds /*
23171da177e4SLinus Torvalds  * Encode an OPEN_DOWNGRADE request
23181da177e4SLinus Torvalds  */
23199f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
23209f06c719SChuck Lever 					struct xdr_stream *xdr,
23219f06c719SChuck Lever 					struct nfs_closeargs *args)
23221da177e4SLinus Torvalds {
23231da177e4SLinus Torvalds 	struct compound_hdr hdr = {
232466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23251da177e4SLinus Torvalds 	};
23261da177e4SLinus Torvalds 
23279f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23289f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23299f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23309f06c719SChuck Lever 	encode_open_downgrade(xdr, args, &hdr);
23319f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2332d017931cSAndy Adamson 	encode_nops(&hdr);
23331da177e4SLinus Torvalds }
23341da177e4SLinus Torvalds 
23351da177e4SLinus Torvalds /*
23361da177e4SLinus Torvalds  * Encode a LOCK request
23371da177e4SLinus Torvalds  */
23389f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
23399f06c719SChuck Lever 			      struct nfs_lock_args *args)
23401da177e4SLinus Torvalds {
23411da177e4SLinus Torvalds 	struct compound_hdr hdr = {
234266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23431da177e4SLinus Torvalds 	};
23441da177e4SLinus Torvalds 
23459f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23469f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23479f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23489f06c719SChuck Lever 	encode_lock(xdr, args, &hdr);
2349d017931cSAndy Adamson 	encode_nops(&hdr);
23501da177e4SLinus Torvalds }
23511da177e4SLinus Torvalds 
23521da177e4SLinus Torvalds /*
23531da177e4SLinus Torvalds  * Encode a LOCKT request
23541da177e4SLinus Torvalds  */
23559f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
23569f06c719SChuck Lever 			       struct nfs_lockt_args *args)
23571da177e4SLinus Torvalds {
23581da177e4SLinus Torvalds 	struct compound_hdr hdr = {
235966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23601da177e4SLinus Torvalds 	};
23611da177e4SLinus Torvalds 
23629f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23639f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23649f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23659f06c719SChuck Lever 	encode_lockt(xdr, args, &hdr);
2366d017931cSAndy Adamson 	encode_nops(&hdr);
23671da177e4SLinus Torvalds }
23681da177e4SLinus Torvalds 
23691da177e4SLinus Torvalds /*
23701da177e4SLinus Torvalds  * Encode a LOCKU request
23711da177e4SLinus Torvalds  */
23729f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
23739f06c719SChuck Lever 			       struct nfs_locku_args *args)
23741da177e4SLinus Torvalds {
23751da177e4SLinus Torvalds 	struct compound_hdr hdr = {
237666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23771da177e4SLinus Torvalds 	};
23781da177e4SLinus Torvalds 
23799f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23809f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23819f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23829f06c719SChuck Lever 	encode_locku(xdr, args, &hdr);
2383d017931cSAndy Adamson 	encode_nops(&hdr);
23841da177e4SLinus Torvalds }
23851da177e4SLinus Torvalds 
23869f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
23879f06c719SChuck Lever 					   struct xdr_stream *xdr,
23889f06c719SChuck Lever 					struct nfs_release_lockowner_args *args)
2389d3c7b7ccSTrond Myklebust {
2390d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr = {
2391d3c7b7ccSTrond Myklebust 		.minorversion = 0,
2392d3c7b7ccSTrond Myklebust 	};
2393d3c7b7ccSTrond Myklebust 
23949f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23959f06c719SChuck Lever 	encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2396d3c7b7ccSTrond Myklebust 	encode_nops(&hdr);
2397d3c7b7ccSTrond Myklebust }
2398d3c7b7ccSTrond Myklebust 
23991da177e4SLinus Torvalds /*
24001da177e4SLinus Torvalds  * Encode a READLINK request
24011da177e4SLinus Torvalds  */
24029f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
24039f06c719SChuck Lever 				  const struct nfs4_readlink *args)
24041da177e4SLinus Torvalds {
24051da177e4SLinus Torvalds 	struct compound_hdr hdr = {
240666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24071da177e4SLinus Torvalds 	};
24081da177e4SLinus Torvalds 
24099f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24109f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24119f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24129f06c719SChuck Lever 	encode_readlink(xdr, args, req, &hdr);
2413e3a535e1STrond Myklebust 
241428f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2415e3a535e1STrond Myklebust 			args->pgbase, args->pglen);
2416d017931cSAndy Adamson 	encode_nops(&hdr);
24171da177e4SLinus Torvalds }
24181da177e4SLinus Torvalds 
24191da177e4SLinus Torvalds /*
24201da177e4SLinus Torvalds  * Encode a READDIR request
24211da177e4SLinus Torvalds  */
24229f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
24239f06c719SChuck Lever 				 const struct nfs4_readdir_arg *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_readdir(xdr, args, req, &hdr);
2433d6ac02dfSTrond Myklebust 
243428f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2435d6ac02dfSTrond Myklebust 			 args->pgbase, args->count);
2436d6ac02dfSTrond Myklebust 	dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
243728f56694SBenny Halevy 			__func__, hdr.replen << 2, args->pages,
2438d6ac02dfSTrond Myklebust 			args->pgbase, args->count);
2439d017931cSAndy Adamson 	encode_nops(&hdr);
24401da177e4SLinus Torvalds }
24411da177e4SLinus Torvalds 
24421da177e4SLinus Torvalds /*
24431da177e4SLinus Torvalds  * Encode a READ request
24441da177e4SLinus Torvalds  */
24459f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
24463c6b899cSAnna Schumaker 			      struct nfs_pgio_args *args)
24471da177e4SLinus Torvalds {
24481da177e4SLinus Torvalds 	struct compound_hdr hdr = {
244966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24501da177e4SLinus Torvalds 	};
24511da177e4SLinus Torvalds 
24529f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24539f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24549f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24559f06c719SChuck Lever 	encode_read(xdr, args, &hdr);
24561da177e4SLinus Torvalds 
245728f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
24581da177e4SLinus Torvalds 			 args->pages, args->pgbase, args->count);
24594f22ccc3S\"Talpey, Thomas\ 	req->rq_rcv_buf.flags |= XDRBUF_READ;
2460d017931cSAndy Adamson 	encode_nops(&hdr);
24611da177e4SLinus Torvalds }
24621da177e4SLinus Torvalds 
24631da177e4SLinus Torvalds /*
24641da177e4SLinus Torvalds  * Encode an SETATTR request
24651da177e4SLinus Torvalds  */
24669f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
24679f06c719SChuck Lever 				 struct nfs_setattrargs *args)
24681da177e4SLinus Torvalds {
24691da177e4SLinus Torvalds 	struct compound_hdr hdr = {
247066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24711da177e4SLinus Torvalds 	};
24721da177e4SLinus Torvalds 
24739f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24749f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24759f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24769f06c719SChuck Lever 	encode_setattr(xdr, args, args->server, &hdr);
24779f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2478d017931cSAndy Adamson 	encode_nops(&hdr);
24791da177e4SLinus Torvalds }
24801da177e4SLinus Torvalds 
24811da177e4SLinus Torvalds /*
2482029d105eSJ. Bruce Fields  * Encode a GETACL request
2483029d105eSJ. Bruce Fields  */
24849f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2485029d105eSJ. Bruce Fields 				struct nfs_getaclargs *args)
2486029d105eSJ. Bruce Fields {
2487029d105eSJ. Bruce Fields 	struct compound_hdr hdr = {
248866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2489029d105eSJ. Bruce Fields 	};
249028f56694SBenny Halevy 	uint32_t replen;
2491029d105eSJ. Bruce Fields 
24929f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24939f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24949f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
2495bf118a34SAndy Adamson 	replen = hdr.replen + op_decode_hdr_maxsz + 1;
24969f06c719SChuck Lever 	encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2497cf8cdbe5SAndy Adamson 
249828f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
24998fbcf237SAndreas Gruenbacher 		args->acl_pages, 0, args->acl_len);
2500bf118a34SAndy Adamson 
2501d017931cSAndy Adamson 	encode_nops(&hdr);
2502029d105eSJ. Bruce Fields }
2503029d105eSJ. Bruce Fields 
2504029d105eSJ. Bruce Fields /*
25051da177e4SLinus Torvalds  * Encode a WRITE request
25061da177e4SLinus Torvalds  */
25079f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
25083c6b899cSAnna Schumaker 			       struct nfs_pgio_args *args)
25091da177e4SLinus Torvalds {
25101da177e4SLinus Torvalds 	struct compound_hdr hdr = {
251166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25121da177e4SLinus Torvalds 	};
25131da177e4SLinus Torvalds 
25149f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25159f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25169f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25179f06c719SChuck Lever 	encode_write(xdr, args, &hdr);
25184f22ccc3S\"Talpey, Thomas\ 	req->rq_snd_buf.flags |= XDRBUF_WRITE;
25197ffd1064SFred Isaman 	if (args->bitmask)
25209f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2521d017931cSAndy Adamson 	encode_nops(&hdr);
25221da177e4SLinus Torvalds }
25231da177e4SLinus Torvalds 
25241da177e4SLinus Torvalds /*
25251da177e4SLinus Torvalds  *  a COMMIT request
25261da177e4SLinus Torvalds  */
25279f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
25280b7c0153SFred Isaman 				struct nfs_commitargs *args)
25291da177e4SLinus Torvalds {
25301da177e4SLinus Torvalds 	struct compound_hdr hdr = {
253166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25321da177e4SLinus Torvalds 	};
25331da177e4SLinus Torvalds 
25349f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25359f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25369f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25379f06c719SChuck Lever 	encode_commit(xdr, args, &hdr);
2538d017931cSAndy Adamson 	encode_nops(&hdr);
25391da177e4SLinus Torvalds }
25401da177e4SLinus Torvalds 
25411da177e4SLinus Torvalds /*
25421da177e4SLinus Torvalds  * FSINFO request
25431da177e4SLinus Torvalds  */
25449f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
25459f06c719SChuck Lever 				struct nfs4_fsinfo_arg *args)
25461da177e4SLinus Torvalds {
25471da177e4SLinus Torvalds 	struct compound_hdr hdr = {
254866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25491da177e4SLinus Torvalds 	};
25501da177e4SLinus Torvalds 
25519f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25529f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25539f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25549f06c719SChuck Lever 	encode_fsinfo(xdr, args->bitmask, &hdr);
2555d017931cSAndy Adamson 	encode_nops(&hdr);
25561da177e4SLinus Torvalds }
25571da177e4SLinus Torvalds 
25581da177e4SLinus Torvalds /*
25591da177e4SLinus Torvalds  * a PATHCONF request
25601da177e4SLinus Torvalds  */
25619f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
25629f06c719SChuck Lever 				  const struct nfs4_pathconf_arg *args)
25631da177e4SLinus Torvalds {
25641da177e4SLinus Torvalds 	struct compound_hdr hdr = {
256566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25661da177e4SLinus Torvalds 	};
25671da177e4SLinus Torvalds 
25689f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25699f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25709f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25719f06c719SChuck Lever 	encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2572d017931cSAndy Adamson 			   &hdr);
2573d017931cSAndy Adamson 	encode_nops(&hdr);
25741da177e4SLinus Torvalds }
25751da177e4SLinus Torvalds 
25761da177e4SLinus Torvalds /*
25771da177e4SLinus Torvalds  * a STATFS request
25781da177e4SLinus Torvalds  */
25799f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
25809f06c719SChuck Lever 				const struct nfs4_statfs_arg *args)
25811da177e4SLinus Torvalds {
25821da177e4SLinus Torvalds 	struct compound_hdr hdr = {
258366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25841da177e4SLinus Torvalds 	};
25851da177e4SLinus Torvalds 
25869f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25879f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25889f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25899f06c719SChuck Lever 	encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2590d017931cSAndy Adamson 			   args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2591d017931cSAndy Adamson 	encode_nops(&hdr);
25921da177e4SLinus Torvalds }
25931da177e4SLinus Torvalds 
25941da177e4SLinus Torvalds /*
25951da177e4SLinus Torvalds  * GETATTR_BITMAP request
25961da177e4SLinus Torvalds  */
25979f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
25989f06c719SChuck Lever 				     struct xdr_stream *xdr,
259943652ad5SBenny Halevy 				     struct nfs4_server_caps_arg *args)
26001da177e4SLinus Torvalds {
26018c61282fSKinglong Mee 	const u32 *bitmask = args->bitmask;
26021da177e4SLinus Torvalds 	struct compound_hdr hdr = {
260366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26041da177e4SLinus Torvalds 	};
26051da177e4SLinus Torvalds 
26069f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26079f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26089f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
26098c61282fSKinglong Mee 	encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
2610d017931cSAndy Adamson 	encode_nops(&hdr);
26111da177e4SLinus Torvalds }
26121da177e4SLinus Torvalds 
26131da177e4SLinus Torvalds /*
26141da177e4SLinus Torvalds  * a RENEW request
26151da177e4SLinus Torvalds  */
26169f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
26179f06c719SChuck Lever 			       struct nfs_client *clp)
26181da177e4SLinus Torvalds {
26191da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2620d017931cSAndy Adamson 		.nops	= 0,
26211da177e4SLinus Torvalds 	};
26221da177e4SLinus Torvalds 
26239f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
2624bb4dae5eSChuck Lever 	encode_renew(xdr, clp->cl_clientid, &hdr);
2625d017931cSAndy Adamson 	encode_nops(&hdr);
26261da177e4SLinus Torvalds }
26271da177e4SLinus Torvalds 
26281da177e4SLinus Torvalds /*
26291da177e4SLinus Torvalds  * a SETCLIENTID request
26301da177e4SLinus Torvalds  */
26319f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
26329f06c719SChuck Lever 				     struct xdr_stream *xdr,
26339f06c719SChuck Lever 				     struct nfs4_setclientid *sc)
26341da177e4SLinus Torvalds {
26351da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2636d017931cSAndy Adamson 		.nops	= 0,
26371da177e4SLinus Torvalds 	};
26381da177e4SLinus Torvalds 
26399f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26409f06c719SChuck Lever 	encode_setclientid(xdr, sc, &hdr);
2641d017931cSAndy Adamson 	encode_nops(&hdr);
26421da177e4SLinus Torvalds }
26431da177e4SLinus Torvalds 
26441da177e4SLinus Torvalds /*
26451da177e4SLinus Torvalds  * a SETCLIENTID_CONFIRM request
26461da177e4SLinus Torvalds  */
26479f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
26489f06c719SChuck Lever 					     struct xdr_stream *xdr,
26499f06c719SChuck Lever 					     struct nfs4_setclientid_res *arg)
26501da177e4SLinus Torvalds {
26511da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2652d017931cSAndy Adamson 		.nops	= 0,
26531da177e4SLinus Torvalds 	};
26541da177e4SLinus Torvalds 
26559f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26569f06c719SChuck Lever 	encode_setclientid_confirm(xdr, arg, &hdr);
2657d017931cSAndy Adamson 	encode_nops(&hdr);
26581da177e4SLinus Torvalds }
26591da177e4SLinus Torvalds 
26601da177e4SLinus Torvalds /*
26611da177e4SLinus Torvalds  * DELEGRETURN request
26621da177e4SLinus Torvalds  */
26639f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
26649f06c719SChuck Lever 				     struct xdr_stream *xdr,
26659f06c719SChuck Lever 				     const struct nfs4_delegreturnargs *args)
26661da177e4SLinus Torvalds {
26671da177e4SLinus Torvalds 	struct compound_hdr hdr = {
266866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26691da177e4SLinus Torvalds 	};
26701da177e4SLinus Torvalds 
26719f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26729f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26739f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
26749f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2675e144cbccSTrond Myklebust 	encode_delegreturn(xdr, args->stateid, &hdr);
2676d017931cSAndy Adamson 	encode_nops(&hdr);
26771da177e4SLinus Torvalds }
26781da177e4SLinus Torvalds 
26791da177e4SLinus Torvalds /*
2680683b57b4STrond Myklebust  * Encode FS_LOCATIONS request
2681683b57b4STrond Myklebust  */
26829f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
26839f06c719SChuck Lever 				      struct xdr_stream *xdr,
26849f06c719SChuck Lever 				      struct nfs4_fs_locations_arg *args)
2685683b57b4STrond Myklebust {
2686683b57b4STrond Myklebust 	struct compound_hdr hdr = {
268766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2688683b57b4STrond Myklebust 	};
268928f56694SBenny Halevy 	uint32_t replen;
2690683b57b4STrond Myklebust 
26919f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26929f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
2693b03d735bSChuck Lever 	if (args->migration) {
2694b03d735bSChuck Lever 		encode_putfh(xdr, args->fh, &hdr);
2695b03d735bSChuck Lever 		replen = hdr.replen;
2696b03d735bSChuck Lever 		encode_fs_locations(xdr, args->bitmask, &hdr);
2697b03d735bSChuck Lever 		if (args->renew)
2698b03d735bSChuck Lever 			encode_renew(xdr, args->clientid, &hdr);
2699b03d735bSChuck Lever 	} else {
27009f06c719SChuck Lever 		encode_putfh(xdr, args->dir_fh, &hdr);
27019f06c719SChuck Lever 		encode_lookup(xdr, args->name, &hdr);
2702b03d735bSChuck Lever 		replen = hdr.replen;
27039f06c719SChuck Lever 		encode_fs_locations(xdr, args->bitmask, &hdr);
2704b03d735bSChuck Lever 	}
2705cf8cdbe5SAndy Adamson 
2706b03d735bSChuck Lever 	/* Set up reply kvec to capture returned fs_locations array. */
270728f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2708683b57b4STrond Myklebust 			0, PAGE_SIZE);
2709d017931cSAndy Adamson 	encode_nops(&hdr);
2710683b57b4STrond Myklebust }
2711683b57b4STrond Myklebust 
27125a5ea0d4SBryan Schumaker /*
27135a5ea0d4SBryan Schumaker  * Encode SECINFO request
27145a5ea0d4SBryan Schumaker  */
27155a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
27165a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
27175a5ea0d4SBryan Schumaker 				struct nfs4_secinfo_arg *args)
27185a5ea0d4SBryan Schumaker {
27195a5ea0d4SBryan Schumaker 	struct compound_hdr hdr = {
27205a5ea0d4SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
27215a5ea0d4SBryan Schumaker 	};
27225a5ea0d4SBryan Schumaker 
27235a5ea0d4SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
27245a5ea0d4SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
27255a5ea0d4SBryan Schumaker 	encode_putfh(xdr, args->dir_fh, &hdr);
27265a5ea0d4SBryan Schumaker 	encode_secinfo(xdr, args->name, &hdr);
27275a5ea0d4SBryan Schumaker 	encode_nops(&hdr);
27285a5ea0d4SBryan Schumaker }
27295a5ea0d4SBryan Schumaker 
273044c99933SChuck Lever /*
273144c99933SChuck Lever  * Encode FSID_PRESENT request
273244c99933SChuck Lever  */
273344c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
273444c99933SChuck Lever 				      struct xdr_stream *xdr,
273544c99933SChuck Lever 				      struct nfs4_fsid_present_arg *args)
273644c99933SChuck Lever {
273744c99933SChuck Lever 	struct compound_hdr hdr = {
273844c99933SChuck Lever 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
273944c99933SChuck Lever 	};
274044c99933SChuck Lever 
274144c99933SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
274244c99933SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
274344c99933SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
274444c99933SChuck Lever 	encode_getfh(xdr, &hdr);
274544c99933SChuck Lever 	if (args->renew)
274644c99933SChuck Lever 		encode_renew(xdr, args->clientid, &hdr);
274744c99933SChuck Lever 	encode_nops(&hdr);
274844c99933SChuck Lever }
274944c99933SChuck Lever 
275099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
275199fe60d0SBenny Halevy /*
27527c44f1aeSWeston Andros Adamson  * BIND_CONN_TO_SESSION request
27537c44f1aeSWeston Andros Adamson  */
27547c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
27557c44f1aeSWeston Andros Adamson 				struct xdr_stream *xdr,
275671a097c6STrond Myklebust 				struct nfs41_bind_conn_to_session_args *args)
27577c44f1aeSWeston Andros Adamson {
27587c44f1aeSWeston Andros Adamson 	struct compound_hdr hdr = {
275971a097c6STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
27607c44f1aeSWeston Andros Adamson 	};
27617c44f1aeSWeston Andros Adamson 
27627c44f1aeSWeston Andros Adamson 	encode_compound_hdr(xdr, req, &hdr);
276371a097c6STrond Myklebust 	encode_bind_conn_to_session(xdr, args, &hdr);
27647c44f1aeSWeston Andros Adamson 	encode_nops(&hdr);
27657c44f1aeSWeston Andros Adamson }
27667c44f1aeSWeston Andros Adamson 
27677c44f1aeSWeston Andros Adamson /*
276899fe60d0SBenny Halevy  * EXCHANGE_ID request
276999fe60d0SBenny Halevy  */
27709f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
27719f06c719SChuck Lever 				     struct xdr_stream *xdr,
277299fe60d0SBenny Halevy 				     struct nfs41_exchange_id_args *args)
277399fe60d0SBenny Halevy {
277499fe60d0SBenny Halevy 	struct compound_hdr hdr = {
2775a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
277699fe60d0SBenny Halevy 	};
277799fe60d0SBenny Halevy 
27789f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27799f06c719SChuck Lever 	encode_exchange_id(xdr, args, &hdr);
278099fe60d0SBenny Halevy 	encode_nops(&hdr);
278199fe60d0SBenny Halevy }
27822050f0ccSAndy Adamson 
27832050f0ccSAndy Adamson /*
2784fc931582SAndy Adamson  * a CREATE_SESSION request
2785fc931582SAndy Adamson  */
27869f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
27879f06c719SChuck Lever 					struct xdr_stream *xdr,
2788fc931582SAndy Adamson 					struct nfs41_create_session_args *args)
2789fc931582SAndy Adamson {
2790fc931582SAndy Adamson 	struct compound_hdr hdr = {
2791a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
2792fc931582SAndy Adamson 	};
2793fc931582SAndy Adamson 
27949f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27959f06c719SChuck Lever 	encode_create_session(xdr, args, &hdr);
2796fc931582SAndy Adamson 	encode_nops(&hdr);
2797fc931582SAndy Adamson }
2798fc931582SAndy Adamson 
2799fc931582SAndy Adamson /*
28000f3e66c6SAndy Adamson  * a DESTROY_SESSION request
28010f3e66c6SAndy Adamson  */
28029f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
28039f06c719SChuck Lever 					 struct xdr_stream *xdr,
28040f3e66c6SAndy Adamson 					 struct nfs4_session *session)
28050f3e66c6SAndy Adamson {
28060f3e66c6SAndy Adamson 	struct compound_hdr hdr = {
2807a4432345STrond Myklebust 		.minorversion = session->clp->cl_mvops->minor_version,
28080f3e66c6SAndy Adamson 	};
28090f3e66c6SAndy Adamson 
28109f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28119f06c719SChuck Lever 	encode_destroy_session(xdr, session, &hdr);
28120f3e66c6SAndy Adamson 	encode_nops(&hdr);
28130f3e66c6SAndy Adamson }
28140f3e66c6SAndy Adamson 
28150f3e66c6SAndy Adamson /*
281666245539STrond Myklebust  * a DESTROY_CLIENTID request
281766245539STrond Myklebust  */
281866245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
281966245539STrond Myklebust 					 struct xdr_stream *xdr,
282066245539STrond Myklebust 					 struct nfs_client *clp)
282166245539STrond Myklebust {
282266245539STrond Myklebust 	struct compound_hdr hdr = {
282366245539STrond Myklebust 		.minorversion = clp->cl_mvops->minor_version,
282466245539STrond Myklebust 	};
282566245539STrond Myklebust 
282666245539STrond Myklebust 	encode_compound_hdr(xdr, req, &hdr);
282766245539STrond Myklebust 	encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
282866245539STrond Myklebust 	encode_nops(&hdr);
282966245539STrond Myklebust }
283066245539STrond Myklebust 
283166245539STrond Myklebust /*
2832fc01cea9SAndy Adamson  * a SEQUENCE request
2833fc01cea9SAndy Adamson  */
28349f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2835fc01cea9SAndy Adamson 				  struct nfs4_sequence_args *args)
2836fc01cea9SAndy Adamson {
2837fc01cea9SAndy Adamson 	struct compound_hdr hdr = {
2838fc01cea9SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(args),
2839fc01cea9SAndy Adamson 	};
2840fc01cea9SAndy Adamson 
28419f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28429f06c719SChuck Lever 	encode_sequence(xdr, args, &hdr);
2843fc01cea9SAndy Adamson 	encode_nops(&hdr);
2844fc01cea9SAndy Adamson }
2845fc01cea9SAndy Adamson 
2846fc01cea9SAndy Adamson /*
28472050f0ccSAndy Adamson  * a GET_LEASE_TIME request
28482050f0ccSAndy Adamson  */
28499f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
28509f06c719SChuck Lever 					struct xdr_stream *xdr,
28512050f0ccSAndy Adamson 					struct nfs4_get_lease_time_args *args)
28522050f0ccSAndy Adamson {
28532050f0ccSAndy Adamson 	struct compound_hdr hdr = {
28542050f0ccSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
28552050f0ccSAndy Adamson 	};
2856dae100c2SFred Isaman 	const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
28572050f0ccSAndy Adamson 
28589f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28599f06c719SChuck Lever 	encode_sequence(xdr, &args->la_seq_args, &hdr);
28609f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
28619f06c719SChuck Lever 	encode_fsinfo(xdr, lease_bitmap, &hdr);
28622050f0ccSAndy Adamson 	encode_nops(&hdr);
28632050f0ccSAndy Adamson }
286418019753SRicardo Labiaga 
286518019753SRicardo Labiaga /*
286618019753SRicardo Labiaga  * a RECLAIM_COMPLETE request
286718019753SRicardo Labiaga  */
28689f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
28699f06c719SChuck Lever 					  struct xdr_stream *xdr,
287018019753SRicardo Labiaga 				struct nfs41_reclaim_complete_args *args)
287118019753SRicardo Labiaga {
287218019753SRicardo Labiaga 	struct compound_hdr hdr = {
287318019753SRicardo Labiaga 		.minorversion = nfs4_xdr_minorversion(&args->seq_args)
287418019753SRicardo Labiaga 	};
287518019753SRicardo Labiaga 
28769f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28779f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
28789f06c719SChuck Lever 	encode_reclaim_complete(xdr, args, &hdr);
287918019753SRicardo Labiaga 	encode_nops(&hdr);
288018019753SRicardo Labiaga }
288118019753SRicardo Labiaga 
2882b1f69b75SAndy Adamson /*
2883b1f69b75SAndy Adamson  * Encode GETDEVICEINFO request
2884b1f69b75SAndy Adamson  */
28859f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
28869f06c719SChuck Lever 				       struct xdr_stream *xdr,
2887b1f69b75SAndy Adamson 				       struct nfs4_getdeviceinfo_args *args)
2888b1f69b75SAndy Adamson {
2889b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
2890b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2891b1f69b75SAndy Adamson 	};
2892b1f69b75SAndy Adamson 
28939f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28949f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
28959f06c719SChuck Lever 	encode_getdeviceinfo(xdr, args, &hdr);
2896b1f69b75SAndy Adamson 
2897b1f69b75SAndy Adamson 	/* set up reply kvec. Subtract notification bitmap max size (2)
2898b1f69b75SAndy Adamson 	 * so that notification bitmap is put in xdr_buf tail */
2899b1f69b75SAndy Adamson 	xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2900b1f69b75SAndy Adamson 			 args->pdev->pages, args->pdev->pgbase,
2901b1f69b75SAndy Adamson 			 args->pdev->pglen);
2902b1f69b75SAndy Adamson 
2903b1f69b75SAndy Adamson 	encode_nops(&hdr);
2904b1f69b75SAndy Adamson }
2905b1f69b75SAndy Adamson 
2906b1f69b75SAndy Adamson /*
2907b1f69b75SAndy Adamson  *  Encode LAYOUTGET request
2908b1f69b75SAndy Adamson  */
29099f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
29109f06c719SChuck Lever 				   struct xdr_stream *xdr,
2911b1f69b75SAndy Adamson 				   struct nfs4_layoutget_args *args)
2912b1f69b75SAndy Adamson {
2913b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
2914b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2915b1f69b75SAndy Adamson 	};
2916b1f69b75SAndy Adamson 
29179f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29189f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
29199f06c719SChuck Lever 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
29209f06c719SChuck Lever 	encode_layoutget(xdr, args, &hdr);
292135124a09SWeston Andros Adamson 
292235124a09SWeston Andros Adamson 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
292335124a09SWeston Andros Adamson 	    args->layout.pages, 0, args->layout.pglen);
292435124a09SWeston Andros Adamson 
2925b1f69b75SAndy Adamson 	encode_nops(&hdr);
2926b1f69b75SAndy Adamson }
2927863a3c6cSAndy Adamson 
2928863a3c6cSAndy Adamson /*
2929863a3c6cSAndy Adamson  *  Encode LAYOUTCOMMIT request
2930863a3c6cSAndy Adamson  */
2931cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2932863a3c6cSAndy Adamson 				      struct xdr_stream *xdr,
2933863a3c6cSAndy Adamson 				      struct nfs4_layoutcommit_args *args)
2934863a3c6cSAndy Adamson {
2935ac7db726SBenny Halevy 	struct nfs4_layoutcommit_data *data =
2936ac7db726SBenny Halevy 		container_of(args, struct nfs4_layoutcommit_data, args);
2937863a3c6cSAndy Adamson 	struct compound_hdr hdr = {
2938863a3c6cSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2939863a3c6cSAndy Adamson 	};
2940863a3c6cSAndy Adamson 
2941863a3c6cSAndy Adamson 	encode_compound_hdr(xdr, req, &hdr);
2942863a3c6cSAndy Adamson 	encode_sequence(xdr, &args->seq_args, &hdr);
2943863a3c6cSAndy Adamson 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2944ac7db726SBenny Halevy 	encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2945863a3c6cSAndy Adamson 	encode_getfattr(xdr, args->bitmask, &hdr);
2946863a3c6cSAndy Adamson 	encode_nops(&hdr);
2947cbe82603SBenny Halevy }
2948cbe82603SBenny Halevy 
2949cbe82603SBenny Halevy /*
2950cbe82603SBenny Halevy  * Encode LAYOUTRETURN request
2951cbe82603SBenny Halevy  */
2952cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2953cbe82603SBenny Halevy 				      struct xdr_stream *xdr,
2954cbe82603SBenny Halevy 				      struct nfs4_layoutreturn_args *args)
2955cbe82603SBenny Halevy {
2956cbe82603SBenny Halevy 	struct compound_hdr hdr = {
2957cbe82603SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2958cbe82603SBenny Halevy 	};
2959cbe82603SBenny Halevy 
2960cbe82603SBenny Halevy 	encode_compound_hdr(xdr, req, &hdr);
2961cbe82603SBenny Halevy 	encode_sequence(xdr, &args->seq_args, &hdr);
2962cbe82603SBenny Halevy 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2963cbe82603SBenny Halevy 	encode_layoutreturn(xdr, args, &hdr);
2964cbe82603SBenny Halevy 	encode_nops(&hdr);
2965863a3c6cSAndy Adamson }
2966fca78d6dSBryan Schumaker 
2967fca78d6dSBryan Schumaker /*
2968fca78d6dSBryan Schumaker  * Encode SECINFO_NO_NAME request
2969fca78d6dSBryan Schumaker  */
2970fca78d6dSBryan Schumaker static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2971fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
2972fca78d6dSBryan Schumaker 					struct nfs41_secinfo_no_name_args *args)
2973fca78d6dSBryan Schumaker {
2974fca78d6dSBryan Schumaker 	struct compound_hdr hdr = {
2975fca78d6dSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2976fca78d6dSBryan Schumaker 	};
2977fca78d6dSBryan Schumaker 
2978fca78d6dSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
2979fca78d6dSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
2980fca78d6dSBryan Schumaker 	encode_putrootfh(xdr, &hdr);
2981fca78d6dSBryan Schumaker 	encode_secinfo_no_name(xdr, args, &hdr);
2982fca78d6dSBryan Schumaker 	encode_nops(&hdr);
2983fca78d6dSBryan Schumaker 	return 0;
2984fca78d6dSBryan Schumaker }
29857d974794SBryan Schumaker 
29867d974794SBryan Schumaker /*
29877d974794SBryan Schumaker  *  Encode TEST_STATEID request
29887d974794SBryan Schumaker  */
29897d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
29907d974794SBryan Schumaker 				      struct xdr_stream *xdr,
29917d974794SBryan Schumaker 				      struct nfs41_test_stateid_args *args)
29927d974794SBryan Schumaker {
29937d974794SBryan Schumaker 	struct compound_hdr hdr = {
29947d974794SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
29957d974794SBryan Schumaker 	};
29967d974794SBryan Schumaker 
29977d974794SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
29987d974794SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
29997d974794SBryan Schumaker 	encode_test_stateid(xdr, args, &hdr);
30007d974794SBryan Schumaker 	encode_nops(&hdr);
30017d974794SBryan Schumaker }
30029aeda35fSBryan Schumaker 
30039aeda35fSBryan Schumaker /*
30049aeda35fSBryan Schumaker  *  Encode FREE_STATEID request
30059aeda35fSBryan Schumaker  */
30069aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
30079aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
30089aeda35fSBryan Schumaker 				     struct nfs41_free_stateid_args *args)
30099aeda35fSBryan Schumaker {
30109aeda35fSBryan Schumaker 	struct compound_hdr hdr = {
30119aeda35fSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
30129aeda35fSBryan Schumaker 	};
30139aeda35fSBryan Schumaker 
30149aeda35fSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
30159aeda35fSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
30169aeda35fSBryan Schumaker 	encode_free_stateid(xdr, args, &hdr);
30179aeda35fSBryan Schumaker 	encode_nops(&hdr);
30189aeda35fSBryan Schumaker }
301999fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
302099fe60d0SBenny Halevy 
3021686841b3SBenny Halevy static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3022686841b3SBenny Halevy {
3023686841b3SBenny Halevy 	dprintk("nfs: %s: prematurely hit end of receive buffer. "
3024686841b3SBenny Halevy 		"Remaining buffer length is %tu words.\n",
3025686841b3SBenny Halevy 		func, xdr->end - xdr->p);
3026686841b3SBenny Halevy }
30271da177e4SLinus Torvalds 
3028683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
30291da177e4SLinus Torvalds {
30308687b63aSAl Viro 	__be32 *p;
30311da177e4SLinus Torvalds 
3032c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3033c0eae66eSBenny Halevy 	if (unlikely(!p))
3034c0eae66eSBenny Halevy 		goto out_overflow;
3035cccddf4fSBenny Halevy 	*len = be32_to_cpup(p);
3036c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, *len);
3037c0eae66eSBenny Halevy 	if (unlikely(!p))
3038c0eae66eSBenny Halevy 		goto out_overflow;
30391da177e4SLinus Torvalds 	*string = (char *)p;
30401da177e4SLinus Torvalds 	return 0;
3041c0eae66eSBenny Halevy out_overflow:
3042c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3043c0eae66eSBenny Halevy 	return -EIO;
30441da177e4SLinus Torvalds }
30451da177e4SLinus Torvalds 
30461da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
30471da177e4SLinus Torvalds {
30488687b63aSAl Viro 	__be32 *p;
30491da177e4SLinus Torvalds 
3050c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3051c0eae66eSBenny Halevy 	if (unlikely(!p))
3052c0eae66eSBenny Halevy 		goto out_overflow;
30536f723f77SBenny Halevy 	hdr->status = be32_to_cpup(p++);
3054cccddf4fSBenny Halevy 	hdr->taglen = be32_to_cpup(p);
30551da177e4SLinus Torvalds 
3056c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, hdr->taglen + 4);
3057c0eae66eSBenny Halevy 	if (unlikely(!p))
3058c0eae66eSBenny Halevy 		goto out_overflow;
30591da177e4SLinus Torvalds 	hdr->tag = (char *)p;
30601da177e4SLinus Torvalds 	p += XDR_QUADLEN(hdr->taglen);
3061cccddf4fSBenny Halevy 	hdr->nops = be32_to_cpup(p);
3062aadf6152SBenny Halevy 	if (unlikely(hdr->nops < 1))
3063aadf6152SBenny Halevy 		return nfs4_stat_to_errno(hdr->status);
30641da177e4SLinus Torvalds 	return 0;
3065c0eae66eSBenny Halevy out_overflow:
3066c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3067c0eae66eSBenny Halevy 	return -EIO;
30681da177e4SLinus Torvalds }
30691da177e4SLinus Torvalds 
3070c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3071c7848f69STrond Myklebust 		int *nfs_retval)
30721da177e4SLinus Torvalds {
30738687b63aSAl Viro 	__be32 *p;
30741da177e4SLinus Torvalds 	uint32_t opnum;
30751da177e4SLinus Torvalds 	int32_t nfserr;
30761da177e4SLinus Torvalds 
3077c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3078c0eae66eSBenny Halevy 	if (unlikely(!p))
3079c0eae66eSBenny Halevy 		goto out_overflow;
30806f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
3081c7848f69STrond Myklebust 	if (unlikely(opnum != expected))
3082c7848f69STrond Myklebust 		goto out_bad_operation;
3083c7848f69STrond Myklebust 	nfserr = be32_to_cpup(p);
3084c7848f69STrond Myklebust 	if (nfserr == NFS_OK)
3085c7848f69STrond Myklebust 		*nfs_retval = 0;
3086c7848f69STrond Myklebust 	else
3087c7848f69STrond Myklebust 		*nfs_retval = nfs4_stat_to_errno(nfserr);
3088c7848f69STrond Myklebust 	return true;
3089c7848f69STrond Myklebust out_bad_operation:
3090fe82a183SChuck Lever 	dprintk("nfs: Server returned operation"
30911da177e4SLinus Torvalds 		" %d but we issued a request for %d\n",
30921da177e4SLinus Torvalds 			opnum, expected);
3093c7848f69STrond Myklebust 	*nfs_retval = -EREMOTEIO;
3094c7848f69STrond Myklebust 	return false;
3095c0eae66eSBenny Halevy out_overflow:
3096c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3097c7848f69STrond Myklebust 	*nfs_retval = -EIO;
3098c7848f69STrond Myklebust 	return false;
3099c7848f69STrond Myklebust }
3100c7848f69STrond Myklebust 
3101c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3102c7848f69STrond Myklebust {
3103c7848f69STrond Myklebust 	int retval;
3104c7848f69STrond Myklebust 
3105c7848f69STrond Myklebust 	__decode_op_hdr(xdr, expected, &retval);
3106c7848f69STrond Myklebust 	return retval;
31071da177e4SLinus Torvalds }
31081da177e4SLinus Torvalds 
31091da177e4SLinus Torvalds /* Dummy routine */
3110adfa6f98SDavid Howells static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
31111da177e4SLinus Torvalds {
31128687b63aSAl Viro 	__be32 *p;
3113683b57b4STrond Myklebust 	unsigned int strlen;
31141da177e4SLinus Torvalds 	char *str;
31151da177e4SLinus Torvalds 
3116c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
3117c0eae66eSBenny Halevy 	if (likely(p))
31181da177e4SLinus Torvalds 		return decode_opaque_inline(xdr, &strlen, &str);
3119c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3120c0eae66eSBenny Halevy 	return -EIO;
31211da177e4SLinus Torvalds }
31221da177e4SLinus Torvalds 
31231da177e4SLinus Torvalds static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
31241da177e4SLinus Torvalds {
31258687b63aSAl Viro 	uint32_t bmlen;
31268687b63aSAl Viro 	__be32 *p;
31271da177e4SLinus Torvalds 
3128c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3129c0eae66eSBenny Halevy 	if (unlikely(!p))
3130c0eae66eSBenny Halevy 		goto out_overflow;
3131cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
31321da177e4SLinus Torvalds 
3133dae100c2SFred Isaman 	bitmap[0] = bitmap[1] = bitmap[2] = 0;
3134c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, (bmlen << 2));
3135c0eae66eSBenny Halevy 	if (unlikely(!p))
3136c0eae66eSBenny Halevy 		goto out_overflow;
31371da177e4SLinus Torvalds 	if (bmlen > 0) {
31386f723f77SBenny Halevy 		bitmap[0] = be32_to_cpup(p++);
3139dae100c2SFred Isaman 		if (bmlen > 1) {
3140dae100c2SFred Isaman 			bitmap[1] = be32_to_cpup(p++);
3141dae100c2SFred Isaman 			if (bmlen > 2)
3142dae100c2SFred Isaman 				bitmap[2] = be32_to_cpup(p);
3143dae100c2SFred Isaman 		}
31441da177e4SLinus Torvalds 	}
31451da177e4SLinus Torvalds 	return 0;
3146c0eae66eSBenny Halevy out_overflow:
3147c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3148c0eae66eSBenny Halevy 	return -EIO;
31491da177e4SLinus Torvalds }
31501da177e4SLinus Torvalds 
3151256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
31521da177e4SLinus Torvalds {
31538687b63aSAl Viro 	__be32 *p;
31541da177e4SLinus Torvalds 
3155c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3156c0eae66eSBenny Halevy 	if (unlikely(!p))
3157c0eae66eSBenny Halevy 		goto out_overflow;
3158cccddf4fSBenny Halevy 	*attrlen = be32_to_cpup(p);
3159256e48bbSTrond Myklebust 	*savep = xdr_stream_pos(xdr);
31601da177e4SLinus Torvalds 	return 0;
3161c0eae66eSBenny Halevy out_overflow:
3162c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3163c0eae66eSBenny Halevy 	return -EIO;
31641da177e4SLinus Torvalds }
31651da177e4SLinus Torvalds 
31661da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
31671da177e4SLinus Torvalds {
31681da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
31693388bff5SRoman Borisov 		int ret;
31703388bff5SRoman Borisov 		ret = decode_attr_bitmap(xdr, bitmask);
31713388bff5SRoman Borisov 		if (unlikely(ret < 0))
31723388bff5SRoman Borisov 			return ret;
31731da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
31741da177e4SLinus Torvalds 	} else
3175dae100c2SFred Isaman 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
3176dae100c2SFred Isaman 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3177dae100c2SFred Isaman 		bitmask[0], bitmask[1], bitmask[2]);
31781da177e4SLinus Torvalds 	return 0;
31791da177e4SLinus Torvalds }
31801da177e4SLinus Torvalds 
31811da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
31821da177e4SLinus Torvalds {
31838687b63aSAl Viro 	__be32 *p;
3184409924e4STrond Myklebust 	int ret = 0;
31851da177e4SLinus Torvalds 
31861da177e4SLinus Torvalds 	*type = 0;
31871da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
31881da177e4SLinus Torvalds 		return -EIO;
31891da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3190c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3191c0eae66eSBenny Halevy 		if (unlikely(!p))
3192c0eae66eSBenny Halevy 			goto out_overflow;
3193cccddf4fSBenny Halevy 		*type = be32_to_cpup(p);
31941da177e4SLinus Torvalds 		if (*type < NF4REG || *type > NF4NAMEDATTR) {
31953110ff80SHarvey Harrison 			dprintk("%s: bad type %d\n", __func__, *type);
31961da177e4SLinus Torvalds 			return -EIO;
31971da177e4SLinus Torvalds 		}
31981da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_TYPE;
3199409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_TYPE;
32001da177e4SLinus Torvalds 	}
3201bca79478STrond Myklebust 	dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3202409924e4STrond Myklebust 	return ret;
3203c0eae66eSBenny Halevy out_overflow:
3204c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3205c0eae66eSBenny Halevy 	return -EIO;
32061da177e4SLinus Torvalds }
32071da177e4SLinus Torvalds 
3208264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3209264e6351SChuck Lever 				      uint32_t *bitmap, uint32_t *type)
3210264e6351SChuck Lever {
3211264e6351SChuck Lever 	__be32 *p;
3212264e6351SChuck Lever 
3213264e6351SChuck Lever 	*type = 0;
3214264e6351SChuck Lever 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3215264e6351SChuck Lever 		return -EIO;
3216264e6351SChuck Lever 	if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3217264e6351SChuck Lever 		p = xdr_inline_decode(xdr, 4);
3218264e6351SChuck Lever 		if (unlikely(!p))
3219264e6351SChuck Lever 			goto out_overflow;
3220264e6351SChuck Lever 		*type = be32_to_cpup(p);
3221264e6351SChuck Lever 		bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3222264e6351SChuck Lever 	}
3223264e6351SChuck Lever 	dprintk("%s: expire type=0x%x\n", __func__, *type);
3224264e6351SChuck Lever 	return 0;
3225264e6351SChuck Lever out_overflow:
3226264e6351SChuck Lever 	print_overflow_msg(__func__, xdr);
3227264e6351SChuck Lever 	return -EIO;
3228264e6351SChuck Lever }
3229264e6351SChuck Lever 
32301da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
32311da177e4SLinus Torvalds {
32328687b63aSAl Viro 	__be32 *p;
3233409924e4STrond Myklebust 	int ret = 0;
32341da177e4SLinus Torvalds 
32351da177e4SLinus Torvalds 	*change = 0;
32361da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
32371da177e4SLinus Torvalds 		return -EIO;
32381da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3239c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3240c0eae66eSBenny Halevy 		if (unlikely(!p))
3241c0eae66eSBenny Halevy 			goto out_overflow;
3242cccddf4fSBenny Halevy 		xdr_decode_hyper(p, change);
32431da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3244409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_CHANGE;
32451da177e4SLinus Torvalds 	}
32463110ff80SHarvey Harrison 	dprintk("%s: change attribute=%Lu\n", __func__,
32471da177e4SLinus Torvalds 			(unsigned long long)*change);
3248409924e4STrond Myklebust 	return ret;
3249c0eae66eSBenny Halevy out_overflow:
3250c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3251c0eae66eSBenny Halevy 	return -EIO;
32521da177e4SLinus Torvalds }
32531da177e4SLinus Torvalds 
32541da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
32551da177e4SLinus Torvalds {
32568687b63aSAl Viro 	__be32 *p;
3257409924e4STrond Myklebust 	int ret = 0;
32581da177e4SLinus Torvalds 
32591da177e4SLinus Torvalds 	*size = 0;
32601da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
32611da177e4SLinus Torvalds 		return -EIO;
32621da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3263c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3264c0eae66eSBenny Halevy 		if (unlikely(!p))
3265c0eae66eSBenny Halevy 			goto out_overflow;
3266cccddf4fSBenny Halevy 		xdr_decode_hyper(p, size);
32671da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SIZE;
3268409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SIZE;
32691da177e4SLinus Torvalds 	}
32703110ff80SHarvey Harrison 	dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3271409924e4STrond Myklebust 	return ret;
3272c0eae66eSBenny Halevy out_overflow:
3273c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3274c0eae66eSBenny Halevy 	return -EIO;
32751da177e4SLinus Torvalds }
32761da177e4SLinus Torvalds 
32771da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
32781da177e4SLinus Torvalds {
32798687b63aSAl Viro 	__be32 *p;
32801da177e4SLinus Torvalds 
32811da177e4SLinus Torvalds 	*res = 0;
32821da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
32831da177e4SLinus Torvalds 		return -EIO;
32841da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3285c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3286c0eae66eSBenny Halevy 		if (unlikely(!p))
3287c0eae66eSBenny Halevy 			goto out_overflow;
3288cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
32891da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
32901da177e4SLinus Torvalds 	}
32913110ff80SHarvey Harrison 	dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
32921da177e4SLinus Torvalds 	return 0;
3293c0eae66eSBenny Halevy out_overflow:
3294c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3295c0eae66eSBenny Halevy 	return -EIO;
32961da177e4SLinus Torvalds }
32971da177e4SLinus Torvalds 
32981da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
32991da177e4SLinus Torvalds {
33008687b63aSAl Viro 	__be32 *p;
33011da177e4SLinus Torvalds 
33021da177e4SLinus Torvalds 	*res = 0;
33031da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
33041da177e4SLinus Torvalds 		return -EIO;
33051da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3306c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3307c0eae66eSBenny Halevy 		if (unlikely(!p))
3308c0eae66eSBenny Halevy 			goto out_overflow;
3309cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33101da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
33111da177e4SLinus Torvalds 	}
33123110ff80SHarvey Harrison 	dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
33131da177e4SLinus Torvalds 	return 0;
3314c0eae66eSBenny Halevy out_overflow:
3315c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3316c0eae66eSBenny Halevy 	return -EIO;
33171da177e4SLinus Torvalds }
33181da177e4SLinus Torvalds 
33198b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
33201da177e4SLinus Torvalds {
33218687b63aSAl Viro 	__be32 *p;
3322409924e4STrond Myklebust 	int ret = 0;
33231da177e4SLinus Torvalds 
33241da177e4SLinus Torvalds 	fsid->major = 0;
33251da177e4SLinus Torvalds 	fsid->minor = 0;
33261da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
33271da177e4SLinus Torvalds 		return -EIO;
33281da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3329c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 16);
3330c0eae66eSBenny Halevy 		if (unlikely(!p))
3331c0eae66eSBenny Halevy 			goto out_overflow;
33323ceb4dbbSBenny Halevy 		p = xdr_decode_hyper(p, &fsid->major);
3333cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &fsid->minor);
33341da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FSID;
3335409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FSID;
33361da177e4SLinus Torvalds 	}
33373110ff80SHarvey Harrison 	dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
33381da177e4SLinus Torvalds 			(unsigned long long)fsid->major,
33391da177e4SLinus Torvalds 			(unsigned long long)fsid->minor);
3340409924e4STrond Myklebust 	return ret;
3341c0eae66eSBenny Halevy out_overflow:
3342c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3343c0eae66eSBenny Halevy 	return -EIO;
33441da177e4SLinus Torvalds }
33451da177e4SLinus Torvalds 
33461da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33471da177e4SLinus Torvalds {
33488687b63aSAl Viro 	__be32 *p;
33491da177e4SLinus Torvalds 
33501da177e4SLinus Torvalds 	*res = 60;
33511da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
33521da177e4SLinus Torvalds 		return -EIO;
33531da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3354c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3355c0eae66eSBenny Halevy 		if (unlikely(!p))
3356c0eae66eSBenny Halevy 			goto out_overflow;
3357cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33581da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
33591da177e4SLinus Torvalds 	}
33603110ff80SHarvey Harrison 	dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
33611da177e4SLinus Torvalds 	return 0;
3362c0eae66eSBenny Halevy out_overflow:
3363c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3364c0eae66eSBenny Halevy 	return -EIO;
33651da177e4SLinus Torvalds }
33661da177e4SLinus Torvalds 
3367ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3368ae42c70aSBryan Schumaker {
3369ae42c70aSBryan Schumaker 	__be32 *p;
3370ae42c70aSBryan Schumaker 
3371ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3372ae42c70aSBryan Schumaker 		return -EIO;
3373ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3374ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3375ae42c70aSBryan Schumaker 		if (unlikely(!p))
3376ae42c70aSBryan Schumaker 			goto out_overflow;
3377ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3378ee7b75fcSTrond Myklebust 		*res = -be32_to_cpup(p);
3379ae42c70aSBryan Schumaker 	}
3380ae42c70aSBryan Schumaker 	return 0;
3381ae42c70aSBryan Schumaker out_overflow:
3382ae42c70aSBryan Schumaker 	print_overflow_msg(__func__, xdr);
3383ae42c70aSBryan Schumaker 	return -EIO;
3384ae42c70aSBryan Schumaker }
3385ae42c70aSBryan Schumaker 
33868c61282fSKinglong Mee static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
33878c61282fSKinglong Mee 				 uint32_t *bitmap, uint32_t *bitmask)
33888c61282fSKinglong Mee {
33898c61282fSKinglong Mee 	if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
33908c61282fSKinglong Mee 		int ret;
33918c61282fSKinglong Mee 		ret = decode_attr_bitmap(xdr, bitmask);
33928c61282fSKinglong Mee 		if (unlikely(ret < 0))
33938c61282fSKinglong Mee 			return ret;
33948c61282fSKinglong Mee 		bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
33958c61282fSKinglong Mee 	} else
33968c61282fSKinglong Mee 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
33978c61282fSKinglong Mee 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
33988c61282fSKinglong Mee 		bitmask[0], bitmask[1], bitmask[2]);
33998c61282fSKinglong Mee 	return 0;
34008c61282fSKinglong Mee }
34018c61282fSKinglong Mee 
3402ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3403ae42c70aSBryan Schumaker {
3404ae42c70aSBryan Schumaker 	__be32 *p;
3405ae42c70aSBryan Schumaker 	int len;
3406ae42c70aSBryan Schumaker 
34077ad07353STrond Myklebust 	if (fh != NULL)
3408ae42c70aSBryan Schumaker 		memset(fh, 0, sizeof(*fh));
3409ae42c70aSBryan Schumaker 
3410ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3411ae42c70aSBryan Schumaker 		return -EIO;
3412ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3413ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3414ae42c70aSBryan Schumaker 		if (unlikely(!p))
3415ae42c70aSBryan Schumaker 			goto out_overflow;
3416ae42c70aSBryan Schumaker 		len = be32_to_cpup(p);
3417ae42c70aSBryan Schumaker 		if (len > NFS4_FHSIZE)
3418ae42c70aSBryan Schumaker 			return -EIO;
3419ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, len);
3420ae42c70aSBryan Schumaker 		if (unlikely(!p))
3421ae42c70aSBryan Schumaker 			goto out_overflow;
34227ad07353STrond Myklebust 		if (fh != NULL) {
3423ae42c70aSBryan Schumaker 			memcpy(fh->data, p, len);
34247ad07353STrond Myklebust 			fh->size = len;
34257ad07353STrond Myklebust 		}
3426ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3427ae42c70aSBryan Schumaker 	}
3428ae42c70aSBryan Schumaker 	return 0;
3429ae42c70aSBryan Schumaker out_overflow:
3430ae42c70aSBryan Schumaker 	print_overflow_msg(__func__, xdr);
3431ae42c70aSBryan Schumaker 	return -EIO;
3432ae42c70aSBryan Schumaker }
3433ae42c70aSBryan Schumaker 
34341da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
34351da177e4SLinus Torvalds {
34368687b63aSAl Viro 	__be32 *p;
34371da177e4SLinus Torvalds 
3438a1800acaSMalahal Naineni 	*res = 0;
34391da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
34401da177e4SLinus Torvalds 		return -EIO;
34411da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3442c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3443c0eae66eSBenny Halevy 		if (unlikely(!p))
3444c0eae66eSBenny Halevy 			goto out_overflow;
3445cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
34461da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
34471da177e4SLinus Torvalds 	}
34483110ff80SHarvey Harrison 	dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
34491da177e4SLinus Torvalds 	return 0;
3450c0eae66eSBenny Halevy out_overflow:
3451c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3452c0eae66eSBenny Halevy 	return -EIO;
34531da177e4SLinus Torvalds }
34541da177e4SLinus Torvalds 
34551da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
34561da177e4SLinus Torvalds {
34578687b63aSAl Viro 	__be32 *p;
3458409924e4STrond Myklebust 	int ret = 0;
34591da177e4SLinus Torvalds 
34601da177e4SLinus Torvalds 	*fileid = 0;
34611da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
34621da177e4SLinus Torvalds 		return -EIO;
34631da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3464c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3465c0eae66eSBenny Halevy 		if (unlikely(!p))
3466c0eae66eSBenny Halevy 			goto out_overflow;
3467cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
34681da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILEID;
3469409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FILEID;
34701da177e4SLinus Torvalds 	}
34713110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3472409924e4STrond Myklebust 	return ret;
3473c0eae66eSBenny Halevy out_overflow:
3474c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3475c0eae66eSBenny Halevy 	return -EIO;
34761da177e4SLinus Torvalds }
34771da177e4SLinus Torvalds 
347899baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
347999baf625SManoj Naik {
34808687b63aSAl Viro 	__be32 *p;
3481409924e4STrond Myklebust 	int ret = 0;
348299baf625SManoj Naik 
348399baf625SManoj Naik 	*fileid = 0;
348499baf625SManoj Naik 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
348599baf625SManoj Naik 		return -EIO;
348699baf625SManoj Naik 	if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3487c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3488c0eae66eSBenny Halevy 		if (unlikely(!p))
3489c0eae66eSBenny Halevy 			goto out_overflow;
3490cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
349199baf625SManoj Naik 		bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
349228331a46STrond Myklebust 		ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
349399baf625SManoj Naik 	}
34943110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3495409924e4STrond Myklebust 	return ret;
3496c0eae66eSBenny Halevy out_overflow:
3497c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3498c0eae66eSBenny Halevy 	return -EIO;
349999baf625SManoj Naik }
350099baf625SManoj Naik 
35011da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35021da177e4SLinus Torvalds {
35038687b63aSAl Viro 	__be32 *p;
35041da177e4SLinus Torvalds 	int status = 0;
35051da177e4SLinus Torvalds 
35061da177e4SLinus Torvalds 	*res = 0;
35071da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
35081da177e4SLinus Torvalds 		return -EIO;
35091da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3510c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3511c0eae66eSBenny Halevy 		if (unlikely(!p))
3512c0eae66eSBenny Halevy 			goto out_overflow;
3513cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35141da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
35151da177e4SLinus Torvalds 	}
35163110ff80SHarvey Harrison 	dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
35171da177e4SLinus Torvalds 	return status;
3518c0eae66eSBenny Halevy out_overflow:
3519c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3520c0eae66eSBenny Halevy 	return -EIO;
35211da177e4SLinus Torvalds }
35221da177e4SLinus Torvalds 
35231da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35241da177e4SLinus Torvalds {
35258687b63aSAl Viro 	__be32 *p;
35261da177e4SLinus Torvalds 	int status = 0;
35271da177e4SLinus Torvalds 
35281da177e4SLinus Torvalds 	*res = 0;
35291da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
35301da177e4SLinus Torvalds 		return -EIO;
35311da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3532c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3533c0eae66eSBenny Halevy 		if (unlikely(!p))
3534c0eae66eSBenny Halevy 			goto out_overflow;
3535cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35361da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
35371da177e4SLinus Torvalds 	}
35383110ff80SHarvey Harrison 	dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
35391da177e4SLinus Torvalds 	return status;
3540c0eae66eSBenny Halevy out_overflow:
3541c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3542c0eae66eSBenny Halevy 	return -EIO;
35431da177e4SLinus Torvalds }
35441da177e4SLinus Torvalds 
35451da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35461da177e4SLinus Torvalds {
35478687b63aSAl Viro 	__be32 *p;
35481da177e4SLinus Torvalds 	int status = 0;
35491da177e4SLinus Torvalds 
35501da177e4SLinus Torvalds 	*res = 0;
35511da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
35521da177e4SLinus Torvalds 		return -EIO;
35531da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3554c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3555c0eae66eSBenny Halevy 		if (unlikely(!p))
3556c0eae66eSBenny Halevy 			goto out_overflow;
3557cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35581da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
35591da177e4SLinus Torvalds 	}
35603110ff80SHarvey Harrison 	dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
35611da177e4SLinus Torvalds 	return status;
3562c0eae66eSBenny Halevy out_overflow:
3563c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3564c0eae66eSBenny Halevy 	return -EIO;
35651da177e4SLinus Torvalds }
35661da177e4SLinus Torvalds 
35677aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
35687aaa0b3bSManoj Naik {
3569464ad6b1SChuck Lever 	u32 n;
35708687b63aSAl Viro 	__be32 *p;
35717aaa0b3bSManoj Naik 	int status = 0;
35727aaa0b3bSManoj Naik 
3573c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3574c0eae66eSBenny Halevy 	if (unlikely(!p))
3575c0eae66eSBenny Halevy 		goto out_overflow;
3576cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
357733a43f28SAndy Adamson 	if (n == 0)
357833a43f28SAndy Adamson 		goto root_path;
357902a2976cSChuck Lever 	dprintk("pathname4: ");
3580809b426cSTrond Myklebust 	if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3581809b426cSTrond Myklebust 		dprintk("cannot parse %d components in path\n", n);
3582809b426cSTrond Myklebust 		goto out_eio;
3583809b426cSTrond Myklebust 	}
3584809b426cSTrond Myklebust 	for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
35857aaa0b3bSManoj Naik 		struct nfs4_string *component = &path->components[path->ncomponents];
35867aaa0b3bSManoj Naik 		status = decode_opaque_inline(xdr, &component->len, &component->data);
35877aaa0b3bSManoj Naik 		if (unlikely(status != 0))
35887aaa0b3bSManoj Naik 			goto out_eio;
358995a13f7bSTrond Myklebust 		ifdebug (XDR)
359002a2976cSChuck Lever 			pr_cont("%s%.*s ",
359102a2976cSChuck Lever 				(path->ncomponents != n ? "/ " : ""),
359202a2976cSChuck Lever 				component->len, component->data);
35937aaa0b3bSManoj Naik 	}
35947aaa0b3bSManoj Naik out:
35957aaa0b3bSManoj Naik 	return status;
359633a43f28SAndy Adamson root_path:
359733a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */
359833a43f28SAndy Adamson 	path->ncomponents = 1;
359933a43f28SAndy Adamson 	path->components[0].len=0;
360033a43f28SAndy Adamson 	path->components[0].data=NULL;
360102a2976cSChuck Lever 	dprintk("pathname4: /\n");
360233a43f28SAndy Adamson 	goto out;
36037aaa0b3bSManoj Naik out_eio:
36047aaa0b3bSManoj Naik 	dprintk(" status %d", status);
36057aaa0b3bSManoj Naik 	status = -EIO;
36067aaa0b3bSManoj Naik 	goto out;
3607c0eae66eSBenny Halevy out_overflow:
3608c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3609c0eae66eSBenny Halevy 	return -EIO;
36107aaa0b3bSManoj Naik }
36117aaa0b3bSManoj Naik 
36127aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3613683b57b4STrond Myklebust {
3614683b57b4STrond Myklebust 	int n;
36158687b63aSAl Viro 	__be32 *p;
3616683b57b4STrond Myklebust 	int status = -EIO;
3617683b57b4STrond Myklebust 
3618683b57b4STrond Myklebust 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3619683b57b4STrond Myklebust 		goto out;
3620683b57b4STrond Myklebust 	status = 0;
3621683b57b4STrond Myklebust 	if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3622683b57b4STrond Myklebust 		goto out;
3623f54423a1SKinglong Mee 	bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
36248b7e3f49STrond Myklebust 	status = -EIO;
36258b7e3f49STrond Myklebust 	/* Ignore borken servers that return unrequested attrs */
36268b7e3f49STrond Myklebust 	if (unlikely(res == NULL))
36278b7e3f49STrond Myklebust 		goto out;
362802a2976cSChuck Lever 	dprintk("%s: fsroot:\n", __func__);
36297aaa0b3bSManoj Naik 	status = decode_pathname(xdr, &res->fs_path);
3630683b57b4STrond Myklebust 	if (unlikely(status != 0))
3631683b57b4STrond Myklebust 		goto out;
3632c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3633c0eae66eSBenny Halevy 	if (unlikely(!p))
3634c0eae66eSBenny Halevy 		goto out_overflow;
3635cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
3636683b57b4STrond Myklebust 	if (n <= 0)
3637683b57b4STrond Myklebust 		goto out_eio;
3638809b426cSTrond Myklebust 	for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3639464ad6b1SChuck Lever 		u32 m;
3640809b426cSTrond Myklebust 		struct nfs4_fs_location *loc;
3641683b57b4STrond Myklebust 
3642809b426cSTrond Myklebust 		if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3643809b426cSTrond Myklebust 			break;
3644809b426cSTrond Myklebust 		loc = &res->locations[res->nlocations];
3645c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3646c0eae66eSBenny Halevy 		if (unlikely(!p))
3647c0eae66eSBenny Halevy 			goto out_overflow;
3648cccddf4fSBenny Halevy 		m = be32_to_cpup(p);
36497aaa0b3bSManoj Naik 
365002a2976cSChuck Lever 		dprintk("%s: servers:\n", __func__);
3651809b426cSTrond Myklebust 		for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3652809b426cSTrond Myklebust 			struct nfs4_string *server;
3653809b426cSTrond Myklebust 
3654809b426cSTrond Myklebust 			if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3655464ad6b1SChuck Lever 				unsigned int i;
3656464ad6b1SChuck Lever 				dprintk("%s: using first %u of %u servers "
3657464ad6b1SChuck Lever 					"returned for location %u\n",
36583110ff80SHarvey Harrison 						__func__,
3659464ad6b1SChuck Lever 						NFS4_FS_LOCATION_MAXSERVERS,
3660464ad6b1SChuck Lever 						m, res->nlocations);
36617aaa0b3bSManoj Naik 				for (i = loc->nservers; i < m; i++) {
36622e42c3e2STrond Myklebust 					unsigned int len;
36637aaa0b3bSManoj Naik 					char *data;
36647aaa0b3bSManoj Naik 					status = decode_opaque_inline(xdr, &len, &data);
3665683b57b4STrond Myklebust 					if (unlikely(status != 0))
3666683b57b4STrond Myklebust 						goto out_eio;
36677aaa0b3bSManoj Naik 				}
3668809b426cSTrond Myklebust 				break;
36697aaa0b3bSManoj Naik 			}
3670809b426cSTrond Myklebust 			server = &loc->servers[loc->nservers];
3671809b426cSTrond Myklebust 			status = decode_opaque_inline(xdr, &server->len, &server->data);
3672809b426cSTrond Myklebust 			if (unlikely(status != 0))
3673809b426cSTrond Myklebust 				goto out_eio;
3674809b426cSTrond Myklebust 			dprintk("%s ", server->data);
36757aaa0b3bSManoj Naik 		}
36767aaa0b3bSManoj Naik 		status = decode_pathname(xdr, &loc->rootpath);
36777aaa0b3bSManoj Naik 		if (unlikely(status != 0))
36787aaa0b3bSManoj Naik 			goto out_eio;
3679683b57b4STrond Myklebust 	}
3680409924e4STrond Myklebust 	if (res->nlocations != 0)
368181934ddbSChuck Lever 		status = NFS_ATTR_FATTR_V4_LOCATIONS;
3682683b57b4STrond Myklebust out:
36833110ff80SHarvey Harrison 	dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3684683b57b4STrond Myklebust 	return status;
3685c0eae66eSBenny Halevy out_overflow:
3686c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3687683b57b4STrond Myklebust out_eio:
3688683b57b4STrond Myklebust 	status = -EIO;
3689683b57b4STrond Myklebust 	goto out;
3690683b57b4STrond Myklebust }
3691683b57b4STrond Myklebust 
36921da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
36931da177e4SLinus Torvalds {
36948687b63aSAl Viro 	__be32 *p;
36951da177e4SLinus Torvalds 	int status = 0;
36961da177e4SLinus Torvalds 
36971da177e4SLinus Torvalds 	*res = 0;
36981da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
36991da177e4SLinus Torvalds 		return -EIO;
37001da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3701c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3702c0eae66eSBenny Halevy 		if (unlikely(!p))
3703c0eae66eSBenny Halevy 			goto out_overflow;
3704cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
37051da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
37061da177e4SLinus Torvalds 	}
37073110ff80SHarvey Harrison 	dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
37081da177e4SLinus Torvalds 	return status;
3709c0eae66eSBenny Halevy out_overflow:
3710c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3711c0eae66eSBenny Halevy 	return -EIO;
37121da177e4SLinus Torvalds }
37131da177e4SLinus Torvalds 
37141da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
37151da177e4SLinus Torvalds {
37168687b63aSAl Viro 	__be32 *p;
37171da177e4SLinus Torvalds 	int status = 0;
37181da177e4SLinus Torvalds 
37191da177e4SLinus Torvalds 	*maxlink = 1;
37201da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
37211da177e4SLinus Torvalds 		return -EIO;
37221da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3723c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3724c0eae66eSBenny Halevy 		if (unlikely(!p))
3725c0eae66eSBenny Halevy 			goto out_overflow;
3726cccddf4fSBenny Halevy 		*maxlink = be32_to_cpup(p);
37271da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
37281da177e4SLinus Torvalds 	}
37293110ff80SHarvey Harrison 	dprintk("%s: maxlink=%u\n", __func__, *maxlink);
37301da177e4SLinus Torvalds 	return status;
3731c0eae66eSBenny Halevy out_overflow:
3732c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3733c0eae66eSBenny Halevy 	return -EIO;
37341da177e4SLinus Torvalds }
37351da177e4SLinus Torvalds 
37361da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
37371da177e4SLinus Torvalds {
37388687b63aSAl Viro 	__be32 *p;
37391da177e4SLinus Torvalds 	int status = 0;
37401da177e4SLinus Torvalds 
37411da177e4SLinus Torvalds 	*maxname = 1024;
37421da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
37431da177e4SLinus Torvalds 		return -EIO;
37441da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3745c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3746c0eae66eSBenny Halevy 		if (unlikely(!p))
3747c0eae66eSBenny Halevy 			goto out_overflow;
3748cccddf4fSBenny Halevy 		*maxname = be32_to_cpup(p);
37491da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
37501da177e4SLinus Torvalds 	}
37513110ff80SHarvey Harrison 	dprintk("%s: maxname=%u\n", __func__, *maxname);
37521da177e4SLinus Torvalds 	return status;
3753c0eae66eSBenny Halevy out_overflow:
3754c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3755c0eae66eSBenny Halevy 	return -EIO;
37561da177e4SLinus Torvalds }
37571da177e4SLinus Torvalds 
37581da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
37591da177e4SLinus Torvalds {
37608687b63aSAl Viro 	__be32 *p;
37611da177e4SLinus Torvalds 	int status = 0;
37621da177e4SLinus Torvalds 
37631da177e4SLinus Torvalds 	*res = 1024;
37641da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
37651da177e4SLinus Torvalds 		return -EIO;
37661da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
37671da177e4SLinus Torvalds 		uint64_t maxread;
3768c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3769c0eae66eSBenny Halevy 		if (unlikely(!p))
3770c0eae66eSBenny Halevy 			goto out_overflow;
3771cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxread);
37721da177e4SLinus Torvalds 		if (maxread > 0x7FFFFFFF)
37731da177e4SLinus Torvalds 			maxread = 0x7FFFFFFF;
37741da177e4SLinus Torvalds 		*res = (uint32_t)maxread;
37751da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
37761da177e4SLinus Torvalds 	}
37773110ff80SHarvey Harrison 	dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
37781da177e4SLinus Torvalds 	return status;
3779c0eae66eSBenny Halevy out_overflow:
3780c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3781c0eae66eSBenny Halevy 	return -EIO;
37821da177e4SLinus Torvalds }
37831da177e4SLinus Torvalds 
37841da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
37851da177e4SLinus Torvalds {
37868687b63aSAl Viro 	__be32 *p;
37871da177e4SLinus Torvalds 	int status = 0;
37881da177e4SLinus Torvalds 
37891da177e4SLinus Torvalds 	*res = 1024;
37901da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
37911da177e4SLinus Torvalds 		return -EIO;
37921da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
37931da177e4SLinus Torvalds 		uint64_t maxwrite;
3794c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3795c0eae66eSBenny Halevy 		if (unlikely(!p))
3796c0eae66eSBenny Halevy 			goto out_overflow;
3797cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxwrite);
37981da177e4SLinus Torvalds 		if (maxwrite > 0x7FFFFFFF)
37991da177e4SLinus Torvalds 			maxwrite = 0x7FFFFFFF;
38001da177e4SLinus Torvalds 		*res = (uint32_t)maxwrite;
38011da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
38021da177e4SLinus Torvalds 	}
38033110ff80SHarvey Harrison 	dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
38041da177e4SLinus Torvalds 	return status;
3805c0eae66eSBenny Halevy out_overflow:
3806c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3807c0eae66eSBenny Halevy 	return -EIO;
38081da177e4SLinus Torvalds }
38091da177e4SLinus Torvalds 
3810bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
38111da177e4SLinus Torvalds {
3812bca79478STrond Myklebust 	uint32_t tmp;
38138687b63aSAl Viro 	__be32 *p;
3814409924e4STrond Myklebust 	int ret = 0;
38151da177e4SLinus Torvalds 
38161da177e4SLinus Torvalds 	*mode = 0;
38171da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
38181da177e4SLinus Torvalds 		return -EIO;
38191da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3820c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3821c0eae66eSBenny Halevy 		if (unlikely(!p))
3822c0eae66eSBenny Halevy 			goto out_overflow;
3823cccddf4fSBenny Halevy 		tmp = be32_to_cpup(p);
3824bca79478STrond Myklebust 		*mode = tmp & ~S_IFMT;
38251da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_MODE;
3826409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_MODE;
38271da177e4SLinus Torvalds 	}
38283110ff80SHarvey Harrison 	dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3829409924e4STrond Myklebust 	return ret;
3830c0eae66eSBenny Halevy out_overflow:
3831c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3832c0eae66eSBenny Halevy 	return -EIO;
38331da177e4SLinus Torvalds }
38341da177e4SLinus Torvalds 
38351da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
38361da177e4SLinus Torvalds {
38378687b63aSAl Viro 	__be32 *p;
3838409924e4STrond Myklebust 	int ret = 0;
38391da177e4SLinus Torvalds 
38401da177e4SLinus Torvalds 	*nlink = 1;
38411da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
38421da177e4SLinus Torvalds 		return -EIO;
38431da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3844c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3845c0eae66eSBenny Halevy 		if (unlikely(!p))
3846c0eae66eSBenny Halevy 			goto out_overflow;
3847cccddf4fSBenny Halevy 		*nlink = be32_to_cpup(p);
38481da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3849409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_NLINK;
38501da177e4SLinus Torvalds 	}
38513110ff80SHarvey Harrison 	dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3852409924e4STrond Myklebust 	return ret;
3853c0eae66eSBenny Halevy out_overflow:
3854c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3855c0eae66eSBenny Halevy 	return -EIO;
38561da177e4SLinus Torvalds }
38571da177e4SLinus Torvalds 
385880e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3859e5782076SEric W. Biederman 		const struct nfs_server *server, kuid_t *uid,
38606926afd1STrond Myklebust 		struct nfs4_string *owner_name)
38611da177e4SLinus Torvalds {
38628687b63aSAl Viro 	uint32_t len;
38638687b63aSAl Viro 	__be32 *p;
3864409924e4STrond Myklebust 	int ret = 0;
38651da177e4SLinus Torvalds 
3866e5782076SEric W. Biederman 	*uid = make_kuid(&init_user_ns, -2);
38671da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
38681da177e4SLinus Torvalds 		return -EIO;
38691da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3870c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3871c0eae66eSBenny Halevy 		if (unlikely(!p))
3872c0eae66eSBenny Halevy 			goto out_overflow;
3873cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
3874c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
3875c0eae66eSBenny Halevy 		if (unlikely(!p))
3876c0eae66eSBenny Halevy 			goto out_overflow;
38776926afd1STrond Myklebust 		if (owner_name != NULL) {
38786926afd1STrond Myklebust 			owner_name->data = kmemdup(p, len, GFP_NOWAIT);
38796926afd1STrond Myklebust 			if (owner_name->data != NULL) {
38806926afd1STrond Myklebust 				owner_name->len = len;
38816926afd1STrond Myklebust 				ret = NFS_ATTR_FATTR_OWNER_NAME;
38826926afd1STrond Myklebust 			}
388380e52aceSTrond Myklebust 		} else if (len < XDR_MAX_NETOBJ) {
3884e4fd72a1STrond Myklebust 			if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3885409924e4STrond Myklebust 				ret = NFS_ATTR_FATTR_OWNER;
3886409924e4STrond Myklebust 			else
38871da177e4SLinus Torvalds 				dprintk("%s: nfs_map_name_to_uid failed!\n",
38883110ff80SHarvey Harrison 						__func__);
38891da177e4SLinus Torvalds 		} else
3890fe82a183SChuck Lever 			dprintk("%s: name too long (%u)!\n",
38913110ff80SHarvey Harrison 					__func__, len);
38921da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_OWNER;
38931da177e4SLinus Torvalds 	}
3894e5782076SEric W. Biederman 	dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3895409924e4STrond Myklebust 	return ret;
3896c0eae66eSBenny Halevy out_overflow:
3897c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3898c0eae66eSBenny Halevy 	return -EIO;
38991da177e4SLinus Torvalds }
39001da177e4SLinus Torvalds 
390180e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3902e5782076SEric W. Biederman 		const struct nfs_server *server, kgid_t *gid,
39036926afd1STrond Myklebust 		struct nfs4_string *group_name)
39041da177e4SLinus Torvalds {
39058687b63aSAl Viro 	uint32_t len;
39068687b63aSAl Viro 	__be32 *p;
3907409924e4STrond Myklebust 	int ret = 0;
39081da177e4SLinus Torvalds 
3909e5782076SEric W. Biederman 	*gid = make_kgid(&init_user_ns, -2);
39101da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
39111da177e4SLinus Torvalds 		return -EIO;
39121da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3913c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3914c0eae66eSBenny Halevy 		if (unlikely(!p))
3915c0eae66eSBenny Halevy 			goto out_overflow;
3916cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
3917c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
3918c0eae66eSBenny Halevy 		if (unlikely(!p))
3919c0eae66eSBenny Halevy 			goto out_overflow;
39206926afd1STrond Myklebust 		if (group_name != NULL) {
39216926afd1STrond Myklebust 			group_name->data = kmemdup(p, len, GFP_NOWAIT);
39226926afd1STrond Myklebust 			if (group_name->data != NULL) {
39236926afd1STrond Myklebust 				group_name->len = len;
39246926afd1STrond Myklebust 				ret = NFS_ATTR_FATTR_GROUP_NAME;
39256926afd1STrond Myklebust 			}
392680e52aceSTrond Myklebust 		} else if (len < XDR_MAX_NETOBJ) {
3927e4fd72a1STrond Myklebust 			if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3928409924e4STrond Myklebust 				ret = NFS_ATTR_FATTR_GROUP;
3929409924e4STrond Myklebust 			else
39301da177e4SLinus Torvalds 				dprintk("%s: nfs_map_group_to_gid failed!\n",
39313110ff80SHarvey Harrison 						__func__);
39321da177e4SLinus Torvalds 		} else
3933fe82a183SChuck Lever 			dprintk("%s: name too long (%u)!\n",
39343110ff80SHarvey Harrison 					__func__, len);
39351da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
39361da177e4SLinus Torvalds 	}
3937e5782076SEric W. Biederman 	dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3938409924e4STrond Myklebust 	return ret;
3939c0eae66eSBenny Halevy out_overflow:
3940c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3941c0eae66eSBenny Halevy 	return -EIO;
39421da177e4SLinus Torvalds }
39431da177e4SLinus Torvalds 
39441da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
39451da177e4SLinus Torvalds {
39468687b63aSAl Viro 	uint32_t major = 0, minor = 0;
39478687b63aSAl Viro 	__be32 *p;
3948409924e4STrond Myklebust 	int ret = 0;
39491da177e4SLinus Torvalds 
39501da177e4SLinus Torvalds 	*rdev = MKDEV(0,0);
39511da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
39521da177e4SLinus Torvalds 		return -EIO;
39531da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
39541da177e4SLinus Torvalds 		dev_t tmp;
39551da177e4SLinus Torvalds 
3956c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3957c0eae66eSBenny Halevy 		if (unlikely(!p))
3958c0eae66eSBenny Halevy 			goto out_overflow;
39596f723f77SBenny Halevy 		major = be32_to_cpup(p++);
3960cccddf4fSBenny Halevy 		minor = be32_to_cpup(p);
39611da177e4SLinus Torvalds 		tmp = MKDEV(major, minor);
39621da177e4SLinus Torvalds 		if (MAJOR(tmp) == major && MINOR(tmp) == minor)
39631da177e4SLinus Torvalds 			*rdev = tmp;
39641da177e4SLinus Torvalds 		bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3965409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_RDEV;
39661da177e4SLinus Torvalds 	}
39673110ff80SHarvey Harrison 	dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3968409924e4STrond Myklebust 	return ret;
3969c0eae66eSBenny Halevy out_overflow:
3970c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3971c0eae66eSBenny Halevy 	return -EIO;
39721da177e4SLinus Torvalds }
39731da177e4SLinus Torvalds 
39741da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
39751da177e4SLinus Torvalds {
39768687b63aSAl Viro 	__be32 *p;
39771da177e4SLinus Torvalds 	int status = 0;
39781da177e4SLinus Torvalds 
39791da177e4SLinus Torvalds 	*res = 0;
39801da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
39811da177e4SLinus Torvalds 		return -EIO;
39821da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3983c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3984c0eae66eSBenny Halevy 		if (unlikely(!p))
3985c0eae66eSBenny Halevy 			goto out_overflow;
3986cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
39871da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
39881da177e4SLinus Torvalds 	}
39893110ff80SHarvey Harrison 	dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
39901da177e4SLinus Torvalds 	return status;
3991c0eae66eSBenny Halevy out_overflow:
3992c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
3993c0eae66eSBenny Halevy 	return -EIO;
39941da177e4SLinus Torvalds }
39951da177e4SLinus Torvalds 
39961da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
39971da177e4SLinus Torvalds {
39988687b63aSAl Viro 	__be32 *p;
39991da177e4SLinus Torvalds 	int status = 0;
40001da177e4SLinus Torvalds 
40011da177e4SLinus Torvalds 	*res = 0;
40021da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
40031da177e4SLinus Torvalds 		return -EIO;
40041da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
4005c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4006c0eae66eSBenny Halevy 		if (unlikely(!p))
4007c0eae66eSBenny Halevy 			goto out_overflow;
4008cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40091da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
40101da177e4SLinus Torvalds 	}
40113110ff80SHarvey Harrison 	dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
40121da177e4SLinus Torvalds 	return status;
4013c0eae66eSBenny Halevy out_overflow:
4014c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4015c0eae66eSBenny Halevy 	return -EIO;
40161da177e4SLinus Torvalds }
40171da177e4SLinus Torvalds 
40181da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40191da177e4SLinus Torvalds {
40208687b63aSAl Viro 	__be32 *p;
40211da177e4SLinus Torvalds 	int status = 0;
40221da177e4SLinus Torvalds 
40231da177e4SLinus Torvalds 	*res = 0;
40241da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
40251da177e4SLinus Torvalds 		return -EIO;
40261da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4027c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4028c0eae66eSBenny Halevy 		if (unlikely(!p))
4029c0eae66eSBenny Halevy 			goto out_overflow;
4030cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40311da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
40321da177e4SLinus Torvalds 	}
40333110ff80SHarvey Harrison 	dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
40341da177e4SLinus Torvalds 	return status;
4035c0eae66eSBenny Halevy out_overflow:
4036c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4037c0eae66eSBenny Halevy 	return -EIO;
40381da177e4SLinus Torvalds }
40391da177e4SLinus Torvalds 
40401da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
40411da177e4SLinus Torvalds {
40428687b63aSAl Viro 	__be32 *p;
4043409924e4STrond Myklebust 	int ret = 0;
40441da177e4SLinus Torvalds 
40451da177e4SLinus Torvalds 	*used = 0;
40461da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
40471da177e4SLinus Torvalds 		return -EIO;
40481da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4049c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4050c0eae66eSBenny Halevy 		if (unlikely(!p))
4051c0eae66eSBenny Halevy 			goto out_overflow;
4052cccddf4fSBenny Halevy 		xdr_decode_hyper(p, used);
40531da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4054409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SPACE_USED;
40551da177e4SLinus Torvalds 	}
40563110ff80SHarvey Harrison 	dprintk("%s: space used=%Lu\n", __func__,
40571da177e4SLinus Torvalds 			(unsigned long long)*used);
4058409924e4STrond Myklebust 	return ret;
4059c0eae66eSBenny Halevy out_overflow:
4060c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4061c0eae66eSBenny Halevy 	return -EIO;
40621da177e4SLinus Torvalds }
40631da177e4SLinus Torvalds 
40641da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
40651da177e4SLinus Torvalds {
40668687b63aSAl Viro 	__be32 *p;
40671da177e4SLinus Torvalds 	uint64_t sec;
40681da177e4SLinus Torvalds 	uint32_t nsec;
40691da177e4SLinus Torvalds 
4070c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
4071c0eae66eSBenny Halevy 	if (unlikely(!p))
4072c0eae66eSBenny Halevy 		goto out_overflow;
40733ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &sec);
4074cccddf4fSBenny Halevy 	nsec = be32_to_cpup(p);
40751da177e4SLinus Torvalds 	time->tv_sec = (time_t)sec;
40761da177e4SLinus Torvalds 	time->tv_nsec = (long)nsec;
40771da177e4SLinus Torvalds 	return 0;
4078c0eae66eSBenny Halevy out_overflow:
4079c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4080c0eae66eSBenny Halevy 	return -EIO;
40811da177e4SLinus Torvalds }
40821da177e4SLinus Torvalds 
40831da177e4SLinus Torvalds static int decode_attr_time_access(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_ACCESS - 1U)))
40901da177e4SLinus Torvalds 		return -EIO;
40911da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
40921da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4093409924e4STrond Myklebust 		if (status == 0)
4094409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_ATIME;
40951da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
40961da177e4SLinus Torvalds 	}
40973110ff80SHarvey Harrison 	dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
40981da177e4SLinus Torvalds 	return status;
40991da177e4SLinus Torvalds }
41001da177e4SLinus Torvalds 
41011da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
41021da177e4SLinus Torvalds {
41031da177e4SLinus Torvalds 	int status = 0;
41041da177e4SLinus Torvalds 
41051da177e4SLinus Torvalds 	time->tv_sec = 0;
41061da177e4SLinus Torvalds 	time->tv_nsec = 0;
41071da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
41081da177e4SLinus Torvalds 		return -EIO;
41091da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
41101da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4111409924e4STrond Myklebust 		if (status == 0)
4112409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_CTIME;
41131da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
41141da177e4SLinus Torvalds 	}
41153110ff80SHarvey Harrison 	dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
41161da177e4SLinus Torvalds 	return status;
41171da177e4SLinus Torvalds }
41181da177e4SLinus Torvalds 
411955b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
412055b6e774SRicardo Labiaga 				  struct timespec *time)
412155b6e774SRicardo Labiaga {
412255b6e774SRicardo Labiaga 	int status = 0;
412355b6e774SRicardo Labiaga 
412455b6e774SRicardo Labiaga 	time->tv_sec = 0;
412555b6e774SRicardo Labiaga 	time->tv_nsec = 0;
412655b6e774SRicardo Labiaga 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
412755b6e774SRicardo Labiaga 		return -EIO;
412855b6e774SRicardo Labiaga 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
412955b6e774SRicardo Labiaga 		status = decode_attr_time(xdr, time);
413055b6e774SRicardo Labiaga 		bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
413155b6e774SRicardo Labiaga 	}
413255b6e774SRicardo Labiaga 	dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
413355b6e774SRicardo Labiaga 		(long)time->tv_nsec);
413455b6e774SRicardo Labiaga 	return status;
413555b6e774SRicardo Labiaga }
413655b6e774SRicardo Labiaga 
4137aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4138aa9c2669SDavid Quigley 					struct nfs4_label *label)
4139aa9c2669SDavid Quigley {
4140aa9c2669SDavid Quigley 	uint32_t pi = 0;
4141aa9c2669SDavid Quigley 	uint32_t lfs = 0;
4142aa9c2669SDavid Quigley 	__u32 len;
4143aa9c2669SDavid Quigley 	__be32 *p;
4144aa9c2669SDavid Quigley 	int status = 0;
4145aa9c2669SDavid Quigley 
4146aa9c2669SDavid Quigley 	if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4147aa9c2669SDavid Quigley 		return -EIO;
4148aa9c2669SDavid Quigley 	if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4149aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4150aa9c2669SDavid Quigley 		if (unlikely(!p))
4151aa9c2669SDavid Quigley 			goto out_overflow;
4152aa9c2669SDavid Quigley 		lfs = be32_to_cpup(p++);
4153aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4154aa9c2669SDavid Quigley 		if (unlikely(!p))
4155aa9c2669SDavid Quigley 			goto out_overflow;
4156aa9c2669SDavid Quigley 		pi = be32_to_cpup(p++);
4157aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4158aa9c2669SDavid Quigley 		if (unlikely(!p))
4159aa9c2669SDavid Quigley 			goto out_overflow;
4160aa9c2669SDavid Quigley 		len = be32_to_cpup(p++);
4161aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, len);
4162aa9c2669SDavid Quigley 		if (unlikely(!p))
4163aa9c2669SDavid Quigley 			goto out_overflow;
4164aa9c2669SDavid Quigley 		if (len < NFS4_MAXLABELLEN) {
4165aa9c2669SDavid Quigley 			if (label) {
4166aa9c2669SDavid Quigley 				memcpy(label->label, p, len);
4167aa9c2669SDavid Quigley 				label->len = len;
4168aa9c2669SDavid Quigley 				label->pi = pi;
4169aa9c2669SDavid Quigley 				label->lfs = lfs;
4170aa9c2669SDavid Quigley 				status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4171aa9c2669SDavid Quigley 			}
4172aa9c2669SDavid Quigley 			bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4173aa9c2669SDavid Quigley 		} else
4174aa9c2669SDavid Quigley 			printk(KERN_WARNING "%s: label too long (%u)!\n",
4175aa9c2669SDavid Quigley 					__func__, len);
4176aa9c2669SDavid Quigley 	}
4177aa9c2669SDavid Quigley 	if (label && label->label)
4178aa9c2669SDavid Quigley 		dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4179aa9c2669SDavid Quigley 			(char *)label->label, label->len, label->pi, label->lfs);
4180aa9c2669SDavid Quigley 	return status;
4181aa9c2669SDavid Quigley 
4182aa9c2669SDavid Quigley out_overflow:
4183aa9c2669SDavid Quigley 	print_overflow_msg(__func__, xdr);
4184aa9c2669SDavid Quigley 	return -EIO;
4185aa9c2669SDavid Quigley }
4186aa9c2669SDavid Quigley 
41871da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
41881da177e4SLinus Torvalds {
41891da177e4SLinus Torvalds 	int status = 0;
41901da177e4SLinus Torvalds 
41911da177e4SLinus Torvalds 	time->tv_sec = 0;
41921da177e4SLinus Torvalds 	time->tv_nsec = 0;
41931da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
41941da177e4SLinus Torvalds 		return -EIO;
41951da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
41961da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4197409924e4STrond Myklebust 		if (status == 0)
4198409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_MTIME;
41991da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
42001da177e4SLinus Torvalds 	}
42013110ff80SHarvey Harrison 	dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
42021da177e4SLinus Torvalds 	return status;
42031da177e4SLinus Torvalds }
42041da177e4SLinus Torvalds 
4205256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
42061da177e4SLinus Torvalds {
42071da177e4SLinus Torvalds 	unsigned int attrwords = XDR_QUADLEN(attrlen);
4208256e48bbSTrond Myklebust 	unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
42091da177e4SLinus Torvalds 
42101da177e4SLinus Torvalds 	if (unlikely(attrwords != nwords)) {
4211fe82a183SChuck Lever 		dprintk("%s: server returned incorrect attribute length: "
4212fe82a183SChuck Lever 			"%u %c %u\n",
42133110ff80SHarvey Harrison 				__func__,
42141da177e4SLinus Torvalds 				attrwords << 2,
42151da177e4SLinus Torvalds 				(attrwords < nwords) ? '<' : '>',
42161da177e4SLinus Torvalds 				nwords << 2);
42171da177e4SLinus Torvalds 		return -EIO;
42181da177e4SLinus Torvalds 	}
42191da177e4SLinus Torvalds 	return 0;
42201da177e4SLinus Torvalds }
42211da177e4SLinus Torvalds 
42221da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
42231da177e4SLinus Torvalds {
42248687b63aSAl Viro 	__be32 *p;
42251da177e4SLinus Torvalds 
4226c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
4227c0eae66eSBenny Halevy 	if (unlikely(!p))
4228c0eae66eSBenny Halevy 		goto out_overflow;
42296f723f77SBenny Halevy 	cinfo->atomic = be32_to_cpup(p++);
42303ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &cinfo->before);
4231cccddf4fSBenny Halevy 	xdr_decode_hyper(p, &cinfo->after);
42321da177e4SLinus Torvalds 	return 0;
4233c0eae66eSBenny Halevy out_overflow:
4234c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4235c0eae66eSBenny Halevy 	return -EIO;
42361da177e4SLinus Torvalds }
42371da177e4SLinus Torvalds 
42386168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
42391da177e4SLinus Torvalds {
42408687b63aSAl Viro 	__be32 *p;
42411da177e4SLinus Torvalds 	uint32_t supp, acc;
42421da177e4SLinus Torvalds 	int status;
42431da177e4SLinus Torvalds 
42441da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_ACCESS);
42451da177e4SLinus Torvalds 	if (status)
42461da177e4SLinus Torvalds 		return status;
4247c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
4248c0eae66eSBenny Halevy 	if (unlikely(!p))
4249c0eae66eSBenny Halevy 		goto out_overflow;
42506f723f77SBenny Halevy 	supp = be32_to_cpup(p++);
4251cccddf4fSBenny Halevy 	acc = be32_to_cpup(p);
42526168f62cSWeston Andros Adamson 	*supported = supp;
42536168f62cSWeston Andros Adamson 	*access = acc;
42541da177e4SLinus Torvalds 	return 0;
4255c0eae66eSBenny Halevy out_overflow:
4256c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4257c0eae66eSBenny Halevy 	return -EIO;
42581da177e4SLinus Torvalds }
42591da177e4SLinus Torvalds 
426007d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
42611da177e4SLinus Torvalds {
42628687b63aSAl Viro 	__be32 *p;
426307d30434SBenny Halevy 
426407d30434SBenny Halevy 	p = xdr_inline_decode(xdr, len);
426507d30434SBenny Halevy 	if (likely(p)) {
426607d30434SBenny Halevy 		memcpy(buf, p, len);
426707d30434SBenny Halevy 		return 0;
426807d30434SBenny Halevy 	}
426907d30434SBenny Halevy 	print_overflow_msg(__func__, xdr);
427007d30434SBenny Halevy 	return -EIO;
427107d30434SBenny Halevy }
427207d30434SBenny Halevy 
427307d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
427407d30434SBenny Halevy {
42752d2f24adSTrond Myklebust 	return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
42761da177e4SLinus Torvalds }
42771da177e4SLinus Torvalds 
427893b717fdSTrond Myklebust static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
427993b717fdSTrond Myklebust {
428093b717fdSTrond Myklebust 	stateid->type = NFS4_OPEN_STATEID_TYPE;
428193b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
428293b717fdSTrond Myklebust }
428393b717fdSTrond Myklebust 
428493b717fdSTrond Myklebust static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
428593b717fdSTrond Myklebust {
428693b717fdSTrond Myklebust 	stateid->type = NFS4_LOCK_STATEID_TYPE;
428793b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
428893b717fdSTrond Myklebust }
428993b717fdSTrond Myklebust 
429093b717fdSTrond Myklebust static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
429193b717fdSTrond Myklebust {
429293b717fdSTrond Myklebust 	stateid->type = NFS4_DELEGATION_STATEID_TYPE;
429393b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
429493b717fdSTrond Myklebust }
429593b717fdSTrond Myklebust 
42961da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
42971da177e4SLinus Torvalds {
42981da177e4SLinus Torvalds 	int status;
42991da177e4SLinus Torvalds 
43001da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CLOSE);
4301c1d51931STrond Myklebust 	if (status != -EIO)
4302c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
430307d30434SBenny Halevy 	if (!status)
430493b717fdSTrond Myklebust 		status = decode_open_stateid(xdr, &res->stateid);
43051da177e4SLinus Torvalds 	return status;
43061da177e4SLinus Torvalds }
43071da177e4SLinus Torvalds 
4308db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4309db942bbdSBenny Halevy {
4310cd93710eSChuck Lever 	return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
43111da177e4SLinus Torvalds }
43121da177e4SLinus Torvalds 
43132f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
43142f2c63bcSTrond Myklebust {
43152f2c63bcSTrond Myklebust 	return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
43162f2c63bcSTrond Myklebust }
43172f2c63bcSTrond Myklebust 
43180b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
43191da177e4SLinus Torvalds {
43201da177e4SLinus Torvalds 	int status;
43211da177e4SLinus Torvalds 
43221da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_COMMIT);
4323db942bbdSBenny Halevy 	if (!status)
43242f2c63bcSTrond Myklebust 		status = decode_write_verifier(xdr, &res->verf->verifier);
43251da177e4SLinus Torvalds 	return status;
43261da177e4SLinus Torvalds }
43271da177e4SLinus Torvalds 
43281da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
43291da177e4SLinus Torvalds {
43308687b63aSAl Viro 	__be32 *p;
43311da177e4SLinus Torvalds 	uint32_t bmlen;
43321da177e4SLinus Torvalds 	int status;
43331da177e4SLinus Torvalds 
43341da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CREATE);
43351da177e4SLinus Torvalds 	if (status)
43361da177e4SLinus Torvalds 		return status;
43371da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, cinfo)))
43381da177e4SLinus Torvalds 		return status;
4339c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4340c0eae66eSBenny Halevy 	if (unlikely(!p))
4341c0eae66eSBenny Halevy 		goto out_overflow;
4342cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
4343c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
4344c0eae66eSBenny Halevy 	if (likely(p))
43451da177e4SLinus Torvalds 		return 0;
4346c0eae66eSBenny Halevy out_overflow:
4347c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4348c0eae66eSBenny Halevy 	return -EIO;
43491da177e4SLinus Torvalds }
43501da177e4SLinus Torvalds 
43511da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
43521da177e4SLinus Torvalds {
4353256e48bbSTrond Myklebust 	unsigned int savep;
4354dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
43551da177e4SLinus Torvalds 	int status;
43561da177e4SLinus Torvalds 
43571da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
43581da177e4SLinus Torvalds 		goto xdr_error;
43591da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
43601da177e4SLinus Torvalds 		goto xdr_error;
43611da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
43621da177e4SLinus Torvalds 		goto xdr_error;
43631da177e4SLinus Torvalds 	if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
43641da177e4SLinus Torvalds 		goto xdr_error;
4365264e6351SChuck Lever 	if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4366264e6351SChuck Lever 						 &res->fh_expire_type)) != 0)
4367264e6351SChuck Lever 		goto xdr_error;
43681da177e4SLinus Torvalds 	if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
43691da177e4SLinus Torvalds 		goto xdr_error;
43701da177e4SLinus Torvalds 	if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
43711da177e4SLinus Torvalds 		goto xdr_error;
43721da177e4SLinus Torvalds 	if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
43731da177e4SLinus Torvalds 		goto xdr_error;
43748c61282fSKinglong Mee 	if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
43758c61282fSKinglong Mee 				res->exclcreat_bitmask)) != 0)
43768c61282fSKinglong Mee 		goto xdr_error;
43771da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
43781da177e4SLinus Torvalds xdr_error:
43793110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
43801da177e4SLinus Torvalds 	return status;
43811da177e4SLinus Torvalds }
43821da177e4SLinus Torvalds 
43831da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
43841da177e4SLinus Torvalds {
4385256e48bbSTrond Myklebust 	unsigned int savep;
4386dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
43871da177e4SLinus Torvalds 	int status;
43881da177e4SLinus Torvalds 
43891da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
43901da177e4SLinus Torvalds 		goto xdr_error;
43911da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
43921da177e4SLinus Torvalds 		goto xdr_error;
43931da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
43941da177e4SLinus Torvalds 		goto xdr_error;
43951da177e4SLinus Torvalds 
43961da177e4SLinus Torvalds 	if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
43971da177e4SLinus Torvalds 		goto xdr_error;
43981da177e4SLinus Torvalds 	if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
43991da177e4SLinus Torvalds 		goto xdr_error;
44001da177e4SLinus Torvalds 	if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
44011da177e4SLinus Torvalds 		goto xdr_error;
44021ca843a2SAndreas Gruenbacher 
44031ca843a2SAndreas Gruenbacher 	status = -EIO;
44041ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[0]))
44051ca843a2SAndreas Gruenbacher 		goto xdr_error;
44061ca843a2SAndreas Gruenbacher 
44071da177e4SLinus Torvalds 	if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
44081da177e4SLinus Torvalds 		goto xdr_error;
44091da177e4SLinus Torvalds 	if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
44101da177e4SLinus Torvalds 		goto xdr_error;
44111da177e4SLinus Torvalds 	if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
44121da177e4SLinus Torvalds 		goto xdr_error;
44131da177e4SLinus Torvalds 
44141da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
44151da177e4SLinus Torvalds xdr_error:
44163110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
44171da177e4SLinus Torvalds 	return status;
44181da177e4SLinus Torvalds }
44191da177e4SLinus Torvalds 
44201da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
44211da177e4SLinus Torvalds {
4422256e48bbSTrond Myklebust 	unsigned int savep;
4423dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
44241da177e4SLinus Torvalds 	int status;
44251da177e4SLinus Torvalds 
44261da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
44271da177e4SLinus Torvalds 		goto xdr_error;
44281da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
44291da177e4SLinus Torvalds 		goto xdr_error;
44301da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
44311da177e4SLinus Torvalds 		goto xdr_error;
44321da177e4SLinus Torvalds 
44331da177e4SLinus Torvalds 	if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
44341da177e4SLinus Torvalds 		goto xdr_error;
44351da177e4SLinus Torvalds 	if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
44361da177e4SLinus Torvalds 		goto xdr_error;
44371da177e4SLinus Torvalds 
44381da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
44391da177e4SLinus Torvalds xdr_error:
44403110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
44411da177e4SLinus Torvalds 	return status;
44421da177e4SLinus Torvalds }
44431da177e4SLinus Torvalds 
444488034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr,
444588034c3dSAndy Adamson 				  uint32_t *bitmap,
444688034c3dSAndy Adamson 				  uint64_t *res,
444788034c3dSAndy Adamson 				  uint32_t hint_bit)
444888034c3dSAndy Adamson {
444988034c3dSAndy Adamson 	__be32 *p;
445088034c3dSAndy Adamson 
445188034c3dSAndy Adamson 	*res = 0;
445288034c3dSAndy Adamson 	if (likely(bitmap[0] & hint_bit)) {
445388034c3dSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
445488034c3dSAndy Adamson 		if (unlikely(!p))
445588034c3dSAndy Adamson 			goto out_overflow;
445688034c3dSAndy Adamson 		xdr_decode_hyper(p, res);
445788034c3dSAndy Adamson 	}
445888034c3dSAndy Adamson 	return 0;
445988034c3dSAndy Adamson out_overflow:
446088034c3dSAndy Adamson 	print_overflow_msg(__func__, xdr);
446188034c3dSAndy Adamson 	return -EIO;
446288034c3dSAndy Adamson }
446388034c3dSAndy Adamson 
446488034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr,
446588034c3dSAndy Adamson 					struct nfs4_threshold *res)
446688034c3dSAndy Adamson {
4467256e48bbSTrond Myklebust 	__be32 *p;
4468256e48bbSTrond Myklebust 	unsigned int savep;
446988034c3dSAndy Adamson 	uint32_t bitmap[3] = {0,}, attrlen;
447088034c3dSAndy Adamson 	int status;
447188034c3dSAndy Adamson 
447288034c3dSAndy Adamson 	/* layout type */
447388034c3dSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
447488034c3dSAndy Adamson 	if (unlikely(!p)) {
447588034c3dSAndy Adamson 		print_overflow_msg(__func__, xdr);
447688034c3dSAndy Adamson 		return -EIO;
447788034c3dSAndy Adamson 	}
447888034c3dSAndy Adamson 	res->l_type = be32_to_cpup(p);
447988034c3dSAndy Adamson 
448088034c3dSAndy Adamson 	/* thi_hintset bitmap */
448188034c3dSAndy Adamson 	status = decode_attr_bitmap(xdr, bitmap);
448288034c3dSAndy Adamson 	if (status < 0)
448388034c3dSAndy Adamson 		goto xdr_error;
448488034c3dSAndy Adamson 
448588034c3dSAndy Adamson 	/* thi_hintlist length */
448688034c3dSAndy Adamson 	status = decode_attr_length(xdr, &attrlen, &savep);
448788034c3dSAndy Adamson 	if (status < 0)
448888034c3dSAndy Adamson 		goto xdr_error;
448988034c3dSAndy Adamson 	/* thi_hintlist */
449088034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
449188034c3dSAndy Adamson 	if (status < 0)
449288034c3dSAndy Adamson 		goto xdr_error;
449388034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
449488034c3dSAndy Adamson 	if (status < 0)
449588034c3dSAndy Adamson 		goto xdr_error;
449688034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
449788034c3dSAndy Adamson 				       THRESHOLD_RD_IO);
449888034c3dSAndy Adamson 	if (status < 0)
449988034c3dSAndy Adamson 		goto xdr_error;
450088034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
450188034c3dSAndy Adamson 				       THRESHOLD_WR_IO);
450288034c3dSAndy Adamson 	if (status < 0)
450388034c3dSAndy Adamson 		goto xdr_error;
450488034c3dSAndy Adamson 
450588034c3dSAndy Adamson 	status = verify_attr_len(xdr, savep, attrlen);
450688034c3dSAndy Adamson 	res->bm = bitmap[0];
450788034c3dSAndy Adamson 
450888034c3dSAndy Adamson 	dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
450988034c3dSAndy Adamson 		 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
451088034c3dSAndy Adamson 		res->wr_io_sz);
451188034c3dSAndy Adamson xdr_error:
451288034c3dSAndy Adamson 	dprintk("%s ret=%d!\n", __func__, status);
451388034c3dSAndy Adamson 	return status;
451488034c3dSAndy Adamson }
451588034c3dSAndy Adamson 
451688034c3dSAndy Adamson /*
451788034c3dSAndy Adamson  * Thresholds on pNFS direct I/O vrs MDS I/O
451888034c3dSAndy Adamson  */
451988034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
452088034c3dSAndy Adamson 				    uint32_t *bitmap,
452188034c3dSAndy Adamson 				    struct nfs4_threshold *res)
452288034c3dSAndy Adamson {
452388034c3dSAndy Adamson 	__be32 *p;
452488034c3dSAndy Adamson 	int status = 0;
452588034c3dSAndy Adamson 	uint32_t num;
452688034c3dSAndy Adamson 
452788034c3dSAndy Adamson 	if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
452888034c3dSAndy Adamson 		return -EIO;
4529029c5347STrond Myklebust 	if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
45301549210fSTrond Myklebust 		/* Did the server return an unrequested attribute? */
45311549210fSTrond Myklebust 		if (unlikely(res == NULL))
45321549210fSTrond Myklebust 			return -EREMOTEIO;
453388034c3dSAndy Adamson 		p = xdr_inline_decode(xdr, 4);
453488034c3dSAndy Adamson 		if (unlikely(!p))
453588034c3dSAndy Adamson 			goto out_overflow;
453688034c3dSAndy Adamson 		num = be32_to_cpup(p);
453788034c3dSAndy Adamson 		if (num == 0)
453888034c3dSAndy Adamson 			return 0;
453988034c3dSAndy Adamson 		if (num > 1)
454088034c3dSAndy Adamson 			printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
454188034c3dSAndy Adamson 				"drivers per filesystem not supported\n",
454288034c3dSAndy Adamson 				__func__);
454388034c3dSAndy Adamson 
454488034c3dSAndy Adamson 		status = decode_first_threshold_item4(xdr, res);
4545029c5347STrond Myklebust 		bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
454688034c3dSAndy Adamson 	}
454788034c3dSAndy Adamson 	return status;
454888034c3dSAndy Adamson out_overflow:
454988034c3dSAndy Adamson 	print_overflow_msg(__func__, xdr);
455088034c3dSAndy Adamson 	return -EIO;
455188034c3dSAndy Adamson }
455288034c3dSAndy Adamson 
4553ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4554ae42c70aSBryan Schumaker 		struct nfs_fattr *fattr, struct nfs_fh *fh,
4555aa9c2669SDavid Quigley 		struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
45566926afd1STrond Myklebust 		const struct nfs_server *server)
45571da177e4SLinus Torvalds {
4558bca79478STrond Myklebust 	int status;
4559bca79478STrond Myklebust 	umode_t fmode = 0;
4560ae42c70aSBryan Schumaker 	uint32_t type;
4561ee7b75fcSTrond Myklebust 	int32_t err;
45621da177e4SLinus Torvalds 
4563f26c7a78STrond Myklebust 	status = decode_attr_type(xdr, bitmap, &type);
4564f26c7a78STrond Myklebust 	if (status < 0)
45651da177e4SLinus Torvalds 		goto xdr_error;
4566409924e4STrond Myklebust 	fattr->mode = 0;
4567409924e4STrond Myklebust 	if (status != 0) {
4568409924e4STrond Myklebust 		fattr->mode |= nfs_type2fmt[type];
4569409924e4STrond Myklebust 		fattr->valid |= status;
4570409924e4STrond Myklebust 	}
45711da177e4SLinus Torvalds 
4572f26c7a78STrond Myklebust 	status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4573f26c7a78STrond Myklebust 	if (status < 0)
45741da177e4SLinus Torvalds 		goto xdr_error;
4575409924e4STrond Myklebust 	fattr->valid |= status;
4576f26c7a78STrond Myklebust 
4577f26c7a78STrond Myklebust 	status = decode_attr_size(xdr, bitmap, &fattr->size);
4578f26c7a78STrond Myklebust 	if (status < 0)
45791da177e4SLinus Torvalds 		goto xdr_error;
4580409924e4STrond Myklebust 	fattr->valid |= status;
4581f26c7a78STrond Myklebust 
4582f26c7a78STrond Myklebust 	status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4583f26c7a78STrond Myklebust 	if (status < 0)
45841da177e4SLinus Torvalds 		goto xdr_error;
4585409924e4STrond Myklebust 	fattr->valid |= status;
4586f26c7a78STrond Myklebust 
4587ee7b75fcSTrond Myklebust 	err = 0;
4588ee7b75fcSTrond Myklebust 	status = decode_attr_error(xdr, bitmap, &err);
4589ae42c70aSBryan Schumaker 	if (status < 0)
4590ae42c70aSBryan Schumaker 		goto xdr_error;
4591ae42c70aSBryan Schumaker 
4592ae42c70aSBryan Schumaker 	status = decode_attr_filehandle(xdr, bitmap, fh);
4593ae42c70aSBryan Schumaker 	if (status < 0)
4594ae42c70aSBryan Schumaker 		goto xdr_error;
4595ae42c70aSBryan Schumaker 
4596f26c7a78STrond Myklebust 	status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4597f26c7a78STrond Myklebust 	if (status < 0)
45981da177e4SLinus Torvalds 		goto xdr_error;
4599409924e4STrond Myklebust 	fattr->valid |= status;
4600f26c7a78STrond Myklebust 
46018b7e3f49STrond Myklebust 	status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4602f26c7a78STrond Myklebust 	if (status < 0)
4603683b57b4STrond Myklebust 		goto xdr_error;
4604409924e4STrond Myklebust 	fattr->valid |= status;
4605f26c7a78STrond Myklebust 
46061ca843a2SAndreas Gruenbacher 	status = -EIO;
46071ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[0]))
46081ca843a2SAndreas Gruenbacher 		goto xdr_error;
46091ca843a2SAndreas Gruenbacher 
4610f26c7a78STrond Myklebust 	status = decode_attr_mode(xdr, bitmap, &fmode);
4611f26c7a78STrond Myklebust 	if (status < 0)
46121da177e4SLinus Torvalds 		goto xdr_error;
4613409924e4STrond Myklebust 	if (status != 0) {
46141da177e4SLinus Torvalds 		fattr->mode |= fmode;
4615409924e4STrond Myklebust 		fattr->valid |= status;
4616409924e4STrond Myklebust 	}
4617f26c7a78STrond Myklebust 
4618f26c7a78STrond Myklebust 	status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4619f26c7a78STrond Myklebust 	if (status < 0)
46201da177e4SLinus Torvalds 		goto xdr_error;
4621409924e4STrond Myklebust 	fattr->valid |= status;
4622f26c7a78STrond Myklebust 
46236926afd1STrond Myklebust 	status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4624f26c7a78STrond Myklebust 	if (status < 0)
46251da177e4SLinus Torvalds 		goto xdr_error;
4626409924e4STrond Myklebust 	fattr->valid |= status;
4627f26c7a78STrond Myklebust 
46286926afd1STrond Myklebust 	status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4629f26c7a78STrond Myklebust 	if (status < 0)
46301da177e4SLinus Torvalds 		goto xdr_error;
4631409924e4STrond Myklebust 	fattr->valid |= status;
4632f26c7a78STrond Myklebust 
4633f26c7a78STrond Myklebust 	status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4634f26c7a78STrond Myklebust 	if (status < 0)
46351da177e4SLinus Torvalds 		goto xdr_error;
4636409924e4STrond Myklebust 	fattr->valid |= status;
4637f26c7a78STrond Myklebust 
4638f26c7a78STrond Myklebust 	status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4639f26c7a78STrond Myklebust 	if (status < 0)
46401da177e4SLinus Torvalds 		goto xdr_error;
4641409924e4STrond Myklebust 	fattr->valid |= status;
4642f26c7a78STrond Myklebust 
4643f26c7a78STrond Myklebust 	status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4644f26c7a78STrond Myklebust 	if (status < 0)
46451da177e4SLinus Torvalds 		goto xdr_error;
4646409924e4STrond Myklebust 	fattr->valid |= status;
4647f26c7a78STrond Myklebust 
4648f26c7a78STrond Myklebust 	status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4649f26c7a78STrond Myklebust 	if (status < 0)
46501da177e4SLinus Torvalds 		goto xdr_error;
4651409924e4STrond Myklebust 	fattr->valid |= status;
4652f26c7a78STrond Myklebust 
4653f26c7a78STrond Myklebust 	status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4654f26c7a78STrond Myklebust 	if (status < 0)
46551da177e4SLinus Torvalds 		goto xdr_error;
4656409924e4STrond Myklebust 	fattr->valid |= status;
4657f26c7a78STrond Myklebust 
465828331a46STrond Myklebust 	status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4659f26c7a78STrond Myklebust 	if (status < 0)
466099baf625SManoj Naik 		goto xdr_error;
4661409924e4STrond Myklebust 	fattr->valid |= status;
4662f26c7a78STrond Myklebust 
46631ca843a2SAndreas Gruenbacher 	status = -EIO;
46641ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[1]))
46651ca843a2SAndreas Gruenbacher 		goto xdr_error;
46661ca843a2SAndreas Gruenbacher 
466788034c3dSAndy Adamson 	status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
466888034c3dSAndy Adamson 	if (status < 0)
466988034c3dSAndy Adamson 		goto xdr_error;
467088034c3dSAndy Adamson 
4671aa9c2669SDavid Quigley 	if (label) {
4672aa9c2669SDavid Quigley 		status = decode_attr_security_label(xdr, bitmap, label);
4673aa9c2669SDavid Quigley 		if (status < 0)
4674aa9c2669SDavid Quigley 			goto xdr_error;
4675aa9c2669SDavid Quigley 		fattr->valid |= status;
4676aa9c2669SDavid Quigley 	}
4677aa9c2669SDavid Quigley 
4678ae42c70aSBryan Schumaker xdr_error:
4679ae42c70aSBryan Schumaker 	dprintk("%s: xdr returned %d\n", __func__, -status);
4680ae42c70aSBryan Schumaker 	return status;
4681ae42c70aSBryan Schumaker }
4682ae42c70aSBryan Schumaker 
4683ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
46848b7e3f49STrond Myklebust 		struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4685aa9c2669SDavid Quigley 		struct nfs4_label *label, const struct nfs_server *server)
4686ae42c70aSBryan Schumaker {
4687256e48bbSTrond Myklebust 	unsigned int savep;
4688ae42c70aSBryan Schumaker 	uint32_t attrlen,
4689dae100c2SFred Isaman 		 bitmap[3] = {0};
4690ae42c70aSBryan Schumaker 	int status;
4691ae42c70aSBryan Schumaker 
4692ae42c70aSBryan Schumaker 	status = decode_op_hdr(xdr, OP_GETATTR);
4693ae42c70aSBryan Schumaker 	if (status < 0)
4694ae42c70aSBryan Schumaker 		goto xdr_error;
4695ae42c70aSBryan Schumaker 
4696ae42c70aSBryan Schumaker 	status = decode_attr_bitmap(xdr, bitmap);
4697ae42c70aSBryan Schumaker 	if (status < 0)
4698ae42c70aSBryan Schumaker 		goto xdr_error;
4699ae42c70aSBryan Schumaker 
4700ae42c70aSBryan Schumaker 	status = decode_attr_length(xdr, &attrlen, &savep);
4701ae42c70aSBryan Schumaker 	if (status < 0)
4702ae42c70aSBryan Schumaker 		goto xdr_error;
4703ae42c70aSBryan Schumaker 
4704aa9c2669SDavid Quigley 	status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4705aa9c2669SDavid Quigley 					label, server);
4706ae42c70aSBryan Schumaker 	if (status < 0)
4707ae42c70aSBryan Schumaker 		goto xdr_error;
4708ae42c70aSBryan Schumaker 
4709f26c7a78STrond Myklebust 	status = verify_attr_len(xdr, savep, attrlen);
47101da177e4SLinus Torvalds xdr_error:
47113110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d\n", __func__, -status);
47121da177e4SLinus Torvalds 	return status;
47131da177e4SLinus Torvalds }
47141da177e4SLinus Torvalds 
4715aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4716aa9c2669SDavid Quigley 		struct nfs4_label *label, const struct nfs_server *server)
4717aa9c2669SDavid Quigley {
4718aa9c2669SDavid Quigley 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4719aa9c2669SDavid Quigley }
4720aa9c2669SDavid Quigley 
4721ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
47226926afd1STrond Myklebust 		const struct nfs_server *server)
4723ae42c70aSBryan Schumaker {
4724aa9c2669SDavid Quigley 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
4725ae42c70aSBryan Schumaker }
47261da177e4SLinus Torvalds 
4727504913fbSAndy Adamson /*
4728504913fbSAndy Adamson  * Decode potentially multiple layout types. Currently we only support
4729504913fbSAndy Adamson  * one layout driver per file system.
4730504913fbSAndy Adamson  */
4731504913fbSAndy Adamson static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4732504913fbSAndy Adamson 					 uint32_t *layouttype)
4733504913fbSAndy Adamson {
4734b8a8a0ddSTrond Myklebust 	__be32 *p;
4735504913fbSAndy Adamson 	int num;
4736504913fbSAndy Adamson 
4737504913fbSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
4738504913fbSAndy Adamson 	if (unlikely(!p))
4739504913fbSAndy Adamson 		goto out_overflow;
4740504913fbSAndy Adamson 	num = be32_to_cpup(p);
4741504913fbSAndy Adamson 
4742504913fbSAndy Adamson 	/* pNFS is not supported by the underlying file system */
4743504913fbSAndy Adamson 	if (num == 0) {
4744504913fbSAndy Adamson 		*layouttype = 0;
4745504913fbSAndy Adamson 		return 0;
4746504913fbSAndy Adamson 	}
4747504913fbSAndy Adamson 	if (num > 1)
4748a030889aSWeston Andros Adamson 		printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4749a030889aSWeston Andros Adamson 			"drivers per filesystem not supported\n", __func__);
4750504913fbSAndy Adamson 
4751504913fbSAndy Adamson 	/* Decode and set first layout type, move xdr->p past unused types */
4752504913fbSAndy Adamson 	p = xdr_inline_decode(xdr, num * 4);
4753504913fbSAndy Adamson 	if (unlikely(!p))
4754504913fbSAndy Adamson 		goto out_overflow;
4755504913fbSAndy Adamson 	*layouttype = be32_to_cpup(p);
4756504913fbSAndy Adamson 	return 0;
4757504913fbSAndy Adamson out_overflow:
4758504913fbSAndy Adamson 	print_overflow_msg(__func__, xdr);
4759504913fbSAndy Adamson 	return -EIO;
4760504913fbSAndy Adamson }
4761504913fbSAndy Adamson 
4762504913fbSAndy Adamson /*
4763504913fbSAndy Adamson  * The type of file system exported.
4764504913fbSAndy Adamson  * Note we must ensure that layouttype is set in any non-error case.
4765504913fbSAndy Adamson  */
4766504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4767504913fbSAndy Adamson 				uint32_t *layouttype)
4768504913fbSAndy Adamson {
4769504913fbSAndy Adamson 	int status = 0;
4770504913fbSAndy Adamson 
4771504913fbSAndy Adamson 	dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4772504913fbSAndy Adamson 	if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4773504913fbSAndy Adamson 		return -EIO;
4774504913fbSAndy Adamson 	if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4775504913fbSAndy Adamson 		status = decode_first_pnfs_layout_type(xdr, layouttype);
4776504913fbSAndy Adamson 		bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4777504913fbSAndy Adamson 	} else
4778504913fbSAndy Adamson 		*layouttype = 0;
4779504913fbSAndy Adamson 	return status;
4780504913fbSAndy Adamson }
4781504913fbSAndy Adamson 
4782dae100c2SFred Isaman /*
4783dae100c2SFred Isaman  * The prefered block size for layout directed io
4784dae100c2SFred Isaman  */
4785dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4786dae100c2SFred Isaman 				      uint32_t *res)
4787dae100c2SFred Isaman {
4788dae100c2SFred Isaman 	__be32 *p;
4789dae100c2SFred Isaman 
4790dae100c2SFred Isaman 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4791dae100c2SFred Isaman 	*res = 0;
4792dae100c2SFred Isaman 	if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4793dae100c2SFred Isaman 		p = xdr_inline_decode(xdr, 4);
4794dae100c2SFred Isaman 		if (unlikely(!p)) {
4795dae100c2SFred Isaman 			print_overflow_msg(__func__, xdr);
4796dae100c2SFred Isaman 			return -EIO;
4797dae100c2SFred Isaman 		}
4798dae100c2SFred Isaman 		*res = be32_to_cpup(p);
4799dae100c2SFred Isaman 		bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4800dae100c2SFred Isaman 	}
4801dae100c2SFred Isaman 	return 0;
4802dae100c2SFred Isaman }
4803dae100c2SFred Isaman 
48042a92ee92SPeng Tao /*
48052a92ee92SPeng Tao  * The granularity of a CLONE operation.
48062a92ee92SPeng Tao  */
48072a92ee92SPeng Tao static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
48082a92ee92SPeng Tao 				     uint32_t *res)
48092a92ee92SPeng Tao {
48102a92ee92SPeng Tao 	__be32 *p;
48112a92ee92SPeng Tao 
48122a92ee92SPeng Tao 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
48132a92ee92SPeng Tao 	*res = 0;
48142a92ee92SPeng Tao 	if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
48152a92ee92SPeng Tao 		p = xdr_inline_decode(xdr, 4);
48162a92ee92SPeng Tao 		if (unlikely(!p)) {
48172a92ee92SPeng Tao 			print_overflow_msg(__func__, xdr);
48182a92ee92SPeng Tao 			return -EIO;
48192a92ee92SPeng Tao 		}
48202a92ee92SPeng Tao 		*res = be32_to_cpup(p);
48212a92ee92SPeng Tao 		bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
48222a92ee92SPeng Tao 	}
48232a92ee92SPeng Tao 	return 0;
48242a92ee92SPeng Tao }
48252a92ee92SPeng Tao 
48261da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
48271da177e4SLinus Torvalds {
4828256e48bbSTrond Myklebust 	unsigned int savep;
4829dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3];
48301da177e4SLinus Torvalds 	int status;
48311da177e4SLinus Torvalds 
48321da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
48331da177e4SLinus Torvalds 		goto xdr_error;
48341da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
48351da177e4SLinus Torvalds 		goto xdr_error;
48361da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
48371da177e4SLinus Torvalds 		goto xdr_error;
48381da177e4SLinus Torvalds 
48391da177e4SLinus Torvalds 	fsinfo->rtmult = fsinfo->wtmult = 512;	/* ??? */
48401da177e4SLinus Torvalds 
48411da177e4SLinus Torvalds 	if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
48421da177e4SLinus Torvalds 		goto xdr_error;
48431da177e4SLinus Torvalds 	if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
48441da177e4SLinus Torvalds 		goto xdr_error;
48451da177e4SLinus Torvalds 	if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
48461da177e4SLinus Torvalds 		goto xdr_error;
48471da177e4SLinus Torvalds 	fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
48481da177e4SLinus Torvalds 	if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
48491da177e4SLinus Torvalds 		goto xdr_error;
48501da177e4SLinus Torvalds 	fsinfo->wtpref = fsinfo->wtmax;
48511ca843a2SAndreas Gruenbacher 
48521ca843a2SAndreas Gruenbacher 	status = -EIO;
48531ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[0]))
48541ca843a2SAndreas Gruenbacher 		goto xdr_error;
48551ca843a2SAndreas Gruenbacher 
485655b6e774SRicardo Labiaga 	status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
485755b6e774SRicardo Labiaga 	if (status != 0)
485855b6e774SRicardo Labiaga 		goto xdr_error;
4859504913fbSAndy Adamson 	status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4860504913fbSAndy Adamson 	if (status != 0)
4861504913fbSAndy Adamson 		goto xdr_error;
48621ca843a2SAndreas Gruenbacher 
48631ca843a2SAndreas Gruenbacher 	status = -EIO;
48641ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[1]))
48651ca843a2SAndreas Gruenbacher 		goto xdr_error;
48661ca843a2SAndreas Gruenbacher 
4867dae100c2SFred Isaman 	status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4868dae100c2SFred Isaman 	if (status)
4869dae100c2SFred Isaman 		goto xdr_error;
48702a92ee92SPeng Tao 	status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
48712a92ee92SPeng Tao 	if (status)
48722a92ee92SPeng Tao 		goto xdr_error;
48731da177e4SLinus Torvalds 
48741da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
48751da177e4SLinus Torvalds xdr_error:
48763110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
48771da177e4SLinus Torvalds 	return status;
48781da177e4SLinus Torvalds }
48791da177e4SLinus Torvalds 
48801da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
48811da177e4SLinus Torvalds {
48828687b63aSAl Viro 	__be32 *p;
48831da177e4SLinus Torvalds 	uint32_t len;
48841da177e4SLinus Torvalds 	int status;
48851da177e4SLinus Torvalds 
48869936781dSTrond Myklebust 	/* Zero handle first to allow comparisons */
48879936781dSTrond Myklebust 	memset(fh, 0, sizeof(*fh));
48889936781dSTrond Myklebust 
48891da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_GETFH);
48901da177e4SLinus Torvalds 	if (status)
48911da177e4SLinus Torvalds 		return status;
48921da177e4SLinus Torvalds 
4893c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4894c0eae66eSBenny Halevy 	if (unlikely(!p))
4895c0eae66eSBenny Halevy 		goto out_overflow;
4896cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
48971da177e4SLinus Torvalds 	if (len > NFS4_FHSIZE)
48981da177e4SLinus Torvalds 		return -EIO;
48991da177e4SLinus Torvalds 	fh->size = len;
4900c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, len);
4901c0eae66eSBenny Halevy 	if (unlikely(!p))
4902c0eae66eSBenny Halevy 		goto out_overflow;
490399398d06SBenny Halevy 	memcpy(fh->data, p, len);
49041da177e4SLinus Torvalds 	return 0;
4905c0eae66eSBenny Halevy out_overflow:
4906c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4907c0eae66eSBenny Halevy 	return -EIO;
49081da177e4SLinus Torvalds }
49091da177e4SLinus Torvalds 
49101da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
49111da177e4SLinus Torvalds {
49121da177e4SLinus Torvalds 	int status;
49131da177e4SLinus Torvalds 
49141da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LINK);
49151da177e4SLinus Torvalds 	if (status)
49161da177e4SLinus Torvalds 		return status;
49171da177e4SLinus Torvalds 	return decode_change_info(xdr, cinfo);
49181da177e4SLinus Torvalds }
49191da177e4SLinus Torvalds 
49201da177e4SLinus Torvalds /*
49211da177e4SLinus Torvalds  * We create the owner, so we know a proper owner.id length is 4.
49221da177e4SLinus Torvalds  */
4923911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
49241da177e4SLinus Torvalds {
4925911d1aafSTrond Myklebust 	uint64_t offset, length, clientid;
49268687b63aSAl Viro 	__be32 *p;
4927911d1aafSTrond Myklebust 	uint32_t namelen, type;
49281da177e4SLinus Torvalds 
4929babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4930c0eae66eSBenny Halevy 	if (unlikely(!p))
4931c0eae66eSBenny Halevy 		goto out_overflow;
4932babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
49333ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &length);
4934babddc72SBryan Schumaker 	type = be32_to_cpup(p++); /* 4 byte read */
4935babddc72SBryan Schumaker 	if (fl != NULL) { /* manipulate file lock */
4936911d1aafSTrond Myklebust 		fl->fl_start = (loff_t)offset;
4937911d1aafSTrond Myklebust 		fl->fl_end = fl->fl_start + (loff_t)length - 1;
4938911d1aafSTrond Myklebust 		if (length == ~(uint64_t)0)
4939911d1aafSTrond Myklebust 			fl->fl_end = OFFSET_MAX;
4940911d1aafSTrond Myklebust 		fl->fl_type = F_WRLCK;
4941911d1aafSTrond Myklebust 		if (type & 1)
4942911d1aafSTrond Myklebust 			fl->fl_type = F_RDLCK;
4943911d1aafSTrond Myklebust 		fl->fl_pid = 0;
4944911d1aafSTrond Myklebust 	}
4945babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4946babddc72SBryan Schumaker 	namelen = be32_to_cpup(p); /* read 4 bytes */  /* have read all 32 bytes now */
4947babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, namelen); /* variable size field */
4948c0eae66eSBenny Halevy 	if (likely(p))
49491da177e4SLinus Torvalds 		return -NFS4ERR_DENIED;
4950c0eae66eSBenny Halevy out_overflow:
4951c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
4952c0eae66eSBenny Halevy 	return -EIO;
49531da177e4SLinus Torvalds }
49541da177e4SLinus Torvalds 
4955911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
49561da177e4SLinus Torvalds {
49571da177e4SLinus Torvalds 	int status;
49581da177e4SLinus Torvalds 
49591da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCK);
4960c1d51931STrond Myklebust 	if (status == -EIO)
4961c1d51931STrond Myklebust 		goto out;
49621da177e4SLinus Torvalds 	if (status == 0) {
496393b717fdSTrond Myklebust 		status = decode_lock_stateid(xdr, &res->stateid);
496407d30434SBenny Halevy 		if (unlikely(status))
496507d30434SBenny Halevy 			goto out;
49661da177e4SLinus Torvalds 	} else if (status == -NFS4ERR_DENIED)
4967c1d51931STrond Myklebust 		status = decode_lock_denied(xdr, NULL);
4968c1d51931STrond Myklebust 	if (res->open_seqid != NULL)
4969c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->open_seqid);
4970c1d51931STrond Myklebust 	nfs_increment_lock_seqid(status, res->lock_seqid);
4971c1d51931STrond Myklebust out:
49721da177e4SLinus Torvalds 	return status;
49731da177e4SLinus Torvalds }
49741da177e4SLinus Torvalds 
4975911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
49761da177e4SLinus Torvalds {
49771da177e4SLinus Torvalds 	int status;
49781da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKT);
49791da177e4SLinus Torvalds 	if (status == -NFS4ERR_DENIED)
4980911d1aafSTrond Myklebust 		return decode_lock_denied(xdr, res->denied);
49811da177e4SLinus Torvalds 	return status;
49821da177e4SLinus Torvalds }
49831da177e4SLinus Torvalds 
4984911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
49851da177e4SLinus Torvalds {
49861da177e4SLinus Torvalds 	int status;
49871da177e4SLinus Torvalds 
49881da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKU);
4989c1d51931STrond Myklebust 	if (status != -EIO)
4990c1d51931STrond Myklebust 		nfs_increment_lock_seqid(status, res->seqid);
499107d30434SBenny Halevy 	if (status == 0)
499293b717fdSTrond Myklebust 		status = decode_lock_stateid(xdr, &res->stateid);
49931da177e4SLinus Torvalds 	return status;
49941da177e4SLinus Torvalds }
49951da177e4SLinus Torvalds 
4996d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr)
4997d3c7b7ccSTrond Myklebust {
4998d3c7b7ccSTrond Myklebust 	return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4999d3c7b7ccSTrond Myklebust }
5000d3c7b7ccSTrond Myklebust 
50011da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr)
50021da177e4SLinus Torvalds {
50031da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_LOOKUP);
50041da177e4SLinus Torvalds }
50051da177e4SLinus Torvalds 
50061da177e4SLinus Torvalds /* This is too sick! */
50077d160a6cSTrond Myklebust static int decode_space_limit(struct xdr_stream *xdr,
50087d160a6cSTrond Myklebust 		unsigned long *pagemod_limit)
50091da177e4SLinus Torvalds {
50108687b63aSAl Viro 	__be32 *p;
50111da177e4SLinus Torvalds 	uint32_t limit_type, nblocks, blocksize;
50127d160a6cSTrond Myklebust 	u64 maxsize = 0;
50131da177e4SLinus Torvalds 
5014c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
5015c0eae66eSBenny Halevy 	if (unlikely(!p))
5016c0eae66eSBenny Halevy 		goto out_overflow;
50176f723f77SBenny Halevy 	limit_type = be32_to_cpup(p++);
50181da177e4SLinus Torvalds 	switch (limit_type) {
50197d160a6cSTrond Myklebust 	case NFS4_LIMIT_SIZE:
50207d160a6cSTrond Myklebust 		xdr_decode_hyper(p, &maxsize);
50211da177e4SLinus Torvalds 		break;
50227d160a6cSTrond Myklebust 	case NFS4_LIMIT_BLOCKS:
50236f723f77SBenny Halevy 		nblocks = be32_to_cpup(p++);
5024cccddf4fSBenny Halevy 		blocksize = be32_to_cpup(p);
50257d160a6cSTrond Myklebust 		maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
50261da177e4SLinus Torvalds 	}
502709cbfeafSKirill A. Shutemov 	maxsize >>= PAGE_SHIFT;
50287d160a6cSTrond Myklebust 	*pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
50291da177e4SLinus Torvalds 	return 0;
5030c0eae66eSBenny Halevy out_overflow:
5031c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5032c0eae66eSBenny Halevy 	return -EIO;
50331da177e4SLinus Torvalds }
50341da177e4SLinus Torvalds 
50356ae37339STrond Myklebust static int decode_rw_delegation(struct xdr_stream *xdr,
50366ae37339STrond Myklebust 		uint32_t delegation_type,
50376ae37339STrond Myklebust 		struct nfs_openres *res)
50381da177e4SLinus Torvalds {
50398687b63aSAl Viro 	__be32 *p;
504007d30434SBenny Halevy 	int status;
50411da177e4SLinus Torvalds 
504293b717fdSTrond Myklebust 	status = decode_delegation_stateid(xdr, &res->delegation);
504307d30434SBenny Halevy 	if (unlikely(status))
504407d30434SBenny Halevy 		return status;
5045c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5046c0eae66eSBenny Halevy 	if (unlikely(!p))
5047c0eae66eSBenny Halevy 		goto out_overflow;
5048cccddf4fSBenny Halevy 	res->do_recall = be32_to_cpup(p);
504905d564feSAndy Adamson 
50501da177e4SLinus Torvalds 	switch (delegation_type) {
50511da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_READ:
50521da177e4SLinus Torvalds 		res->delegation_type = FMODE_READ;
50531da177e4SLinus Torvalds 		break;
50541da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_WRITE:
50551da177e4SLinus Torvalds 		res->delegation_type = FMODE_WRITE|FMODE_READ;
50567d160a6cSTrond Myklebust 		if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
50571da177e4SLinus Torvalds 				return -EIO;
50581da177e4SLinus Torvalds 	}
50597539bbabSDavid Howells 	return decode_ace(xdr, NULL, res->server->nfs_client);
5060c0eae66eSBenny Halevy out_overflow:
5061c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5062c0eae66eSBenny Halevy 	return -EIO;
50631da177e4SLinus Torvalds }
50641da177e4SLinus Torvalds 
50656ae37339STrond Myklebust static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
50666ae37339STrond Myklebust {
50676ae37339STrond Myklebust 	__be32 *p;
50686ae37339STrond Myklebust 	uint32_t why_no_delegation;
50696ae37339STrond Myklebust 
50706ae37339STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
50716ae37339STrond Myklebust 	if (unlikely(!p))
50726ae37339STrond Myklebust 		goto out_overflow;
50736ae37339STrond Myklebust 	why_no_delegation = be32_to_cpup(p);
50746ae37339STrond Myklebust 	switch (why_no_delegation) {
50756ae37339STrond Myklebust 		case WND4_CONTENTION:
50766ae37339STrond Myklebust 		case WND4_RESOURCE:
50776ae37339STrond Myklebust 			xdr_inline_decode(xdr, 4);
50786ae37339STrond Myklebust 			/* Ignore for now */
50796ae37339STrond Myklebust 	}
50806ae37339STrond Myklebust 	return 0;
50816ae37339STrond Myklebust out_overflow:
50826ae37339STrond Myklebust 	print_overflow_msg(__func__, xdr);
50836ae37339STrond Myklebust 	return -EIO;
50846ae37339STrond Myklebust }
50856ae37339STrond Myklebust 
50866ae37339STrond Myklebust static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
50876ae37339STrond Myklebust {
50886ae37339STrond Myklebust 	__be32 *p;
50896ae37339STrond Myklebust 	uint32_t delegation_type;
50906ae37339STrond Myklebust 
50916ae37339STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
50926ae37339STrond Myklebust 	if (unlikely(!p))
50936ae37339STrond Myklebust 		goto out_overflow;
50946ae37339STrond Myklebust 	delegation_type = be32_to_cpup(p);
50956ae37339STrond Myklebust 	res->delegation_type = 0;
50966ae37339STrond Myklebust 	switch (delegation_type) {
50976ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_NONE:
50986ae37339STrond Myklebust 		return 0;
50996ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_READ:
51006ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_WRITE:
51016ae37339STrond Myklebust 		return decode_rw_delegation(xdr, delegation_type, res);
51026ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_NONE_EXT:
51036ae37339STrond Myklebust 		return decode_no_delegation(xdr, res);
51046ae37339STrond Myklebust 	}
51056ae37339STrond Myklebust 	return -EIO;
51066ae37339STrond Myklebust out_overflow:
51076ae37339STrond Myklebust 	print_overflow_msg(__func__, xdr);
51086ae37339STrond Myklebust 	return -EIO;
51096ae37339STrond Myklebust }
51106ae37339STrond Myklebust 
51111da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
51121da177e4SLinus Torvalds {
51138687b63aSAl Viro 	__be32 *p;
5114aa53ed54SJeff Layton 	uint32_t savewords, bmlen, i;
51151da177e4SLinus Torvalds 	int status;
51161da177e4SLinus Torvalds 
5117c7848f69STrond Myklebust 	if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5118c7848f69STrond Myklebust 		return status;
5119c1d51931STrond Myklebust 	nfs_increment_open_seqid(status, res->seqid);
5120c7848f69STrond Myklebust 	if (status)
5121c7848f69STrond Myklebust 		return status;
512293b717fdSTrond Myklebust 	status = decode_open_stateid(xdr, &res->stateid);
512307d30434SBenny Halevy 	if (unlikely(status))
51241da177e4SLinus Torvalds 		return status;
51251da177e4SLinus Torvalds 
51261da177e4SLinus Torvalds 	decode_change_info(xdr, &res->cinfo);
51271da177e4SLinus Torvalds 
5128c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5129c0eae66eSBenny Halevy 	if (unlikely(!p))
5130c0eae66eSBenny Halevy 		goto out_overflow;
51316f723f77SBenny Halevy 	res->rflags = be32_to_cpup(p++);
5132cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
51331da177e4SLinus Torvalds 	if (bmlen > 10)
51341da177e4SLinus Torvalds 		goto xdr_error;
51351da177e4SLinus Torvalds 
5136c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
5137c0eae66eSBenny Halevy 	if (unlikely(!p))
5138c0eae66eSBenny Halevy 		goto out_overflow;
5139aa53ed54SJeff Layton 	savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5140aa53ed54SJeff Layton 	for (i = 0; i < savewords; ++i)
51416f723f77SBenny Halevy 		res->attrset[i] = be32_to_cpup(p++);
5142aa53ed54SJeff Layton 	for (; i < NFS4_BITMAP_SIZE; i++)
5143aa53ed54SJeff Layton 		res->attrset[i] = 0;
5144aa53ed54SJeff Layton 
51451da177e4SLinus Torvalds 	return decode_delegation(xdr, res);
51461da177e4SLinus Torvalds xdr_error:
51473110ff80SHarvey Harrison 	dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
51481da177e4SLinus Torvalds 	return -EIO;
5149c0eae66eSBenny Halevy out_overflow:
5150c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5151c0eae66eSBenny Halevy 	return -EIO;
51521da177e4SLinus Torvalds }
51531da177e4SLinus Torvalds 
51541da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
51551da177e4SLinus Torvalds {
51561da177e4SLinus Torvalds 	int status;
51571da177e4SLinus Torvalds 
51581da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5159c1d51931STrond Myklebust 	if (status != -EIO)
5160c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
516107d30434SBenny Halevy 	if (!status)
516293b717fdSTrond Myklebust 		status = decode_open_stateid(xdr, &res->stateid);
51631da177e4SLinus Torvalds 	return status;
51641da177e4SLinus Torvalds }
51651da177e4SLinus Torvalds 
51661da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
51671da177e4SLinus Torvalds {
51681da177e4SLinus Torvalds 	int status;
51691da177e4SLinus Torvalds 
51701da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5171c1d51931STrond Myklebust 	if (status != -EIO)
5172c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
517307d30434SBenny Halevy 	if (!status)
517493b717fdSTrond Myklebust 		status = decode_open_stateid(xdr, &res->stateid);
51751da177e4SLinus Torvalds 	return status;
51761da177e4SLinus Torvalds }
51771da177e4SLinus Torvalds 
51781da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr)
51791da177e4SLinus Torvalds {
51801da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTFH);
51811da177e4SLinus Torvalds }
51821da177e4SLinus Torvalds 
51831da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr)
51841da177e4SLinus Torvalds {
51851da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTROOTFH);
51861da177e4SLinus Torvalds }
51871da177e4SLinus Torvalds 
51889137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
51899137bdf3SAnna Schumaker 		       struct nfs_pgio_res *res)
51901da177e4SLinus Torvalds {
51918687b63aSAl Viro 	__be32 *p;
519264bd577eSTrond Myklebust 	uint32_t count, eof, recvd;
51931da177e4SLinus Torvalds 	int status;
51941da177e4SLinus Torvalds 
51951da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READ);
51961da177e4SLinus Torvalds 	if (status)
51971da177e4SLinus Torvalds 		return status;
5198c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5199c0eae66eSBenny Halevy 	if (unlikely(!p))
5200c0eae66eSBenny Halevy 		goto out_overflow;
52016f723f77SBenny Halevy 	eof = be32_to_cpup(p++);
5202cccddf4fSBenny Halevy 	count = be32_to_cpup(p);
520364bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, count);
52041da177e4SLinus Torvalds 	if (count > recvd) {
5205fe82a183SChuck Lever 		dprintk("NFS: server cheating in read reply: "
52061da177e4SLinus Torvalds 				"count %u > recvd %u\n", count, recvd);
52071da177e4SLinus Torvalds 		count = recvd;
52081da177e4SLinus Torvalds 		eof = 0;
52091da177e4SLinus Torvalds 	}
52101da177e4SLinus Torvalds 	res->eof = eof;
52111da177e4SLinus Torvalds 	res->count = count;
52121da177e4SLinus Torvalds 	return 0;
5213c0eae66eSBenny Halevy out_overflow:
5214c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5215c0eae66eSBenny Halevy 	return -EIO;
52161da177e4SLinus Torvalds }
52171da177e4SLinus Torvalds 
52181da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
52191da177e4SLinus Torvalds {
5220bcecff77SChuck Lever 	int		status;
5221cd93710eSChuck Lever 	__be32		verf[2];
52221da177e4SLinus Torvalds 
52231da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READDIR);
5224db942bbdSBenny Halevy 	if (!status)
5225db942bbdSBenny Halevy 		status = decode_verifier(xdr, readdir->verifier.data);
5226db942bbdSBenny Halevy 	if (unlikely(status))
52271da177e4SLinus Torvalds 		return status;
5228cd93710eSChuck Lever 	memcpy(verf, readdir->verifier.data, sizeof(verf));
522944109241SFred Isaman 	dprintk("%s: verifier = %08x:%08x\n",
5230cd93710eSChuck Lever 			__func__, verf[0], verf[1]);
523164bd577eSTrond Myklebust 	return xdr_read_pages(xdr, xdr->buf->page_len);
52321da177e4SLinus Torvalds }
52331da177e4SLinus Torvalds 
52341da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
52351da177e4SLinus Torvalds {
52361da177e4SLinus Torvalds 	struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5237bcecff77SChuck Lever 	u32 len, recvd;
52388687b63aSAl Viro 	__be32 *p;
52391da177e4SLinus Torvalds 	int status;
52401da177e4SLinus Torvalds 
52411da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READLINK);
52421da177e4SLinus Torvalds 	if (status)
52431da177e4SLinus Torvalds 		return status;
52441da177e4SLinus Torvalds 
52451da177e4SLinus Torvalds 	/* Convert length of symlink */
5246c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5247c0eae66eSBenny Halevy 	if (unlikely(!p))
5248c0eae66eSBenny Halevy 		goto out_overflow;
5249cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
52501da177e4SLinus Torvalds 	if (len >= rcvbuf->page_len || len <= 0) {
5251fe82a183SChuck Lever 		dprintk("nfs: server returned giant symlink!\n");
52521da177e4SLinus Torvalds 		return -ENAMETOOLONG;
52531da177e4SLinus Torvalds 	}
525464bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, len);
52551da177e4SLinus Torvalds 	if (recvd < len) {
5256fe82a183SChuck Lever 		dprintk("NFS: server cheating in readlink reply: "
52571da177e4SLinus Torvalds 				"count %u > recvd %u\n", len, recvd);
52581da177e4SLinus Torvalds 		return -EIO;
52591da177e4SLinus Torvalds 	}
52601da177e4SLinus Torvalds 	/*
52611da177e4SLinus Torvalds 	 * The XDR encode routine has set things up so that
52621da177e4SLinus Torvalds 	 * the link text will be copied directly into the
52631da177e4SLinus Torvalds 	 * buffer.  We just have to do overflow-checking,
52641da177e4SLinus Torvalds 	 * and and null-terminate the text (the VFS expects
52651da177e4SLinus Torvalds 	 * null-termination).
52661da177e4SLinus Torvalds 	 */
5267b4687da7SChuck Lever 	xdr_terminate_string(rcvbuf, len);
52681da177e4SLinus Torvalds 	return 0;
5269c0eae66eSBenny Halevy out_overflow:
5270c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5271c0eae66eSBenny Halevy 	return -EIO;
52721da177e4SLinus Torvalds }
52731da177e4SLinus Torvalds 
52741da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
52751da177e4SLinus Torvalds {
52761da177e4SLinus Torvalds 	int status;
52771da177e4SLinus Torvalds 
52781da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_REMOVE);
52791da177e4SLinus Torvalds 	if (status)
52801da177e4SLinus Torvalds 		goto out;
52811da177e4SLinus Torvalds 	status = decode_change_info(xdr, cinfo);
52821da177e4SLinus Torvalds out:
52831da177e4SLinus Torvalds 	return status;
52841da177e4SLinus Torvalds }
52851da177e4SLinus Torvalds 
52861da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
52871da177e4SLinus Torvalds 	      struct nfs4_change_info *new_cinfo)
52881da177e4SLinus Torvalds {
52891da177e4SLinus Torvalds 	int status;
52901da177e4SLinus Torvalds 
52911da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_RENAME);
52921da177e4SLinus Torvalds 	if (status)
52931da177e4SLinus Torvalds 		goto out;
52941da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, old_cinfo)))
52951da177e4SLinus Torvalds 		goto out;
52961da177e4SLinus Torvalds 	status = decode_change_info(xdr, new_cinfo);
52971da177e4SLinus Torvalds out:
52981da177e4SLinus Torvalds 	return status;
52991da177e4SLinus Torvalds }
53001da177e4SLinus Torvalds 
53011da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr)
53021da177e4SLinus Torvalds {
53031da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_RENEW);
53041da177e4SLinus Torvalds }
53051da177e4SLinus Torvalds 
530656ae19f3STrond Myklebust static int
530756ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr)
530856ae19f3STrond Myklebust {
530956ae19f3STrond Myklebust 	return decode_op_hdr(xdr, OP_RESTOREFH);
531056ae19f3STrond Myklebust }
531156ae19f3STrond Myklebust 
5312029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5313bf118a34SAndy Adamson 			 struct nfs_getaclres *res)
5314029d105eSJ. Bruce Fields {
5315256e48bbSTrond Myklebust 	unsigned int savep;
5316029d105eSJ. Bruce Fields 	uint32_t attrlen,
5317dae100c2SFred Isaman 		 bitmap[3] = {0};
5318029d105eSJ. Bruce Fields 	int status;
5319cff298c7STrond Myklebust 	unsigned int pg_offset;
5320029d105eSJ. Bruce Fields 
5321bf118a34SAndy Adamson 	res->acl_len = 0;
5322029d105eSJ. Bruce Fields 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5323029d105eSJ. Bruce Fields 		goto out;
53245a006899SSachin Prabhu 
5325519d3959STrond Myklebust 	xdr_enter_page(xdr, xdr->buf->page_len);
5326519d3959STrond Myklebust 
5327cff298c7STrond Myklebust 	/* Calculate the offset of the page data */
5328cff298c7STrond Myklebust 	pg_offset = xdr->buf->head[0].iov_len;
53295a006899SSachin Prabhu 
5330029d105eSJ. Bruce Fields 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5331029d105eSJ. Bruce Fields 		goto out;
5332029d105eSJ. Bruce Fields 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5333029d105eSJ. Bruce Fields 		goto out;
5334029d105eSJ. Bruce Fields 
5335029d105eSJ. Bruce Fields 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5336029d105eSJ. Bruce Fields 		return -EIO;
5337029d105eSJ. Bruce Fields 	if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5338029d105eSJ. Bruce Fields 
5339bf118a34SAndy Adamson 		/* The bitmap (xdr len + bitmaps) and the attr xdr len words
5340bf118a34SAndy Adamson 		 * are stored with the acl data to handle the problem of
5341bf118a34SAndy Adamson 		 * variable length bitmaps.*/
5342cff298c7STrond Myklebust 		res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
5343519d3959STrond Myklebust 		res->acl_len = attrlen;
53441f1ea6c2STrond Myklebust 
53451f1ea6c2STrond Myklebust 		/* Check for receive buffer overflow */
53461f1ea6c2STrond Myklebust 		if (res->acl_len > (xdr->nwords << 2) ||
53471f1ea6c2STrond Myklebust 		    res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
53481f1ea6c2STrond Myklebust 			res->acl_flags |= NFS4_ACL_TRUNC;
5349519d3959STrond Myklebust 			dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5350cff298c7STrond Myklebust 					attrlen, xdr->nwords << 2);
5351029d105eSJ. Bruce Fields 		}
53528c233cf9SJ. Bruce Fields 	} else
53538c233cf9SJ. Bruce Fields 		status = -EOPNOTSUPP;
5354029d105eSJ. Bruce Fields 
5355029d105eSJ. Bruce Fields out:
5356029d105eSJ. Bruce Fields 	return status;
5357029d105eSJ. Bruce Fields }
5358029d105eSJ. Bruce Fields 
53591da177e4SLinus Torvalds static int
53601da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr)
53611da177e4SLinus Torvalds {
53621da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SAVEFH);
53631da177e4SLinus Torvalds }
53641da177e4SLinus Torvalds 
53659e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr)
53661da177e4SLinus Torvalds {
53678687b63aSAl Viro 	__be32 *p;
53681da177e4SLinus Torvalds 	uint32_t bmlen;
53691da177e4SLinus Torvalds 	int status;
53701da177e4SLinus Torvalds 
53711da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_SETATTR);
53721da177e4SLinus Torvalds 	if (status)
53731da177e4SLinus Torvalds 		return status;
5374c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5375c0eae66eSBenny Halevy 	if (unlikely(!p))
5376c0eae66eSBenny Halevy 		goto out_overflow;
5377cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
5378c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
5379c0eae66eSBenny Halevy 	if (likely(p))
53801da177e4SLinus Torvalds 		return 0;
5381c0eae66eSBenny Halevy out_overflow:
5382c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5383c0eae66eSBenny Halevy 	return -EIO;
53841da177e4SLinus Torvalds }
53851da177e4SLinus Torvalds 
5386bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
53871da177e4SLinus Torvalds {
53888687b63aSAl Viro 	__be32 *p;
53891da177e4SLinus Torvalds 	uint32_t opnum;
53901da177e4SLinus Torvalds 	int32_t nfserr;
53911da177e4SLinus Torvalds 
5392c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5393c0eae66eSBenny Halevy 	if (unlikely(!p))
5394c0eae66eSBenny Halevy 		goto out_overflow;
53956f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
53961da177e4SLinus Torvalds 	if (opnum != OP_SETCLIENTID) {
5397fe82a183SChuck Lever 		dprintk("nfs: decode_setclientid: Server returned operation"
53981da177e4SLinus Torvalds 			" %d\n", opnum);
53991da177e4SLinus Torvalds 		return -EIO;
54001da177e4SLinus Torvalds 	}
5401cccddf4fSBenny Halevy 	nfserr = be32_to_cpup(p);
54021da177e4SLinus Torvalds 	if (nfserr == NFS_OK) {
5403c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5404c0eae66eSBenny Halevy 		if (unlikely(!p))
5405c0eae66eSBenny Halevy 			goto out_overflow;
5406bb8b27e5STrond Myklebust 		p = xdr_decode_hyper(p, &res->clientid);
5407bb8b27e5STrond Myklebust 		memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
54081da177e4SLinus Torvalds 	} else if (nfserr == NFSERR_CLID_INUSE) {
54091da177e4SLinus Torvalds 		uint32_t len;
54101da177e4SLinus Torvalds 
54111da177e4SLinus Torvalds 		/* skip netid string */
5412c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5413c0eae66eSBenny Halevy 		if (unlikely(!p))
5414c0eae66eSBenny Halevy 			goto out_overflow;
5415cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5416c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5417c0eae66eSBenny Halevy 		if (unlikely(!p))
5418c0eae66eSBenny Halevy 			goto out_overflow;
54191da177e4SLinus Torvalds 
54201da177e4SLinus Torvalds 		/* skip uaddr string */
5421c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5422c0eae66eSBenny Halevy 		if (unlikely(!p))
5423c0eae66eSBenny Halevy 			goto out_overflow;
5424cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5425c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5426c0eae66eSBenny Halevy 		if (unlikely(!p))
5427c0eae66eSBenny Halevy 			goto out_overflow;
54281da177e4SLinus Torvalds 		return -NFSERR_CLID_INUSE;
54291da177e4SLinus Torvalds 	} else
5430856dff3dSBenny Halevy 		return nfs4_stat_to_errno(nfserr);
54311da177e4SLinus Torvalds 
54321da177e4SLinus Torvalds 	return 0;
5433c0eae66eSBenny Halevy out_overflow:
5434c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5435c0eae66eSBenny Halevy 	return -EIO;
54361da177e4SLinus Torvalds }
54371da177e4SLinus Torvalds 
54381da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr)
54391da177e4SLinus Torvalds {
54401da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
54411da177e4SLinus Torvalds }
54421da177e4SLinus Torvalds 
54439137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
54441da177e4SLinus Torvalds {
54458687b63aSAl Viro 	__be32 *p;
54461da177e4SLinus Torvalds 	int status;
54471da177e4SLinus Torvalds 
54481da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_WRITE);
54491da177e4SLinus Torvalds 	if (status)
54501da177e4SLinus Torvalds 		return status;
54511da177e4SLinus Torvalds 
54522f2c63bcSTrond Myklebust 	p = xdr_inline_decode(xdr, 8);
5453c0eae66eSBenny Halevy 	if (unlikely(!p))
5454c0eae66eSBenny Halevy 		goto out_overflow;
54556f723f77SBenny Halevy 	res->count = be32_to_cpup(p++);
54566f723f77SBenny Halevy 	res->verf->committed = be32_to_cpup(p++);
54572f2c63bcSTrond Myklebust 	return decode_write_verifier(xdr, &res->verf->verifier);
5458c0eae66eSBenny Halevy out_overflow:
5459c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5460c0eae66eSBenny Halevy 	return -EIO;
54611da177e4SLinus Torvalds }
54621da177e4SLinus Torvalds 
54631da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr)
54641da177e4SLinus Torvalds {
54651da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_DELEGRETURN);
54661da177e4SLinus Torvalds }
54671da177e4SLinus Torvalds 
5468fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr,
5469fb15b26fSChuck Lever 			      struct nfs4_secinfo4 *flavor)
54705a5ea0d4SBryan Schumaker {
5471fb15b26fSChuck Lever 	u32 oid_len;
54725a5ea0d4SBryan Schumaker 	__be32 *p;
54735a5ea0d4SBryan Schumaker 
54745a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
54755a5ea0d4SBryan Schumaker 	if (unlikely(!p))
54765a5ea0d4SBryan Schumaker 		goto out_overflow;
5477fb15b26fSChuck Lever 	oid_len = be32_to_cpup(p);
5478fb15b26fSChuck Lever 	if (oid_len > GSS_OID_MAX_LEN)
54795a5ea0d4SBryan Schumaker 		goto out_err;
54805a5ea0d4SBryan Schumaker 
5481fb15b26fSChuck Lever 	p = xdr_inline_decode(xdr, oid_len);
54825a5ea0d4SBryan Schumaker 	if (unlikely(!p))
54835a5ea0d4SBryan Schumaker 		goto out_overflow;
5484fb15b26fSChuck Lever 	memcpy(flavor->flavor_info.oid.data, p, oid_len);
5485fb15b26fSChuck Lever 	flavor->flavor_info.oid.len = oid_len;
54865a5ea0d4SBryan Schumaker 
54875a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 8);
54885a5ea0d4SBryan Schumaker 	if (unlikely(!p))
54895a5ea0d4SBryan Schumaker 		goto out_overflow;
5490fb15b26fSChuck Lever 	flavor->flavor_info.qop = be32_to_cpup(p++);
5491fb15b26fSChuck Lever 	flavor->flavor_info.service = be32_to_cpup(p);
54925a5ea0d4SBryan Schumaker 
54935a5ea0d4SBryan Schumaker 	return 0;
54945a5ea0d4SBryan Schumaker 
54955a5ea0d4SBryan Schumaker out_overflow:
54965a5ea0d4SBryan Schumaker 	print_overflow_msg(__func__, xdr);
54975a5ea0d4SBryan Schumaker 	return -EIO;
54985a5ea0d4SBryan Schumaker out_err:
54995a5ea0d4SBryan Schumaker 	return -EINVAL;
55005a5ea0d4SBryan Schumaker }
55015a5ea0d4SBryan Schumaker 
550231e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
55035a5ea0d4SBryan Schumaker {
5504fb15b26fSChuck Lever 	struct nfs4_secinfo4 *sec_flavor;
5505fb15b26fSChuck Lever 	unsigned int i, num_flavors;
55065a5ea0d4SBryan Schumaker 	int status;
55075a5ea0d4SBryan Schumaker 	__be32 *p;
55085a5ea0d4SBryan Schumaker 
55095a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
55105a5ea0d4SBryan Schumaker 	if (unlikely(!p))
55115a5ea0d4SBryan Schumaker 		goto out_overflow;
55125a5ea0d4SBryan Schumaker 
5513c3dfc280SBryan Schumaker 	res->flavors->num_flavors = 0;
5514c3dfc280SBryan Schumaker 	num_flavors = be32_to_cpup(p);
5515c3dfc280SBryan Schumaker 
5516c3dfc280SBryan Schumaker 	for (i = 0; i < num_flavors; i++) {
55175a5ea0d4SBryan Schumaker 		sec_flavor = &res->flavors->flavors[i];
5518c3dfc280SBryan Schumaker 		if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
55195a5ea0d4SBryan Schumaker 			break;
55205a5ea0d4SBryan Schumaker 
55215a5ea0d4SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
55225a5ea0d4SBryan Schumaker 		if (unlikely(!p))
55235a5ea0d4SBryan Schumaker 			goto out_overflow;
55245a5ea0d4SBryan Schumaker 		sec_flavor->flavor = be32_to_cpup(p);
55255a5ea0d4SBryan Schumaker 
55265a5ea0d4SBryan Schumaker 		if (sec_flavor->flavor == RPC_AUTH_GSS) {
5527613e901eSBryan Schumaker 			status = decode_secinfo_gss(xdr, sec_flavor);
5528613e901eSBryan Schumaker 			if (status)
5529613e901eSBryan Schumaker 				goto out;
55305a5ea0d4SBryan Schumaker 		}
5531c3dfc280SBryan Schumaker 		res->flavors->num_flavors++;
55325a5ea0d4SBryan Schumaker 	}
55335a5ea0d4SBryan Schumaker 
553431e4dda4SBryan Schumaker 	status = 0;
5535613e901eSBryan Schumaker out:
5536613e901eSBryan Schumaker 	return status;
55375a5ea0d4SBryan Schumaker out_overflow:
55385a5ea0d4SBryan Schumaker 	print_overflow_msg(__func__, xdr);
55395a5ea0d4SBryan Schumaker 	return -EIO;
55405a5ea0d4SBryan Schumaker }
55415a5ea0d4SBryan Schumaker 
554231e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
554331e4dda4SBryan Schumaker {
554431e4dda4SBryan Schumaker 	int status = decode_op_hdr(xdr, OP_SECINFO);
554531e4dda4SBryan Schumaker 	if (status)
554631e4dda4SBryan Schumaker 		return status;
554731e4dda4SBryan Schumaker 	return decode_secinfo_common(xdr, res);
554831e4dda4SBryan Schumaker }
554931e4dda4SBryan Schumaker 
555099fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
555131e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
555231e4dda4SBryan Schumaker {
555331e4dda4SBryan Schumaker 	int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
555431e4dda4SBryan Schumaker 	if (status)
555531e4dda4SBryan Schumaker 		return status;
555631e4dda4SBryan Schumaker 	return decode_secinfo_common(xdr, res);
555731e4dda4SBryan Schumaker }
555831e4dda4SBryan Schumaker 
55592031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
55602031cd1aSWeston Andros Adamson {
55612031cd1aSWeston Andros Adamson 	__be32 *p;
55622031cd1aSWeston Andros Adamson 	uint32_t bitmap_words;
55632031cd1aSWeston Andros Adamson 	unsigned int i;
55642031cd1aSWeston Andros Adamson 
55652031cd1aSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4);
55662031cd1aSWeston Andros Adamson 	bitmap_words = be32_to_cpup(p++);
55672031cd1aSWeston Andros Adamson 	if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
55682031cd1aSWeston Andros Adamson 		return -EIO;
55692031cd1aSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4 * bitmap_words);
55702031cd1aSWeston Andros Adamson 	for (i = 0; i < bitmap_words; i++)
55712031cd1aSWeston Andros Adamson 		op_map->u.words[i] = be32_to_cpup(p++);
55722031cd1aSWeston Andros Adamson 
55732031cd1aSWeston Andros Adamson 	return 0;
55742031cd1aSWeston Andros Adamson }
55752031cd1aSWeston Andros Adamson 
557699fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr,
557799fe60d0SBenny Halevy 			      struct nfs41_exchange_id_res *res)
557899fe60d0SBenny Halevy {
557999fe60d0SBenny Halevy 	__be32 *p;
558099fe60d0SBenny Halevy 	uint32_t dummy;
55812460ba57SBenny Halevy 	char *dummy_str;
558299fe60d0SBenny Halevy 	int status;
55837d2ed9acSWeston Andros Adamson 	uint32_t impl_id_count;
558499fe60d0SBenny Halevy 
558599fe60d0SBenny Halevy 	status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
558699fe60d0SBenny Halevy 	if (status)
558799fe60d0SBenny Halevy 		return status;
558899fe60d0SBenny Halevy 
5589c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5590c0eae66eSBenny Halevy 	if (unlikely(!p))
5591c0eae66eSBenny Halevy 		goto out_overflow;
559232b01310STrond Myklebust 	xdr_decode_hyper(p, &res->clientid);
5593c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
5594c0eae66eSBenny Halevy 	if (unlikely(!p))
5595c0eae66eSBenny Halevy 		goto out_overflow;
559632b01310STrond Myklebust 	res->seqid = be32_to_cpup(p++);
559732b01310STrond Myklebust 	res->flags = be32_to_cpup(p++);
559899fe60d0SBenny Halevy 
55992031cd1aSWeston Andros Adamson 	res->state_protect.how = be32_to_cpup(p);
56002031cd1aSWeston Andros Adamson 	switch (res->state_protect.how) {
56012031cd1aSWeston Andros Adamson 	case SP4_NONE:
56022031cd1aSWeston Andros Adamson 		break;
56032031cd1aSWeston Andros Adamson 	case SP4_MACH_CRED:
56042031cd1aSWeston Andros Adamson 		status = decode_op_map(xdr, &res->state_protect.enforce);
56052031cd1aSWeston Andros Adamson 		if (status)
56062031cd1aSWeston Andros Adamson 			return status;
56072031cd1aSWeston Andros Adamson 		status = decode_op_map(xdr, &res->state_protect.allow);
56082031cd1aSWeston Andros Adamson 		if (status)
56092031cd1aSWeston Andros Adamson 			return status;
56102031cd1aSWeston Andros Adamson 		break;
56112031cd1aSWeston Andros Adamson 	default:
56122031cd1aSWeston Andros Adamson 		WARN_ON_ONCE(1);
561399fe60d0SBenny Halevy 		return -EIO;
56142031cd1aSWeston Andros Adamson 	}
561599fe60d0SBenny Halevy 
5616acdeb69dSChuck Lever 	/* server_owner4.so_minor_id */
5617c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5618c0eae66eSBenny Halevy 	if (unlikely(!p))
5619c0eae66eSBenny Halevy 		goto out_overflow;
5620acdeb69dSChuck Lever 	p = xdr_decode_hyper(p, &res->server_owner->minor_id);
562199fe60d0SBenny Halevy 
5622acdeb69dSChuck Lever 	/* server_owner4.so_major_id */
56232460ba57SBenny Halevy 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
56242460ba57SBenny Halevy 	if (unlikely(status))
56252460ba57SBenny Halevy 		return status;
562678fe0f41SWeston Andros Adamson 	if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
562778fe0f41SWeston Andros Adamson 		return -EIO;
5628acdeb69dSChuck Lever 	memcpy(res->server_owner->major_id, dummy_str, dummy);
5629acdeb69dSChuck Lever 	res->server_owner->major_id_sz = dummy;
563078fe0f41SWeston Andros Adamson 
5631acdeb69dSChuck Lever 	/* server_scope4 */
5632acdeb69dSChuck Lever 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5633acdeb69dSChuck Lever 	if (unlikely(status))
5634acdeb69dSChuck Lever 		return status;
5635acdeb69dSChuck Lever 	if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5636acdeb69dSChuck Lever 		return -EIO;
563778fe0f41SWeston Andros Adamson 	memcpy(res->server_scope->server_scope, dummy_str, dummy);
563878fe0f41SWeston Andros Adamson 	res->server_scope->server_scope_sz = dummy;
563978fe0f41SWeston Andros Adamson 
56407d2ed9acSWeston Andros Adamson 	/* Implementation Id */
56417d2ed9acSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4);
56427d2ed9acSWeston Andros Adamson 	if (unlikely(!p))
56437d2ed9acSWeston Andros Adamson 		goto out_overflow;
56447d2ed9acSWeston Andros Adamson 	impl_id_count = be32_to_cpup(p++);
56457d2ed9acSWeston Andros Adamson 
56467d2ed9acSWeston Andros Adamson 	if (impl_id_count) {
56477d2ed9acSWeston Andros Adamson 		/* nii_domain */
56482460ba57SBenny Halevy 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
56492460ba57SBenny Halevy 		if (unlikely(status))
56502460ba57SBenny Halevy 			return status;
56517d2ed9acSWeston Andros Adamson 		if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
56527d2ed9acSWeston Andros Adamson 			return -EIO;
56537d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->domain, dummy_str, dummy);
565499fe60d0SBenny Halevy 
56557d2ed9acSWeston Andros Adamson 		/* nii_name */
56567d2ed9acSWeston Andros Adamson 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
56577d2ed9acSWeston Andros Adamson 		if (unlikely(status))
56587d2ed9acSWeston Andros Adamson 			return status;
56597d2ed9acSWeston Andros Adamson 		if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
56607d2ed9acSWeston Andros Adamson 			return -EIO;
56617d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->name, dummy_str, dummy);
56627d2ed9acSWeston Andros Adamson 
56637d2ed9acSWeston Andros Adamson 		/* nii_date */
56647d2ed9acSWeston Andros Adamson 		p = xdr_inline_decode(xdr, 12);
56657d2ed9acSWeston Andros Adamson 		if (unlikely(!p))
56667d2ed9acSWeston Andros Adamson 			goto out_overflow;
56677d2ed9acSWeston Andros Adamson 		p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
56687d2ed9acSWeston Andros Adamson 		res->impl_id->date.nseconds = be32_to_cpup(p);
56697d2ed9acSWeston Andros Adamson 
56707d2ed9acSWeston Andros Adamson 		/* if there's more than one entry, ignore the rest */
56717d2ed9acSWeston Andros Adamson 	}
567299fe60d0SBenny Halevy 	return 0;
5673c0eae66eSBenny Halevy out_overflow:
5674c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5675c0eae66eSBenny Halevy 	return -EIO;
567699fe60d0SBenny Halevy }
5677fc931582SAndy Adamson 
5678fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr,
5679fc931582SAndy Adamson 			     struct nfs4_channel_attrs *attrs)
5680fc931582SAndy Adamson {
5681fc931582SAndy Adamson 	__be32 *p;
5682c9c30dd5SBenny Halevy 	u32 nr_attrs, val;
5683fc931582SAndy Adamson 
5684c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 28);
5685c0eae66eSBenny Halevy 	if (unlikely(!p))
5686c0eae66eSBenny Halevy 		goto out_overflow;
5687c9c30dd5SBenny Halevy 	val = be32_to_cpup(p++);	/* headerpadsz */
5688c9c30dd5SBenny Halevy 	if (val)
5689c9c30dd5SBenny Halevy 		return -EINVAL;		/* no support for header padding yet */
56906f723f77SBenny Halevy 	attrs->max_rqst_sz = be32_to_cpup(p++);
56916f723f77SBenny Halevy 	attrs->max_resp_sz = be32_to_cpup(p++);
56926f723f77SBenny Halevy 	attrs->max_resp_sz_cached = be32_to_cpup(p++);
56936f723f77SBenny Halevy 	attrs->max_ops = be32_to_cpup(p++);
56946f723f77SBenny Halevy 	attrs->max_reqs = be32_to_cpup(p++);
5695cccddf4fSBenny Halevy 	nr_attrs = be32_to_cpup(p);
5696fc931582SAndy Adamson 	if (unlikely(nr_attrs > 1)) {
5697a030889aSWeston Andros Adamson 		printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5698a030889aSWeston Andros Adamson 			"count %u\n", __func__, nr_attrs);
5699fc931582SAndy Adamson 		return -EINVAL;
5700fc931582SAndy Adamson 	}
5701c0eae66eSBenny Halevy 	if (nr_attrs == 1) {
5702c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5703c0eae66eSBenny Halevy 		if (unlikely(!p))
5704c0eae66eSBenny Halevy 			goto out_overflow;
5705c0eae66eSBenny Halevy 	}
5706fc931582SAndy Adamson 	return 0;
5707c0eae66eSBenny Halevy out_overflow:
5708c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5709c0eae66eSBenny Halevy 	return -EIO;
5710fc931582SAndy Adamson }
5711fc931582SAndy Adamson 
5712e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5713e78291e4SBenny Halevy {
5714e78291e4SBenny Halevy 	return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5715fc931582SAndy Adamson }
5716fc931582SAndy Adamson 
57177c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr,
57187c44f1aeSWeston Andros Adamson 				struct nfs41_bind_conn_to_session_res *res)
57197c44f1aeSWeston Andros Adamson {
57207c44f1aeSWeston Andros Adamson 	__be32 *p;
57217c44f1aeSWeston Andros Adamson 	int status;
57227c44f1aeSWeston Andros Adamson 
57237c44f1aeSWeston Andros Adamson 	status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
57247c44f1aeSWeston Andros Adamson 	if (!status)
572571a097c6STrond Myklebust 		status = decode_sessionid(xdr, &res->sessionid);
57267c44f1aeSWeston Andros Adamson 	if (unlikely(status))
57277c44f1aeSWeston Andros Adamson 		return status;
57287c44f1aeSWeston Andros Adamson 
57297c44f1aeSWeston Andros Adamson 	/* dir flags, rdma mode bool */
57307c44f1aeSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 8);
57317c44f1aeSWeston Andros Adamson 	if (unlikely(!p))
57327c44f1aeSWeston Andros Adamson 		goto out_overflow;
57337c44f1aeSWeston Andros Adamson 
57347c44f1aeSWeston Andros Adamson 	res->dir = be32_to_cpup(p++);
57357c44f1aeSWeston Andros Adamson 	if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
57367c44f1aeSWeston Andros Adamson 		return -EIO;
57377c44f1aeSWeston Andros Adamson 	if (be32_to_cpup(p) == 0)
57387c44f1aeSWeston Andros Adamson 		res->use_conn_in_rdma_mode = false;
57397c44f1aeSWeston Andros Adamson 	else
57407c44f1aeSWeston Andros Adamson 		res->use_conn_in_rdma_mode = true;
57417c44f1aeSWeston Andros Adamson 
57427c44f1aeSWeston Andros Adamson 	return 0;
57437c44f1aeSWeston Andros Adamson out_overflow:
57447c44f1aeSWeston Andros Adamson 	print_overflow_msg(__func__, xdr);
57457c44f1aeSWeston Andros Adamson 	return -EIO;
57467c44f1aeSWeston Andros Adamson }
57477c44f1aeSWeston Andros Adamson 
5748fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr,
5749fc931582SAndy Adamson 				 struct nfs41_create_session_res *res)
5750fc931582SAndy Adamson {
5751fc931582SAndy Adamson 	__be32 *p;
5752fc931582SAndy Adamson 	int status;
5753fc931582SAndy Adamson 
5754fc931582SAndy Adamson 	status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5755e78291e4SBenny Halevy 	if (!status)
575679969dd1STrond Myklebust 		status = decode_sessionid(xdr, &res->sessionid);
5757e78291e4SBenny Halevy 	if (unlikely(status))
5758fc931582SAndy Adamson 		return status;
5759fc931582SAndy Adamson 
5760fc931582SAndy Adamson 	/* seqid, flags */
5761c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5762c0eae66eSBenny Halevy 	if (unlikely(!p))
5763c0eae66eSBenny Halevy 		goto out_overflow;
576479969dd1STrond Myklebust 	res->seqid = be32_to_cpup(p++);
576579969dd1STrond Myklebust 	res->flags = be32_to_cpup(p);
5766fc931582SAndy Adamson 
5767fc931582SAndy Adamson 	/* Channel attributes */
576879969dd1STrond Myklebust 	status = decode_chan_attrs(xdr, &res->fc_attrs);
5769fc931582SAndy Adamson 	if (!status)
577079969dd1STrond Myklebust 		status = decode_chan_attrs(xdr, &res->bc_attrs);
5771fc931582SAndy Adamson 	return status;
5772c0eae66eSBenny Halevy out_overflow:
5773c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5774c0eae66eSBenny Halevy 	return -EIO;
5775fc931582SAndy Adamson }
57760f3e66c6SAndy Adamson 
57770f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
57780f3e66c6SAndy Adamson {
57790f3e66c6SAndy Adamson 	return decode_op_hdr(xdr, OP_DESTROY_SESSION);
57800f3e66c6SAndy Adamson }
578118019753SRicardo Labiaga 
578266245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
578366245539STrond Myklebust {
578466245539STrond Myklebust 	return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
578566245539STrond Myklebust }
578666245539STrond Myklebust 
578718019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
578818019753SRicardo Labiaga {
578918019753SRicardo Labiaga 	return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
579018019753SRicardo Labiaga }
579199fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
579299fe60d0SBenny Halevy 
57939b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr,
57949b7b9fccSAndy Adamson 			   struct nfs4_sequence_res *res,
57959b7b9fccSAndy Adamson 			   struct rpc_rqst *rqstp)
57969b7b9fccSAndy Adamson {
57979b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
5798e3725ec0STrond Myklebust 	struct nfs4_session *session;
5799fc01cea9SAndy Adamson 	struct nfs4_sessionid id;
5800fc01cea9SAndy Adamson 	u32 dummy;
5801fc01cea9SAndy Adamson 	int status;
5802fc01cea9SAndy Adamson 	__be32 *p;
5803fc01cea9SAndy Adamson 
5804e3725ec0STrond Myklebust 	if (res->sr_slot == NULL)
58059b7b9fccSAndy Adamson 		return 0;
58063bd2384aSChuck Lever 	if (!res->sr_slot->table->session)
58073bd2384aSChuck Lever 		return 0;
58089b7b9fccSAndy Adamson 
5809fc01cea9SAndy Adamson 	status = decode_op_hdr(xdr, OP_SEQUENCE);
5810e78291e4SBenny Halevy 	if (!status)
5811e78291e4SBenny Halevy 		status = decode_sessionid(xdr, &id);
5812e78291e4SBenny Halevy 	if (unlikely(status))
5813fc01cea9SAndy Adamson 		goto out_err;
58149b7b9fccSAndy Adamson 
5815fc01cea9SAndy Adamson 	/*
5816fc01cea9SAndy Adamson 	 * If the server returns different values for sessionID, slotID or
5817fc01cea9SAndy Adamson 	 * sequence number, the server is looney tunes.
5818fc01cea9SAndy Adamson 	 */
5819fdcb4577STrond Myklebust 	status = -EREMOTEIO;
5820e3725ec0STrond Myklebust 	session = res->sr_slot->table->session;
5821fc01cea9SAndy Adamson 
5822e3725ec0STrond Myklebust 	if (memcmp(id.data, session->sess_id.data,
5823fc01cea9SAndy Adamson 		   NFS4_MAX_SESSIONID_LEN)) {
5824fc01cea9SAndy Adamson 		dprintk("%s Invalid session id\n", __func__);
5825fc01cea9SAndy Adamson 		goto out_err;
5826fc01cea9SAndy Adamson 	}
5827e78291e4SBenny Halevy 
5828c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
5829c0eae66eSBenny Halevy 	if (unlikely(!p))
5830c0eae66eSBenny Halevy 		goto out_overflow;
5831e78291e4SBenny Halevy 
5832fc01cea9SAndy Adamson 	/* seqid */
58336f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5834dfb4f309SBenny Halevy 	if (dummy != res->sr_slot->seq_nr) {
5835fc01cea9SAndy Adamson 		dprintk("%s Invalid sequence number\n", __func__);
5836fc01cea9SAndy Adamson 		goto out_err;
5837fc01cea9SAndy Adamson 	}
5838fc01cea9SAndy Adamson 	/* slot id */
58396f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5840df2fabffSTrond Myklebust 	if (dummy != res->sr_slot->slot_nr) {
5841fc01cea9SAndy Adamson 		dprintk("%s Invalid slot id\n", __func__);
5842fc01cea9SAndy Adamson 		goto out_err;
5843fc01cea9SAndy Adamson 	}
5844da0507b7STrond Myklebust 	/* highest slot id */
5845da0507b7STrond Myklebust 	res->sr_highest_slotid = be32_to_cpup(p++);
5846464ee9f9STrond Myklebust 	/* target highest slot id */
5847464ee9f9STrond Myklebust 	res->sr_target_highest_slotid = be32_to_cpup(p++);
58480629e370SAlexandros Batsakis 	/* result flags */
58490629e370SAlexandros Batsakis 	res->sr_status_flags = be32_to_cpup(p);
5850fc01cea9SAndy Adamson 	status = 0;
5851fc01cea9SAndy Adamson out_err:
5852fc01cea9SAndy Adamson 	res->sr_status = status;
5853fc01cea9SAndy Adamson 	return status;
5854c0eae66eSBenny Halevy out_overflow:
5855c0eae66eSBenny Halevy 	print_overflow_msg(__func__, xdr);
5856c0eae66eSBenny Halevy 	status = -EIO;
5857c0eae66eSBenny Halevy 	goto out_err;
5858fc01cea9SAndy Adamson #else  /* CONFIG_NFS_V4_1 */
58599b7b9fccSAndy Adamson 	return 0;
5860fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
58619b7b9fccSAndy Adamson }
58629b7b9fccSAndy Adamson 
5863b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1)
586493b717fdSTrond Myklebust static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
586593b717fdSTrond Myklebust {
586693b717fdSTrond Myklebust 	stateid->type = NFS4_LAYOUT_STATEID_TYPE;
586793b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
586893b717fdSTrond Myklebust }
586993b717fdSTrond Myklebust 
5870b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr,
58714e590803STrond Myklebust 				struct nfs4_getdeviceinfo_res *res)
5872b1f69b75SAndy Adamson {
58734e590803STrond Myklebust 	struct pnfs_device *pdev = res->pdev;
5874b1f69b75SAndy Adamson 	__be32 *p;
5875b1f69b75SAndy Adamson 	uint32_t len, type;
5876b1f69b75SAndy Adamson 	int status;
5877b1f69b75SAndy Adamson 
5878b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5879b1f69b75SAndy Adamson 	if (status) {
5880b1f69b75SAndy Adamson 		if (status == -ETOOSMALL) {
5881b1f69b75SAndy Adamson 			p = xdr_inline_decode(xdr, 4);
5882b1f69b75SAndy Adamson 			if (unlikely(!p))
5883b1f69b75SAndy Adamson 				goto out_overflow;
5884b1f69b75SAndy Adamson 			pdev->mincount = be32_to_cpup(p);
5885b1f69b75SAndy Adamson 			dprintk("%s: Min count too small. mincnt = %u\n",
5886b1f69b75SAndy Adamson 				__func__, pdev->mincount);
5887b1f69b75SAndy Adamson 		}
5888b1f69b75SAndy Adamson 		return status;
5889b1f69b75SAndy Adamson 	}
5890b1f69b75SAndy Adamson 
5891b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 8);
5892b1f69b75SAndy Adamson 	if (unlikely(!p))
5893b1f69b75SAndy Adamson 		goto out_overflow;
5894b1f69b75SAndy Adamson 	type = be32_to_cpup(p++);
5895b1f69b75SAndy Adamson 	if (type != pdev->layout_type) {
5896b1f69b75SAndy Adamson 		dprintk("%s: layout mismatch req: %u pdev: %u\n",
5897b1f69b75SAndy Adamson 			__func__, pdev->layout_type, type);
5898b1f69b75SAndy Adamson 		return -EINVAL;
5899b1f69b75SAndy Adamson 	}
5900b1f69b75SAndy Adamson 	/*
5901b1f69b75SAndy Adamson 	 * Get the length of the opaque device_addr4. xdr_read_pages places
5902b1f69b75SAndy Adamson 	 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5903b1f69b75SAndy Adamson 	 * and places the remaining xdr data in xdr_buf->tail
5904b1f69b75SAndy Adamson 	 */
5905b1f69b75SAndy Adamson 	pdev->mincount = be32_to_cpup(p);
590613fe4ba1STrond Myklebust 	if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
590713fe4ba1STrond Myklebust 		goto out_overflow;
5908b1f69b75SAndy Adamson 
5909b1f69b75SAndy Adamson 	/* Parse notification bitmap, verifying that it is zero. */
5910b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 4);
5911b1f69b75SAndy Adamson 	if (unlikely(!p))
5912b1f69b75SAndy Adamson 		goto out_overflow;
5913b1f69b75SAndy Adamson 	len = be32_to_cpup(p);
5914b1f69b75SAndy Adamson 	if (len) {
5915ead00597SChuck Lever 		uint32_t i;
5916b1f69b75SAndy Adamson 
5917b1f69b75SAndy Adamson 		p = xdr_inline_decode(xdr, 4 * len);
5918b1f69b75SAndy Adamson 		if (unlikely(!p))
5919b1f69b75SAndy Adamson 			goto out_overflow;
592084c9dee3SChristoph Hellwig 
59214e590803STrond Myklebust 		res->notification = be32_to_cpup(p++);
592284c9dee3SChristoph Hellwig 		for (i = 1; i < len; i++) {
592384c9dee3SChristoph Hellwig 			if (be32_to_cpup(p++)) {
592484c9dee3SChristoph Hellwig 				dprintk("%s: unsupported notification\n",
5925b1f69b75SAndy Adamson 					__func__);
5926b1f69b75SAndy Adamson 				return -EIO;
5927b1f69b75SAndy Adamson 			}
5928b1f69b75SAndy Adamson 		}
5929b1f69b75SAndy Adamson 	}
5930b1f69b75SAndy Adamson 	return 0;
5931b1f69b75SAndy Adamson out_overflow:
5932b1f69b75SAndy Adamson 	print_overflow_msg(__func__, xdr);
5933b1f69b75SAndy Adamson 	return -EIO;
5934b1f69b75SAndy Adamson }
5935b1f69b75SAndy Adamson 
5936b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5937b1f69b75SAndy Adamson 			    struct nfs4_layoutget_res *res)
5938b1f69b75SAndy Adamson {
5939b1f69b75SAndy Adamson 	__be32 *p;
5940b1f69b75SAndy Adamson 	int status;
5941b1f69b75SAndy Adamson 	u32 layout_count;
594264bd577eSTrond Myklebust 	u32 recvd;
5943b1f69b75SAndy Adamson 
5944b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTGET);
5945b1f69b75SAndy Adamson 	if (status)
5946b1f69b75SAndy Adamson 		return status;
5947ea9d23f5STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
5948b1f69b75SAndy Adamson 	if (unlikely(!p))
5949b1f69b75SAndy Adamson 		goto out_overflow;
5950ea9d23f5STrond Myklebust 	res->return_on_close = be32_to_cpup(p);
595193b717fdSTrond Myklebust 	decode_layout_stateid(xdr, &res->stateid);
5952ea9d23f5STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
5953ea9d23f5STrond Myklebust 	if (unlikely(!p))
5954ea9d23f5STrond Myklebust 		goto out_overflow;
5955b1f69b75SAndy Adamson 	layout_count = be32_to_cpup(p);
5956b1f69b75SAndy Adamson 	if (!layout_count) {
5957b1f69b75SAndy Adamson 		dprintk("%s: server responded with empty layout array\n",
5958b1f69b75SAndy Adamson 			__func__);
5959b1f69b75SAndy Adamson 		return -EINVAL;
5960b1f69b75SAndy Adamson 	}
5961b1f69b75SAndy Adamson 
596235124a09SWeston Andros Adamson 	p = xdr_inline_decode(xdr, 28);
5963b1f69b75SAndy Adamson 	if (unlikely(!p))
5964b1f69b75SAndy Adamson 		goto out_overflow;
5965b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.offset);
5966b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.length);
5967b1f69b75SAndy Adamson 	res->range.iomode = be32_to_cpup(p++);
5968b1f69b75SAndy Adamson 	res->type = be32_to_cpup(p++);
596935124a09SWeston Andros Adamson 	res->layoutp->len = be32_to_cpup(p);
5970b1f69b75SAndy Adamson 
5971b1f69b75SAndy Adamson 	dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5972b1f69b75SAndy Adamson 		__func__,
5973b1f69b75SAndy Adamson 		(unsigned long)res->range.offset,
5974b1f69b75SAndy Adamson 		(unsigned long)res->range.length,
5975b1f69b75SAndy Adamson 		res->range.iomode,
5976b1f69b75SAndy Adamson 		res->type,
597735124a09SWeston Andros Adamson 		res->layoutp->len);
5978b1f69b75SAndy Adamson 
597964bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, res->layoutp->len);
598035124a09SWeston Andros Adamson 	if (res->layoutp->len > recvd) {
598135124a09SWeston Andros Adamson 		dprintk("NFS: server cheating in layoutget reply: "
598235124a09SWeston Andros Adamson 				"layout len %u > recvd %u\n",
598335124a09SWeston Andros Adamson 				res->layoutp->len, recvd);
598435124a09SWeston Andros Adamson 		return -EINVAL;
598535124a09SWeston Andros Adamson 	}
598635124a09SWeston Andros Adamson 
5987b1f69b75SAndy Adamson 	if (layout_count > 1) {
5988b1f69b75SAndy Adamson 		/* We only handle a length one array at the moment.  Any
5989b1f69b75SAndy Adamson 		 * further entries are just ignored.  Note that this means
5990b1f69b75SAndy Adamson 		 * the client may see a response that is less than the
5991b1f69b75SAndy Adamson 		 * minimum it requested.
5992b1f69b75SAndy Adamson 		 */
5993b1f69b75SAndy Adamson 		dprintk("%s: server responded with %d layouts, dropping tail\n",
5994b1f69b75SAndy Adamson 			__func__, layout_count);
5995b1f69b75SAndy Adamson 	}
5996b1f69b75SAndy Adamson 
5997b1f69b75SAndy Adamson 	return 0;
5998b1f69b75SAndy Adamson out_overflow:
5999b1f69b75SAndy Adamson 	print_overflow_msg(__func__, xdr);
6000b1f69b75SAndy Adamson 	return -EIO;
6001b1f69b75SAndy Adamson }
6002863a3c6cSAndy Adamson 
6003cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr,
6004cbe82603SBenny Halevy 			       struct nfs4_layoutreturn_res *res)
6005cbe82603SBenny Halevy {
6006cbe82603SBenny Halevy 	__be32 *p;
6007cbe82603SBenny Halevy 	int status;
6008cbe82603SBenny Halevy 
6009cbe82603SBenny Halevy 	status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6010cbe82603SBenny Halevy 	if (status)
6011cbe82603SBenny Halevy 		return status;
6012cbe82603SBenny Halevy 	p = xdr_inline_decode(xdr, 4);
6013cbe82603SBenny Halevy 	if (unlikely(!p))
6014cbe82603SBenny Halevy 		goto out_overflow;
6015cbe82603SBenny Halevy 	res->lrs_present = be32_to_cpup(p);
6016cbe82603SBenny Halevy 	if (res->lrs_present)
601793b717fdSTrond Myklebust 		status = decode_layout_stateid(xdr, &res->stateid);
6018cbe82603SBenny Halevy 	return status;
6019cbe82603SBenny Halevy out_overflow:
6020cbe82603SBenny Halevy 	print_overflow_msg(__func__, xdr);
6021cbe82603SBenny Halevy 	return -EIO;
6022cbe82603SBenny Halevy }
6023cbe82603SBenny Halevy 
6024863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr,
6025863a3c6cSAndy Adamson 			       struct rpc_rqst *req,
6026863a3c6cSAndy Adamson 			       struct nfs4_layoutcommit_res *res)
6027863a3c6cSAndy Adamson {
6028863a3c6cSAndy Adamson 	__be32 *p;
6029863a3c6cSAndy Adamson 	__u32 sizechanged;
6030863a3c6cSAndy Adamson 	int status;
6031863a3c6cSAndy Adamson 
6032863a3c6cSAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
6033db29c089SAndy Adamson 	res->status = status;
6034863a3c6cSAndy Adamson 	if (status)
6035863a3c6cSAndy Adamson 		return status;
6036863a3c6cSAndy Adamson 
6037863a3c6cSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
6038863a3c6cSAndy Adamson 	if (unlikely(!p))
6039863a3c6cSAndy Adamson 		goto out_overflow;
6040863a3c6cSAndy Adamson 	sizechanged = be32_to_cpup(p);
6041863a3c6cSAndy Adamson 
6042863a3c6cSAndy Adamson 	if (sizechanged) {
6043863a3c6cSAndy Adamson 		/* throw away new size */
6044863a3c6cSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
6045863a3c6cSAndy Adamson 		if (unlikely(!p))
6046863a3c6cSAndy Adamson 			goto out_overflow;
6047863a3c6cSAndy Adamson 	}
6048863a3c6cSAndy Adamson 	return 0;
6049863a3c6cSAndy Adamson out_overflow:
6050863a3c6cSAndy Adamson 	print_overflow_msg(__func__, xdr);
6051863a3c6cSAndy Adamson 	return -EIO;
6052863a3c6cSAndy Adamson }
60537d974794SBryan Schumaker 
60547d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr,
60557d974794SBryan Schumaker 			       struct nfs41_test_stateid_res *res)
60567d974794SBryan Schumaker {
60577d974794SBryan Schumaker 	__be32 *p;
60587d974794SBryan Schumaker 	int status;
60597d974794SBryan Schumaker 	int num_res;
60607d974794SBryan Schumaker 
60617d974794SBryan Schumaker 	status = decode_op_hdr(xdr, OP_TEST_STATEID);
60627d974794SBryan Schumaker 	if (status)
60637d974794SBryan Schumaker 		return status;
60647d974794SBryan Schumaker 
60657d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
60667d974794SBryan Schumaker 	if (unlikely(!p))
60677d974794SBryan Schumaker 		goto out_overflow;
60687d974794SBryan Schumaker 	num_res = be32_to_cpup(p++);
60697d974794SBryan Schumaker 	if (num_res != 1)
60707d974794SBryan Schumaker 		goto out;
60717d974794SBryan Schumaker 
60727d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
60737d974794SBryan Schumaker 	if (unlikely(!p))
60747d974794SBryan Schumaker 		goto out_overflow;
60757d974794SBryan Schumaker 	res->status = be32_to_cpup(p++);
60761cab0652SBryan Schumaker 
60771cab0652SBryan Schumaker 	return status;
60787d974794SBryan Schumaker out_overflow:
60797d974794SBryan Schumaker 	print_overflow_msg(__func__, xdr);
60807d974794SBryan Schumaker out:
60817d974794SBryan Schumaker 	return -EIO;
60827d974794SBryan Schumaker }
60839aeda35fSBryan Schumaker 
60849aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr,
60859aeda35fSBryan Schumaker 			       struct nfs41_free_stateid_res *res)
60869aeda35fSBryan Schumaker {
60879f79fb48SAndy Adamson 	res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
60889aeda35fSBryan Schumaker 	return res->status;
60899aeda35fSBryan Schumaker }
6090b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
6091b1f69b75SAndy Adamson 
60921da177e4SLinus Torvalds /*
609349c2559eSBenny Halevy  * END OF "GENERIC" DECODE ROUTINES.
609449c2559eSBenny Halevy  */
609549c2559eSBenny Halevy 
609649c2559eSBenny Halevy /*
60971da177e4SLinus Torvalds  * Decode OPEN_DOWNGRADE response
60981da177e4SLinus Torvalds  */
6099bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6100bf269551SChuck Lever 				       struct xdr_stream *xdr,
6101bf269551SChuck Lever 				       struct nfs_closeres *res)
61021da177e4SLinus Torvalds {
61031da177e4SLinus Torvalds 	struct compound_hdr hdr;
61041da177e4SLinus Torvalds 	int status;
61051da177e4SLinus Torvalds 
6106bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61071da177e4SLinus Torvalds 	if (status)
61081da177e4SLinus Torvalds 		goto out;
6109bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61109b7b9fccSAndy Adamson 	if (status)
61119b7b9fccSAndy Adamson 		goto out;
6112bf269551SChuck Lever 	status = decode_putfh(xdr);
61131da177e4SLinus Torvalds 	if (status)
61141da177e4SLinus Torvalds 		goto out;
6115bf269551SChuck Lever 	status = decode_open_downgrade(xdr, res);
6116516a6af6STrond Myklebust 	if (status != 0)
6117516a6af6STrond Myklebust 		goto out;
61186926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
61191da177e4SLinus Torvalds out:
61201da177e4SLinus Torvalds 	return status;
61211da177e4SLinus Torvalds }
61221da177e4SLinus Torvalds 
61231da177e4SLinus Torvalds /*
61241da177e4SLinus Torvalds  * Decode ACCESS response
61251da177e4SLinus Torvalds  */
6126bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6127bf269551SChuck Lever 			       struct nfs4_accessres *res)
61281da177e4SLinus Torvalds {
61291da177e4SLinus Torvalds 	struct compound_hdr hdr;
61301da177e4SLinus Torvalds 	int status;
61311da177e4SLinus Torvalds 
6132bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61339b7b9fccSAndy Adamson 	if (status)
61349b7b9fccSAndy Adamson 		goto out;
6135bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61369b7b9fccSAndy Adamson 	if (status)
61371da177e4SLinus Torvalds 		goto out;
6138bf269551SChuck Lever 	status = decode_putfh(xdr);
613976b32999STrond Myklebust 	if (status != 0)
614076b32999STrond Myklebust 		goto out;
61416168f62cSWeston Andros Adamson 	status = decode_access(xdr, &res->supported, &res->access);
614276b32999STrond Myklebust 	if (status != 0)
614376b32999STrond Myklebust 		goto out;
61446926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
61451da177e4SLinus Torvalds out:
61461da177e4SLinus Torvalds 	return status;
61471da177e4SLinus Torvalds }
61481da177e4SLinus Torvalds 
61491da177e4SLinus Torvalds /*
61501da177e4SLinus Torvalds  * Decode LOOKUP response
61511da177e4SLinus Torvalds  */
6152bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6153bf269551SChuck Lever 			       struct nfs4_lookup_res *res)
61541da177e4SLinus Torvalds {
61551da177e4SLinus Torvalds 	struct compound_hdr hdr;
61561da177e4SLinus Torvalds 	int status;
61571da177e4SLinus Torvalds 
6158bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61599b7b9fccSAndy Adamson 	if (status)
61609b7b9fccSAndy Adamson 		goto out;
6161bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61629b7b9fccSAndy Adamson 	if (status)
61631da177e4SLinus Torvalds 		goto out;
6164bf269551SChuck Lever 	status = decode_putfh(xdr);
6165bf269551SChuck Lever 	if (status)
61661da177e4SLinus Torvalds 		goto out;
6167bf269551SChuck Lever 	status = decode_lookup(xdr);
6168bf269551SChuck Lever 	if (status)
61691da177e4SLinus Torvalds 		goto out;
6170bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6171bf269551SChuck Lever 	if (status)
61721da177e4SLinus Torvalds 		goto out;
6173aa9c2669SDavid Quigley 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
61741da177e4SLinus Torvalds out:
61751da177e4SLinus Torvalds 	return status;
61761da177e4SLinus Torvalds }
61771da177e4SLinus Torvalds 
61781da177e4SLinus Torvalds /*
61791da177e4SLinus Torvalds  * Decode LOOKUP_ROOT response
61801da177e4SLinus Torvalds  */
6181bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6182bf269551SChuck Lever 				    struct xdr_stream *xdr,
6183bf269551SChuck Lever 				    struct nfs4_lookup_res *res)
61841da177e4SLinus Torvalds {
61851da177e4SLinus Torvalds 	struct compound_hdr hdr;
61861da177e4SLinus Torvalds 	int status;
61871da177e4SLinus Torvalds 
6188bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61899b7b9fccSAndy Adamson 	if (status)
61909b7b9fccSAndy Adamson 		goto out;
6191bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61929b7b9fccSAndy Adamson 	if (status)
61931da177e4SLinus Torvalds 		goto out;
6194bf269551SChuck Lever 	status = decode_putrootfh(xdr);
6195bf269551SChuck Lever 	if (status)
61961da177e4SLinus Torvalds 		goto out;
6197bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6198bf269551SChuck Lever 	if (status == 0)
6199aa9c2669SDavid Quigley 		status = decode_getfattr_label(xdr, res->fattr,
6200aa9c2669SDavid Quigley 						res->label, res->server);
62011da177e4SLinus Torvalds out:
62021da177e4SLinus Torvalds 	return status;
62031da177e4SLinus Torvalds }
62041da177e4SLinus Torvalds 
62051da177e4SLinus Torvalds /*
62061da177e4SLinus Torvalds  * Decode REMOVE response
62071da177e4SLinus Torvalds  */
6208bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6209bf269551SChuck Lever 			       struct nfs_removeres *res)
62101da177e4SLinus Torvalds {
62111da177e4SLinus Torvalds 	struct compound_hdr hdr;
62121da177e4SLinus Torvalds 	int status;
62131da177e4SLinus Torvalds 
6214bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62159b7b9fccSAndy Adamson 	if (status)
62169b7b9fccSAndy Adamson 		goto out;
6217bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62189b7b9fccSAndy Adamson 	if (status)
62191da177e4SLinus Torvalds 		goto out;
6220bf269551SChuck Lever 	status = decode_putfh(xdr);
6221bf269551SChuck Lever 	if (status)
622216e42959STrond Myklebust 		goto out;
6223bf269551SChuck Lever 	status = decode_remove(xdr, &res->cinfo);
62241da177e4SLinus Torvalds out:
62251da177e4SLinus Torvalds 	return status;
62261da177e4SLinus Torvalds }
62271da177e4SLinus Torvalds 
62281da177e4SLinus Torvalds /*
62291da177e4SLinus Torvalds  * Decode RENAME response
62301da177e4SLinus Torvalds  */
6231bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6232bf269551SChuck Lever 			       struct nfs_renameres *res)
62331da177e4SLinus Torvalds {
62341da177e4SLinus Torvalds 	struct compound_hdr hdr;
62351da177e4SLinus Torvalds 	int status;
62361da177e4SLinus Torvalds 
6237bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62389b7b9fccSAndy Adamson 	if (status)
62399b7b9fccSAndy Adamson 		goto out;
6240bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62419b7b9fccSAndy Adamson 	if (status)
62421da177e4SLinus Torvalds 		goto out;
6243bf269551SChuck Lever 	status = decode_putfh(xdr);
6244bf269551SChuck Lever 	if (status)
62451da177e4SLinus Torvalds 		goto out;
6246bf269551SChuck Lever 	status = decode_savefh(xdr);
6247bf269551SChuck Lever 	if (status)
62481da177e4SLinus Torvalds 		goto out;
6249bf269551SChuck Lever 	status = decode_putfh(xdr);
6250bf269551SChuck Lever 	if (status)
62511da177e4SLinus Torvalds 		goto out;
6252bf269551SChuck Lever 	status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
62531da177e4SLinus Torvalds out:
62541da177e4SLinus Torvalds 	return status;
62551da177e4SLinus Torvalds }
62561da177e4SLinus Torvalds 
62571da177e4SLinus Torvalds /*
62581da177e4SLinus Torvalds  * Decode LINK response
62591da177e4SLinus Torvalds  */
6260bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6261bf269551SChuck Lever 			     struct nfs4_link_res *res)
62621da177e4SLinus Torvalds {
62631da177e4SLinus Torvalds 	struct compound_hdr hdr;
62641da177e4SLinus Torvalds 	int status;
62651da177e4SLinus Torvalds 
6266bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62679b7b9fccSAndy Adamson 	if (status)
62689b7b9fccSAndy Adamson 		goto out;
6269bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62709b7b9fccSAndy Adamson 	if (status)
62711da177e4SLinus Torvalds 		goto out;
6272bf269551SChuck Lever 	status = decode_putfh(xdr);
6273bf269551SChuck Lever 	if (status)
62741da177e4SLinus Torvalds 		goto out;
6275bf269551SChuck Lever 	status = decode_savefh(xdr);
6276bf269551SChuck Lever 	if (status)
62771da177e4SLinus Torvalds 		goto out;
6278bf269551SChuck Lever 	status = decode_putfh(xdr);
6279bf269551SChuck Lever 	if (status)
62801da177e4SLinus Torvalds 		goto out;
6281bf269551SChuck Lever 	status = decode_link(xdr, &res->cinfo);
6282bf269551SChuck Lever 	if (status)
628391ba2eeeSTrond Myklebust 		goto out;
628491ba2eeeSTrond Myklebust 	/*
628591ba2eeeSTrond Myklebust 	 * Note order: OP_LINK leaves the directory as the current
628691ba2eeeSTrond Myklebust 	 *             filehandle.
628791ba2eeeSTrond Myklebust 	 */
6288bf269551SChuck Lever 	status = decode_restorefh(xdr);
6289bf269551SChuck Lever 	if (status)
629091ba2eeeSTrond Myklebust 		goto out;
6291aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
62921da177e4SLinus Torvalds out:
62931da177e4SLinus Torvalds 	return status;
62941da177e4SLinus Torvalds }
62951da177e4SLinus Torvalds 
62961da177e4SLinus Torvalds /*
62971da177e4SLinus Torvalds  * Decode CREATE response
62981da177e4SLinus Torvalds  */
6299bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6300bf269551SChuck Lever 			       struct nfs4_create_res *res)
63011da177e4SLinus Torvalds {
63021da177e4SLinus Torvalds 	struct compound_hdr hdr;
63031da177e4SLinus Torvalds 	int status;
63041da177e4SLinus Torvalds 
6305bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63069b7b9fccSAndy Adamson 	if (status)
63079b7b9fccSAndy Adamson 		goto out;
6308bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63099b7b9fccSAndy Adamson 	if (status)
63101da177e4SLinus Torvalds 		goto out;
6311bf269551SChuck Lever 	status = decode_putfh(xdr);
6312bf269551SChuck Lever 	if (status)
63131da177e4SLinus Torvalds 		goto out;
6314bf269551SChuck Lever 	status = decode_create(xdr, &res->dir_cinfo);
6315bf269551SChuck Lever 	if (status)
63161da177e4SLinus Torvalds 		goto out;
6317bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6318bf269551SChuck Lever 	if (status)
63191da177e4SLinus Torvalds 		goto out;
6320aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
63211da177e4SLinus Torvalds out:
63221da177e4SLinus Torvalds 	return status;
63231da177e4SLinus Torvalds }
63241da177e4SLinus Torvalds 
63251da177e4SLinus Torvalds /*
63261da177e4SLinus Torvalds  * Decode SYMLINK response
63271da177e4SLinus Torvalds  */
6328bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6329bf269551SChuck Lever 				struct nfs4_create_res *res)
63301da177e4SLinus Torvalds {
6331bf269551SChuck Lever 	return nfs4_xdr_dec_create(rqstp, xdr, res);
63321da177e4SLinus Torvalds }
63331da177e4SLinus Torvalds 
63341da177e4SLinus Torvalds /*
63351da177e4SLinus Torvalds  * Decode GETATTR response
63361da177e4SLinus Torvalds  */
6337bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6338bf269551SChuck Lever 				struct nfs4_getattr_res *res)
63391da177e4SLinus Torvalds {
63401da177e4SLinus Torvalds 	struct compound_hdr hdr;
63411da177e4SLinus Torvalds 	int status;
63421da177e4SLinus Torvalds 
6343bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63441da177e4SLinus Torvalds 	if (status)
63451da177e4SLinus Torvalds 		goto out;
6346bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63479b7b9fccSAndy Adamson 	if (status)
63489b7b9fccSAndy Adamson 		goto out;
6349bf269551SChuck Lever 	status = decode_putfh(xdr);
63501da177e4SLinus Torvalds 	if (status)
63511da177e4SLinus Torvalds 		goto out;
6352aa9c2669SDavid Quigley 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
63531da177e4SLinus Torvalds out:
63541da177e4SLinus Torvalds 	return status;
63551da177e4SLinus Torvalds }
63561da177e4SLinus Torvalds 
635723ec6965SJ. Bruce Fields /*
635823ec6965SJ. Bruce Fields  * Encode an SETACL request
635923ec6965SJ. Bruce Fields  */
63609f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
63619f06c719SChuck Lever 				struct nfs_setaclargs *args)
636223ec6965SJ. Bruce Fields {
636323ec6965SJ. Bruce Fields 	struct compound_hdr hdr = {
636466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
636523ec6965SJ. Bruce Fields 	};
636623ec6965SJ. Bruce Fields 
63679f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
63689f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
63699f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
63709f06c719SChuck Lever 	encode_setacl(xdr, args, &hdr);
6371d017931cSAndy Adamson 	encode_nops(&hdr);
637223ec6965SJ. Bruce Fields }
637305d564feSAndy Adamson 
637423ec6965SJ. Bruce Fields /*
637523ec6965SJ. Bruce Fields  * Decode SETACL response
637623ec6965SJ. Bruce Fields  */
637723ec6965SJ. Bruce Fields static int
6378bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
637973c403a9SBenny Halevy 		    struct nfs_setaclres *res)
638023ec6965SJ. Bruce Fields {
638123ec6965SJ. Bruce Fields 	struct compound_hdr hdr;
638223ec6965SJ. Bruce Fields 	int status;
638323ec6965SJ. Bruce Fields 
6384bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
638523ec6965SJ. Bruce Fields 	if (status)
638623ec6965SJ. Bruce Fields 		goto out;
6387bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63889b7b9fccSAndy Adamson 	if (status)
63899b7b9fccSAndy Adamson 		goto out;
6390bf269551SChuck Lever 	status = decode_putfh(xdr);
639123ec6965SJ. Bruce Fields 	if (status)
639223ec6965SJ. Bruce Fields 		goto out;
6393bf269551SChuck Lever 	status = decode_setattr(xdr);
639423ec6965SJ. Bruce Fields out:
639523ec6965SJ. Bruce Fields 	return status;
639623ec6965SJ. Bruce Fields }
63971da177e4SLinus Torvalds 
63981da177e4SLinus Torvalds /*
6399029d105eSJ. Bruce Fields  * Decode GETACL response
6400029d105eSJ. Bruce Fields  */
6401029d105eSJ. Bruce Fields static int
6402bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6403663c79b3SBenny Halevy 		    struct nfs_getaclres *res)
6404029d105eSJ. Bruce Fields {
6405029d105eSJ. Bruce Fields 	struct compound_hdr hdr;
6406029d105eSJ. Bruce Fields 	int status;
6407029d105eSJ. Bruce Fields 
6408331818f1STrond Myklebust 	if (res->acl_scratch != NULL) {
6409331818f1STrond Myklebust 		void *p = page_address(res->acl_scratch);
6410331818f1STrond Myklebust 		xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6411331818f1STrond Myklebust 	}
6412bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6413029d105eSJ. Bruce Fields 	if (status)
6414029d105eSJ. Bruce Fields 		goto out;
6415bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64169b7b9fccSAndy Adamson 	if (status)
64179b7b9fccSAndy Adamson 		goto out;
6418bf269551SChuck Lever 	status = decode_putfh(xdr);
6419029d105eSJ. Bruce Fields 	if (status)
6420029d105eSJ. Bruce Fields 		goto out;
6421bf118a34SAndy Adamson 	status = decode_getacl(xdr, rqstp, res);
6422029d105eSJ. Bruce Fields 
6423029d105eSJ. Bruce Fields out:
6424029d105eSJ. Bruce Fields 	return status;
6425029d105eSJ. Bruce Fields }
6426029d105eSJ. Bruce Fields 
6427029d105eSJ. Bruce Fields /*
64281da177e4SLinus Torvalds  * Decode CLOSE response
64291da177e4SLinus Torvalds  */
6430bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6431bf269551SChuck Lever 			      struct nfs_closeres *res)
64321da177e4SLinus Torvalds {
64331da177e4SLinus Torvalds 	struct compound_hdr hdr;
64341da177e4SLinus Torvalds 	int status;
64351da177e4SLinus Torvalds 
6436bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64371da177e4SLinus Torvalds 	if (status)
64381da177e4SLinus Torvalds 		goto out;
6439bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64409b7b9fccSAndy Adamson 	if (status)
64419b7b9fccSAndy Adamson 		goto out;
6442bf269551SChuck Lever 	status = decode_putfh(xdr);
64431da177e4SLinus Torvalds 	if (status)
64441da177e4SLinus Torvalds 		goto out;
6445bf269551SChuck Lever 	status = decode_close(xdr, res);
6446516a6af6STrond Myklebust 	if (status != 0)
6447516a6af6STrond Myklebust 		goto out;
6448516a6af6STrond Myklebust 	/*
6449516a6af6STrond Myklebust 	 * Note: Server may do delete on close for this file
6450516a6af6STrond Myklebust 	 * 	in which case the getattr call will fail with
6451516a6af6STrond Myklebust 	 * 	an ESTALE error. Shouldn't be a problem,
6452516a6af6STrond Myklebust 	 * 	though, since fattr->valid will remain unset.
6453516a6af6STrond Myklebust 	 */
64546926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
64551da177e4SLinus Torvalds out:
64561da177e4SLinus Torvalds 	return status;
64571da177e4SLinus Torvalds }
64581da177e4SLinus Torvalds 
64591da177e4SLinus Torvalds /*
64601da177e4SLinus Torvalds  * Decode OPEN response
64611da177e4SLinus Torvalds  */
6462bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6463bf269551SChuck Lever 			     struct nfs_openres *res)
64641da177e4SLinus Torvalds {
64651da177e4SLinus Torvalds 	struct compound_hdr hdr;
64661da177e4SLinus Torvalds 	int status;
64671da177e4SLinus Torvalds 
6468bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64691da177e4SLinus Torvalds 	if (status)
64701da177e4SLinus Torvalds 		goto out;
6471bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64729b7b9fccSAndy Adamson 	if (status)
64739b7b9fccSAndy Adamson 		goto out;
6474bf269551SChuck Lever 	status = decode_putfh(xdr);
64751da177e4SLinus Torvalds 	if (status)
64761da177e4SLinus Torvalds 		goto out;
6477bf269551SChuck Lever 	status = decode_open(xdr, res);
64781da177e4SLinus Torvalds 	if (status)
64791da177e4SLinus Torvalds 		goto out;
648001913b49SWeston Andros Adamson 	status = decode_getfh(xdr, &res->fh);
648101913b49SWeston Andros Adamson 	if (status)
64821da177e4SLinus Torvalds 		goto out;
6483ae2bb032SWeston Andros Adamson 	if (res->access_request)
64846168f62cSWeston Andros Adamson 		decode_access(xdr, &res->access_supported, &res->access_result);
6485aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
64861da177e4SLinus Torvalds out:
64871da177e4SLinus Torvalds 	return status;
64881da177e4SLinus Torvalds }
64891da177e4SLinus Torvalds 
64901da177e4SLinus Torvalds /*
64911da177e4SLinus Torvalds  * Decode OPEN_CONFIRM response
64921da177e4SLinus Torvalds  */
6493bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6494bf269551SChuck Lever 				     struct xdr_stream *xdr,
6495bf269551SChuck Lever 				     struct nfs_open_confirmres *res)
64961da177e4SLinus Torvalds {
64971da177e4SLinus Torvalds 	struct compound_hdr hdr;
64981da177e4SLinus Torvalds 	int status;
64991da177e4SLinus Torvalds 
6500bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65011da177e4SLinus Torvalds 	if (status)
65021da177e4SLinus Torvalds 		goto out;
6503bf269551SChuck Lever 	status = decode_putfh(xdr);
65041da177e4SLinus Torvalds 	if (status)
65051da177e4SLinus Torvalds 		goto out;
6506bf269551SChuck Lever 	status = decode_open_confirm(xdr, res);
65071da177e4SLinus Torvalds out:
65081da177e4SLinus Torvalds 	return status;
65091da177e4SLinus Torvalds }
65101da177e4SLinus Torvalds 
65111da177e4SLinus Torvalds /*
65121da177e4SLinus Torvalds  * Decode OPEN response
65131da177e4SLinus Torvalds  */
6514bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6515bf269551SChuck Lever 				    struct xdr_stream *xdr,
6516bf269551SChuck Lever 				    struct nfs_openres *res)
65171da177e4SLinus Torvalds {
65181da177e4SLinus Torvalds 	struct compound_hdr hdr;
65191da177e4SLinus Torvalds 	int status;
65201da177e4SLinus Torvalds 
6521bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65221da177e4SLinus Torvalds 	if (status)
65231da177e4SLinus Torvalds 		goto out;
6524bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65259b7b9fccSAndy Adamson 	if (status)
65269b7b9fccSAndy Adamson 		goto out;
6527bf269551SChuck Lever 	status = decode_putfh(xdr);
65281da177e4SLinus Torvalds 	if (status)
65291da177e4SLinus Torvalds 		goto out;
6530bf269551SChuck Lever 	status = decode_open(xdr, res);
6531864472e9STrond Myklebust 	if (status)
6532864472e9STrond Myklebust 		goto out;
6533ae2bb032SWeston Andros Adamson 	if (res->access_request)
65346168f62cSWeston Andros Adamson 		decode_access(xdr, &res->access_supported, &res->access_result);
65356926afd1STrond Myklebust 	decode_getfattr(xdr, res->f_attr, res->server);
65361da177e4SLinus Torvalds out:
65371da177e4SLinus Torvalds 	return status;
65381da177e4SLinus Torvalds }
65391da177e4SLinus Torvalds 
65401da177e4SLinus Torvalds /*
65411da177e4SLinus Torvalds  * Decode SETATTR response
65421da177e4SLinus Torvalds  */
6543bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6544bf269551SChuck Lever 				struct xdr_stream *xdr,
6545bf269551SChuck Lever 				struct nfs_setattrres *res)
65461da177e4SLinus Torvalds {
65471da177e4SLinus Torvalds 	struct compound_hdr hdr;
65481da177e4SLinus Torvalds 	int status;
65491da177e4SLinus Torvalds 
6550bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65511da177e4SLinus Torvalds 	if (status)
65521da177e4SLinus Torvalds 		goto out;
6553bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65549b7b9fccSAndy Adamson 	if (status)
65559b7b9fccSAndy Adamson 		goto out;
6556bf269551SChuck Lever 	status = decode_putfh(xdr);
65571da177e4SLinus Torvalds 	if (status)
65581da177e4SLinus Torvalds 		goto out;
6559bf269551SChuck Lever 	status = decode_setattr(xdr);
65601da177e4SLinus Torvalds 	if (status)
65611da177e4SLinus Torvalds 		goto out;
6562aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
65631da177e4SLinus Torvalds out:
65641da177e4SLinus Torvalds 	return status;
65651da177e4SLinus Torvalds }
65661da177e4SLinus Torvalds 
65671da177e4SLinus Torvalds /*
65681da177e4SLinus Torvalds  * Decode LOCK response
65691da177e4SLinus Torvalds  */
6570bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6571bf269551SChuck Lever 			     struct nfs_lock_res *res)
65721da177e4SLinus Torvalds {
65731da177e4SLinus Torvalds 	struct compound_hdr hdr;
65741da177e4SLinus Torvalds 	int status;
65751da177e4SLinus Torvalds 
6576bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65771da177e4SLinus Torvalds 	if (status)
65781da177e4SLinus Torvalds 		goto out;
6579bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65809b7b9fccSAndy Adamson 	if (status)
65819b7b9fccSAndy Adamson 		goto out;
6582bf269551SChuck Lever 	status = decode_putfh(xdr);
65831da177e4SLinus Torvalds 	if (status)
65841da177e4SLinus Torvalds 		goto out;
6585bf269551SChuck Lever 	status = decode_lock(xdr, res);
65861da177e4SLinus Torvalds out:
65871da177e4SLinus Torvalds 	return status;
65881da177e4SLinus Torvalds }
65891da177e4SLinus Torvalds 
65901da177e4SLinus Torvalds /*
65911da177e4SLinus Torvalds  * Decode LOCKT response
65921da177e4SLinus Torvalds  */
6593bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6594bf269551SChuck Lever 			      struct nfs_lockt_res *res)
65951da177e4SLinus Torvalds {
65961da177e4SLinus Torvalds 	struct compound_hdr hdr;
65971da177e4SLinus Torvalds 	int status;
65981da177e4SLinus Torvalds 
6599bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66001da177e4SLinus Torvalds 	if (status)
66011da177e4SLinus Torvalds 		goto out;
6602bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66039b7b9fccSAndy Adamson 	if (status)
66049b7b9fccSAndy Adamson 		goto out;
6605bf269551SChuck Lever 	status = decode_putfh(xdr);
66061da177e4SLinus Torvalds 	if (status)
66071da177e4SLinus Torvalds 		goto out;
6608bf269551SChuck Lever 	status = decode_lockt(xdr, res);
66091da177e4SLinus Torvalds out:
66101da177e4SLinus Torvalds 	return status;
66111da177e4SLinus Torvalds }
66121da177e4SLinus Torvalds 
66131da177e4SLinus Torvalds /*
66141da177e4SLinus Torvalds  * Decode LOCKU response
66151da177e4SLinus Torvalds  */
6616bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6617bf269551SChuck Lever 			      struct nfs_locku_res *res)
66181da177e4SLinus Torvalds {
66191da177e4SLinus Torvalds 	struct compound_hdr hdr;
66201da177e4SLinus Torvalds 	int status;
66211da177e4SLinus Torvalds 
6622bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66231da177e4SLinus Torvalds 	if (status)
66241da177e4SLinus Torvalds 		goto out;
6625bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66269b7b9fccSAndy Adamson 	if (status)
66279b7b9fccSAndy Adamson 		goto out;
6628bf269551SChuck Lever 	status = decode_putfh(xdr);
66291da177e4SLinus Torvalds 	if (status)
66301da177e4SLinus Torvalds 		goto out;
6631bf269551SChuck Lever 	status = decode_locku(xdr, res);
66321da177e4SLinus Torvalds out:
66331da177e4SLinus Torvalds 	return status;
66341da177e4SLinus Torvalds }
66351da177e4SLinus Torvalds 
6636bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6637bf269551SChuck Lever 					  struct xdr_stream *xdr, void *dummy)
6638d3c7b7ccSTrond Myklebust {
6639d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr;
6640d3c7b7ccSTrond Myklebust 	int status;
6641d3c7b7ccSTrond Myklebust 
6642bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6643d3c7b7ccSTrond Myklebust 	if (!status)
6644bf269551SChuck Lever 		status = decode_release_lockowner(xdr);
6645d3c7b7ccSTrond Myklebust 	return status;
6646d3c7b7ccSTrond Myklebust }
6647d3c7b7ccSTrond Myklebust 
66481da177e4SLinus Torvalds /*
66491da177e4SLinus Torvalds  * Decode READLINK response
66501da177e4SLinus Torvalds  */
6651bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6652bf269551SChuck Lever 				 struct xdr_stream *xdr,
6653f50c7000SBenny Halevy 				 struct nfs4_readlink_res *res)
66541da177e4SLinus Torvalds {
66551da177e4SLinus Torvalds 	struct compound_hdr hdr;
66561da177e4SLinus Torvalds 	int status;
66571da177e4SLinus Torvalds 
6658bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66591da177e4SLinus Torvalds 	if (status)
66601da177e4SLinus Torvalds 		goto out;
6661bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66629b7b9fccSAndy Adamson 	if (status)
66639b7b9fccSAndy Adamson 		goto out;
6664bf269551SChuck Lever 	status = decode_putfh(xdr);
66651da177e4SLinus Torvalds 	if (status)
66661da177e4SLinus Torvalds 		goto out;
6667bf269551SChuck Lever 	status = decode_readlink(xdr, rqstp);
66681da177e4SLinus Torvalds out:
66691da177e4SLinus Torvalds 	return status;
66701da177e4SLinus Torvalds }
66711da177e4SLinus Torvalds 
66721da177e4SLinus Torvalds /*
66731da177e4SLinus Torvalds  * Decode READDIR response
66741da177e4SLinus Torvalds  */
6675bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6676bf269551SChuck Lever 				struct nfs4_readdir_res *res)
66771da177e4SLinus Torvalds {
66781da177e4SLinus Torvalds 	struct compound_hdr hdr;
66791da177e4SLinus Torvalds 	int status;
66801da177e4SLinus Torvalds 
6681bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66821da177e4SLinus Torvalds 	if (status)
66831da177e4SLinus Torvalds 		goto out;
6684bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66859b7b9fccSAndy Adamson 	if (status)
66869b7b9fccSAndy Adamson 		goto out;
6687bf269551SChuck Lever 	status = decode_putfh(xdr);
66881da177e4SLinus Torvalds 	if (status)
66891da177e4SLinus Torvalds 		goto out;
6690bf269551SChuck Lever 	status = decode_readdir(xdr, rqstp, res);
66911da177e4SLinus Torvalds out:
66921da177e4SLinus Torvalds 	return status;
66931da177e4SLinus Torvalds }
66941da177e4SLinus Torvalds 
66951da177e4SLinus Torvalds /*
66961da177e4SLinus Torvalds  * Decode Read response
66971da177e4SLinus Torvalds  */
6698bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
66999137bdf3SAnna Schumaker 			     struct nfs_pgio_res *res)
67001da177e4SLinus Torvalds {
67011da177e4SLinus Torvalds 	struct compound_hdr hdr;
67021da177e4SLinus Torvalds 	int status;
67031da177e4SLinus Torvalds 
6704bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6705aabff4ddSPeng Tao 	res->op_status = hdr.status;
67061da177e4SLinus Torvalds 	if (status)
67071da177e4SLinus Torvalds 		goto out;
6708bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67099b7b9fccSAndy Adamson 	if (status)
67109b7b9fccSAndy Adamson 		goto out;
6711bf269551SChuck Lever 	status = decode_putfh(xdr);
67121da177e4SLinus Torvalds 	if (status)
67131da177e4SLinus Torvalds 		goto out;
6714bf269551SChuck Lever 	status = decode_read(xdr, rqstp, res);
67151da177e4SLinus Torvalds 	if (!status)
67161da177e4SLinus Torvalds 		status = res->count;
67171da177e4SLinus Torvalds out:
67181da177e4SLinus Torvalds 	return status;
67191da177e4SLinus Torvalds }
67201da177e4SLinus Torvalds 
67211da177e4SLinus Torvalds /*
67221da177e4SLinus Torvalds  * Decode WRITE response
67231da177e4SLinus Torvalds  */
6724bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
67259137bdf3SAnna Schumaker 			      struct nfs_pgio_res *res)
67261da177e4SLinus Torvalds {
67271da177e4SLinus Torvalds 	struct compound_hdr hdr;
67281da177e4SLinus Torvalds 	int status;
67291da177e4SLinus Torvalds 
6730bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6731aabff4ddSPeng Tao 	res->op_status = hdr.status;
67321da177e4SLinus Torvalds 	if (status)
67331da177e4SLinus Torvalds 		goto out;
6734bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67359b7b9fccSAndy Adamson 	if (status)
67369b7b9fccSAndy Adamson 		goto out;
6737bf269551SChuck Lever 	status = decode_putfh(xdr);
67381da177e4SLinus Torvalds 	if (status)
67391da177e4SLinus Torvalds 		goto out;
6740bf269551SChuck Lever 	status = decode_write(xdr, res);
67414f9838c7STrond Myklebust 	if (status)
67424f9838c7STrond Myklebust 		goto out;
67437ffd1064SFred Isaman 	if (res->fattr)
67446926afd1STrond Myklebust 		decode_getfattr(xdr, res->fattr, res->server);
67451da177e4SLinus Torvalds 	if (!status)
67461da177e4SLinus Torvalds 		status = res->count;
67471da177e4SLinus Torvalds out:
67481da177e4SLinus Torvalds 	return status;
67491da177e4SLinus Torvalds }
67501da177e4SLinus Torvalds 
67511da177e4SLinus Torvalds /*
67521da177e4SLinus Torvalds  * Decode COMMIT response
67531da177e4SLinus Torvalds  */
6754bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
67550b7c0153SFred Isaman 			       struct nfs_commitres *res)
67561da177e4SLinus Torvalds {
67571da177e4SLinus Torvalds 	struct compound_hdr hdr;
67581da177e4SLinus Torvalds 	int status;
67591da177e4SLinus Torvalds 
6760bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6761aabff4ddSPeng Tao 	res->op_status = hdr.status;
67621da177e4SLinus Torvalds 	if (status)
67631da177e4SLinus Torvalds 		goto out;
6764bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67659b7b9fccSAndy Adamson 	if (status)
67669b7b9fccSAndy Adamson 		goto out;
6767bf269551SChuck Lever 	status = decode_putfh(xdr);
67681da177e4SLinus Torvalds 	if (status)
67691da177e4SLinus Torvalds 		goto out;
6770bf269551SChuck Lever 	status = decode_commit(xdr, res);
67711da177e4SLinus Torvalds out:
67721da177e4SLinus Torvalds 	return status;
67731da177e4SLinus Torvalds }
67741da177e4SLinus Torvalds 
67751da177e4SLinus Torvalds /*
67768b173218SRicardo Labiaga  * Decode FSINFO response
67771da177e4SLinus Torvalds  */
6778bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
67793dda5e43SBenny Halevy 			       struct nfs4_fsinfo_res *res)
67801da177e4SLinus Torvalds {
67811da177e4SLinus Torvalds 	struct compound_hdr hdr;
67821da177e4SLinus Torvalds 	int status;
67831da177e4SLinus Torvalds 
6784bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67851da177e4SLinus Torvalds 	if (!status)
6786bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
67879b7b9fccSAndy Adamson 	if (!status)
6788bf269551SChuck Lever 		status = decode_putfh(xdr);
67891da177e4SLinus Torvalds 	if (!status)
6790bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->fsinfo);
67911da177e4SLinus Torvalds 	return status;
67921da177e4SLinus Torvalds }
67931da177e4SLinus Torvalds 
67941da177e4SLinus Torvalds /*
67958b173218SRicardo Labiaga  * Decode PATHCONF response
67961da177e4SLinus Torvalds  */
6797bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6798d45b2989SBenny Halevy 				 struct nfs4_pathconf_res *res)
67991da177e4SLinus Torvalds {
68001da177e4SLinus Torvalds 	struct compound_hdr hdr;
68011da177e4SLinus Torvalds 	int status;
68021da177e4SLinus Torvalds 
6803bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68041da177e4SLinus Torvalds 	if (!status)
6805bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
68069b7b9fccSAndy Adamson 	if (!status)
6807bf269551SChuck Lever 		status = decode_putfh(xdr);
68081da177e4SLinus Torvalds 	if (!status)
6809bf269551SChuck Lever 		status = decode_pathconf(xdr, res->pathconf);
68101da177e4SLinus Torvalds 	return status;
68111da177e4SLinus Torvalds }
68121da177e4SLinus Torvalds 
68131da177e4SLinus Torvalds /*
68148b173218SRicardo Labiaga  * Decode STATFS response
68151da177e4SLinus Torvalds  */
6816bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
681724ad148aSBenny Halevy 			       struct nfs4_statfs_res *res)
68181da177e4SLinus Torvalds {
68191da177e4SLinus Torvalds 	struct compound_hdr hdr;
68201da177e4SLinus Torvalds 	int status;
68211da177e4SLinus Torvalds 
6822bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68231da177e4SLinus Torvalds 	if (!status)
6824bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
68259b7b9fccSAndy Adamson 	if (!status)
6826bf269551SChuck Lever 		status = decode_putfh(xdr);
68271da177e4SLinus Torvalds 	if (!status)
6828bf269551SChuck Lever 		status = decode_statfs(xdr, res->fsstat);
68291da177e4SLinus Torvalds 	return status;
68301da177e4SLinus Torvalds }
68311da177e4SLinus Torvalds 
68321da177e4SLinus Torvalds /*
68338b173218SRicardo Labiaga  * Decode GETATTR_BITMAP response
68341da177e4SLinus Torvalds  */
6835bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6836bf269551SChuck Lever 				    struct xdr_stream *xdr,
6837bf269551SChuck Lever 				    struct nfs4_server_caps_res *res)
68381da177e4SLinus Torvalds {
68391da177e4SLinus Torvalds 	struct compound_hdr hdr;
68401da177e4SLinus Torvalds 	int status;
68411da177e4SLinus Torvalds 
6842bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68439b7b9fccSAndy Adamson 	if (status)
68449b7b9fccSAndy Adamson 		goto out;
6845bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
68469b7b9fccSAndy Adamson 	if (status)
68471da177e4SLinus Torvalds 		goto out;
6848bf269551SChuck Lever 	status = decode_putfh(xdr);
6849bf269551SChuck Lever 	if (status)
68501da177e4SLinus Torvalds 		goto out;
6851bf269551SChuck Lever 	status = decode_server_caps(xdr, res);
68521da177e4SLinus Torvalds out:
68531da177e4SLinus Torvalds 	return status;
68541da177e4SLinus Torvalds }
68551da177e4SLinus Torvalds 
68561da177e4SLinus Torvalds /*
68571da177e4SLinus Torvalds  * Decode RENEW response
68581da177e4SLinus Torvalds  */
6859bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6860bf269551SChuck Lever 			      void *__unused)
68611da177e4SLinus Torvalds {
68621da177e4SLinus Torvalds 	struct compound_hdr hdr;
68631da177e4SLinus Torvalds 	int status;
68641da177e4SLinus Torvalds 
6865bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68661da177e4SLinus Torvalds 	if (!status)
6867bf269551SChuck Lever 		status = decode_renew(xdr);
68681da177e4SLinus Torvalds 	return status;
68691da177e4SLinus Torvalds }
68701da177e4SLinus Torvalds 
68711da177e4SLinus Torvalds /*
68728b173218SRicardo Labiaga  * Decode SETCLIENTID response
68731da177e4SLinus Torvalds  */
6874bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6875bf269551SChuck Lever 				    struct xdr_stream *xdr,
6876bb8b27e5STrond Myklebust 				    struct nfs4_setclientid_res *res)
68771da177e4SLinus Torvalds {
68781da177e4SLinus Torvalds 	struct compound_hdr hdr;
68791da177e4SLinus Torvalds 	int status;
68801da177e4SLinus Torvalds 
6881bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68821da177e4SLinus Torvalds 	if (!status)
6883bf269551SChuck Lever 		status = decode_setclientid(xdr, res);
68841da177e4SLinus Torvalds 	return status;
68851da177e4SLinus Torvalds }
68861da177e4SLinus Torvalds 
68871da177e4SLinus Torvalds /*
68888b173218SRicardo Labiaga  * Decode SETCLIENTID_CONFIRM response
68891da177e4SLinus Torvalds  */
6890bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
689183ca7f5aSChuck Lever 					    struct xdr_stream *xdr)
68921da177e4SLinus Torvalds {
68931da177e4SLinus Torvalds 	struct compound_hdr hdr;
68941da177e4SLinus Torvalds 	int status;
68951da177e4SLinus Torvalds 
6896bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68971da177e4SLinus Torvalds 	if (!status)
6898bf269551SChuck Lever 		status = decode_setclientid_confirm(xdr);
68991da177e4SLinus Torvalds 	return status;
69001da177e4SLinus Torvalds }
69011da177e4SLinus Torvalds 
69021da177e4SLinus Torvalds /*
69038b173218SRicardo Labiaga  * Decode DELEGRETURN response
69041da177e4SLinus Torvalds  */
6905bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6906bf269551SChuck Lever 				    struct xdr_stream *xdr,
6907bf269551SChuck Lever 				    struct nfs4_delegreturnres *res)
69081da177e4SLinus Torvalds {
69091da177e4SLinus Torvalds 	struct compound_hdr hdr;
69101da177e4SLinus Torvalds 	int status;
69111da177e4SLinus Torvalds 
6912bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
69139b7b9fccSAndy Adamson 	if (status)
69149b7b9fccSAndy Adamson 		goto out;
6915bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
69169b7b9fccSAndy Adamson 	if (status)
6917fa178f29STrond Myklebust 		goto out;
6918bf269551SChuck Lever 	status = decode_putfh(xdr);
6919fa178f29STrond Myklebust 	if (status != 0)
6920fa178f29STrond Myklebust 		goto out;
6921e144cbccSTrond Myklebust 	status = decode_getfattr(xdr, res->fattr, res->server);
6922556ae3bbSJeff Layton 	if (status != 0)
6923556ae3bbSJeff Layton 		goto out;
6924e144cbccSTrond Myklebust 	status = decode_delegreturn(xdr);
6925fa178f29STrond Myklebust out:
69261da177e4SLinus Torvalds 	return status;
69271da177e4SLinus Torvalds }
69281da177e4SLinus Torvalds 
6929683b57b4STrond Myklebust /*
69308b173218SRicardo Labiaga  * Decode FS_LOCATIONS response
6931683b57b4STrond Myklebust  */
6932bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6933bf269551SChuck Lever 				     struct xdr_stream *xdr,
693422958463SBenny Halevy 				     struct nfs4_fs_locations_res *res)
6935683b57b4STrond Myklebust {
6936683b57b4STrond Myklebust 	struct compound_hdr hdr;
6937683b57b4STrond Myklebust 	int status;
6938683b57b4STrond Myklebust 
6939bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
69409b7b9fccSAndy Adamson 	if (status)
69419b7b9fccSAndy Adamson 		goto out;
6942bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
69439b7b9fccSAndy Adamson 	if (status)
6944683b57b4STrond Myklebust 		goto out;
6945bf269551SChuck Lever 	status = decode_putfh(xdr);
6946bf269551SChuck Lever 	if (status)
6947683b57b4STrond Myklebust 		goto out;
6948b03d735bSChuck Lever 	if (res->migration) {
6949b03d735bSChuck Lever 		xdr_enter_page(xdr, PAGE_SIZE);
6950b03d735bSChuck Lever 		status = decode_getfattr_generic(xdr,
6951b03d735bSChuck Lever 					&res->fs_locations->fattr,
6952b03d735bSChuck Lever 					 NULL, res->fs_locations,
6953b03d735bSChuck Lever 					 NULL, res->fs_locations->server);
6954b03d735bSChuck Lever 		if (status)
6955b03d735bSChuck Lever 			goto out;
6956b03d735bSChuck Lever 		if (res->renew)
6957b03d735bSChuck Lever 			status = decode_renew(xdr);
6958b03d735bSChuck Lever 	} else {
6959bf269551SChuck Lever 		status = decode_lookup(xdr);
6960bf269551SChuck Lever 		if (status)
6961683b57b4STrond Myklebust 			goto out;
6962bf269551SChuck Lever 		xdr_enter_page(xdr, PAGE_SIZE);
6963b03d735bSChuck Lever 		status = decode_getfattr_generic(xdr,
6964b03d735bSChuck Lever 					&res->fs_locations->fattr,
69658b7e3f49STrond Myklebust 					 NULL, res->fs_locations,
6966aa9c2669SDavid Quigley 					 NULL, res->fs_locations->server);
6967b03d735bSChuck Lever 	}
6968683b57b4STrond Myklebust out:
6969683b57b4STrond Myklebust 	return status;
6970683b57b4STrond Myklebust }
6971683b57b4STrond Myklebust 
69725a5ea0d4SBryan Schumaker /*
69735a5ea0d4SBryan Schumaker  * Decode SECINFO response
69745a5ea0d4SBryan Schumaker  */
69755a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
69765a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
69775a5ea0d4SBryan Schumaker 				struct nfs4_secinfo_res *res)
69785a5ea0d4SBryan Schumaker {
69795a5ea0d4SBryan Schumaker 	struct compound_hdr hdr;
69805a5ea0d4SBryan Schumaker 	int status;
69815a5ea0d4SBryan Schumaker 
69825a5ea0d4SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
69835a5ea0d4SBryan Schumaker 	if (status)
69845a5ea0d4SBryan Schumaker 		goto out;
69855a5ea0d4SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
69865a5ea0d4SBryan Schumaker 	if (status)
69875a5ea0d4SBryan Schumaker 		goto out;
69885a5ea0d4SBryan Schumaker 	status = decode_putfh(xdr);
69895a5ea0d4SBryan Schumaker 	if (status)
69905a5ea0d4SBryan Schumaker 		goto out;
69915a5ea0d4SBryan Schumaker 	status = decode_secinfo(xdr, res);
69925a5ea0d4SBryan Schumaker out:
69935a5ea0d4SBryan Schumaker 	return status;
69945a5ea0d4SBryan Schumaker }
69955a5ea0d4SBryan Schumaker 
699644c99933SChuck Lever /*
699744c99933SChuck Lever  * Decode FSID_PRESENT response
699844c99933SChuck Lever  */
699944c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
700044c99933SChuck Lever 				     struct xdr_stream *xdr,
700144c99933SChuck Lever 				     struct nfs4_fsid_present_res *res)
700244c99933SChuck Lever {
700344c99933SChuck Lever 	struct compound_hdr hdr;
700444c99933SChuck Lever 	int status;
700544c99933SChuck Lever 
700644c99933SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
700744c99933SChuck Lever 	if (status)
700844c99933SChuck Lever 		goto out;
700944c99933SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
701044c99933SChuck Lever 	if (status)
701144c99933SChuck Lever 		goto out;
701244c99933SChuck Lever 	status = decode_putfh(xdr);
701344c99933SChuck Lever 	if (status)
701444c99933SChuck Lever 		goto out;
701544c99933SChuck Lever 	status = decode_getfh(xdr, res->fh);
701644c99933SChuck Lever 	if (status)
701744c99933SChuck Lever 		goto out;
701844c99933SChuck Lever 	if (res->renew)
701944c99933SChuck Lever 		status = decode_renew(xdr);
702044c99933SChuck Lever out:
702144c99933SChuck Lever 	return status;
702244c99933SChuck Lever }
702344c99933SChuck Lever 
702499fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
702599fe60d0SBenny Halevy /*
70267c44f1aeSWeston Andros Adamson  * Decode BIND_CONN_TO_SESSION response
70277c44f1aeSWeston Andros Adamson  */
70287c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
70297c44f1aeSWeston Andros Adamson 					struct xdr_stream *xdr,
70307c44f1aeSWeston Andros Adamson 					void *res)
70317c44f1aeSWeston Andros Adamson {
70327c44f1aeSWeston Andros Adamson 	struct compound_hdr hdr;
70337c44f1aeSWeston Andros Adamson 	int status;
70347c44f1aeSWeston Andros Adamson 
70357c44f1aeSWeston Andros Adamson 	status = decode_compound_hdr(xdr, &hdr);
70367c44f1aeSWeston Andros Adamson 	if (!status)
70377c44f1aeSWeston Andros Adamson 		status = decode_bind_conn_to_session(xdr, res);
70387c44f1aeSWeston Andros Adamson 	return status;
70397c44f1aeSWeston Andros Adamson }
70407c44f1aeSWeston Andros Adamson 
70417c44f1aeSWeston Andros Adamson /*
70428b173218SRicardo Labiaga  * Decode EXCHANGE_ID response
704399fe60d0SBenny Halevy  */
7044bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7045bf269551SChuck Lever 				    struct xdr_stream *xdr,
704699fe60d0SBenny Halevy 				    void *res)
704799fe60d0SBenny Halevy {
704899fe60d0SBenny Halevy 	struct compound_hdr hdr;
704999fe60d0SBenny Halevy 	int status;
705099fe60d0SBenny Halevy 
7051bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
705299fe60d0SBenny Halevy 	if (!status)
7053bf269551SChuck Lever 		status = decode_exchange_id(xdr, res);
705499fe60d0SBenny Halevy 	return status;
705599fe60d0SBenny Halevy }
70562050f0ccSAndy Adamson 
70572050f0ccSAndy Adamson /*
70588b173218SRicardo Labiaga  * Decode CREATE_SESSION response
7059fc931582SAndy Adamson  */
7060bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7061bf269551SChuck Lever 				       struct xdr_stream *xdr,
7062fc931582SAndy Adamson 				       struct nfs41_create_session_res *res)
7063fc931582SAndy Adamson {
7064fc931582SAndy Adamson 	struct compound_hdr hdr;
7065fc931582SAndy Adamson 	int status;
7066fc931582SAndy Adamson 
7067bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7068fc931582SAndy Adamson 	if (!status)
7069bf269551SChuck Lever 		status = decode_create_session(xdr, res);
7070fc931582SAndy Adamson 	return status;
7071fc931582SAndy Adamson }
7072fc931582SAndy Adamson 
7073fc931582SAndy Adamson /*
70748b173218SRicardo Labiaga  * Decode DESTROY_SESSION response
70750f3e66c6SAndy Adamson  */
7076bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7077bf269551SChuck Lever 					struct xdr_stream *xdr,
7078bf269551SChuck Lever 					void *res)
70790f3e66c6SAndy Adamson {
70800f3e66c6SAndy Adamson 	struct compound_hdr hdr;
70810f3e66c6SAndy Adamson 	int status;
70820f3e66c6SAndy Adamson 
7083bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
70840f3e66c6SAndy Adamson 	if (!status)
7085bf269551SChuck Lever 		status = decode_destroy_session(xdr, res);
70860f3e66c6SAndy Adamson 	return status;
70870f3e66c6SAndy Adamson }
70880f3e66c6SAndy Adamson 
70890f3e66c6SAndy Adamson /*
709066245539STrond Myklebust  * Decode DESTROY_CLIENTID response
709166245539STrond Myklebust  */
709266245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
709366245539STrond Myklebust 					struct xdr_stream *xdr,
709466245539STrond Myklebust 					void *res)
709566245539STrond Myklebust {
709666245539STrond Myklebust 	struct compound_hdr hdr;
709766245539STrond Myklebust 	int status;
709866245539STrond Myklebust 
709966245539STrond Myklebust 	status = decode_compound_hdr(xdr, &hdr);
710066245539STrond Myklebust 	if (!status)
710166245539STrond Myklebust 		status = decode_destroy_clientid(xdr, res);
710266245539STrond Myklebust 	return status;
710366245539STrond Myklebust }
710466245539STrond Myklebust 
710566245539STrond Myklebust /*
71068b173218SRicardo Labiaga  * Decode SEQUENCE response
7107fc01cea9SAndy Adamson  */
7108bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7109bf269551SChuck Lever 				 struct xdr_stream *xdr,
7110fc01cea9SAndy Adamson 				 struct nfs4_sequence_res *res)
7111fc01cea9SAndy Adamson {
7112fc01cea9SAndy Adamson 	struct compound_hdr hdr;
7113fc01cea9SAndy Adamson 	int status;
7114fc01cea9SAndy Adamson 
7115bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7116fc01cea9SAndy Adamson 	if (!status)
7117bf269551SChuck Lever 		status = decode_sequence(xdr, res, rqstp);
7118fc01cea9SAndy Adamson 	return status;
7119fc01cea9SAndy Adamson }
7120fc01cea9SAndy Adamson 
7121fc01cea9SAndy Adamson /*
71228b173218SRicardo Labiaga  * Decode GET_LEASE_TIME response
71232050f0ccSAndy Adamson  */
7124bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7125bf269551SChuck Lever 				       struct xdr_stream *xdr,
71262050f0ccSAndy Adamson 				       struct nfs4_get_lease_time_res *res)
71272050f0ccSAndy Adamson {
71282050f0ccSAndy Adamson 	struct compound_hdr hdr;
71292050f0ccSAndy Adamson 	int status;
71302050f0ccSAndy Adamson 
7131bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
71322050f0ccSAndy Adamson 	if (!status)
7133bf269551SChuck Lever 		status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
71342050f0ccSAndy Adamson 	if (!status)
7135bf269551SChuck Lever 		status = decode_putrootfh(xdr);
71362050f0ccSAndy Adamson 	if (!status)
7137bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->lr_fsinfo);
71382050f0ccSAndy Adamson 	return status;
71392050f0ccSAndy Adamson }
714018019753SRicardo Labiaga 
714118019753SRicardo Labiaga /*
714218019753SRicardo Labiaga  * Decode RECLAIM_COMPLETE response
714318019753SRicardo Labiaga  */
7144bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7145bf269551SChuck Lever 					 struct xdr_stream *xdr,
714618019753SRicardo Labiaga 					 struct nfs41_reclaim_complete_res *res)
714718019753SRicardo Labiaga {
714818019753SRicardo Labiaga 	struct compound_hdr hdr;
714918019753SRicardo Labiaga 	int status;
715018019753SRicardo Labiaga 
7151bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
715218019753SRicardo Labiaga 	if (!status)
7153bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, rqstp);
715418019753SRicardo Labiaga 	if (!status)
71558ee2b78aSHimangi Saraogi 		status = decode_reclaim_complete(xdr, NULL);
715618019753SRicardo Labiaga 	return status;
715718019753SRicardo Labiaga }
7158b1f69b75SAndy Adamson 
7159b1f69b75SAndy Adamson /*
7160b1f69b75SAndy Adamson  * Decode GETDEVINFO response
7161b1f69b75SAndy Adamson  */
7162bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7163bf269551SChuck Lever 				      struct xdr_stream *xdr,
7164b1f69b75SAndy Adamson 				      struct nfs4_getdeviceinfo_res *res)
7165b1f69b75SAndy Adamson {
7166b1f69b75SAndy Adamson 	struct compound_hdr hdr;
7167b1f69b75SAndy Adamson 	int status;
7168b1f69b75SAndy Adamson 
7169bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7170b1f69b75SAndy Adamson 	if (status != 0)
7171b1f69b75SAndy Adamson 		goto out;
7172bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7173b1f69b75SAndy Adamson 	if (status != 0)
7174b1f69b75SAndy Adamson 		goto out;
71754e590803STrond Myklebust 	status = decode_getdeviceinfo(xdr, res);
7176b1f69b75SAndy Adamson out:
7177b1f69b75SAndy Adamson 	return status;
7178b1f69b75SAndy Adamson }
7179b1f69b75SAndy Adamson 
7180b1f69b75SAndy Adamson /*
7181b1f69b75SAndy Adamson  * Decode LAYOUTGET response
7182b1f69b75SAndy Adamson  */
7183bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7184bf269551SChuck Lever 				  struct xdr_stream *xdr,
7185b1f69b75SAndy Adamson 				  struct nfs4_layoutget_res *res)
7186b1f69b75SAndy Adamson {
7187b1f69b75SAndy Adamson 	struct compound_hdr hdr;
7188b1f69b75SAndy Adamson 	int status;
7189b1f69b75SAndy Adamson 
7190bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7191b1f69b75SAndy Adamson 	if (status)
7192b1f69b75SAndy Adamson 		goto out;
7193bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7194b1f69b75SAndy Adamson 	if (status)
7195b1f69b75SAndy Adamson 		goto out;
7196bf269551SChuck Lever 	status = decode_putfh(xdr);
7197b1f69b75SAndy Adamson 	if (status)
7198b1f69b75SAndy Adamson 		goto out;
7199bf269551SChuck Lever 	status = decode_layoutget(xdr, rqstp, res);
7200b1f69b75SAndy Adamson out:
7201b1f69b75SAndy Adamson 	return status;
7202b1f69b75SAndy Adamson }
7203863a3c6cSAndy Adamson 
7204863a3c6cSAndy Adamson /*
7205cbe82603SBenny Halevy  * Decode LAYOUTRETURN response
7206cbe82603SBenny Halevy  */
7207cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7208cbe82603SBenny Halevy 				     struct xdr_stream *xdr,
7209cbe82603SBenny Halevy 				     struct nfs4_layoutreturn_res *res)
7210cbe82603SBenny Halevy {
7211cbe82603SBenny Halevy 	struct compound_hdr hdr;
7212cbe82603SBenny Halevy 	int status;
7213cbe82603SBenny Halevy 
7214cbe82603SBenny Halevy 	status = decode_compound_hdr(xdr, &hdr);
7215cbe82603SBenny Halevy 	if (status)
7216cbe82603SBenny Halevy 		goto out;
7217cbe82603SBenny Halevy 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7218cbe82603SBenny Halevy 	if (status)
7219cbe82603SBenny Halevy 		goto out;
7220cbe82603SBenny Halevy 	status = decode_putfh(xdr);
7221cbe82603SBenny Halevy 	if (status)
7222cbe82603SBenny Halevy 		goto out;
7223cbe82603SBenny Halevy 	status = decode_layoutreturn(xdr, res);
7224cbe82603SBenny Halevy out:
7225cbe82603SBenny Halevy 	return status;
7226cbe82603SBenny Halevy }
7227cbe82603SBenny Halevy 
7228cbe82603SBenny Halevy /*
7229863a3c6cSAndy Adamson  * Decode LAYOUTCOMMIT response
7230863a3c6cSAndy Adamson  */
7231863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7232863a3c6cSAndy Adamson 				     struct xdr_stream *xdr,
7233863a3c6cSAndy Adamson 				     struct nfs4_layoutcommit_res *res)
7234863a3c6cSAndy Adamson {
7235863a3c6cSAndy Adamson 	struct compound_hdr hdr;
7236863a3c6cSAndy Adamson 	int status;
7237863a3c6cSAndy Adamson 
7238863a3c6cSAndy Adamson 	status = decode_compound_hdr(xdr, &hdr);
7239863a3c6cSAndy Adamson 	if (status)
7240863a3c6cSAndy Adamson 		goto out;
7241863a3c6cSAndy Adamson 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7242863a3c6cSAndy Adamson 	if (status)
7243863a3c6cSAndy Adamson 		goto out;
7244863a3c6cSAndy Adamson 	status = decode_putfh(xdr);
7245863a3c6cSAndy Adamson 	if (status)
7246863a3c6cSAndy Adamson 		goto out;
7247863a3c6cSAndy Adamson 	status = decode_layoutcommit(xdr, rqstp, res);
7248863a3c6cSAndy Adamson 	if (status)
7249863a3c6cSAndy Adamson 		goto out;
72506926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
7251863a3c6cSAndy Adamson out:
7252863a3c6cSAndy Adamson 	return status;
7253863a3c6cSAndy Adamson }
7254fca78d6dSBryan Schumaker 
7255fca78d6dSBryan Schumaker /*
7256fca78d6dSBryan Schumaker  * Decode SECINFO_NO_NAME response
7257fca78d6dSBryan Schumaker  */
7258fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7259fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
7260fca78d6dSBryan Schumaker 					struct nfs4_secinfo_res *res)
7261fca78d6dSBryan Schumaker {
7262fca78d6dSBryan Schumaker 	struct compound_hdr hdr;
7263fca78d6dSBryan Schumaker 	int status;
7264fca78d6dSBryan Schumaker 
7265fca78d6dSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
7266fca78d6dSBryan Schumaker 	if (status)
7267fca78d6dSBryan Schumaker 		goto out;
7268fca78d6dSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7269fca78d6dSBryan Schumaker 	if (status)
7270fca78d6dSBryan Schumaker 		goto out;
7271fca78d6dSBryan Schumaker 	status = decode_putrootfh(xdr);
7272fca78d6dSBryan Schumaker 	if (status)
7273fca78d6dSBryan Schumaker 		goto out;
727431e4dda4SBryan Schumaker 	status = decode_secinfo_no_name(xdr, res);
7275fca78d6dSBryan Schumaker out:
7276fca78d6dSBryan Schumaker 	return status;
7277fca78d6dSBryan Schumaker }
72787d974794SBryan Schumaker 
72797d974794SBryan Schumaker /*
72807d974794SBryan Schumaker  * Decode TEST_STATEID response
72817d974794SBryan Schumaker  */
72827d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
72837d974794SBryan Schumaker 				     struct xdr_stream *xdr,
72847d974794SBryan Schumaker 				     struct nfs41_test_stateid_res *res)
72857d974794SBryan Schumaker {
72867d974794SBryan Schumaker 	struct compound_hdr hdr;
72877d974794SBryan Schumaker 	int status;
72887d974794SBryan Schumaker 
72897d974794SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
72907d974794SBryan Schumaker 	if (status)
72917d974794SBryan Schumaker 		goto out;
72927d974794SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
72937d974794SBryan Schumaker 	if (status)
72947d974794SBryan Schumaker 		goto out;
72957d974794SBryan Schumaker 	status = decode_test_stateid(xdr, res);
72967d974794SBryan Schumaker out:
72977d974794SBryan Schumaker 	return status;
72987d974794SBryan Schumaker }
72999aeda35fSBryan Schumaker 
73009aeda35fSBryan Schumaker /*
73019aeda35fSBryan Schumaker  * Decode FREE_STATEID response
73029aeda35fSBryan Schumaker  */
73039aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
73049aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
73059aeda35fSBryan Schumaker 				     struct nfs41_free_stateid_res *res)
73069aeda35fSBryan Schumaker {
73079aeda35fSBryan Schumaker 	struct compound_hdr hdr;
73089aeda35fSBryan Schumaker 	int status;
73099aeda35fSBryan Schumaker 
73109aeda35fSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
73119aeda35fSBryan Schumaker 	if (status)
73129aeda35fSBryan Schumaker 		goto out;
73139aeda35fSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
73149aeda35fSBryan Schumaker 	if (status)
73159aeda35fSBryan Schumaker 		goto out;
73169aeda35fSBryan Schumaker 	status = decode_free_stateid(xdr, res);
73179aeda35fSBryan Schumaker out:
73189aeda35fSBryan Schumaker 	return status;
73199aeda35fSBryan Schumaker }
732099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
732199fe60d0SBenny Halevy 
7322573c4e1eSChuck Lever /**
7323573c4e1eSChuck Lever  * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7324573c4e1eSChuck Lever  *                      the local page cache.
7325573c4e1eSChuck Lever  * @xdr: XDR stream where entry resides
7326573c4e1eSChuck Lever  * @entry: buffer to fill in with entry data
7327573c4e1eSChuck Lever  * @plus: boolean indicating whether this should be a readdirplus entry
7328573c4e1eSChuck Lever  *
7329573c4e1eSChuck Lever  * Returns zero if successful, otherwise a negative errno value is
7330573c4e1eSChuck Lever  * returned.
7331573c4e1eSChuck Lever  *
7332573c4e1eSChuck Lever  * This function is not invoked during READDIR reply decoding, but
7333573c4e1eSChuck Lever  * rather whenever an application invokes the getdents(2) system call
7334573c4e1eSChuck Lever  * on a directory already in our cache.
7335573c4e1eSChuck Lever  */
7336573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7337573c4e1eSChuck Lever 		       int plus)
73381da177e4SLinus Torvalds {
7339256e48bbSTrond Myklebust 	unsigned int savep;
7340dae100c2SFred Isaman 	uint32_t bitmap[3] = {0};
73411da177e4SLinus Torvalds 	uint32_t len;
7342babddc72SBryan Schumaker 	__be32 *p = xdr_inline_decode(xdr, 4);
7343babddc72SBryan Schumaker 	if (unlikely(!p))
7344babddc72SBryan Schumaker 		goto out_overflow;
7345c08e76d0SChuck Lever 	if (*p == xdr_zero) {
7346babddc72SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
7347babddc72SBryan Schumaker 		if (unlikely(!p))
7348babddc72SBryan Schumaker 			goto out_overflow;
7349c08e76d0SChuck Lever 		if (*p == xdr_zero)
7350573c4e1eSChuck Lever 			return -EAGAIN;
73511da177e4SLinus Torvalds 		entry->eof = 1;
7352573c4e1eSChuck Lever 		return -EBADCOOKIE;
73531da177e4SLinus Torvalds 	}
73541da177e4SLinus Torvalds 
7355babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 12);
7356babddc72SBryan Schumaker 	if (unlikely(!p))
7357babddc72SBryan Schumaker 		goto out_overflow;
73581da177e4SLinus Torvalds 	entry->prev_cookie = entry->cookie;
73591da177e4SLinus Torvalds 	p = xdr_decode_hyper(p, &entry->cookie);
7360c08e76d0SChuck Lever 	entry->len = be32_to_cpup(p);
7361babddc72SBryan Schumaker 
73629af8c222STrond Myklebust 	p = xdr_inline_decode(xdr, entry->len);
7363babddc72SBryan Schumaker 	if (unlikely(!p))
7364babddc72SBryan Schumaker 		goto out_overflow;
73651da177e4SLinus Torvalds 	entry->name = (const char *) p;
73661da177e4SLinus Torvalds 
73671da177e4SLinus Torvalds 	/*
73681da177e4SLinus Torvalds 	 * In case the server doesn't return an inode number,
73691da177e4SLinus Torvalds 	 * we fake one here.  (We don't use inode number 0,
73701da177e4SLinus Torvalds 	 * since glibc seems to choke on it...)
73711da177e4SLinus Torvalds 	 */
73721da177e4SLinus Torvalds 	entry->ino = 1;
73734f082222STrond Myklebust 	entry->fattr->valid = 0;
73741da177e4SLinus Torvalds 
73759af8c222STrond Myklebust 	if (decode_attr_bitmap(xdr, bitmap) < 0)
7376babddc72SBryan Schumaker 		goto out_overflow;
73779af8c222STrond Myklebust 
7378256e48bbSTrond Myklebust 	if (decode_attr_length(xdr, &len, &savep) < 0)
7379babddc72SBryan Schumaker 		goto out_overflow;
73809af8c222STrond Myklebust 
7381573c4e1eSChuck Lever 	if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7382aa9c2669SDavid Quigley 			NULL, entry->label, entry->server) < 0)
7383babddc72SBryan Schumaker 		goto out_overflow;
738428331a46STrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
738528331a46STrond Myklebust 		entry->ino = entry->fattr->mounted_on_fileid;
738628331a46STrond Myklebust 	else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
738782f2e547SBryan Schumaker 		entry->ino = entry->fattr->fileid;
73889af8c222STrond Myklebust 
73890b26a0bfSTrond Myklebust 	entry->d_type = DT_UNKNOWN;
73900b26a0bfSTrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
73910b26a0bfSTrond Myklebust 		entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
73920b26a0bfSTrond Myklebust 
7393573c4e1eSChuck Lever 	return 0;
7394babddc72SBryan Schumaker 
7395babddc72SBryan Schumaker out_overflow:
7396babddc72SBryan Schumaker 	print_overflow_msg(__func__, xdr);
7397573c4e1eSChuck Lever 	return -EAGAIN;
73981da177e4SLinus Torvalds }
73991da177e4SLinus Torvalds 
74001da177e4SLinus Torvalds /*
74011da177e4SLinus Torvalds  * We need to translate between nfs status return values and
74021da177e4SLinus Torvalds  * the local errno values which may not be the same.
74031da177e4SLinus Torvalds  */
74041da177e4SLinus Torvalds static struct {
74051da177e4SLinus Torvalds 	int stat;
74061da177e4SLinus Torvalds 	int errno;
74071da177e4SLinus Torvalds } nfs_errtbl[] = {
74081da177e4SLinus Torvalds 	{ NFS4_OK,		0		},
7409856dff3dSBenny Halevy 	{ NFS4ERR_PERM,		-EPERM		},
7410856dff3dSBenny Halevy 	{ NFS4ERR_NOENT,	-ENOENT		},
7411856dff3dSBenny Halevy 	{ NFS4ERR_IO,		-errno_NFSERR_IO},
7412856dff3dSBenny Halevy 	{ NFS4ERR_NXIO,		-ENXIO		},
7413856dff3dSBenny Halevy 	{ NFS4ERR_ACCESS,	-EACCES		},
7414856dff3dSBenny Halevy 	{ NFS4ERR_EXIST,	-EEXIST		},
7415856dff3dSBenny Halevy 	{ NFS4ERR_XDEV,		-EXDEV		},
7416856dff3dSBenny Halevy 	{ NFS4ERR_NOTDIR,	-ENOTDIR	},
7417856dff3dSBenny Halevy 	{ NFS4ERR_ISDIR,	-EISDIR		},
7418856dff3dSBenny Halevy 	{ NFS4ERR_INVAL,	-EINVAL		},
7419856dff3dSBenny Halevy 	{ NFS4ERR_FBIG,		-EFBIG		},
7420856dff3dSBenny Halevy 	{ NFS4ERR_NOSPC,	-ENOSPC		},
7421856dff3dSBenny Halevy 	{ NFS4ERR_ROFS,		-EROFS		},
7422856dff3dSBenny Halevy 	{ NFS4ERR_MLINK,	-EMLINK		},
7423856dff3dSBenny Halevy 	{ NFS4ERR_NAMETOOLONG,	-ENAMETOOLONG	},
7424856dff3dSBenny Halevy 	{ NFS4ERR_NOTEMPTY,	-ENOTEMPTY	},
7425856dff3dSBenny Halevy 	{ NFS4ERR_DQUOT,	-EDQUOT		},
7426856dff3dSBenny Halevy 	{ NFS4ERR_STALE,	-ESTALE		},
7427856dff3dSBenny Halevy 	{ NFS4ERR_BADHANDLE,	-EBADHANDLE	},
7428856dff3dSBenny Halevy 	{ NFS4ERR_BAD_COOKIE,	-EBADCOOKIE	},
7429856dff3dSBenny Halevy 	{ NFS4ERR_NOTSUPP,	-ENOTSUPP	},
7430856dff3dSBenny Halevy 	{ NFS4ERR_TOOSMALL,	-ETOOSMALL	},
7431fdcb4577STrond Myklebust 	{ NFS4ERR_SERVERFAULT,	-EREMOTEIO	},
7432856dff3dSBenny Halevy 	{ NFS4ERR_BADTYPE,	-EBADTYPE	},
7433856dff3dSBenny Halevy 	{ NFS4ERR_LOCKED,	-EAGAIN		},
7434856dff3dSBenny Halevy 	{ NFS4ERR_SYMLINK,	-ELOOP		},
7435856dff3dSBenny Halevy 	{ NFS4ERR_OP_ILLEGAL,	-EOPNOTSUPP	},
7436856dff3dSBenny Halevy 	{ NFS4ERR_DEADLOCK,	-EDEADLK	},
7437856dff3dSBenny Halevy 	{ -1,			-EIO		}
74381da177e4SLinus Torvalds };
74391da177e4SLinus Torvalds 
74401da177e4SLinus Torvalds /*
74411da177e4SLinus Torvalds  * Convert an NFS error code to a local one.
74421da177e4SLinus Torvalds  * This one is used jointly by NFSv2 and NFSv3.
74431da177e4SLinus Torvalds  */
74441da177e4SLinus Torvalds static int
74450a8ea437SDavid Howells nfs4_stat_to_errno(int stat)
74461da177e4SLinus Torvalds {
74471da177e4SLinus Torvalds 	int i;
74481da177e4SLinus Torvalds 	for (i = 0; nfs_errtbl[i].stat != -1; i++) {
74491da177e4SLinus Torvalds 		if (nfs_errtbl[i].stat == stat)
74501da177e4SLinus Torvalds 			return nfs_errtbl[i].errno;
74511da177e4SLinus Torvalds 	}
74521da177e4SLinus Torvalds 	if (stat <= 10000 || stat > 10100) {
74531da177e4SLinus Torvalds 		/* The server is looney tunes. */
7454fdcb4577STrond Myklebust 		return -EREMOTEIO;
74551da177e4SLinus Torvalds 	}
74561da177e4SLinus Torvalds 	/* If we cannot translate the error, the recovery routines should
74571da177e4SLinus Torvalds 	 * handle it.
74581da177e4SLinus Torvalds 	 * Note: remaining NFSv4 error codes have values > 10000, so should
74591da177e4SLinus Torvalds 	 * not conflict with native Linux error codes.
74601da177e4SLinus Torvalds 	 */
7461856dff3dSBenny Halevy 	return -stat;
74621da177e4SLinus Torvalds }
74631da177e4SLinus Torvalds 
74641c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2
74651c6dcbe5SAnna Schumaker #include "nfs42xdr.c"
74661c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */
74671c6dcbe5SAnna Schumaker 
74681da177e4SLinus Torvalds #define PROC(proc, argtype, restype)				\
74691da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = {					\
74701da177e4SLinus Torvalds 	.p_proc   = NFSPROC4_COMPOUND,				\
74719f06c719SChuck Lever 	.p_encode = (kxdreproc_t)nfs4_xdr_##argtype,		\
7472bf269551SChuck Lever 	.p_decode = (kxdrdproc_t)nfs4_xdr_##restype,		\
74732bea90d4SChuck Lever 	.p_arglen = NFS4_##argtype##_sz,			\
74742bea90d4SChuck Lever 	.p_replen = NFS4_##restype##_sz,			\
7475cc0175c1SChuck Lever 	.p_statidx = NFSPROC4_CLNT_##proc,			\
7476cc0175c1SChuck Lever 	.p_name   = #proc,					\
74771da177e4SLinus Torvalds }
74781da177e4SLinus Torvalds 
74797c61f0d3SAnna Schumaker #define STUB(proc)		\
74807c61f0d3SAnna Schumaker [NFSPROC4_CLNT_##proc] = {	\
74817c61f0d3SAnna Schumaker 	.p_name = #proc,	\
74827c61f0d3SAnna Schumaker }
74837c61f0d3SAnna Schumaker 
74841da177e4SLinus Torvalds struct rpc_procinfo	nfs4_procedures[] = {
74851da177e4SLinus Torvalds 	PROC(READ,		enc_read,		dec_read),
74861da177e4SLinus Torvalds 	PROC(WRITE,		enc_write,		dec_write),
74871da177e4SLinus Torvalds 	PROC(COMMIT,		enc_commit,		dec_commit),
74881da177e4SLinus Torvalds 	PROC(OPEN,		enc_open,		dec_open),
74891da177e4SLinus Torvalds 	PROC(OPEN_CONFIRM,	enc_open_confirm,	dec_open_confirm),
74901da177e4SLinus Torvalds 	PROC(OPEN_NOATTR,	enc_open_noattr,	dec_open_noattr),
74911da177e4SLinus Torvalds 	PROC(OPEN_DOWNGRADE,	enc_open_downgrade,	dec_open_downgrade),
74921da177e4SLinus Torvalds 	PROC(CLOSE,		enc_close,		dec_close),
74931da177e4SLinus Torvalds 	PROC(SETATTR,		enc_setattr,		dec_setattr),
74941da177e4SLinus Torvalds 	PROC(FSINFO,		enc_fsinfo,		dec_fsinfo),
74951da177e4SLinus Torvalds 	PROC(RENEW,		enc_renew,		dec_renew),
74961da177e4SLinus Torvalds 	PROC(SETCLIENTID,	enc_setclientid,	dec_setclientid),
74971da177e4SLinus Torvalds 	PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
74981da177e4SLinus Torvalds 	PROC(LOCK,		enc_lock,		dec_lock),
74991da177e4SLinus Torvalds 	PROC(LOCKT,		enc_lockt,		dec_lockt),
75001da177e4SLinus Torvalds 	PROC(LOCKU,		enc_locku,		dec_locku),
75011da177e4SLinus Torvalds 	PROC(ACCESS,		enc_access,		dec_access),
75021da177e4SLinus Torvalds 	PROC(GETATTR,		enc_getattr,		dec_getattr),
75031da177e4SLinus Torvalds 	PROC(LOOKUP,		enc_lookup,		dec_lookup),
75041da177e4SLinus Torvalds 	PROC(LOOKUP_ROOT,	enc_lookup_root,	dec_lookup_root),
75051da177e4SLinus Torvalds 	PROC(REMOVE,		enc_remove,		dec_remove),
75061da177e4SLinus Torvalds 	PROC(RENAME,		enc_rename,		dec_rename),
75071da177e4SLinus Torvalds 	PROC(LINK,		enc_link,		dec_link),
75081da177e4SLinus Torvalds 	PROC(SYMLINK,		enc_symlink,		dec_symlink),
75091da177e4SLinus Torvalds 	PROC(CREATE,		enc_create,		dec_create),
75101da177e4SLinus Torvalds 	PROC(PATHCONF,		enc_pathconf,		dec_pathconf),
75111da177e4SLinus Torvalds 	PROC(STATFS,		enc_statfs,		dec_statfs),
75121da177e4SLinus Torvalds 	PROC(READLINK,		enc_readlink,		dec_readlink),
75131da177e4SLinus Torvalds 	PROC(READDIR,		enc_readdir,		dec_readdir),
75141da177e4SLinus Torvalds 	PROC(SERVER_CAPS,	enc_server_caps,	dec_server_caps),
75151da177e4SLinus Torvalds 	PROC(DELEGRETURN,	enc_delegreturn,	dec_delegreturn),
7516029d105eSJ. Bruce Fields 	PROC(GETACL,		enc_getacl,		dec_getacl),
751723ec6965SJ. Bruce Fields 	PROC(SETACL,		enc_setacl,		dec_setacl),
7518683b57b4STrond Myklebust 	PROC(FS_LOCATIONS,	enc_fs_locations,	dec_fs_locations),
7519d3c7b7ccSTrond Myklebust 	PROC(RELEASE_LOCKOWNER,	enc_release_lockowner,	dec_release_lockowner),
75205a5ea0d4SBryan Schumaker 	PROC(SECINFO,		enc_secinfo,		dec_secinfo),
752144c99933SChuck Lever 	PROC(FSID_PRESENT,	enc_fsid_present,	dec_fsid_present),
752299fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
752399fe60d0SBenny Halevy 	PROC(EXCHANGE_ID,	enc_exchange_id,	dec_exchange_id),
7524fc931582SAndy Adamson 	PROC(CREATE_SESSION,	enc_create_session,	dec_create_session),
75250f3e66c6SAndy Adamson 	PROC(DESTROY_SESSION,	enc_destroy_session,	dec_destroy_session),
7526fc01cea9SAndy Adamson 	PROC(SEQUENCE,		enc_sequence,		dec_sequence),
75272050f0ccSAndy Adamson 	PROC(GET_LEASE_TIME,	enc_get_lease_time,	dec_get_lease_time),
752818019753SRicardo Labiaga 	PROC(RECLAIM_COMPLETE,	enc_reclaim_complete,	dec_reclaim_complete),
7529b1f69b75SAndy Adamson 	PROC(GETDEVICEINFO,	enc_getdeviceinfo,	dec_getdeviceinfo),
7530b1f69b75SAndy Adamson 	PROC(LAYOUTGET,		enc_layoutget,		dec_layoutget),
7531863a3c6cSAndy Adamson 	PROC(LAYOUTCOMMIT,	enc_layoutcommit,	dec_layoutcommit),
7532cbe82603SBenny Halevy 	PROC(LAYOUTRETURN,	enc_layoutreturn,	dec_layoutreturn),
7533fca78d6dSBryan Schumaker 	PROC(SECINFO_NO_NAME,	enc_secinfo_no_name,	dec_secinfo_no_name),
75347d974794SBryan Schumaker 	PROC(TEST_STATEID,	enc_test_stateid,	dec_test_stateid),
75359aeda35fSBryan Schumaker 	PROC(FREE_STATEID,	enc_free_stateid,	dec_free_stateid),
75367c61f0d3SAnna Schumaker 	STUB(GETDEVICELIST),
7537ad24ecfbSTrond Myklebust 	PROC(BIND_CONN_TO_SESSION,
7538ad24ecfbSTrond Myklebust 			enc_bind_conn_to_session, dec_bind_conn_to_session),
753966245539STrond Myklebust 	PROC(DESTROY_CLIENTID,	enc_destroy_clientid,	dec_destroy_clientid),
754099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
75411c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2
75421c6dcbe5SAnna Schumaker 	PROC(SEEK,		enc_seek,		dec_seek),
7543f4ac1674SAnna Schumaker 	PROC(ALLOCATE,		enc_allocate,		dec_allocate),
7544624bd5b7SAnna Schumaker 	PROC(DEALLOCATE,	enc_deallocate,		dec_deallocate),
7545be3a5d23STrond Myklebust 	PROC(LAYOUTSTATS,	enc_layoutstats,	dec_layoutstats),
754636022770SPeng Tao 	PROC(CLONE,		enc_clone,		dec_clone),
75472e72448bSAnna Schumaker 	PROC(COPY,		enc_copy,		dec_copy),
75481c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */
75491da177e4SLinus Torvalds };
75501da177e4SLinus Torvalds 
7551a613fa16STrond Myklebust const struct rpc_version nfs_version4 = {
75521da177e4SLinus Torvalds 	.number			= 4,
7553e8c96f8cSTobias Klauser 	.nrprocs		= ARRAY_SIZE(nfs4_procedures),
75541da177e4SLinus Torvalds 	.procs			= nfs4_procedures
75551da177e4SLinus Torvalds };
75561da177e4SLinus Torvalds 
75571da177e4SLinus Torvalds /*
75581da177e4SLinus Torvalds  * Local variables:
75591da177e4SLinus Torvalds  *  c-basic-offset: 8
75601da177e4SLinus Torvalds  * End:
75611da177e4SLinus Torvalds  */
7562