xref: /openbmc/linux/fs/nfs/nfs4xdr.c (revision f23f6584)
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"
57f23f6584SChuck Lever #include "nfs4trace.h"
584882ef72SAlexandros Batsakis #include "internal.h"
5940c64c26SAnna Schumaker #include "nfs4idmap.h"
6076e697baSTrond Myklebust #include "nfs4session.h"
61b1f69b75SAndy Adamson #include "pnfs.h"
62f092075dSChuck Lever #include "netns.h"
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds #define NFSDBG_FACILITY		NFSDBG_XDR
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */
671da177e4SLinus Torvalds #define errno_NFSERR_IO		EIO
681da177e4SLinus Torvalds 
6956f487f8SFred Isaman struct compound_hdr;
700a8ea437SDavid Howells static int nfs4_stat_to_errno(int);
7156f487f8SFred Isaman static void encode_layoutget(struct xdr_stream *xdr,
7256f487f8SFred Isaman 			     const struct nfs4_layoutget_args *args,
7356f487f8SFred Isaman 			     struct compound_hdr *hdr);
7456f487f8SFred Isaman static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
7556f487f8SFred Isaman 			     struct nfs4_layoutget_res *res);
761da177e4SLinus Torvalds 
771da177e4SLinus Torvalds /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
781da177e4SLinus Torvalds #ifdef DEBUG
791da177e4SLinus Torvalds #define NFS4_MAXTAGLEN		20
801da177e4SLinus Torvalds #else
811da177e4SLinus Torvalds #define NFS4_MAXTAGLEN		0
821da177e4SLinus Torvalds #endif
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds /* lock,open owner id:
859f958ab8STrond Myklebust  * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT  >> 2)
861da177e4SLinus Torvalds  */
8795b72eb0STrond Myklebust #define open_owner_id_maxsz	(1 + 2 + 1 + 1 + 2)
88d035c36cSTrond Myklebust #define lock_owner_id_maxsz	(1 + 1 + 4)
899104a55dSTrond Myklebust #define decode_lockowner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
901da177e4SLinus Torvalds #define compound_encode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
911da177e4SLinus Torvalds #define compound_decode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
921da177e4SLinus Torvalds #define op_encode_hdr_maxsz	(1)
931da177e4SLinus Torvalds #define op_decode_hdr_maxsz	(2)
949104a55dSTrond Myklebust #define encode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
959104a55dSTrond Myklebust #define decode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
969104a55dSTrond Myklebust #define encode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
979104a55dSTrond Myklebust #define decode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
981da177e4SLinus Torvalds #define encode_putfh_maxsz	(op_encode_hdr_maxsz + 1 + \
991da177e4SLinus Torvalds 				(NFS4_FHSIZE >> 2))
1001da177e4SLinus Torvalds #define decode_putfh_maxsz	(op_decode_hdr_maxsz)
1011da177e4SLinus Torvalds #define encode_putrootfh_maxsz	(op_encode_hdr_maxsz)
1021da177e4SLinus Torvalds #define decode_putrootfh_maxsz	(op_decode_hdr_maxsz)
1031da177e4SLinus Torvalds #define encode_getfh_maxsz      (op_encode_hdr_maxsz)
1041da177e4SLinus Torvalds #define decode_getfh_maxsz      (op_decode_hdr_maxsz + 1 + \
1051da177e4SLinus Torvalds 				((3+NFS4_FHSIZE) >> 2))
106e5012d1fSAndy Adamson #define nfs4_fattr_bitmap_maxsz 4
10796928206SJ. Bruce Fields #define encode_getattr_maxsz    (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
10836b3743fSTrond Myklebust #define nfstime4_maxsz		(3)
1091da177e4SLinus Torvalds #define nfs4_name_maxsz		(1 + ((3 + NFS4_MAXNAMLEN) >> 2))
1101da177e4SLinus Torvalds #define nfs4_path_maxsz		(1 + ((3 + NFS4_MAXPATHLEN) >> 2))
111bd625ba8STrond Myklebust #define nfs4_owner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
112bd625ba8STrond Myklebust #define nfs4_group_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
113aa9c2669SDavid Quigley #ifdef CONFIG_NFS_V4_SECURITY_LABEL
114aa9c2669SDavid Quigley /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
115aa9c2669SDavid Quigley #define	nfs4_label_maxsz	(4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
116aa9c2669SDavid Quigley #else
117aa9c2669SDavid Quigley #define	nfs4_label_maxsz	0
118aa9c2669SDavid Quigley #endif
11988034c3dSAndy Adamson /* We support only one layout type per file system */
12088034c3dSAndy Adamson #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
12196928206SJ. Bruce Fields /* This is based on getfattr, which uses the most attributes: */
12296928206SJ. Bruce Fields #define nfs4_fattr_value_maxsz	(1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
12336b3743fSTrond Myklebust 				3*nfstime4_maxsz + \
12436b3743fSTrond Myklebust 				nfs4_owner_maxsz + \
125aa9c2669SDavid Quigley 				nfs4_group_maxsz + nfs4_label_maxsz + \
126aa9c2669SDavid Quigley 				 decode_mdsthreshold_maxsz))
12796928206SJ. Bruce Fields #define nfs4_fattr_maxsz	(nfs4_fattr_bitmap_maxsz + \
12896928206SJ. Bruce Fields 				nfs4_fattr_value_maxsz)
12996928206SJ. Bruce Fields #define decode_getattr_maxsz    (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
1309104a55dSTrond Myklebust #define encode_attrs_maxsz	(nfs4_fattr_bitmap_maxsz + \
1319104a55dSTrond Myklebust 				 1 + 2 + 1 + \
1329104a55dSTrond Myklebust 				nfs4_owner_maxsz + \
1339104a55dSTrond Myklebust 				nfs4_group_maxsz + \
134aa9c2669SDavid Quigley 				nfs4_label_maxsz + \
13536b3743fSTrond Myklebust 				1 + nfstime4_maxsz + \
13636b3743fSTrond Myklebust 				1 + nfstime4_maxsz)
1371da177e4SLinus Torvalds #define encode_savefh_maxsz     (op_encode_hdr_maxsz)
1381da177e4SLinus Torvalds #define decode_savefh_maxsz     (op_decode_hdr_maxsz)
13956ae19f3STrond Myklebust #define encode_restorefh_maxsz  (op_encode_hdr_maxsz)
14056ae19f3STrond Myklebust #define decode_restorefh_maxsz  (op_decode_hdr_maxsz)
1412f42b5d0SFred Isaman #define encode_fsinfo_maxsz	(encode_getattr_maxsz)
142dae100c2SFred Isaman /* The 5 accounts for the PNFS attributes, and assumes that at most three
143dae100c2SFred Isaman  * layout types will be returned.
144dae100c2SFred Isaman  */
145dae100c2SFred Isaman #define decode_fsinfo_maxsz	(op_decode_hdr_maxsz + \
146dae100c2SFred Isaman 				 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
1471da177e4SLinus Torvalds #define encode_renew_maxsz	(op_encode_hdr_maxsz + 3)
1481da177e4SLinus Torvalds #define decode_renew_maxsz	(op_decode_hdr_maxsz)
1491da177e4SLinus Torvalds #define encode_setclientid_maxsz \
1501da177e4SLinus Torvalds 				(op_encode_hdr_maxsz + \
151cc38bac3SChuck Lever 				XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
152b8fb2f59SJeff Layton 				/* client name */ \
153b8fb2f59SJeff Layton 				1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
154cc38bac3SChuck Lever 				1 /* sc_prog */ + \
1556dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
1566dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
157cc38bac3SChuck Lever 				1) /* sc_cb_ident */
1581da177e4SLinus Torvalds #define decode_setclientid_maxsz \
1591da177e4SLinus Torvalds 				(op_decode_hdr_maxsz + \
1606dd3436bSChuck Lever 				2 /* clientid */ + \
1616dd3436bSChuck Lever 				XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
1626dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
1636dd3436bSChuck Lever 				1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
1641da177e4SLinus Torvalds #define encode_setclientid_confirm_maxsz \
1651da177e4SLinus Torvalds 				(op_encode_hdr_maxsz + \
1661da177e4SLinus Torvalds 				3 + (NFS4_VERIFIER_SIZE >> 2))
1671da177e4SLinus Torvalds #define decode_setclientid_confirm_maxsz \
1681da177e4SLinus Torvalds 				(op_decode_hdr_maxsz)
169e6889620STrond Myklebust #define encode_lookup_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
170e6889620STrond Myklebust #define decode_lookup_maxsz	(op_decode_hdr_maxsz)
1715b5faaf6SJeff Layton #define encode_lookupp_maxsz	(op_encode_hdr_maxsz)
1725b5faaf6SJeff Layton #define decode_lookupp_maxsz	(op_decode_hdr_maxsz)
1732cebf828STrond Myklebust #define encode_share_access_maxsz \
1742cebf828STrond Myklebust 				(2)
1754882ef72SAlexandros Batsakis #define encode_createmode_maxsz	(1 + encode_attrs_maxsz + encode_verifier_maxsz)
1762cebf828STrond Myklebust #define encode_opentype_maxsz	(1 + encode_createmode_maxsz)
1772cebf828STrond Myklebust #define encode_claim_null_maxsz	(1 + nfs4_name_maxsz)
1782cebf828STrond Myklebust #define encode_open_maxsz	(op_encode_hdr_maxsz + \
1792cebf828STrond Myklebust 				2 + encode_share_access_maxsz + 2 + \
1802cebf828STrond Myklebust 				open_owner_id_maxsz + \
1812cebf828STrond Myklebust 				encode_opentype_maxsz + \
1822cebf828STrond Myklebust 				encode_claim_null_maxsz)
1835a1f6d9eSTrond Myklebust #define decode_space_limit_maxsz	(3)
1842cebf828STrond Myklebust #define decode_ace_maxsz	(3 + nfs4_owner_maxsz)
1859104a55dSTrond Myklebust #define decode_delegation_maxsz	(1 + decode_stateid_maxsz + 1 + \
1865a1f6d9eSTrond Myklebust 				decode_space_limit_maxsz + \
1872cebf828STrond Myklebust 				decode_ace_maxsz)
1882cebf828STrond Myklebust #define decode_change_info_maxsz	(5)
1892cebf828STrond Myklebust #define decode_open_maxsz	(op_decode_hdr_maxsz + \
1909104a55dSTrond Myklebust 				decode_stateid_maxsz + \
1912cebf828STrond Myklebust 				decode_change_info_maxsz + 1 + \
1922cebf828STrond Myklebust 				nfs4_fattr_bitmap_maxsz + \
1932cebf828STrond Myklebust 				decode_delegation_maxsz)
1949104a55dSTrond Myklebust #define encode_open_confirm_maxsz \
1959104a55dSTrond Myklebust 				(op_encode_hdr_maxsz + \
1969104a55dSTrond Myklebust 				 encode_stateid_maxsz + 1)
1979104a55dSTrond Myklebust #define decode_open_confirm_maxsz \
1989104a55dSTrond Myklebust 				(op_decode_hdr_maxsz + \
1999104a55dSTrond Myklebust 				 decode_stateid_maxsz)
2009104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \
2019104a55dSTrond Myklebust 				(op_encode_hdr_maxsz + \
2029104a55dSTrond Myklebust 				 encode_stateid_maxsz + 1 + \
2039104a55dSTrond Myklebust 				 encode_share_access_maxsz)
2049104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \
2059104a55dSTrond Myklebust 				(op_decode_hdr_maxsz + \
2069104a55dSTrond Myklebust 				 decode_stateid_maxsz)
2079104a55dSTrond Myklebust #define encode_close_maxsz	(op_encode_hdr_maxsz + \
2089104a55dSTrond Myklebust 				 1 + encode_stateid_maxsz)
2099104a55dSTrond Myklebust #define decode_close_maxsz	(op_decode_hdr_maxsz + \
2109104a55dSTrond Myklebust 				 decode_stateid_maxsz)
2119104a55dSTrond Myklebust #define encode_setattr_maxsz	(op_encode_hdr_maxsz + \
2129104a55dSTrond Myklebust 				 encode_stateid_maxsz + \
2139104a55dSTrond Myklebust 				 encode_attrs_maxsz)
2149104a55dSTrond Myklebust #define decode_setattr_maxsz	(op_decode_hdr_maxsz + \
2159104a55dSTrond Myklebust 				 nfs4_fattr_bitmap_maxsz)
2169104a55dSTrond Myklebust #define encode_read_maxsz	(op_encode_hdr_maxsz + \
2179104a55dSTrond Myklebust 				 encode_stateid_maxsz + 3)
2189104a55dSTrond Myklebust #define decode_read_maxsz	(op_decode_hdr_maxsz + 2)
2199104a55dSTrond Myklebust #define encode_readdir_maxsz	(op_encode_hdr_maxsz + \
220aa9c2669SDavid Quigley 				 2 + encode_verifier_maxsz + 5 + \
221aa9c2669SDavid Quigley 				nfs4_label_maxsz)
2229104a55dSTrond Myklebust #define decode_readdir_maxsz	(op_decode_hdr_maxsz + \
223a7697f6fSChuck Lever 				 decode_verifier_maxsz)
2249104a55dSTrond Myklebust #define encode_readlink_maxsz	(op_encode_hdr_maxsz)
2259104a55dSTrond Myklebust #define decode_readlink_maxsz	(op_decode_hdr_maxsz + 1)
2269104a55dSTrond Myklebust #define encode_write_maxsz	(op_encode_hdr_maxsz + \
2279104a55dSTrond Myklebust 				 encode_stateid_maxsz + 4)
2289104a55dSTrond Myklebust #define decode_write_maxsz	(op_decode_hdr_maxsz + \
2299104a55dSTrond Myklebust 				 2 + decode_verifier_maxsz)
2309104a55dSTrond Myklebust #define encode_commit_maxsz	(op_encode_hdr_maxsz + 3)
2319104a55dSTrond Myklebust #define decode_commit_maxsz	(op_decode_hdr_maxsz + \
2329104a55dSTrond Myklebust 				 decode_verifier_maxsz)
2331da177e4SLinus Torvalds #define encode_remove_maxsz	(op_encode_hdr_maxsz + \
2341da177e4SLinus Torvalds 				nfs4_name_maxsz)
2356ce18391SBenny Halevy #define decode_remove_maxsz	(op_decode_hdr_maxsz + \
2366ce18391SBenny Halevy 				 decode_change_info_maxsz)
2371da177e4SLinus Torvalds #define encode_rename_maxsz	(op_encode_hdr_maxsz + \
2381da177e4SLinus Torvalds 				2 * nfs4_name_maxsz)
2396ce18391SBenny Halevy #define decode_rename_maxsz	(op_decode_hdr_maxsz + \
2406ce18391SBenny Halevy 				 decode_change_info_maxsz + \
2416ce18391SBenny Halevy 				 decode_change_info_maxsz)
2421da177e4SLinus Torvalds #define encode_link_maxsz	(op_encode_hdr_maxsz + \
2431da177e4SLinus Torvalds 				nfs4_name_maxsz)
2446ce18391SBenny Halevy #define decode_link_maxsz	(op_decode_hdr_maxsz + decode_change_info_maxsz)
245daccbdedSTrond Myklebust #define encode_lockowner_maxsz	(7)
2469104a55dSTrond Myklebust #define encode_lock_maxsz	(op_encode_hdr_maxsz + \
2479104a55dSTrond Myklebust 				 7 + \
248daccbdedSTrond Myklebust 				 1 + encode_stateid_maxsz + 1 + \
249daccbdedSTrond Myklebust 				 encode_lockowner_maxsz)
2509104a55dSTrond Myklebust #define decode_lock_denied_maxsz \
2519104a55dSTrond Myklebust 				(8 + decode_lockowner_maxsz)
2529104a55dSTrond Myklebust #define decode_lock_maxsz	(op_decode_hdr_maxsz + \
2539104a55dSTrond Myklebust 				 decode_lock_denied_maxsz)
254daccbdedSTrond Myklebust #define encode_lockt_maxsz	(op_encode_hdr_maxsz + 5 + \
255daccbdedSTrond Myklebust 				encode_lockowner_maxsz)
2569104a55dSTrond Myklebust #define decode_lockt_maxsz	(op_decode_hdr_maxsz + \
2579104a55dSTrond Myklebust 				 decode_lock_denied_maxsz)
2589104a55dSTrond Myklebust #define encode_locku_maxsz	(op_encode_hdr_maxsz + 3 + \
2599104a55dSTrond Myklebust 				 encode_stateid_maxsz + \
2609104a55dSTrond Myklebust 				 4)
2619104a55dSTrond Myklebust #define decode_locku_maxsz	(op_decode_hdr_maxsz + \
2629104a55dSTrond Myklebust 				 decode_stateid_maxsz)
263d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \
264d3c7b7ccSTrond Myklebust 				(op_encode_hdr_maxsz + \
265d3c7b7ccSTrond Myklebust 				 encode_lockowner_maxsz)
266d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \
267d3c7b7ccSTrond Myklebust 				(op_decode_hdr_maxsz)
2689104a55dSTrond Myklebust #define encode_access_maxsz	(op_encode_hdr_maxsz + 1)
2699104a55dSTrond Myklebust #define decode_access_maxsz	(op_decode_hdr_maxsz + 2)
2701da177e4SLinus Torvalds #define encode_symlink_maxsz	(op_encode_hdr_maxsz + \
2711da177e4SLinus Torvalds 				1 + nfs4_name_maxsz + \
27294a6d753SChuck Lever 				1 + \
27396928206SJ. Bruce Fields 				nfs4_fattr_maxsz)
2741da177e4SLinus Torvalds #define decode_symlink_maxsz	(op_decode_hdr_maxsz + 8)
2751da177e4SLinus Torvalds #define encode_create_maxsz	(op_encode_hdr_maxsz + \
2769104a55dSTrond Myklebust 				1 + 2 + nfs4_name_maxsz + \
2779104a55dSTrond Myklebust 				encode_attrs_maxsz)
2782cebf828STrond Myklebust #define decode_create_maxsz	(op_decode_hdr_maxsz + \
2792cebf828STrond Myklebust 				decode_change_info_maxsz + \
2802cebf828STrond Myklebust 				nfs4_fattr_bitmap_maxsz)
2819104a55dSTrond Myklebust #define encode_statfs_maxsz	(encode_getattr_maxsz)
2829104a55dSTrond Myklebust #define decode_statfs_maxsz	(decode_getattr_maxsz)
2831da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
2841da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
2859104a55dSTrond Myklebust #define encode_getacl_maxsz	(encode_getattr_maxsz)
2869104a55dSTrond Myklebust #define decode_getacl_maxsz	(op_decode_hdr_maxsz + \
2879104a55dSTrond Myklebust 				 nfs4_fattr_bitmap_maxsz + 1)
2889104a55dSTrond Myklebust #define encode_setacl_maxsz	(op_encode_hdr_maxsz + \
2899104a55dSTrond Myklebust 				 encode_stateid_maxsz + 3)
2909104a55dSTrond Myklebust #define decode_setacl_maxsz	(decode_setattr_maxsz)
291e6889620STrond Myklebust #define encode_fs_locations_maxsz \
292e6889620STrond Myklebust 				(encode_getattr_maxsz)
293e6889620STrond Myklebust #define decode_fs_locations_maxsz \
294e6889620STrond Myklebust 				(0)
2955a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
2961650add2SBryan Schumaker #define decode_secinfo_maxsz	(op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
2979b7b9fccSAndy Adamson 
2989b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
299fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64)
300d751f748SJim Rees #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
301d751f748SJim Rees 			 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
302fc931582SAndy Adamson 
30399fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
30499fe60d0SBenny Halevy 				encode_verifier_maxsz + \
30599fe60d0SBenny Halevy 				1 /* co_ownerid.len */ + \
306b8fb2f59SJeff Layton 				/* eia_clientowner */ \
307b8fb2f59SJeff Layton 				1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
30899fe60d0SBenny Halevy 				1 /* flags */ + \
30999fe60d0SBenny Halevy 				1 /* spa_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 + \
313db8ac8baSWeston Andros Adamson 				1 /* implementation id array of size 1 */ + \
314db8ac8baSWeston Andros Adamson 				1 /* nii_domain */ + \
315db8ac8baSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
316db8ac8baSWeston Andros Adamson 				1 /* nii_name */ + \
317d751f748SJim Rees 				XDR_QUADLEN(IMPL_NAME_LIMIT) + \
318db8ac8baSWeston Andros Adamson 				3 /* nii_date */)
31999fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
32099fe60d0SBenny Halevy 				2 /* eir_clientid */ + \
32199fe60d0SBenny Halevy 				1 /* eir_sequenceid */ + \
32299fe60d0SBenny Halevy 				1 /* eir_flags */ + \
32399fe60d0SBenny Halevy 				1 /* spr_how */ + \
3242031cd1aSWeston Andros Adamson 				  /* max is SP4_MACH_CRED (for now) */ + \
3252031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
3262031cd1aSWeston Andros Adamson 				1 + NFS4_OP_MAP_NUM_WORDS + \
32799fe60d0SBenny Halevy 				2 /* eir_server_owner.so_minor_id */ + \
32899fe60d0SBenny Halevy 				/* eir_server_owner.so_major_id<> */ \
32999fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
33099fe60d0SBenny Halevy 				/* eir_server_scope<> */ \
33199fe60d0SBenny Halevy 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
33299fe60d0SBenny Halevy 				1 /* eir_server_impl_id array length */ + \
3337d2ed9acSWeston Andros Adamson 				1 /* nii_domain */ + \
3347d2ed9acSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
3357d2ed9acSWeston Andros Adamson 				1 /* nii_name */ + \
3367d2ed9acSWeston Andros Adamson 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
3377d2ed9acSWeston Andros Adamson 				3 /* nii_date */)
338fc931582SAndy Adamson #define encode_channel_attrs_maxsz  (6 + 1 /* ca_rdma_ird.len (0) */)
339fc931582SAndy Adamson #define decode_channel_attrs_maxsz  (6 + \
340fc931582SAndy Adamson 				     1 /* ca_rdma_ird.len */ + \
341fc931582SAndy Adamson 				     1 /* ca_rdma_ird */)
342fc931582SAndy Adamson #define encode_create_session_maxsz  (op_encode_hdr_maxsz + \
343fc931582SAndy Adamson 				     2 /* csa_clientid */ + \
344fc931582SAndy Adamson 				     1 /* csa_sequence */ + \
345fc931582SAndy Adamson 				     1 /* csa_flags */ + \
346fc931582SAndy Adamson 				     encode_channel_attrs_maxsz + \
347fc931582SAndy Adamson 				     encode_channel_attrs_maxsz + \
348fc931582SAndy Adamson 				     1 /* csa_cb_program */ + \
349fc931582SAndy Adamson 				     1 /* csa_sec_parms.len (1) */ + \
350fc931582SAndy Adamson 				     1 /* cb_secflavor (AUTH_SYS) */ + \
351fc931582SAndy Adamson 				     1 /* stamp */ + \
352fc931582SAndy Adamson 				     1 /* machinename.len */ + \
353fc931582SAndy Adamson 				     XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
354fc931582SAndy Adamson 				     1 /* uid */ + \
355fc931582SAndy Adamson 				     1 /* gid */ + \
356fc931582SAndy Adamson 				     1 /* gids.len (0) */)
357fc931582SAndy Adamson #define decode_create_session_maxsz  (op_decode_hdr_maxsz +	\
358fc931582SAndy Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
359fc931582SAndy Adamson 				     1 /* csr_sequence */ + \
360fc931582SAndy Adamson 				     1 /* csr_flags */ + \
361fc931582SAndy Adamson 				     decode_channel_attrs_maxsz + \
362fc931582SAndy Adamson 				     decode_channel_attrs_maxsz)
3637c44f1aeSWeston Andros Adamson #define encode_bind_conn_to_session_maxsz  (op_encode_hdr_maxsz + \
3647c44f1aeSWeston Andros Adamson 				     /* bctsa_sessid */ \
3657c44f1aeSWeston Andros Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
3667c44f1aeSWeston Andros Adamson 				     1 /* bctsa_dir */ + \
3677c44f1aeSWeston Andros Adamson 				     1 /* bctsa_use_conn_in_rdma_mode */)
3687c44f1aeSWeston Andros Adamson #define decode_bind_conn_to_session_maxsz  (op_decode_hdr_maxsz +	\
3697c44f1aeSWeston Andros Adamson 				     /* bctsr_sessid */ \
3707c44f1aeSWeston Andros Adamson 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
3717c44f1aeSWeston Andros Adamson 				     1 /* bctsr_dir */ + \
3727c44f1aeSWeston Andros Adamson 				     1 /* bctsr_use_conn_in_rdma_mode */)
3730f3e66c6SAndy Adamson #define encode_destroy_session_maxsz    (op_encode_hdr_maxsz + 4)
3740f3e66c6SAndy Adamson #define decode_destroy_session_maxsz    (op_decode_hdr_maxsz)
37566245539STrond Myklebust #define encode_destroy_clientid_maxsz   (op_encode_hdr_maxsz + 2)
37666245539STrond Myklebust #define decode_destroy_clientid_maxsz   (op_decode_hdr_maxsz)
377fc01cea9SAndy Adamson #define encode_sequence_maxsz	(op_encode_hdr_maxsz + \
378fc01cea9SAndy Adamson 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
379fc01cea9SAndy Adamson #define decode_sequence_maxsz	(op_decode_hdr_maxsz + \
380fc01cea9SAndy Adamson 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
38118019753SRicardo Labiaga #define encode_reclaim_complete_maxsz	(op_encode_hdr_maxsz + 4)
38218019753SRicardo Labiaga #define decode_reclaim_complete_maxsz	(op_decode_hdr_maxsz + 4)
38384c9dee3SChristoph Hellwig #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
38484c9dee3SChristoph Hellwig 				XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
38584c9dee3SChristoph Hellwig 				1 /* layout type */ + \
38684c9dee3SChristoph Hellwig 				1 /* maxcount */ + \
38784c9dee3SChristoph Hellwig 				1 /* bitmap size */ + \
38884c9dee3SChristoph Hellwig 				1 /* notification bitmap length */ + \
38984c9dee3SChristoph Hellwig 				1 /* notification bitmap, word 0 */)
390b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
391b1f69b75SAndy Adamson 				1 /* layout type */ + \
392b1f69b75SAndy Adamson 				1 /* opaque devaddr4 length */ + \
393b1f69b75SAndy Adamson 				  /* devaddr4 payload is read into page */ \
394b1f69b75SAndy Adamson 				1 /* notification bitmap length */ + \
39584c9dee3SChristoph Hellwig 				1 /* notification bitmap, word 0 */)
396b1f69b75SAndy Adamson #define encode_layoutget_maxsz	(op_encode_hdr_maxsz + 10 + \
397b1f69b75SAndy Adamson 				encode_stateid_maxsz)
398b1f69b75SAndy Adamson #define decode_layoutget_maxsz	(op_decode_hdr_maxsz + 8 + \
399b1f69b75SAndy Adamson 				decode_stateid_maxsz + \
400b1f69b75SAndy Adamson 				XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
401863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
402863a3c6cSAndy Adamson 				2 /* offset */ + \
403863a3c6cSAndy Adamson 				2 /* length */ + \
404863a3c6cSAndy Adamson 				1 /* reclaim */ + \
405863a3c6cSAndy Adamson 				encode_stateid_maxsz + \
406863a3c6cSAndy Adamson 				1 /* new offset (true) */ + \
407863a3c6cSAndy Adamson 				2 /* last byte written */ + \
408863a3c6cSAndy Adamson 				1 /* nt_timechanged (false) */ + \
409863a3c6cSAndy Adamson 				1 /* layoutupdate4 layout type */ + \
4105f919c9fSChristoph Hellwig 				1 /* layoutupdate4 opaqueue len */)
4115f919c9fSChristoph Hellwig 				  /* the actual content of layoutupdate4 should
4125f919c9fSChristoph Hellwig 				     be allocated by drivers and spliced in
4135f919c9fSChristoph Hellwig 				     using xdr_write_pages */
414863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
415cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
416cbe82603SBenny Halevy 				encode_stateid_maxsz + \
4176669cb8bSTrond Myklebust 				1 + \
4186669cb8bSTrond Myklebust 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
419cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
420cbe82603SBenny Halevy 				1 + decode_stateid_maxsz)
421fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
422fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
4237d974794SBryan Schumaker #define encode_test_stateid_maxsz	(op_encode_hdr_maxsz + 2 + \
4247d974794SBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
4257d974794SBryan Schumaker #define decode_test_stateid_maxsz	(op_decode_hdr_maxsz + 2 + 1)
4269aeda35fSBryan Schumaker #define encode_free_stateid_maxsz	(op_encode_hdr_maxsz + 1 + \
4279aeda35fSBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
4289f79fb48SAndy Adamson #define decode_free_stateid_maxsz	(op_decode_hdr_maxsz)
4299b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */
4309b7b9fccSAndy Adamson #define encode_sequence_maxsz	0
4319b7b9fccSAndy Adamson #define decode_sequence_maxsz	0
432cf805165STrond Myklebust #define encode_layoutreturn_maxsz 0
433cf805165STrond Myklebust #define decode_layoutreturn_maxsz 0
43456f487f8SFred Isaman #define encode_layoutget_maxsz	0
43556f487f8SFred Isaman #define decode_layoutget_maxsz	0
4369b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
4379b7b9fccSAndy Adamson 
4381da177e4SLinus Torvalds #define NFS4_enc_compound_sz	(1024)  /* XXX: large enough? */
4391da177e4SLinus Torvalds #define NFS4_dec_compound_sz	(1024)  /* XXX: large enough? */
4401da177e4SLinus Torvalds #define NFS4_enc_read_sz	(compound_encode_hdr_maxsz + \
4419b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4421da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4439104a55dSTrond Myklebust 				encode_read_maxsz)
4441da177e4SLinus Torvalds #define NFS4_dec_read_sz	(compound_decode_hdr_maxsz + \
4459b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4461da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4479104a55dSTrond Myklebust 				decode_read_maxsz)
4481da177e4SLinus Torvalds #define NFS4_enc_readlink_sz	(compound_encode_hdr_maxsz + \
4499b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4501da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4519104a55dSTrond Myklebust 				encode_readlink_maxsz)
4521da177e4SLinus Torvalds #define NFS4_dec_readlink_sz	(compound_decode_hdr_maxsz + \
4539b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4541da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4559104a55dSTrond Myklebust 				decode_readlink_maxsz)
4561da177e4SLinus Torvalds #define NFS4_enc_readdir_sz	(compound_encode_hdr_maxsz + \
4579b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4581da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4599104a55dSTrond Myklebust 				encode_readdir_maxsz)
4601da177e4SLinus Torvalds #define NFS4_dec_readdir_sz	(compound_decode_hdr_maxsz + \
4619b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4621da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4639104a55dSTrond Myklebust 				decode_readdir_maxsz)
4641da177e4SLinus Torvalds #define NFS4_enc_write_sz	(compound_encode_hdr_maxsz + \
4659b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4661da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4679104a55dSTrond Myklebust 				encode_write_maxsz + \
4684f9838c7STrond Myklebust 				encode_getattr_maxsz)
4691da177e4SLinus Torvalds #define NFS4_dec_write_sz	(compound_decode_hdr_maxsz + \
4709b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4711da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4729104a55dSTrond Myklebust 				decode_write_maxsz + \
4734f9838c7STrond Myklebust 				decode_getattr_maxsz)
4741da177e4SLinus Torvalds #define NFS4_enc_commit_sz	(compound_encode_hdr_maxsz + \
4759b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4761da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4778582715eSTrond Myklebust 				encode_commit_maxsz)
4781da177e4SLinus Torvalds #define NFS4_dec_commit_sz	(compound_decode_hdr_maxsz + \
4799b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4801da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4818582715eSTrond Myklebust 				decode_commit_maxsz)
4821da177e4SLinus Torvalds #define NFS4_enc_open_sz        (compound_encode_hdr_maxsz + \
4839b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4841da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4852cebf828STrond Myklebust 				encode_open_maxsz + \
4866168f62cSWeston Andros Adamson 				encode_access_maxsz + \
4872cebf828STrond Myklebust 				encode_getfh_maxsz + \
48856f487f8SFred Isaman 				encode_getattr_maxsz + \
48956f487f8SFred Isaman 				encode_layoutget_maxsz)
4901da177e4SLinus Torvalds #define NFS4_dec_open_sz        (compound_decode_hdr_maxsz + \
4919b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4921da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4932cebf828STrond Myklebust 				decode_open_maxsz + \
4946168f62cSWeston Andros Adamson 				decode_access_maxsz + \
4952cebf828STrond Myklebust 				decode_getfh_maxsz + \
49656f487f8SFred Isaman 				decode_getattr_maxsz + \
49756f487f8SFred Isaman 				decode_layoutget_maxsz)
4981da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \
4991da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
5001da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
5019104a55dSTrond Myklebust 				 encode_open_confirm_maxsz)
5029104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \
5039104a55dSTrond Myklebust 				(compound_decode_hdr_maxsz + \
5041da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
5059104a55dSTrond Myklebust 				 decode_open_confirm_maxsz)
5061da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz	(compound_encode_hdr_maxsz + \
5079b7b9fccSAndy Adamson 					encode_sequence_maxsz + \
5081da177e4SLinus Torvalds 					encode_putfh_maxsz + \
5092cebf828STrond Myklebust 					encode_open_maxsz + \
5106168f62cSWeston Andros Adamson 					encode_access_maxsz + \
51156f487f8SFred Isaman 					encode_getattr_maxsz + \
51256f487f8SFred Isaman 					encode_layoutget_maxsz)
5131da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz	(compound_decode_hdr_maxsz + \
5149b7b9fccSAndy Adamson 					decode_sequence_maxsz + \
5151da177e4SLinus Torvalds 					decode_putfh_maxsz + \
5162cebf828STrond Myklebust 					decode_open_maxsz + \
5176168f62cSWeston Andros Adamson 					decode_access_maxsz + \
51856f487f8SFred Isaman 					decode_getattr_maxsz + \
51956f487f8SFred Isaman 					decode_layoutget_maxsz)
5201da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \
5211da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
5229b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5231da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
524b6808145STrond Myklebust 				 encode_layoutreturn_maxsz + \
5253947b74dSTrond Myklebust 				 encode_open_downgrade_maxsz)
5261da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \
5271da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
5289b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5291da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
530b6808145STrond Myklebust 				 decode_layoutreturn_maxsz + \
5313947b74dSTrond Myklebust 				 decode_open_downgrade_maxsz)
5321da177e4SLinus Torvalds #define NFS4_enc_close_sz	(compound_encode_hdr_maxsz + \
5339b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5341da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
535cf805165STrond Myklebust 				 encode_layoutreturn_maxsz + \
5369104a55dSTrond Myklebust 				 encode_close_maxsz + \
537516a6af6STrond Myklebust 				 encode_getattr_maxsz)
5381da177e4SLinus Torvalds #define NFS4_dec_close_sz	(compound_decode_hdr_maxsz + \
5399b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5401da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
541cf805165STrond Myklebust 				 decode_layoutreturn_maxsz + \
5429104a55dSTrond Myklebust 				 decode_close_maxsz + \
543516a6af6STrond Myklebust 				 decode_getattr_maxsz)
5441da177e4SLinus Torvalds #define NFS4_enc_setattr_sz	(compound_encode_hdr_maxsz + \
5459b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5461da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
5479104a55dSTrond Myklebust 				 encode_setattr_maxsz + \
5481da177e4SLinus Torvalds 				 encode_getattr_maxsz)
5491da177e4SLinus Torvalds #define NFS4_dec_setattr_sz	(compound_decode_hdr_maxsz + \
5509b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5511da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
5529104a55dSTrond Myklebust 				 decode_setattr_maxsz + \
5539104a55dSTrond Myklebust 				 decode_getattr_maxsz)
5541da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz	(compound_encode_hdr_maxsz + \
5559b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5561da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5571da177e4SLinus Torvalds 				encode_fsinfo_maxsz)
5581da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz	(compound_decode_hdr_maxsz + \
5599b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5601da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5611da177e4SLinus Torvalds 				decode_fsinfo_maxsz)
5621da177e4SLinus Torvalds #define NFS4_enc_renew_sz	(compound_encode_hdr_maxsz + \
5631da177e4SLinus Torvalds 				encode_renew_maxsz)
5641da177e4SLinus Torvalds #define NFS4_dec_renew_sz	(compound_decode_hdr_maxsz + \
5651da177e4SLinus Torvalds 				decode_renew_maxsz)
5661da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz	(compound_encode_hdr_maxsz + \
5671da177e4SLinus Torvalds 				encode_setclientid_maxsz)
5681da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz	(compound_decode_hdr_maxsz + \
5691da177e4SLinus Torvalds 				decode_setclientid_maxsz)
5701da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \
5711da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
57283ca7f5aSChuck Lever 				encode_setclientid_confirm_maxsz)
5731da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \
5741da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
57583ca7f5aSChuck Lever 				decode_setclientid_confirm_maxsz)
5761da177e4SLinus Torvalds #define NFS4_enc_lock_sz        (compound_encode_hdr_maxsz + \
5779b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5781da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5799104a55dSTrond Myklebust 				encode_lock_maxsz)
5801da177e4SLinus Torvalds #define NFS4_dec_lock_sz        (compound_decode_hdr_maxsz + \
5819b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5821da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5839104a55dSTrond Myklebust 				decode_lock_maxsz)
5841da177e4SLinus Torvalds #define NFS4_enc_lockt_sz       (compound_encode_hdr_maxsz + \
5859b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5861da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5879104a55dSTrond Myklebust 				encode_lockt_maxsz)
5889104a55dSTrond Myklebust #define NFS4_dec_lockt_sz       (compound_decode_hdr_maxsz + \
5899b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5909104a55dSTrond Myklebust 				 decode_putfh_maxsz + \
5919104a55dSTrond Myklebust 				 decode_lockt_maxsz)
5921da177e4SLinus Torvalds #define NFS4_enc_locku_sz       (compound_encode_hdr_maxsz + \
5939b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5941da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5959104a55dSTrond Myklebust 				encode_locku_maxsz)
5961da177e4SLinus Torvalds #define NFS4_dec_locku_sz       (compound_decode_hdr_maxsz + \
5979b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5981da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5999104a55dSTrond Myklebust 				decode_locku_maxsz)
600d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \
601d3c7b7ccSTrond Myklebust 				(compound_encode_hdr_maxsz + \
602d3c7b7ccSTrond Myklebust 				 encode_lockowner_maxsz)
603d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \
604d3c7b7ccSTrond Myklebust 				(compound_decode_hdr_maxsz + \
605d3c7b7ccSTrond Myklebust 				 decode_lockowner_maxsz)
6061da177e4SLinus Torvalds #define NFS4_enc_access_sz	(compound_encode_hdr_maxsz + \
6079b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6081da177e4SLinus Torvalds 				encode_putfh_maxsz + \
60976b32999STrond Myklebust 				encode_access_maxsz + \
61076b32999STrond Myklebust 				encode_getattr_maxsz)
6111da177e4SLinus Torvalds #define NFS4_dec_access_sz	(compound_decode_hdr_maxsz + \
6129b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6131da177e4SLinus Torvalds 				decode_putfh_maxsz + \
61476b32999STrond Myklebust 				decode_access_maxsz + \
61576b32999STrond Myklebust 				decode_getattr_maxsz)
6161da177e4SLinus Torvalds #define NFS4_enc_getattr_sz	(compound_encode_hdr_maxsz + \
6179b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6181da177e4SLinus Torvalds 				encode_putfh_maxsz + \
61944c99933SChuck Lever 				encode_getattr_maxsz + \
62044c99933SChuck Lever 				encode_renew_maxsz)
6211da177e4SLinus Torvalds #define NFS4_dec_getattr_sz	(compound_decode_hdr_maxsz + \
6229b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6231da177e4SLinus Torvalds 				decode_putfh_maxsz + \
62444c99933SChuck Lever 				decode_getattr_maxsz + \
62544c99933SChuck Lever 				decode_renew_maxsz)
6261da177e4SLinus Torvalds #define NFS4_enc_lookup_sz	(compound_encode_hdr_maxsz + \
6279b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6281da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6291da177e4SLinus Torvalds 				encode_lookup_maxsz + \
6301da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6311da177e4SLinus Torvalds 				encode_getfh_maxsz)
6321da177e4SLinus Torvalds #define NFS4_dec_lookup_sz	(compound_decode_hdr_maxsz + \
6339b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6341da177e4SLinus Torvalds 				decode_putfh_maxsz + \
635e6889620STrond Myklebust 				decode_lookup_maxsz + \
6361da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6371da177e4SLinus Torvalds 				decode_getfh_maxsz)
6385b5faaf6SJeff Layton #define NFS4_enc_lookupp_sz	(compound_encode_hdr_maxsz + \
6395b5faaf6SJeff Layton 				encode_sequence_maxsz + \
6405b5faaf6SJeff Layton 				encode_putfh_maxsz + \
6415b5faaf6SJeff Layton 				encode_lookupp_maxsz + \
6425b5faaf6SJeff Layton 				encode_getattr_maxsz + \
6435b5faaf6SJeff Layton 				encode_getfh_maxsz)
6445b5faaf6SJeff Layton #define NFS4_dec_lookupp_sz	(compound_decode_hdr_maxsz + \
6455b5faaf6SJeff Layton 				decode_sequence_maxsz + \
6465b5faaf6SJeff Layton 				decode_putfh_maxsz + \
6475b5faaf6SJeff Layton 				decode_lookupp_maxsz + \
6485b5faaf6SJeff Layton 				decode_getattr_maxsz + \
6495b5faaf6SJeff Layton 				decode_getfh_maxsz)
6501da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
6519b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6521da177e4SLinus Torvalds 				encode_putrootfh_maxsz + \
6531da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6541da177e4SLinus Torvalds 				encode_getfh_maxsz)
6551da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
6569b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6571da177e4SLinus Torvalds 				decode_putrootfh_maxsz + \
6581da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6591da177e4SLinus Torvalds 				decode_getfh_maxsz)
6601da177e4SLinus Torvalds #define NFS4_enc_remove_sz	(compound_encode_hdr_maxsz + \
6619b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6621da177e4SLinus Torvalds 				encode_putfh_maxsz + \
663778d2817STrond Myklebust 				encode_remove_maxsz)
6641da177e4SLinus Torvalds #define NFS4_dec_remove_sz	(compound_decode_hdr_maxsz + \
6659b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6661da177e4SLinus Torvalds 				decode_putfh_maxsz + \
667778d2817STrond Myklebust 				decode_remove_maxsz)
6681da177e4SLinus Torvalds #define NFS4_enc_rename_sz	(compound_encode_hdr_maxsz + \
6699b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6701da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6711da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6721da177e4SLinus Torvalds 				encode_putfh_maxsz + \
673778d2817STrond Myklebust 				encode_rename_maxsz)
6741da177e4SLinus Torvalds #define NFS4_dec_rename_sz	(compound_decode_hdr_maxsz + \
6759b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6761da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6771da177e4SLinus Torvalds 				decode_savefh_maxsz + \
6781da177e4SLinus Torvalds 				decode_putfh_maxsz + \
679778d2817STrond Myklebust 				decode_rename_maxsz)
6801da177e4SLinus Torvalds #define NFS4_enc_link_sz	(compound_encode_hdr_maxsz + \
6819b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6821da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6831da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6841da177e4SLinus Torvalds 				encode_putfh_maxsz + \
68591ba2eeeSTrond Myklebust 				encode_link_maxsz + \
68691ba2eeeSTrond Myklebust 				encode_restorefh_maxsz + \
687a9f6991bSTrond Myklebust 				encode_getattr_maxsz)
6881da177e4SLinus Torvalds #define NFS4_dec_link_sz	(compound_decode_hdr_maxsz + \
6899b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6901da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6911da177e4SLinus Torvalds 				decode_savefh_maxsz + \
6921da177e4SLinus Torvalds 				decode_putfh_maxsz + \
69391ba2eeeSTrond Myklebust 				decode_link_maxsz + \
69491ba2eeeSTrond Myklebust 				decode_restorefh_maxsz + \
69591ba2eeeSTrond Myklebust 				decode_getattr_maxsz)
6961da177e4SLinus Torvalds #define NFS4_enc_symlink_sz	(compound_encode_hdr_maxsz + \
6979b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6981da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6991da177e4SLinus Torvalds 				encode_symlink_maxsz + \
7001da177e4SLinus Torvalds 				encode_getattr_maxsz + \
7011da177e4SLinus Torvalds 				encode_getfh_maxsz)
7021da177e4SLinus Torvalds #define NFS4_dec_symlink_sz	(compound_decode_hdr_maxsz + \
7039b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
7041da177e4SLinus Torvalds 				decode_putfh_maxsz + \
7051da177e4SLinus Torvalds 				decode_symlink_maxsz + \
7061da177e4SLinus Torvalds 				decode_getattr_maxsz + \
7071da177e4SLinus Torvalds 				decode_getfh_maxsz)
7081da177e4SLinus Torvalds #define NFS4_enc_create_sz	(compound_encode_hdr_maxsz + \
7099b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
7101da177e4SLinus Torvalds 				encode_putfh_maxsz + \
7111da177e4SLinus Torvalds 				encode_create_maxsz + \
71256ae19f3STrond Myklebust 				encode_getfh_maxsz + \
71356ae19f3STrond Myklebust 				encode_getattr_maxsz)
7141da177e4SLinus Torvalds #define NFS4_dec_create_sz	(compound_decode_hdr_maxsz + \
7159b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
7161da177e4SLinus Torvalds 				decode_putfh_maxsz + \
7171da177e4SLinus Torvalds 				decode_create_maxsz + \
71856ae19f3STrond Myklebust 				decode_getfh_maxsz + \
71956ae19f3STrond Myklebust 				decode_getattr_maxsz)
7201da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz	(compound_encode_hdr_maxsz + \
7219b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
7221da177e4SLinus Torvalds 				encode_putfh_maxsz + \
7231da177e4SLinus Torvalds 				encode_getattr_maxsz)
7241da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz	(compound_decode_hdr_maxsz + \
7259b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
7261da177e4SLinus Torvalds 				decode_putfh_maxsz + \
7271da177e4SLinus Torvalds 				decode_getattr_maxsz)
7281da177e4SLinus Torvalds #define NFS4_enc_statfs_sz	(compound_encode_hdr_maxsz + \
7299b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
7301da177e4SLinus Torvalds 				encode_putfh_maxsz + \
7319104a55dSTrond Myklebust 				encode_statfs_maxsz)
7321da177e4SLinus Torvalds #define NFS4_dec_statfs_sz	(compound_decode_hdr_maxsz + \
7339b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
7341da177e4SLinus Torvalds 				decode_putfh_maxsz + \
7359104a55dSTrond Myklebust 				decode_statfs_maxsz)
7361da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
7379b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
738ab91f264STrond Myklebust 				encode_putfh_maxsz + \
7391da177e4SLinus Torvalds 				encode_getattr_maxsz)
7401da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
7419b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
742ab91f264STrond Myklebust 				decode_putfh_maxsz + \
7431da177e4SLinus Torvalds 				decode_getattr_maxsz)
7441da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz	(compound_encode_hdr_maxsz + \
7459b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
7461da177e4SLinus Torvalds 				encode_putfh_maxsz + \
747586f1c39STrond Myklebust 				encode_layoutreturn_maxsz + \
748fa178f29STrond Myklebust 				encode_delegreturn_maxsz + \
749fa178f29STrond Myklebust 				encode_getattr_maxsz)
7501da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
7519b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
752d8434d4cSTrond Myklebust 				decode_putfh_maxsz + \
753586f1c39STrond Myklebust 				decode_layoutreturn_maxsz + \
754fa178f29STrond Myklebust 				decode_delegreturn_maxsz + \
755fa178f29STrond Myklebust 				decode_getattr_maxsz)
756029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz	(compound_encode_hdr_maxsz + \
7579b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
758029d105eSJ. Bruce Fields 				encode_putfh_maxsz + \
7599104a55dSTrond Myklebust 				encode_getacl_maxsz)
760029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz	(compound_decode_hdr_maxsz + \
7619b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
762029d105eSJ. Bruce Fields 				decode_putfh_maxsz + \
7639104a55dSTrond Myklebust 				decode_getacl_maxsz)
76423ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz	(compound_encode_hdr_maxsz + \
7659b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
76623ec6965SJ. Bruce Fields 				encode_putfh_maxsz + \
7679104a55dSTrond Myklebust 				encode_setacl_maxsz)
76823ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz	(compound_decode_hdr_maxsz + \
7699b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
77023ec6965SJ. Bruce Fields 				decode_putfh_maxsz + \
7719104a55dSTrond Myklebust 				decode_setacl_maxsz)
772683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \
773683b57b4STrond Myklebust 				(compound_encode_hdr_maxsz + \
7749b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
775683b57b4STrond Myklebust 				 encode_putfh_maxsz + \
776e6889620STrond Myklebust 				 encode_lookup_maxsz + \
777b03d735bSChuck Lever 				 encode_fs_locations_maxsz + \
778b03d735bSChuck Lever 				 encode_renew_maxsz)
779683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \
780683b57b4STrond Myklebust 				(compound_decode_hdr_maxsz + \
7819b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
782683b57b4STrond Myklebust 				 decode_putfh_maxsz + \
783e6889620STrond Myklebust 				 decode_lookup_maxsz + \
784b03d735bSChuck Lever 				 decode_fs_locations_maxsz + \
785b03d735bSChuck Lever 				 decode_renew_maxsz)
7865a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz 	(compound_encode_hdr_maxsz + \
7875a5ea0d4SBryan Schumaker 				encode_sequence_maxsz + \
7885a5ea0d4SBryan Schumaker 				encode_putfh_maxsz + \
7895a5ea0d4SBryan Schumaker 				encode_secinfo_maxsz)
7905a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz	(compound_decode_hdr_maxsz + \
7915a5ea0d4SBryan Schumaker 				decode_sequence_maxsz + \
7925a5ea0d4SBryan Schumaker 				decode_putfh_maxsz + \
7935a5ea0d4SBryan Schumaker 				decode_secinfo_maxsz)
79444c99933SChuck Lever #define NFS4_enc_fsid_present_sz \
79544c99933SChuck Lever 				(compound_encode_hdr_maxsz + \
79644c99933SChuck Lever 				 encode_sequence_maxsz + \
79744c99933SChuck Lever 				 encode_putfh_maxsz + \
79844c99933SChuck Lever 				 encode_getfh_maxsz + \
79944c99933SChuck Lever 				 encode_renew_maxsz)
80044c99933SChuck Lever #define NFS4_dec_fsid_present_sz \
80144c99933SChuck Lever 				(compound_decode_hdr_maxsz + \
80244c99933SChuck Lever 				 decode_sequence_maxsz + \
80344c99933SChuck Lever 				 decode_putfh_maxsz + \
80444c99933SChuck Lever 				 decode_getfh_maxsz + \
80544c99933SChuck Lever 				 decode_renew_maxsz)
80699fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
8077c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \
8087c44f1aeSWeston Andros Adamson 				(compound_encode_hdr_maxsz + \
8097c44f1aeSWeston Andros Adamson 				 encode_bind_conn_to_session_maxsz)
8107c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \
8117c44f1aeSWeston Andros Adamson 				(compound_decode_hdr_maxsz + \
8127c44f1aeSWeston Andros Adamson 				 decode_bind_conn_to_session_maxsz)
81399fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \
81499fe60d0SBenny Halevy 				(compound_encode_hdr_maxsz + \
81599fe60d0SBenny Halevy 				 encode_exchange_id_maxsz)
81699fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \
81799fe60d0SBenny Halevy 				(compound_decode_hdr_maxsz + \
81899fe60d0SBenny Halevy 				 decode_exchange_id_maxsz)
819fc931582SAndy Adamson #define NFS4_enc_create_session_sz \
820fc931582SAndy Adamson 				(compound_encode_hdr_maxsz + \
821fc931582SAndy Adamson 				 encode_create_session_maxsz)
822fc931582SAndy Adamson #define NFS4_dec_create_session_sz \
823fc931582SAndy Adamson 				(compound_decode_hdr_maxsz + \
824fc931582SAndy Adamson 				 decode_create_session_maxsz)
8250f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz	(compound_encode_hdr_maxsz + \
8260f3e66c6SAndy Adamson 					 encode_destroy_session_maxsz)
8270f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz	(compound_decode_hdr_maxsz + \
8280f3e66c6SAndy Adamson 					 decode_destroy_session_maxsz)
82966245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz	(compound_encode_hdr_maxsz + \
83066245539STrond Myklebust 					 encode_destroy_clientid_maxsz)
83166245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz	(compound_decode_hdr_maxsz + \
83266245539STrond Myklebust 					 decode_destroy_clientid_maxsz)
833fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \
834fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
835fc01cea9SAndy Adamson 				 encode_sequence_maxsz)
836fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \
837fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
838fc01cea9SAndy Adamson 				 decode_sequence_maxsz)
8392050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz	(compound_encode_hdr_maxsz + \
8402050f0ccSAndy Adamson 					 encode_sequence_maxsz + \
8412050f0ccSAndy Adamson 					 encode_putrootfh_maxsz + \
8422050f0ccSAndy Adamson 					 encode_fsinfo_maxsz)
8432050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz	(compound_decode_hdr_maxsz + \
8442050f0ccSAndy Adamson 					 decode_sequence_maxsz + \
8452050f0ccSAndy Adamson 					 decode_putrootfh_maxsz + \
8462050f0ccSAndy Adamson 					 decode_fsinfo_maxsz)
84718019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz	(compound_encode_hdr_maxsz + \
84818019753SRicardo Labiaga 					 encode_sequence_maxsz + \
84918019753SRicardo Labiaga 					 encode_reclaim_complete_maxsz)
85018019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz	(compound_decode_hdr_maxsz + \
85118019753SRicardo Labiaga 					 decode_sequence_maxsz + \
85218019753SRicardo Labiaga 					 decode_reclaim_complete_maxsz)
853b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz +    \
854b1f69b75SAndy Adamson 				encode_sequence_maxsz +\
855b1f69b75SAndy Adamson 				encode_getdeviceinfo_maxsz)
856b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz +    \
857b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
858b1f69b75SAndy Adamson 				decode_getdeviceinfo_maxsz)
859b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz	(compound_encode_hdr_maxsz + \
860b1f69b75SAndy Adamson 				encode_sequence_maxsz + \
861b1f69b75SAndy Adamson 				encode_putfh_maxsz +        \
862b1f69b75SAndy Adamson 				encode_layoutget_maxsz)
863b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz	(compound_decode_hdr_maxsz + \
864b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
865b1f69b75SAndy Adamson 				decode_putfh_maxsz +        \
866b1f69b75SAndy Adamson 				decode_layoutget_maxsz)
867863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
868863a3c6cSAndy Adamson 				encode_sequence_maxsz +\
869863a3c6cSAndy Adamson 				encode_putfh_maxsz + \
870863a3c6cSAndy Adamson 				encode_layoutcommit_maxsz + \
871863a3c6cSAndy Adamson 				encode_getattr_maxsz)
872863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
873863a3c6cSAndy Adamson 				decode_sequence_maxsz + \
874863a3c6cSAndy Adamson 				decode_putfh_maxsz + \
875863a3c6cSAndy Adamson 				decode_layoutcommit_maxsz + \
876863a3c6cSAndy Adamson 				decode_getattr_maxsz)
877cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
878cbe82603SBenny Halevy 				encode_sequence_maxsz + \
879cbe82603SBenny Halevy 				encode_putfh_maxsz + \
880cbe82603SBenny Halevy 				encode_layoutreturn_maxsz)
881cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
882cbe82603SBenny Halevy 				decode_sequence_maxsz + \
883cbe82603SBenny Halevy 				decode_putfh_maxsz + \
884cbe82603SBenny Halevy 				decode_layoutreturn_maxsz)
885fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz	(compound_encode_hdr_maxsz + \
886fca78d6dSBryan Schumaker 					encode_sequence_maxsz + \
887fca78d6dSBryan Schumaker 					encode_putrootfh_maxsz +\
888fca78d6dSBryan Schumaker 					encode_secinfo_no_name_maxsz)
889fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz	(compound_decode_hdr_maxsz + \
890fca78d6dSBryan Schumaker 					decode_sequence_maxsz + \
891fca78d6dSBryan Schumaker 					decode_putrootfh_maxsz + \
892fca78d6dSBryan Schumaker 					decode_secinfo_no_name_maxsz)
8937d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz	(compound_encode_hdr_maxsz + \
8947d974794SBryan Schumaker 					 encode_sequence_maxsz + \
8957d974794SBryan Schumaker 					 encode_test_stateid_maxsz)
8967d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz	(compound_decode_hdr_maxsz + \
8977d974794SBryan Schumaker 					 decode_sequence_maxsz + \
8987d974794SBryan Schumaker 					 decode_test_stateid_maxsz)
8999aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz	(compound_encode_hdr_maxsz + \
9009aeda35fSBryan Schumaker 					 encode_sequence_maxsz + \
9019aeda35fSBryan Schumaker 					 encode_free_stateid_maxsz)
9029aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz	(compound_decode_hdr_maxsz + \
9039aeda35fSBryan Schumaker 					 decode_sequence_maxsz + \
9049aeda35fSBryan Schumaker 					 decode_free_stateid_maxsz)
9052449ea2eSAlexandros Batsakis 
9062449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
9072449ea2eSAlexandros Batsakis 				      compound_encode_hdr_maxsz +
9082449ea2eSAlexandros Batsakis 				      encode_sequence_maxsz +
9092449ea2eSAlexandros Batsakis 				      encode_putfh_maxsz +
9102449ea2eSAlexandros Batsakis 				      encode_getattr_maxsz) *
9112449ea2eSAlexandros Batsakis 				     XDR_UNIT);
9122449ea2eSAlexandros Batsakis 
9132449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
9142449ea2eSAlexandros Batsakis 				     compound_decode_hdr_maxsz +
9152449ea2eSAlexandros Batsakis 				     decode_sequence_maxsz +
9162449ea2eSAlexandros Batsakis 				     decode_putfh_maxsz) *
9172449ea2eSAlexandros Batsakis 				    XDR_UNIT);
918f1c097beSAndy Adamson 
919f1c097beSAndy Adamson const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
920f1c097beSAndy Adamson 					   compound_decode_hdr_maxsz +
921f1c097beSAndy Adamson 					   decode_sequence_maxsz) *
922f1c097beSAndy Adamson 					  XDR_UNIT);
923f1c097beSAndy Adamson EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
92499fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
9251da177e4SLinus Torvalds 
926bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = {
927bca79478STrond Myklebust 	[NF4BAD] = 0,
928bca79478STrond Myklebust 	[NF4REG] = S_IFREG,
929bca79478STrond Myklebust 	[NF4DIR] = S_IFDIR,
930bca79478STrond Myklebust 	[NF4BLK] = S_IFBLK,
931bca79478STrond Myklebust 	[NF4CHR] = S_IFCHR,
932bca79478STrond Myklebust 	[NF4LNK] = S_IFLNK,
933bca79478STrond Myklebust 	[NF4SOCK] = S_IFSOCK,
934bca79478STrond Myklebust 	[NF4FIFO] = S_IFIFO,
935bca79478STrond Myklebust 	[NF4ATTRDIR] = 0,
936bca79478STrond Myklebust 	[NF4NAMEDATTR] = 0,
9371da177e4SLinus Torvalds };
9381da177e4SLinus Torvalds 
9391da177e4SLinus Torvalds struct compound_hdr {
9401da177e4SLinus Torvalds 	int32_t		status;
9411da177e4SLinus Torvalds 	uint32_t	nops;
942d017931cSAndy Adamson 	__be32 *	nops_p;
9431da177e4SLinus Torvalds 	uint32_t	taglen;
9441da177e4SLinus Torvalds 	char *		tag;
9450c4e8c18SBenny Halevy 	uint32_t	replen;		/* expected reply words */
94666cc0429SBenny Halevy 	u32		minorversion;
9471da177e4SLinus Torvalds };
9481da177e4SLinus Torvalds 
94913c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
95013c65ce9SBenny Halevy {
95113c65ce9SBenny Halevy 	__be32 *p = xdr_reserve_space(xdr, nbytes);
95213c65ce9SBenny Halevy 	BUG_ON(!p);
95313c65ce9SBenny Halevy 	return p;
95413c65ce9SBenny Halevy }
9551da177e4SLinus Torvalds 
956cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
957cb17e556STrond Myklebust {
958ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
959cb17e556STrond Myklebust }
960cb17e556STrond Myklebust 
9611da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
9621da177e4SLinus Torvalds {
963ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
9641da177e4SLinus Torvalds }
9651da177e4SLinus Torvalds 
9664ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n)
9674ade9821STrond Myklebust {
968ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
9694ade9821STrond Myklebust }
9704ade9821STrond Myklebust 
971ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n)
972ff2eb681STrond Myklebust {
973ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
974ff2eb681STrond Myklebust }
975ff2eb681STrond Myklebust 
97637c88763STrond Myklebust static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
97737c88763STrond Myklebust 		const __u32 *bitmap, size_t len)
97837c88763STrond Myklebust {
97937c88763STrond Myklebust 	ssize_t ret;
98037c88763STrond Myklebust 
98137c88763STrond Myklebust 	/* Trim empty words */
98237c88763STrond Myklebust 	while (len > 0 && bitmap[len-1] == 0)
98337c88763STrond Myklebust 		len--;
98437c88763STrond Myklebust 	ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
98537c88763STrond Myklebust 	if (WARN_ON_ONCE(ret < 0))
98637c88763STrond Myklebust 		return ret;
98737c88763STrond Myklebust 	return len;
98837c88763STrond Myklebust }
98937c88763STrond Myklebust 
99037c88763STrond Myklebust static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
99137c88763STrond Myklebust 		__u32 *res, size_t len)
99237c88763STrond Myklebust {
99337c88763STrond Myklebust 	size_t i;
99437c88763STrond Myklebust 	__u32 tmp;
99537c88763STrond Myklebust 
99637c88763STrond Myklebust 	while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
99737c88763STrond Myklebust 		len--;
99837c88763STrond Myklebust 	for (i = len; i-- > 0;) {
99937c88763STrond Myklebust 		tmp = bitmap[i] & mask[i];
100037c88763STrond Myklebust 		res[i] = tmp;
100137c88763STrond Myklebust 	}
100237c88763STrond Myklebust 	return len;
100337c88763STrond Myklebust }
100437c88763STrond Myklebust 
10054ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr,
10064ade9821STrond Myklebust 		const struct nfs_seqid *seqid)
10074ade9821STrond Myklebust {
1008a6796419STrond Myklebust 	if (seqid != NULL)
10094ade9821STrond Myklebust 		encode_uint32(xdr, seqid->sequence->counter);
1010a6796419STrond Myklebust 	else
1011a6796419STrond Myklebust 		encode_uint32(xdr, 0);
10124ade9821STrond Myklebust }
10134ade9821STrond Myklebust 
10140c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr,
10150c4e8c18SBenny Halevy 				struct rpc_rqst *req,
10160c4e8c18SBenny Halevy 				struct compound_hdr *hdr)
10171da177e4SLinus Torvalds {
10188687b63aSAl Viro 	__be32 *p;
1019a17c2153STrond Myklebust 	struct rpc_auth *auth = req->rq_cred->cr_auth;
10200c4e8c18SBenny Halevy 
10210c4e8c18SBenny Halevy 	/* initialize running count of expected bytes in reply.
10220c4e8c18SBenny Halevy 	 * NOTE: the replied tag SHOULD be the same is the one sent,
10230c4e8c18SBenny Halevy 	 * but this is not required as a MUST for the server to do so. */
10240c4e8c18SBenny Halevy 	hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
10251da177e4SLinus Torvalds 
10267fc38846STrond Myklebust 	WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
10276fdfb0bcSTrond Myklebust 	encode_string(xdr, hdr->taglen, hdr->tag);
10286fdfb0bcSTrond Myklebust 	p = reserve_space(xdr, 8);
1029e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(hdr->minorversion);
1030d017931cSAndy Adamson 	hdr->nops_p = p;
103134558513SBenny Halevy 	*p = cpu_to_be32(hdr->nops);
1032d017931cSAndy Adamson }
1033d017931cSAndy Adamson 
1034ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
1035ab19b481STrond Myklebust 		uint32_t replen,
1036ab19b481STrond Myklebust 		struct compound_hdr *hdr)
1037ab19b481STrond Myklebust {
1038ab19b481STrond Myklebust 	encode_uint32(xdr, op);
1039ab19b481STrond Myklebust 	hdr->nops++;
1040ab19b481STrond Myklebust 	hdr->replen += replen;
1041ab19b481STrond Myklebust }
1042ab19b481STrond Myklebust 
1043d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr)
1044d017931cSAndy Adamson {
10457fc38846STrond Myklebust 	WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
1046d017931cSAndy Adamson 	*hdr->nops_p = htonl(hdr->nops);
10471da177e4SLinus Torvalds }
10481da177e4SLinus Torvalds 
1049ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1050ea9d23f5STrond Myklebust {
10512d2f24adSTrond Myklebust 	encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
1052ea9d23f5STrond Myklebust }
1053ea9d23f5STrond Myklebust 
10541da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
10551da177e4SLinus Torvalds {
1056cb17e556STrond Myklebust 	encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
10571da177e4SLinus Torvalds }
10581da177e4SLinus Torvalds 
105936b3743fSTrond Myklebust static __be32 *
106036b3743fSTrond Myklebust xdr_encode_nfstime4(__be32 *p, const struct timespec *t)
106136b3743fSTrond Myklebust {
106236b3743fSTrond Myklebust 	p = xdr_encode_hyper(p, (__s64)t->tv_sec);
106336b3743fSTrond Myklebust 	*p++ = cpu_to_be32(t->tv_nsec);
106436b3743fSTrond Myklebust 	return p;
106536b3743fSTrond Myklebust }
106636b3743fSTrond Myklebust 
1067aa9c2669SDavid Quigley static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1068aa9c2669SDavid Quigley 				const struct nfs4_label *label,
106928cf22d0STrond Myklebust 				const umode_t *umask,
10705334c5bdSKinglong Mee 				const struct nfs_server *server,
107128cf22d0STrond Myklebust 				const uint32_t attrmask[])
10721da177e4SLinus Torvalds {
107395582b00SDeepa Dinamani 	struct timespec ts;
10741da177e4SLinus Torvalds 	char owner_name[IDMAP_NAMESZ];
10751da177e4SLinus Torvalds 	char owner_group[IDMAP_NAMESZ];
10761da177e4SLinus Torvalds 	int owner_namelen = 0;
10771da177e4SLinus Torvalds 	int owner_grouplen = 0;
10788687b63aSAl Viro 	__be32 *p;
1079d7067b2dSTrond Myklebust 	uint32_t len = 0;
1080d7067b2dSTrond Myklebust 	uint32_t bmval[3] = { 0 };
10811da177e4SLinus Torvalds 
10821da177e4SLinus Torvalds 	/*
10831da177e4SLinus Torvalds 	 * We reserve enough space to write the entire attribute buffer at once.
10841da177e4SLinus Torvalds 	 */
108528cf22d0STrond Myklebust 	if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
1086d7067b2dSTrond Myklebust 		bmval[0] |= FATTR4_WORD0_SIZE;
10871da177e4SLinus Torvalds 		len += 8;
1088d7067b2dSTrond Myklebust 	}
1089d7067b2dSTrond Myklebust 	if (iap->ia_valid & ATTR_MODE) {
109028cf22d0STrond Myklebust 		if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
1091dff25ddbSAndreas Gruenbacher 			bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1092dff25ddbSAndreas Gruenbacher 			len += 8;
109328cf22d0STrond Myklebust 		} else if (attrmask[1] & FATTR4_WORD1_MODE) {
1094d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_MODE;
10951da177e4SLinus Torvalds 			len += 4;
1096d7067b2dSTrond Myklebust 		}
1097dff25ddbSAndreas Gruenbacher 	}
109828cf22d0STrond Myklebust 	if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
1099e4fd72a1STrond Myklebust 		owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
11001da177e4SLinus Torvalds 		if (owner_namelen < 0) {
1101fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve uid %d to string\n",
1102e5782076SEric W. Biederman 					from_kuid(&init_user_ns, iap->ia_uid));
11031da177e4SLinus Torvalds 			/* XXX */
11041da177e4SLinus Torvalds 			strcpy(owner_name, "nobody");
11051da177e4SLinus Torvalds 			owner_namelen = sizeof("nobody") - 1;
11061da177e4SLinus Torvalds 			/* goto out; */
11071da177e4SLinus Torvalds 		}
1108d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_OWNER;
11091da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
11101da177e4SLinus Torvalds 	}
111128cf22d0STrond Myklebust 	if ((iap->ia_valid & ATTR_GID) &&
111228cf22d0STrond Myklebust 	   (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
1113e4fd72a1STrond Myklebust 		owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
11141da177e4SLinus Torvalds 		if (owner_grouplen < 0) {
1115fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve gid %d to string\n",
1116e5782076SEric W. Biederman 					from_kgid(&init_user_ns, iap->ia_gid));
11171da177e4SLinus Torvalds 			strcpy(owner_group, "nobody");
11181da177e4SLinus Torvalds 			owner_grouplen = sizeof("nobody") - 1;
11191da177e4SLinus Torvalds 			/* goto out; */
11201da177e4SLinus Torvalds 		}
1121d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
11221da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
11231da177e4SLinus Torvalds 	}
112428cf22d0STrond Myklebust 	if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1125d7067b2dSTrond Myklebust 		if (iap->ia_valid & ATTR_ATIME_SET) {
1126d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
112736b3743fSTrond Myklebust 			len += 4 + (nfstime4_maxsz << 2);
1128d7067b2dSTrond Myklebust 		} else if (iap->ia_valid & ATTR_ATIME) {
1129d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
11301da177e4SLinus Torvalds 			len += 4;
1131d7067b2dSTrond Myklebust 		}
113228cf22d0STrond Myklebust 	}
113328cf22d0STrond Myklebust 	if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1134d7067b2dSTrond Myklebust 		if (iap->ia_valid & ATTR_MTIME_SET) {
1135d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
113636b3743fSTrond Myklebust 			len += 4 + (nfstime4_maxsz << 2);
1137d7067b2dSTrond Myklebust 		} else if (iap->ia_valid & ATTR_MTIME) {
1138d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
11391da177e4SLinus Torvalds 			len += 4;
1140d7067b2dSTrond Myklebust 		}
11415334c5bdSKinglong Mee 	}
11425334c5bdSKinglong Mee 
114328cf22d0STrond Myklebust 	if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
1144b4a2cf76STrond Myklebust 		len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1145d7067b2dSTrond Myklebust 		bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1146d7067b2dSTrond Myklebust 	}
1147d7067b2dSTrond Myklebust 
114840a3426cSTrond Myklebust 	xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
114940a3426cSTrond Myklebust 	xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
11501da177e4SLinus Torvalds 
1151d7067b2dSTrond Myklebust 	if (bmval[0] & FATTR4_WORD0_SIZE)
1152b95be5a9SBenny Halevy 		p = xdr_encode_hyper(p, iap->ia_size);
1153d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_MODE)
1154e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1155d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_OWNER)
1156811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_name, owner_namelen);
1157d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1158811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1159d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
11601da177e4SLinus Torvalds 		if (iap->ia_valid & ATTR_ATIME_SET) {
1161e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
116295582b00SDeepa Dinamani 			ts = timespec64_to_timespec(iap->ia_atime);
116395582b00SDeepa Dinamani 			p = xdr_encode_nfstime4(p, &ts);
1164d7067b2dSTrond Myklebust 		} else
1165e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
11661da177e4SLinus Torvalds 	}
1167d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
11681da177e4SLinus Torvalds 		if (iap->ia_valid & ATTR_MTIME_SET) {
1169e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
117095582b00SDeepa Dinamani 			ts = timespec64_to_timespec(iap->ia_mtime);
117195582b00SDeepa Dinamani 			p = xdr_encode_nfstime4(p, &ts);
1172d7067b2dSTrond Myklebust 		} else
1173e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
11741da177e4SLinus Torvalds 	}
1175d7067b2dSTrond Myklebust 	if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
1176aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->lfs);
1177aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->pi);
1178aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->len);
1179aa9c2669SDavid Quigley 		p = xdr_encode_opaque_fixed(p, label->label, label->len);
1180aa9c2669SDavid Quigley 	}
1181dff25ddbSAndreas Gruenbacher 	if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1182dff25ddbSAndreas Gruenbacher 		*p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1183dff25ddbSAndreas Gruenbacher 		*p++ = cpu_to_be32(*umask);
1184dff25ddbSAndreas Gruenbacher 	}
11851da177e4SLinus Torvalds 
11861da177e4SLinus Torvalds /* out: */
11871da177e4SLinus Torvalds }
11881da177e4SLinus Torvalds 
1189cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
11901da177e4SLinus Torvalds {
1191475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1192475d4ba0STrond Myklebust 	encode_uint32(xdr, access);
11931da177e4SLinus Torvalds }
11941da177e4SLinus Torvalds 
1195cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
11961da177e4SLinus Torvalds {
1197ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
11984ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
1199566fcec6STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
12001da177e4SLinus Torvalds }
12011da177e4SLinus Torvalds 
12020b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
12031da177e4SLinus Torvalds {
12048687b63aSAl Viro 	__be32 *p;
12051da177e4SLinus Torvalds 
1206475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1207475d4ba0STrond Myklebust 	p = reserve_space(xdr, 12);
1208b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
120934558513SBenny Halevy 	*p = cpu_to_be32(args->count);
12101da177e4SLinus Torvalds }
12111da177e4SLinus Torvalds 
1212cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
12131da177e4SLinus Torvalds {
12148687b63aSAl Viro 	__be32 *p;
12151da177e4SLinus Torvalds 
1216475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1217475d4ba0STrond Myklebust 	encode_uint32(xdr, create->ftype);
12181da177e4SLinus Torvalds 
12191da177e4SLinus Torvalds 	switch (create->ftype) {
12201da177e4SLinus Torvalds 	case NF4LNK:
122113c65ce9SBenny Halevy 		p = reserve_space(xdr, 4);
122234558513SBenny Halevy 		*p = cpu_to_be32(create->u.symlink.len);
12232fcc213aSChuck Lever 		xdr_write_pages(xdr, create->u.symlink.pages, 0,
12242fcc213aSChuck Lever 				create->u.symlink.len);
12252fcc213aSChuck Lever 		xdr->buf->flags |= XDRBUF_WRITE;
12261da177e4SLinus Torvalds 		break;
12271da177e4SLinus Torvalds 
12281da177e4SLinus Torvalds 	case NF4BLK: case NF4CHR:
122913c65ce9SBenny Halevy 		p = reserve_space(xdr, 8);
1230e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(create->u.device.specdata1);
123134558513SBenny Halevy 		*p = cpu_to_be32(create->u.device.specdata2);
12321da177e4SLinus Torvalds 		break;
12331da177e4SLinus Torvalds 
12341da177e4SLinus Torvalds 	default:
12351da177e4SLinus Torvalds 		break;
12361da177e4SLinus Torvalds 	}
12371da177e4SLinus Torvalds 
1238811652bdSBenny Halevy 	encode_string(xdr, create->name->len, create->name->name);
123928cf22d0STrond Myklebust 	encode_attrs(xdr, create->attrs, create->label, &create->umask,
124028cf22d0STrond Myklebust 			create->server, create->server->attr_bitmask);
12411da177e4SLinus Torvalds }
12421da177e4SLinus Torvalds 
124337c88763STrond Myklebust static void encode_getattr(struct xdr_stream *xdr,
124437c88763STrond Myklebust 		const __u32 *bitmap, const __u32 *mask, size_t len,
1245dae100c2SFred Isaman 		struct compound_hdr *hdr)
1246dae100c2SFred Isaman {
124737c88763STrond Myklebust 	__u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
1248dae100c2SFred Isaman 
1249ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
125037c88763STrond Myklebust 	if (mask) {
125137c88763STrond Myklebust 		if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
125237c88763STrond Myklebust 			len = ARRAY_SIZE(masked_bitmap);
125337c88763STrond Myklebust 		len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
125437c88763STrond Myklebust 		bitmap = masked_bitmap;
1255dae100c2SFred Isaman 	}
125637c88763STrond Myklebust 	xdr_encode_bitmap4(xdr, bitmap, len);
1257dae100c2SFred Isaman }
1258dae100c2SFred Isaman 
1259cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
12601da177e4SLinus Torvalds {
126137c88763STrond Myklebust 	encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
126237c88763STrond Myklebust 			ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
12631da177e4SLinus Torvalds }
12641da177e4SLinus Torvalds 
126588034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
12661549210fSTrond Myklebust 				 const u32 *open_bitmap,
126788034c3dSAndy Adamson 				 struct compound_hdr *hdr)
126888034c3dSAndy Adamson {
126937c88763STrond Myklebust 	encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
127088034c3dSAndy Adamson }
127188034c3dSAndy Adamson 
1272cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
12731da177e4SLinus Torvalds {
127437c88763STrond Myklebust 	encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
127537c88763STrond Myklebust 			ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
12761da177e4SLinus Torvalds }
12771da177e4SLinus Torvalds 
1278cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1279830b8e33SManoj Naik {
128037c88763STrond Myklebust 	encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
128137c88763STrond Myklebust 			ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
1282830b8e33SManoj Naik }
1283830b8e33SManoj Naik 
1284cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
12851da177e4SLinus Torvalds {
1286ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
12871da177e4SLinus Torvalds }
12881da177e4SLinus Torvalds 
1289cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
12901da177e4SLinus Torvalds {
1291ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
12926fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
12931da177e4SLinus Torvalds }
12941da177e4SLinus Torvalds 
1295911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block)
1296911d1aafSTrond Myklebust {
1297f44106e2SJeff Layton 	if (fl->fl_type == F_RDLCK)
1298911d1aafSTrond Myklebust 		return block ? NFS4_READW_LT : NFS4_READ_LT;
1299911d1aafSTrond Myklebust 	return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1300911d1aafSTrond Myklebust }
1301911d1aafSTrond Myklebust 
1302911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1303911d1aafSTrond Myklebust {
1304911d1aafSTrond Myklebust 	if (fl->fl_end == OFFSET_MAX)
1305911d1aafSTrond Myklebust 		return ~(uint64_t)0;
1306911d1aafSTrond Myklebust 	return fl->fl_end - fl->fl_start + 1;
1307911d1aafSTrond Myklebust }
1308911d1aafSTrond Myklebust 
1309daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1310daccbdedSTrond Myklebust {
1311daccbdedSTrond Myklebust 	__be32 *p;
1312daccbdedSTrond Myklebust 
1313d035c36cSTrond Myklebust 	p = reserve_space(xdr, 32);
1314daccbdedSTrond Myklebust 	p = xdr_encode_hyper(p, lowner->clientid);
1315d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(20);
1316daccbdedSTrond Myklebust 	p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1317d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(lowner->s_dev);
1318daccbdedSTrond Myklebust 	xdr_encode_hyper(p, lowner->id);
1319daccbdedSTrond Myklebust }
1320daccbdedSTrond Myklebust 
13211da177e4SLinus Torvalds /*
13221da177e4SLinus Torvalds  * opcode,type,reclaim,offset,length,new_lock_owner = 32
13231da177e4SLinus Torvalds  * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
13241da177e4SLinus Torvalds  */
1325cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
13261da177e4SLinus Torvalds {
13278687b63aSAl Viro 	__be32 *p;
13281da177e4SLinus Torvalds 
1329475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1330475d4ba0STrond Myklebust 	p = reserve_space(xdr, 28);
1331e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1332e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->reclaim);
1333b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1334b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
133534558513SBenny Halevy 	*p = cpu_to_be32(args->new_lock_owner);
1336911d1aafSTrond Myklebust 	if (args->new_lock_owner){
13374ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->open_seqid);
1338425c1d4eSTrond Myklebust 		encode_nfs4_stateid(xdr, &args->open_stateid);
13394ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->lock_seqid);
1340daccbdedSTrond Myklebust 		encode_lockowner(xdr, &args->lock_owner);
13411da177e4SLinus Torvalds 	}
13421da177e4SLinus Torvalds 	else {
1343425c1d4eSTrond Myklebust 		encode_nfs4_stateid(xdr, &args->lock_stateid);
13444ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->lock_seqid);
13451da177e4SLinus Torvalds 	}
13461da177e4SLinus Torvalds }
13471da177e4SLinus Torvalds 
1348cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
13491da177e4SLinus Torvalds {
13508687b63aSAl Viro 	__be32 *p;
13511da177e4SLinus Torvalds 
1352475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1353475d4ba0STrond Myklebust 	p = reserve_space(xdr, 20);
1354e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1355b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1356b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1357daccbdedSTrond Myklebust 	encode_lockowner(xdr, &args->lock_owner);
13581da177e4SLinus Torvalds }
13591da177e4SLinus Torvalds 
1360cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
13611da177e4SLinus Torvalds {
13628687b63aSAl Viro 	__be32 *p;
13631da177e4SLinus Torvalds 
1364475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1365475d4ba0STrond Myklebust 	encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
13664ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, args->seqid);
1367425c1d4eSTrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
1368ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 16);
1369b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
137034558513SBenny Halevy 	xdr_encode_hyper(p, nfs4_lock_length(args->fl));
13711da177e4SLinus Torvalds }
13721da177e4SLinus Torvalds 
1373d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1374d3c7b7ccSTrond Myklebust {
1375ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1376d3c7b7ccSTrond Myklebust 	encode_lockowner(xdr, lowner);
1377d3c7b7ccSTrond Myklebust }
1378d3c7b7ccSTrond Myklebust 
1379cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
13801da177e4SLinus Torvalds {
1381ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
13826fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
13831da177e4SLinus Torvalds }
13841da177e4SLinus Torvalds 
13855b5faaf6SJeff Layton static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
13865b5faaf6SJeff Layton {
13875b5faaf6SJeff Layton 	encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
13885b5faaf6SJeff Layton }
13895b5faaf6SJeff Layton 
13906ae37339STrond Myklebust static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
13911da177e4SLinus Torvalds {
13928687b63aSAl Viro 	__be32 *p;
13931da177e4SLinus Torvalds 
139413c65ce9SBenny Halevy 	p = reserve_space(xdr, 8);
13956ae37339STrond Myklebust 	*p++ = cpu_to_be32(share_access);
139634558513SBenny Halevy 	*p = cpu_to_be32(0);		/* for linux, share_deny = 0 always */
13971da177e4SLinus Torvalds }
13981da177e4SLinus Torvalds 
13991da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14001da177e4SLinus Torvalds {
14018687b63aSAl Viro 	__be32 *p;
14021da177e4SLinus Torvalds  /*
14031da177e4SLinus Torvalds  * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
14041da177e4SLinus Torvalds  * owner 4 = 32
14051da177e4SLinus Torvalds  */
14064ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
14076ae37339STrond Myklebust 	encode_share_access(xdr, arg->share_access);
140895b72eb0STrond Myklebust 	p = reserve_space(xdr, 36);
1409b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, arg->clientid);
141095b72eb0STrond Myklebust 	*p++ = cpu_to_be32(24);
141193f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, "open id:", 8);
1412d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(arg->server->s_dev);
141395b72eb0STrond Myklebust 	*p++ = cpu_to_be32(arg->id.uniquifier);
141495b72eb0STrond Myklebust 	xdr_encode_hyper(p, arg->id.create_time);
14151da177e4SLinus Torvalds }
14161da177e4SLinus Torvalds 
14171da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14181da177e4SLinus Torvalds {
14198687b63aSAl Viro 	__be32 *p;
14201da177e4SLinus Torvalds 
142113c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
1422549b19ccSTrond Myklebust 	switch(arg->createmode) {
1423549b19ccSTrond Myklebust 	case NFS4_CREATE_UNCHECKED:
142434558513SBenny Halevy 		*p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
142528cf22d0STrond Myklebust 		encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
142628cf22d0STrond Myklebust 				arg->server, arg->server->attr_bitmask);
14271da177e4SLinus Torvalds 		break;
1428549b19ccSTrond Myklebust 	case NFS4_CREATE_GUARDED:
14294882ef72SAlexandros Batsakis 		*p = cpu_to_be32(NFS4_CREATE_GUARDED);
143028cf22d0STrond Myklebust 		encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
143128cf22d0STrond Myklebust 				arg->server, arg->server->attr_bitmask);
1432549b19ccSTrond Myklebust 		break;
1433549b19ccSTrond Myklebust 	case NFS4_CREATE_EXCLUSIVE:
1434549b19ccSTrond Myklebust 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1435549b19ccSTrond Myklebust 		encode_nfs4_verifier(xdr, &arg->u.verifier);
1436549b19ccSTrond Myklebust 		break;
1437549b19ccSTrond Myklebust 	case NFS4_CREATE_EXCLUSIVE4_1:
14384882ef72SAlexandros Batsakis 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
14394882ef72SAlexandros Batsakis 		encode_nfs4_verifier(xdr, &arg->u.verifier);
144028cf22d0STrond Myklebust 		encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
144128cf22d0STrond Myklebust 				arg->server, arg->server->exclcreat_bitmask);
14424882ef72SAlexandros Batsakis 	}
14434882ef72SAlexandros Batsakis }
14441da177e4SLinus Torvalds 
14451da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14461da177e4SLinus Torvalds {
14478687b63aSAl Viro 	__be32 *p;
14481da177e4SLinus Torvalds 
144913c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14501da177e4SLinus Torvalds 	switch (arg->open_flags & O_CREAT) {
14511da177e4SLinus Torvalds 	case 0:
145234558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_NOCREATE);
14531da177e4SLinus Torvalds 		break;
14541da177e4SLinus Torvalds 	default:
145534558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_CREATE);
14561da177e4SLinus Torvalds 		encode_createmode(xdr, arg);
14571da177e4SLinus Torvalds 	}
14581da177e4SLinus Torvalds }
14591da177e4SLinus Torvalds 
1460bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
14611da177e4SLinus Torvalds {
14628687b63aSAl Viro 	__be32 *p;
14631da177e4SLinus Torvalds 
146413c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14651da177e4SLinus Torvalds 	switch (delegation_type) {
14661da177e4SLinus Torvalds 	case 0:
146734558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
14681da177e4SLinus Torvalds 		break;
14691da177e4SLinus Torvalds 	case FMODE_READ:
147034558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
14711da177e4SLinus Torvalds 		break;
14721da177e4SLinus Torvalds 	case FMODE_WRITE|FMODE_READ:
147334558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
14741da177e4SLinus Torvalds 		break;
14751da177e4SLinus Torvalds 	default:
14761da177e4SLinus Torvalds 		BUG();
14771da177e4SLinus Torvalds 	}
14781da177e4SLinus Torvalds }
14791da177e4SLinus Torvalds 
14801da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
14811da177e4SLinus Torvalds {
14828687b63aSAl Viro 	__be32 *p;
14831da177e4SLinus Torvalds 
148413c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
148534558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
14861da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14871da177e4SLinus Torvalds }
14881da177e4SLinus Torvalds 
1489bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
14901da177e4SLinus Torvalds {
14918687b63aSAl Viro 	__be32 *p;
14921da177e4SLinus Torvalds 
149313c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
149434558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
14951da177e4SLinus Torvalds 	encode_delegation_type(xdr, type);
14961da177e4SLinus Torvalds }
14971da177e4SLinus Torvalds 
14981da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
14991da177e4SLinus Torvalds {
15008687b63aSAl Viro 	__be32 *p;
15011da177e4SLinus Torvalds 
1502ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 4);
1503ea9d23f5STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1504ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
15051da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
15061da177e4SLinus Torvalds }
15071da177e4SLinus Torvalds 
1508d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr)
1509d9fc6619STrond Myklebust {
1510d9fc6619STrond Myklebust 	__be32 *p;
1511d9fc6619STrond Myklebust 
1512d9fc6619STrond Myklebust 	p = reserve_space(xdr, 4);
1513d9fc6619STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1514d9fc6619STrond Myklebust }
1515d9fc6619STrond Myklebust 
1516d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1517d9fc6619STrond Myklebust {
1518d9fc6619STrond Myklebust 	__be32 *p;
1519d9fc6619STrond Myklebust 
1520d9fc6619STrond Myklebust 	p = reserve_space(xdr, 4);
1521d9fc6619STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1522d9fc6619STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
1523d9fc6619STrond Myklebust }
1524d9fc6619STrond Myklebust 
1525cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
15261da177e4SLinus Torvalds {
1527ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
15281da177e4SLinus Torvalds 	encode_openhdr(xdr, arg);
15291da177e4SLinus Torvalds 	encode_opentype(xdr, arg);
15301da177e4SLinus Torvalds 	switch (arg->claim) {
15311da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_NULL:
15321da177e4SLinus Torvalds 		encode_claim_null(xdr, arg->name);
15331da177e4SLinus Torvalds 		break;
15341da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_PREVIOUS:
15351da177e4SLinus Torvalds 		encode_claim_previous(xdr, arg->u.delegation_type);
15361da177e4SLinus Torvalds 		break;
15371da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_DELEGATE_CUR:
15381da177e4SLinus Torvalds 		encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
15391da177e4SLinus Torvalds 		break;
1540d9fc6619STrond Myklebust 	case NFS4_OPEN_CLAIM_FH:
1541d9fc6619STrond Myklebust 		encode_claim_fh(xdr);
1542d9fc6619STrond Myklebust 		break;
1543d9fc6619STrond Myklebust 	case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1544d9fc6619STrond Myklebust 		encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1545d9fc6619STrond Myklebust 		break;
15461da177e4SLinus Torvalds 	default:
15471da177e4SLinus Torvalds 		BUG();
15481da177e4SLinus Torvalds 	}
15491da177e4SLinus Torvalds }
15501da177e4SLinus Torvalds 
1551cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
15521da177e4SLinus Torvalds {
1553ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1554ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, arg->stateid);
15554ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
15561da177e4SLinus Torvalds }
15571da177e4SLinus Torvalds 
1558cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
15591da177e4SLinus Torvalds {
1560ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1561566fcec6STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
15624ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
15636ae37339STrond Myklebust 	encode_share_access(xdr, arg->share_access);
15641da177e4SLinus Torvalds }
15651da177e4SLinus Torvalds 
1566cf8cdbe5SAndy Adamson static void
1567d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
15681da177e4SLinus Torvalds {
1569ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
15706fdfb0bcSTrond Myklebust 	encode_string(xdr, fh->size, fh->data);
15711da177e4SLinus Torvalds }
15721da177e4SLinus Torvalds 
1573cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
15741da177e4SLinus Torvalds {
1575ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
15761da177e4SLinus Torvalds }
15771da177e4SLinus Torvalds 
15783c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
15793c6b899cSAnna Schumaker 			struct compound_hdr *hdr)
15801da177e4SLinus Torvalds {
15818687b63aSAl Viro 	__be32 *p;
15821da177e4SLinus Torvalds 
1583ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
15849b206149STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
15851da177e4SLinus Torvalds 
158613c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1587b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
158834558513SBenny Halevy 	*p = cpu_to_be32(args->count);
15891da177e4SLinus Torvalds }
15901da177e4SLinus Torvalds 
1591cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
15921da177e4SLinus Torvalds {
1593aa9c2669SDavid Quigley 	uint32_t attrs[3] = {
159428331a46STrond Myklebust 		FATTR4_WORD0_RDATTR_ERROR,
159528331a46STrond Myklebust 		FATTR4_WORD1_MOUNTED_ON_FILEID,
159628331a46STrond Myklebust 	};
15976f7a35bdSTrond Myklebust 	uint32_t dircount = readdir->count >> 1;
1598cd93710eSChuck Lever 	__be32 *p, verf[2];
1599d204c5d2STrond Myklebust 	uint32_t attrlen = 0;
1600d204c5d2STrond Myklebust 	unsigned int i;
16011da177e4SLinus Torvalds 
160282f2e547SBryan Schumaker 	if (readdir->plus) {
160382f2e547SBryan Schumaker 		attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
160428331a46STrond Myklebust 			FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
160582f2e547SBryan Schumaker 		attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
160682f2e547SBryan Schumaker 			FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
160782f2e547SBryan Schumaker 			FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
160882f2e547SBryan Schumaker 			FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1609d204c5d2STrond Myklebust 		attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
16106f7a35bdSTrond Myklebust 		dircount >>= 1;
161182f2e547SBryan Schumaker 	}
161228331a46STrond Myklebust 	/* Use mounted_on_fileid only if the server supports it */
161328331a46STrond Myklebust 	if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
161428331a46STrond Myklebust 		attrs[0] |= FATTR4_WORD0_FILEID;
1615d204c5d2STrond Myklebust 	for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1616d204c5d2STrond Myklebust 		attrs[i] &= readdir->bitmask[i];
1617d204c5d2STrond Myklebust 		if (attrs[i] != 0)
1618d204c5d2STrond Myklebust 			attrlen = i+1;
1619d204c5d2STrond Myklebust 	}
16206f7a35bdSTrond Myklebust 
1621475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1622ff2eb681STrond Myklebust 	encode_uint64(xdr, readdir->cookie);
1623cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, &readdir->verifier);
1624d204c5d2STrond Myklebust 	p = reserve_space(xdr, 12 + (attrlen << 2));
16256f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(dircount);
16266f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(readdir->count);
1627d204c5d2STrond Myklebust 	*p++ = cpu_to_be32(attrlen);
1628d204c5d2STrond Myklebust 	for (i = 0; i < attrlen; i++)
1629d204c5d2STrond Myklebust 		*p++ = cpu_to_be32(attrs[i]);
1630cd93710eSChuck Lever 	memcpy(verf, readdir->verifier.data, sizeof(verf));
1631aa9c2669SDavid Quigley 
1632aa9c2669SDavid Quigley 	dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
163344109241SFred Isaman 			__func__,
1634eadf4598STrond Myklebust 			(unsigned long long)readdir->cookie,
1635cd93710eSChuck Lever 			verf[0], verf[1],
1636eadf4598STrond Myklebust 			attrs[0] & readdir->bitmask[0],
1637aa9c2669SDavid Quigley 			attrs[1] & readdir->bitmask[1],
1638aa9c2669SDavid Quigley 			attrs[2] & readdir->bitmask[2]);
16391da177e4SLinus Torvalds }
16401da177e4SLinus Torvalds 
1641cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
16421da177e4SLinus Torvalds {
1643ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
16441da177e4SLinus Torvalds }
16451da177e4SLinus Torvalds 
1646cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
16471da177e4SLinus Torvalds {
1648ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
16496fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
16501da177e4SLinus Torvalds }
16511da177e4SLinus Torvalds 
1652cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
16531da177e4SLinus Torvalds {
1654ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1655811652bdSBenny Halevy 	encode_string(xdr, oldname->len, oldname->name);
1656811652bdSBenny Halevy 	encode_string(xdr, newname->len, newname->name);
16571da177e4SLinus Torvalds }
16581da177e4SLinus Torvalds 
1659bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1660bb4dae5eSChuck Lever 			 struct compound_hdr *hdr)
16611da177e4SLinus Torvalds {
1662475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1663ff2eb681STrond Myklebust 	encode_uint64(xdr, clid);
16641da177e4SLinus Torvalds }
16651da177e4SLinus Torvalds 
1666cf8cdbe5SAndy Adamson static void
1667d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
166856ae19f3STrond Myklebust {
1669ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
167056ae19f3STrond Myklebust }
167156ae19f3STrond Myklebust 
16729f06c719SChuck Lever static void
1673fcc85819SChristoph Hellwig encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1674fcc85819SChristoph Hellwig 		struct compound_hdr *hdr)
167523ec6965SJ. Bruce Fields {
16768687b63aSAl Viro 	__be32 *p;
167723ec6965SJ. Bruce Fields 
1678ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1679ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &zero_stateid);
168013c65ce9SBenny Halevy 	p = reserve_space(xdr, 2*4);
1681e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
168234558513SBenny Halevy 	*p = cpu_to_be32(FATTR4_WORD0_ACL);
168313c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
168434558513SBenny Halevy 	*p = cpu_to_be32(arg->acl_len);
16858fbcf237SAndreas Gruenbacher 	xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
168623ec6965SJ. Bruce Fields }
168723ec6965SJ. Bruce Fields 
1688cf8cdbe5SAndy Adamson static void
1689d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
16901da177e4SLinus Torvalds {
1691ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
16921da177e4SLinus Torvalds }
16931da177e4SLinus Torvalds 
1694cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
16951da177e4SLinus Torvalds {
1696ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1697ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
169828cf22d0STrond Myklebust 	encode_attrs(xdr, arg->iap, arg->label, NULL, server,
169928cf22d0STrond Myklebust 			server->attr_bitmask);
17001da177e4SLinus Torvalds }
17011da177e4SLinus Torvalds 
1702cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
17031da177e4SLinus Torvalds {
17048687b63aSAl Viro 	__be32 *p;
17051da177e4SLinus Torvalds 
170670019514STrond Myklebust 	encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1707cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, setclientid->sc_verifier);
17081da177e4SLinus Torvalds 
17093a6bb738SJeff Layton 	encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
17103a6bb738SJeff Layton 			setclientid->sc_clnt->cl_owner_id);
171113c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
171234558513SBenny Halevy 	*p = cpu_to_be32(setclientid->sc_prog);
17131da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
17141da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
171513c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
17163a6bb738SJeff Layton 	*p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
17171da177e4SLinus Torvalds }
17181da177e4SLinus Torvalds 
1719bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
17201da177e4SLinus Torvalds {
1721475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1722475d4ba0STrond Myklebust 			decode_setclientid_confirm_maxsz, hdr);
1723ff2eb681STrond Myklebust 	encode_uint64(xdr, arg->clientid);
1724cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, &arg->confirm);
17251da177e4SLinus Torvalds }
17261da177e4SLinus Torvalds 
17273c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
17283c6b899cSAnna Schumaker 			 struct compound_hdr *hdr)
17291da177e4SLinus Torvalds {
17308687b63aSAl Viro 	__be32 *p;
17311da177e4SLinus Torvalds 
1732ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
17339b206149STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
17341da177e4SLinus Torvalds 
173513c65ce9SBenny Halevy 	p = reserve_space(xdr, 16);
1736b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
1737e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->stable);
173834558513SBenny Halevy 	*p = cpu_to_be32(args->count);
17391da177e4SLinus Torvalds 
17401da177e4SLinus Torvalds 	xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
17411da177e4SLinus Torvalds }
17421da177e4SLinus Torvalds 
1743cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
17441da177e4SLinus Torvalds {
1745ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1746ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
17471da177e4SLinus Torvalds }
17489b7b9fccSAndy Adamson 
17495a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
17505a5ea0d4SBryan Schumaker {
1751ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
17526fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
17535a5ea0d4SBryan Schumaker }
17545a5ea0d4SBryan Schumaker 
175599fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
17569b7b9fccSAndy Adamson /* NFSv4.1 operations */
17577c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1758fcc85819SChristoph Hellwig 				   const struct nfs41_bind_conn_to_session_args *args,
17597c44f1aeSWeston Andros Adamson 				   struct compound_hdr *hdr)
17607c44f1aeSWeston Andros Adamson {
17617c44f1aeSWeston Andros Adamson 	__be32 *p;
17627c44f1aeSWeston Andros Adamson 
17637c44f1aeSWeston Andros Adamson 	encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
17647c44f1aeSWeston Andros Adamson 		decode_bind_conn_to_session_maxsz, hdr);
176571a097c6STrond Myklebust 	encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
17667c44f1aeSWeston Andros Adamson 	p = xdr_reserve_space(xdr, 8);
176771a097c6STrond Myklebust 	*p++ = cpu_to_be32(args->dir);
176871a097c6STrond Myklebust 	*p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
17697c44f1aeSWeston Andros Adamson }
17707c44f1aeSWeston Andros Adamson 
1771fcc85819SChristoph Hellwig static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
17722031cd1aSWeston Andros Adamson {
17732031cd1aSWeston Andros Adamson 	unsigned int i;
17742031cd1aSWeston Andros Adamson 	encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
17752031cd1aSWeston Andros Adamson 	for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
17762031cd1aSWeston Andros Adamson 		encode_uint32(xdr, op_map->u.words[i]);
17772031cd1aSWeston Andros Adamson }
17782031cd1aSWeston Andros Adamson 
177999fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr,
1780fcc85819SChristoph Hellwig 			       const struct nfs41_exchange_id_args *args,
178199fe60d0SBenny Halevy 			       struct compound_hdr *hdr)
178299fe60d0SBenny Halevy {
178399fe60d0SBenny Halevy 	__be32 *p;
1784d751f748SJim Rees 	char impl_name[IMPL_NAME_LIMIT];
1785db8ac8baSWeston Andros Adamson 	int len = 0;
178699fe60d0SBenny Halevy 
178770019514STrond Myklebust 	encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1788fd40559cSTrond Myklebust 	encode_nfs4_verifier(xdr, &args->verifier);
178999fe60d0SBenny Halevy 
17903a6bb738SJeff Layton 	encode_string(xdr, strlen(args->client->cl_owner_id),
17913a6bb738SJeff Layton 			args->client->cl_owner_id);
179299fe60d0SBenny Halevy 
17932031cd1aSWeston Andros Adamson 	encode_uint32(xdr, args->flags);
17942031cd1aSWeston Andros Adamson 	encode_uint32(xdr, args->state_protect.how);
17952031cd1aSWeston Andros Adamson 
17962031cd1aSWeston Andros Adamson 	switch (args->state_protect.how) {
17972031cd1aSWeston Andros Adamson 	case SP4_NONE:
17982031cd1aSWeston Andros Adamson 		break;
17992031cd1aSWeston Andros Adamson 	case SP4_MACH_CRED:
18002031cd1aSWeston Andros Adamson 		encode_op_map(xdr, &args->state_protect.enforce);
18012031cd1aSWeston Andros Adamson 		encode_op_map(xdr, &args->state_protect.allow);
18022031cd1aSWeston Andros Adamson 		break;
18032031cd1aSWeston Andros Adamson 	default:
18042031cd1aSWeston Andros Adamson 		WARN_ON_ONCE(1);
18052031cd1aSWeston Andros Adamson 		break;
18062031cd1aSWeston Andros Adamson 	}
1807db8ac8baSWeston Andros Adamson 
1808db8ac8baSWeston Andros Adamson 	if (send_implementation_id &&
1809db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1810db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1811d751f748SJim Rees 		<= sizeof(impl_name) + 1)
1812db8ac8baSWeston Andros Adamson 		len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1813db8ac8baSWeston Andros Adamson 			       utsname()->sysname, utsname()->release,
1814db8ac8baSWeston Andros Adamson 			       utsname()->version, utsname()->machine);
1815db8ac8baSWeston Andros Adamson 
1816db8ac8baSWeston Andros Adamson 	if (len > 0) {
18172031cd1aSWeston Andros Adamson 		encode_uint32(xdr, 1);	/* implementation id array length=1 */
1818db8ac8baSWeston Andros Adamson 
1819db8ac8baSWeston Andros Adamson 		encode_string(xdr,
1820db8ac8baSWeston Andros Adamson 			sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1821db8ac8baSWeston Andros Adamson 			CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1822db8ac8baSWeston Andros Adamson 		encode_string(xdr, len, impl_name);
1823db8ac8baSWeston Andros Adamson 		/* just send zeros for nii_date - the date is in nii_name */
1824db8ac8baSWeston Andros Adamson 		p = reserve_space(xdr, 12);
1825db8ac8baSWeston Andros Adamson 		p = xdr_encode_hyper(p, 0);
1826db8ac8baSWeston Andros Adamson 		*p = cpu_to_be32(0);
1827db8ac8baSWeston Andros Adamson 	} else
18282031cd1aSWeston Andros Adamson 		encode_uint32(xdr, 0);	/* implementation id array length=0 */
182999fe60d0SBenny Halevy }
1830fc931582SAndy Adamson 
1831fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr,
1832fcc85819SChristoph Hellwig 				  const struct nfs41_create_session_args *args,
1833fc931582SAndy Adamson 				  struct compound_hdr *hdr)
1834fc931582SAndy Adamson {
1835fc931582SAndy Adamson 	__be32 *p;
1836fc931582SAndy Adamson 	struct nfs_client *clp = args->client;
183789f0ff38STrond Myklebust 	struct rpc_clnt *clnt = clp->cl_rpcclient;
1838f092075dSChuck Lever 	struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
18398e0d46e1SMike Sager 	u32 max_resp_sz_cached;
18408e0d46e1SMike Sager 
18418e0d46e1SMike Sager 	/*
18428e0d46e1SMike Sager 	 * Assumes OPEN is the biggest non-idempotent compound.
18438e0d46e1SMike Sager 	 * 2 is the verifier.
18448e0d46e1SMike Sager 	 */
184535c036efSJ. Bruce Fields 	max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
184635c036efSJ. Bruce Fields 				* XDR_UNIT + RPC_MAX_AUTH_SIZE;
1847fc931582SAndy Adamson 
1848475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
184989f0ff38STrond Myklebust 	p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
185079969dd1STrond Myklebust 	p = xdr_encode_hyper(p, args->clientid);
185179969dd1STrond Myklebust 	*p++ = cpu_to_be32(args->seqid);			/*Sequence id */
1852e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->flags);			/*flags */
1853fc931582SAndy Adamson 
1854fc931582SAndy Adamson 	/* Fore Channel */
1855c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1856e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz);	/* max req size */
1857e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_resp_sz);	/* max resp size */
18588e0d46e1SMike Sager 	*p++ = cpu_to_be32(max_resp_sz_cached);		/* Max resp sz cached */
1859e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_ops);	/* max operations */
1860e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_reqs);	/* max requests */
1861e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1862fc931582SAndy Adamson 
1863fc931582SAndy Adamson 	/* Back Channel */
1864c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1865e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz);	/* max req size */
1866e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz);	/* max resp size */
1867e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached);	/* Max resp sz cached */
1868e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_ops);	/* max operations */
1869e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_reqs);	/* max requests */
1870e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1871fc931582SAndy Adamson 
1872e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->cb_program);		/* cb_program */
1873e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
1874e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(RPC_AUTH_UNIX);			/* auth_sys */
1875fc931582SAndy Adamson 
1876fc931582SAndy Adamson 	/* authsys_parms rfc1831 */
18772f86e091SDeepa Dinamani 	*p++ = cpu_to_be32(ktime_to_ns(nn->boot_time));	/* stamp */
187889f0ff38STrond Myklebust 	p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
1879e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* UID */
1880e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* GID */
188134558513SBenny Halevy 	*p = cpu_to_be32(0);				/* No more gids */
1882fc931582SAndy Adamson }
18830f3e66c6SAndy Adamson 
18840f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr,
1885fcc85819SChristoph Hellwig 				   const struct nfs4_session *session,
18860f3e66c6SAndy Adamson 				   struct compound_hdr *hdr)
18870f3e66c6SAndy Adamson {
1888475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1889475d4ba0STrond Myklebust 	encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
18900f3e66c6SAndy Adamson }
189118019753SRicardo Labiaga 
189266245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr,
189366245539STrond Myklebust 				   uint64_t clientid,
189466245539STrond Myklebust 				   struct compound_hdr *hdr)
189566245539STrond Myklebust {
189666245539STrond Myklebust 	encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
189766245539STrond Myklebust 	encode_uint64(xdr, clientid);
189866245539STrond Myklebust }
189966245539STrond Myklebust 
190018019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr,
1901fcc85819SChristoph Hellwig 				    const struct nfs41_reclaim_complete_args *args,
190218019753SRicardo Labiaga 				    struct compound_hdr *hdr)
190318019753SRicardo Labiaga {
1904475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1905475d4ba0STrond Myklebust 	encode_uint32(xdr, args->one_fs);
190618019753SRicardo Labiaga }
190799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
190899fe60d0SBenny Halevy 
19099b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr,
19109b7b9fccSAndy Adamson 			    const struct nfs4_sequence_args *args,
19119b7b9fccSAndy Adamson 			    struct compound_hdr *hdr)
19129b7b9fccSAndy Adamson {
19139b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
19142b2fa717STrond Myklebust 	struct nfs4_session *session;
1915fc01cea9SAndy Adamson 	struct nfs4_slot_table *tp;
19162b2fa717STrond Myklebust 	struct nfs4_slot *slot = args->sa_slot;
1917fc01cea9SAndy Adamson 	__be32 *p;
19189b7b9fccSAndy Adamson 
19192b2fa717STrond Myklebust 	tp = slot->table;
19202b2fa717STrond Myklebust 	session = tp->session;
19213bd2384aSChuck Lever 	if (!session)
19223bd2384aSChuck Lever 		return;
1923fc01cea9SAndy Adamson 
1924475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1925fc01cea9SAndy Adamson 
1926fc01cea9SAndy Adamson 	/*
1927fc01cea9SAndy Adamson 	 * Sessionid + seqid + slotid + max slotid + cache_this
1928fc01cea9SAndy Adamson 	 */
1929fc01cea9SAndy Adamson 	dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1930fc01cea9SAndy Adamson 		"max_slotid=%d cache_this=%d\n",
1931fc01cea9SAndy Adamson 		__func__,
1932fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[0],
1933fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[1],
1934fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[2],
1935fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[3],
19362b2fa717STrond Myklebust 		slot->seq_nr, slot->slot_nr,
1937fc01cea9SAndy Adamson 		tp->highest_used_slotid, args->sa_cache_this);
1938475d4ba0STrond Myklebust 	p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
193993f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1940e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(slot->seq_nr);
19412b2fa717STrond Myklebust 	*p++ = cpu_to_be32(slot->slot_nr);
1942e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(tp->highest_used_slotid);
194334558513SBenny Halevy 	*p = cpu_to_be32(args->sa_cache_this);
19449b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
19459b7b9fccSAndy Adamson }
19469b7b9fccSAndy Adamson 
1947b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1
1948b1f69b75SAndy Adamson static void
1949b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr,
1950b1f69b75SAndy Adamson 		     const struct nfs4_getdeviceinfo_args *args,
1951b1f69b75SAndy Adamson 		     struct compound_hdr *hdr)
1952b1f69b75SAndy Adamson {
1953b1f69b75SAndy Adamson 	__be32 *p;
1954b1f69b75SAndy Adamson 
1955475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
195684c9dee3SChristoph Hellwig 	p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
1957b1f69b75SAndy Adamson 	p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1958b1f69b75SAndy Adamson 				    NFS4_DEVICEID4_SIZE);
1959b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->pdev->layout_type);
1960f1c097beSAndy Adamson 	*p++ = cpu_to_be32(args->pdev->maxcount);	/* gdia_maxcount */
196184c9dee3SChristoph Hellwig 
196284c9dee3SChristoph Hellwig 	p = reserve_space(xdr, 4 + 4);
196384c9dee3SChristoph Hellwig 	*p++ = cpu_to_be32(1);			/* bitmap length */
19644e590803STrond Myklebust 	*p++ = cpu_to_be32(args->notify_types);
1965b1f69b75SAndy Adamson }
1966b1f69b75SAndy Adamson 
1967b1f69b75SAndy Adamson static void
1968b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr,
1969b1f69b75SAndy Adamson 		      const struct nfs4_layoutget_args *args,
1970b1f69b75SAndy Adamson 		      struct compound_hdr *hdr)
1971b1f69b75SAndy Adamson {
1972b1f69b75SAndy Adamson 	__be32 *p;
1973b1f69b75SAndy Adamson 
1974475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1975475d4ba0STrond Myklebust 	p = reserve_space(xdr, 36);
1976b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(0);     /* Signal layout available */
1977b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->type);
1978b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->range.iomode);
1979b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.offset);
1980b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.length);
1981b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->minlength);
1982ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
1983475d4ba0STrond Myklebust 	encode_uint32(xdr, args->maxcount);
1984b1f69b75SAndy Adamson 
1985b1f69b75SAndy Adamson 	dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1986b1f69b75SAndy Adamson 		__func__,
1987b1f69b75SAndy Adamson 		args->type,
1988b1f69b75SAndy Adamson 		args->range.iomode,
1989b1f69b75SAndy Adamson 		(unsigned long)args->range.offset,
1990b1f69b75SAndy Adamson 		(unsigned long)args->range.length,
1991b1f69b75SAndy Adamson 		args->maxcount);
1992b1f69b75SAndy Adamson }
1993863a3c6cSAndy Adamson 
1994863a3c6cSAndy Adamson static int
1995863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr,
1996ac7db726SBenny Halevy 		    struct inode *inode,
1997fcc85819SChristoph Hellwig 		    const struct nfs4_layoutcommit_args *args,
1998863a3c6cSAndy Adamson 		    struct compound_hdr *hdr)
1999863a3c6cSAndy Adamson {
2000863a3c6cSAndy Adamson 	__be32 *p;
2001863a3c6cSAndy Adamson 
2002863a3c6cSAndy Adamson 	dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2003863a3c6cSAndy Adamson 		NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2004863a3c6cSAndy Adamson 
2005475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2006475d4ba0STrond Myklebust 	p = reserve_space(xdr, 20);
2007863a3c6cSAndy Adamson 	/* Only whole file layouts */
2008863a3c6cSAndy Adamson 	p = xdr_encode_hyper(p, 0); /* offset */
20093557c6c3SPeng Tao 	p = xdr_encode_hyper(p, args->lastbytewritten + 1);	/* length */
2010ea9d23f5STrond Myklebust 	*p = cpu_to_be32(0); /* reclaim */
2011ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
20122e18d4d8STrond Myklebust 	if (args->lastbytewritten != U64_MAX) {
2013ea9d23f5STrond Myklebust 		p = reserve_space(xdr, 20);
2014863a3c6cSAndy Adamson 		*p++ = cpu_to_be32(1); /* newoffset = TRUE */
2015863a3c6cSAndy Adamson 		p = xdr_encode_hyper(p, args->lastbytewritten);
20162e18d4d8STrond Myklebust 	} else {
20172e18d4d8STrond Myklebust 		p = reserve_space(xdr, 12);
20182e18d4d8STrond Myklebust 		*p++ = cpu_to_be32(0); /* newoffset = FALSE */
20192e18d4d8STrond Myklebust 	}
2020863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2021863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2022ac7db726SBenny Halevy 
20235f919c9fSChristoph Hellwig 	encode_uint32(xdr, args->layoutupdate_len);
202473504740STrond Myklebust 	if (args->layoutupdate_pages)
20255f919c9fSChristoph Hellwig 		xdr_write_pages(xdr, args->layoutupdate_pages, 0,
20265f919c9fSChristoph Hellwig 				args->layoutupdate_len);
2027863a3c6cSAndy Adamson 
2028863a3c6cSAndy Adamson 	return 0;
2029863a3c6cSAndy Adamson }
2030cbe82603SBenny Halevy 
2031cbe82603SBenny Halevy static void
2032cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr,
2033cbe82603SBenny Halevy 		    const struct nfs4_layoutreturn_args *args,
2034cbe82603SBenny Halevy 		    struct compound_hdr *hdr)
2035cbe82603SBenny Halevy {
2036cbe82603SBenny Halevy 	__be32 *p;
2037cbe82603SBenny Halevy 
2038475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2039475d4ba0STrond Myklebust 	p = reserve_space(xdr, 16);
2040cbe82603SBenny Halevy 	*p++ = cpu_to_be32(0);		/* reclaim. always 0 for now */
2041cbe82603SBenny Halevy 	*p++ = cpu_to_be32(args->layout_type);
204215eb67c1SPeng Tao 	*p++ = cpu_to_be32(args->range.iomode);
2043cbe82603SBenny Halevy 	*p = cpu_to_be32(RETURN_FILE);
2044ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 16);
204515eb67c1SPeng Tao 	p = xdr_encode_hyper(p, args->range.offset);
204615eb67c1SPeng Tao 	p = xdr_encode_hyper(p, args->range.length);
2047cbe82603SBenny Halevy 	spin_lock(&args->inode->i_lock);
2048ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
2049cbe82603SBenny Halevy 	spin_unlock(&args->inode->i_lock);
20504d796d75STrond Myklebust 	if (args->ld_private->ops && args->ld_private->ops->encode)
20514d796d75STrond Myklebust 		args->ld_private->ops->encode(xdr, args, args->ld_private);
205294e5c571STrond Myklebust 	else
2053475d4ba0STrond Myklebust 		encode_uint32(xdr, 0);
2054cbe82603SBenny Halevy }
2055fca78d6dSBryan Schumaker 
2056fca78d6dSBryan Schumaker static int
2057fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr,
2058fca78d6dSBryan Schumaker 		       const struct nfs41_secinfo_no_name_args *args,
2059fca78d6dSBryan Schumaker 		       struct compound_hdr *hdr)
2060fca78d6dSBryan Schumaker {
2061475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2062475d4ba0STrond Myklebust 	encode_uint32(xdr, args->style);
2063fca78d6dSBryan Schumaker 	return 0;
2064fca78d6dSBryan Schumaker }
20657d974794SBryan Schumaker 
20667d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr,
2067fcc85819SChristoph Hellwig 				const struct nfs41_test_stateid_args *args,
20687d974794SBryan Schumaker 				struct compound_hdr *hdr)
20697d974794SBryan Schumaker {
2070475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2071475d4ba0STrond Myklebust 	encode_uint32(xdr, 1);
2072ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, args->stateid);
20737d974794SBryan Schumaker }
20749aeda35fSBryan Schumaker 
20759aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr,
2076fcc85819SChristoph Hellwig 				const struct nfs41_free_stateid_args *args,
20779aeda35fSBryan Schumaker 				struct compound_hdr *hdr)
20789aeda35fSBryan Schumaker {
2079ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
20807c1d5faeSTrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
20819aeda35fSBryan Schumaker }
2082cf805165STrond Myklebust #else
2083cf805165STrond Myklebust static inline void
2084cf805165STrond Myklebust encode_layoutreturn(struct xdr_stream *xdr,
2085cf805165STrond Myklebust 		    const struct nfs4_layoutreturn_args *args,
2086cf805165STrond Myklebust 		    struct compound_hdr *hdr)
2087cf805165STrond Myklebust {
2088cf805165STrond Myklebust }
208956f487f8SFred Isaman 
209056f487f8SFred Isaman static void
209156f487f8SFred Isaman encode_layoutget(struct xdr_stream *xdr,
209256f487f8SFred Isaman 		      const struct nfs4_layoutget_args *args,
209356f487f8SFred Isaman 		      struct compound_hdr *hdr)
209456f487f8SFred Isaman {
209556f487f8SFred Isaman }
2096b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
2097b1f69b75SAndy Adamson 
20981da177e4SLinus Torvalds /*
20991da177e4SLinus Torvalds  * END OF "GENERIC" ENCODE ROUTINES.
21001da177e4SLinus Torvalds  */
21011da177e4SLinus Torvalds 
210266cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
210366cc0429SBenny Halevy {
210466cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1)
21053bd2384aSChuck Lever 	struct nfs4_session *session = args->sa_slot->table->session;
21063bd2384aSChuck Lever 	if (session)
21073bd2384aSChuck Lever 		return session->clp->cl_mvops->minor_version;
210866cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
210966cc0429SBenny Halevy 	return 0;
211066cc0429SBenny Halevy }
211166cc0429SBenny Halevy 
21121da177e4SLinus Torvalds /*
21131da177e4SLinus Torvalds  * Encode an ACCESS request
21141da177e4SLinus Torvalds  */
21159f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2116fcc85819SChristoph Hellwig 				const void *data)
21171da177e4SLinus Torvalds {
2118fcc85819SChristoph Hellwig 	const struct nfs4_accessargs *args = data;
21191da177e4SLinus Torvalds 	struct compound_hdr hdr = {
212066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21211da177e4SLinus Torvalds 	};
21221da177e4SLinus Torvalds 
21239f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21249f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21259f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21269f06c719SChuck Lever 	encode_access(xdr, args->access, &hdr);
21278bcbe7d9STrond Myklebust 	if (args->bitmask)
21289f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2129d017931cSAndy Adamson 	encode_nops(&hdr);
21301da177e4SLinus Torvalds }
21311da177e4SLinus Torvalds 
21321da177e4SLinus Torvalds /*
21331da177e4SLinus Torvalds  * Encode LOOKUP request
21341da177e4SLinus Torvalds  */
21359f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2136fcc85819SChristoph Hellwig 				const void *data)
21371da177e4SLinus Torvalds {
2138fcc85819SChristoph Hellwig 	const struct nfs4_lookup_arg *args = data;
21391da177e4SLinus Torvalds 	struct compound_hdr hdr = {
214066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21411da177e4SLinus Torvalds 	};
21421da177e4SLinus Torvalds 
21439f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21449f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21459f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
21469f06c719SChuck Lever 	encode_lookup(xdr, args->name, &hdr);
21479f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21489f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2149d017931cSAndy Adamson 	encode_nops(&hdr);
21501da177e4SLinus Torvalds }
21511da177e4SLinus Torvalds 
21521da177e4SLinus Torvalds /*
21535b5faaf6SJeff Layton  * Encode LOOKUPP request
21545b5faaf6SJeff Layton  */
21555b5faaf6SJeff Layton static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
21565b5faaf6SJeff Layton 		const void *data)
21575b5faaf6SJeff Layton {
21585b5faaf6SJeff Layton 	const struct nfs4_lookupp_arg *args = data;
21595b5faaf6SJeff Layton 	struct compound_hdr hdr = {
21605b5faaf6SJeff Layton 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21615b5faaf6SJeff Layton 	};
21625b5faaf6SJeff Layton 
21635b5faaf6SJeff Layton 	encode_compound_hdr(xdr, req, &hdr);
21645b5faaf6SJeff Layton 	encode_sequence(xdr, &args->seq_args, &hdr);
21655b5faaf6SJeff Layton 	encode_putfh(xdr, args->fh, &hdr);
21665b5faaf6SJeff Layton 	encode_lookupp(xdr, &hdr);
21675b5faaf6SJeff Layton 	encode_getfh(xdr, &hdr);
21685b5faaf6SJeff Layton 	encode_getfattr(xdr, args->bitmask, &hdr);
21695b5faaf6SJeff Layton 	encode_nops(&hdr);
21705b5faaf6SJeff Layton }
21715b5faaf6SJeff Layton 
21725b5faaf6SJeff Layton /*
21731da177e4SLinus Torvalds  * Encode LOOKUP_ROOT request
21741da177e4SLinus Torvalds  */
21759f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
21769f06c719SChuck Lever 				     struct xdr_stream *xdr,
2177fcc85819SChristoph Hellwig 				     const void *data)
21781da177e4SLinus Torvalds {
2179fcc85819SChristoph Hellwig 	const struct nfs4_lookup_root_arg *args = data;
21801da177e4SLinus Torvalds 	struct compound_hdr hdr = {
218166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21821da177e4SLinus Torvalds 	};
21831da177e4SLinus Torvalds 
21849f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21859f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21869f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
21879f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21889f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2189d017931cSAndy Adamson 	encode_nops(&hdr);
21901da177e4SLinus Torvalds }
21911da177e4SLinus Torvalds 
21921da177e4SLinus Torvalds /*
21931da177e4SLinus Torvalds  * Encode REMOVE request
21941da177e4SLinus Torvalds  */
21959f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2196fcc85819SChristoph Hellwig 				const void *data)
21971da177e4SLinus Torvalds {
2198fcc85819SChristoph Hellwig 	const struct nfs_removeargs *args = data;
21991da177e4SLinus Torvalds 	struct compound_hdr hdr = {
220066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22011da177e4SLinus Torvalds 	};
22021da177e4SLinus Torvalds 
22039f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22049f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22059f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22069f06c719SChuck Lever 	encode_remove(xdr, &args->name, &hdr);
2207d017931cSAndy Adamson 	encode_nops(&hdr);
22081da177e4SLinus Torvalds }
22091da177e4SLinus Torvalds 
22101da177e4SLinus Torvalds /*
22111da177e4SLinus Torvalds  * Encode RENAME request
22121da177e4SLinus Torvalds  */
22139f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2214fcc85819SChristoph Hellwig 				const void *data)
22151da177e4SLinus Torvalds {
2216fcc85819SChristoph Hellwig 	const struct nfs_renameargs *args = data;
22171da177e4SLinus Torvalds 	struct compound_hdr hdr = {
221866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22191da177e4SLinus Torvalds 	};
22201da177e4SLinus Torvalds 
22219f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22229f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22239f06c719SChuck Lever 	encode_putfh(xdr, args->old_dir, &hdr);
22249f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
22259f06c719SChuck Lever 	encode_putfh(xdr, args->new_dir, &hdr);
22269f06c719SChuck Lever 	encode_rename(xdr, args->old_name, args->new_name, &hdr);
2227d017931cSAndy Adamson 	encode_nops(&hdr);
22281da177e4SLinus Torvalds }
22291da177e4SLinus Torvalds 
22301da177e4SLinus Torvalds /*
22311da177e4SLinus Torvalds  * Encode LINK request
22321da177e4SLinus Torvalds  */
22339f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2234fcc85819SChristoph Hellwig 			      const void *data)
22351da177e4SLinus Torvalds {
2236fcc85819SChristoph Hellwig 	const struct nfs4_link_arg *args = data;
22371da177e4SLinus Torvalds 	struct compound_hdr hdr = {
223866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22391da177e4SLinus Torvalds 	};
22401da177e4SLinus Torvalds 
22419f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22429f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22439f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22449f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
22459f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
22469f06c719SChuck Lever 	encode_link(xdr, args->name, &hdr);
22479f06c719SChuck Lever 	encode_restorefh(xdr, &hdr);
22489f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2249d017931cSAndy Adamson 	encode_nops(&hdr);
22501da177e4SLinus Torvalds }
22511da177e4SLinus Torvalds 
22521da177e4SLinus Torvalds /*
22531da177e4SLinus Torvalds  * Encode CREATE request
22541da177e4SLinus Torvalds  */
22559f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2256fcc85819SChristoph Hellwig 				const void *data)
22571da177e4SLinus Torvalds {
2258fcc85819SChristoph Hellwig 	const struct nfs4_create_arg *args = data;
22591da177e4SLinus Torvalds 	struct compound_hdr hdr = {
226066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22611da177e4SLinus Torvalds 	};
22621da177e4SLinus Torvalds 
22639f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22649f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22659f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
22669f06c719SChuck Lever 	encode_create(xdr, args, &hdr);
22679f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
22689f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2269d017931cSAndy Adamson 	encode_nops(&hdr);
22701da177e4SLinus Torvalds }
22711da177e4SLinus Torvalds 
22721da177e4SLinus Torvalds /*
22731da177e4SLinus Torvalds  * Encode SYMLINK request
22741da177e4SLinus Torvalds  */
22759f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2276fcc85819SChristoph Hellwig 				 const void *data)
22771da177e4SLinus Torvalds {
2278fcc85819SChristoph Hellwig 	const struct nfs4_create_arg *args = data;
2279fcc85819SChristoph Hellwig 
22809f06c719SChuck Lever 	nfs4_xdr_enc_create(req, xdr, args);
22811da177e4SLinus Torvalds }
22821da177e4SLinus Torvalds 
22831da177e4SLinus Torvalds /*
22841da177e4SLinus Torvalds  * Encode GETATTR request
22851da177e4SLinus Torvalds  */
22869f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2287fcc85819SChristoph Hellwig 				 const void *data)
22881da177e4SLinus Torvalds {
2289fcc85819SChristoph Hellwig 	const struct nfs4_getattr_arg *args = data;
22901da177e4SLinus Torvalds 	struct compound_hdr hdr = {
229166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22921da177e4SLinus Torvalds 	};
22931da177e4SLinus Torvalds 
22949f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22959f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22969f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22979f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2298d017931cSAndy Adamson 	encode_nops(&hdr);
22991da177e4SLinus Torvalds }
23001da177e4SLinus Torvalds 
23011da177e4SLinus Torvalds /*
23021da177e4SLinus Torvalds  * Encode a CLOSE request
23031da177e4SLinus Torvalds  */
23049f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2305fcc85819SChristoph Hellwig 			       const void *data)
23061da177e4SLinus Torvalds {
2307fcc85819SChristoph Hellwig 	const struct nfs_closeargs *args = data;
23081da177e4SLinus Torvalds 	struct compound_hdr hdr = {
230966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23101da177e4SLinus Torvalds 	};
23111da177e4SLinus Torvalds 
23129f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23139f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23149f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
2315cf805165STrond Myklebust 	if (args->lr_args)
2316cf805165STrond Myklebust 		encode_layoutreturn(xdr, args->lr_args, &hdr);
23173ecefc92STrond Myklebust 	if (args->bitmask != NULL)
23189f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2319d8d84983STrond Myklebust 	encode_close(xdr, args, &hdr);
2320d017931cSAndy Adamson 	encode_nops(&hdr);
23211da177e4SLinus Torvalds }
23221da177e4SLinus Torvalds 
23231da177e4SLinus Torvalds /*
23241da177e4SLinus Torvalds  * Encode an OPEN request
23251da177e4SLinus Torvalds  */
23269f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2327fcc85819SChristoph Hellwig 			      const void *data)
23281da177e4SLinus Torvalds {
2329fcc85819SChristoph Hellwig 	const struct nfs_openargs *args = data;
23301da177e4SLinus Torvalds 	struct compound_hdr hdr = {
233166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23321da177e4SLinus Torvalds 	};
23331da177e4SLinus Torvalds 
23349f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23359f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23369f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23379f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
23389f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
2339ae2bb032SWeston Andros Adamson 	if (args->access)
23406168f62cSWeston Andros Adamson 		encode_access(xdr, args->access, &hdr);
23411549210fSTrond Myklebust 	encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
234256f487f8SFred Isaman 	if (args->lg_args) {
234356f487f8SFred Isaman 		encode_layoutget(xdr, args->lg_args, &hdr);
234456f487f8SFred Isaman 		xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
234556f487f8SFred Isaman 				 args->lg_args->layout.pages,
234656f487f8SFred Isaman 				 0, args->lg_args->layout.pglen);
234756f487f8SFred Isaman 	}
2348d017931cSAndy Adamson 	encode_nops(&hdr);
23491da177e4SLinus Torvalds }
23501da177e4SLinus Torvalds 
23511da177e4SLinus Torvalds /*
23521da177e4SLinus Torvalds  * Encode an OPEN_CONFIRM request
23531da177e4SLinus Torvalds  */
23549f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
23559f06c719SChuck Lever 				      struct xdr_stream *xdr,
2356fcc85819SChristoph Hellwig 				      const void *data)
23571da177e4SLinus Torvalds {
2358fcc85819SChristoph Hellwig 	const struct nfs_open_confirmargs *args = data;
23591da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2360d017931cSAndy Adamson 		.nops   = 0,
23611da177e4SLinus Torvalds 	};
23621da177e4SLinus Torvalds 
23639f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23649f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23659f06c719SChuck Lever 	encode_open_confirm(xdr, args, &hdr);
2366d017931cSAndy Adamson 	encode_nops(&hdr);
23671da177e4SLinus Torvalds }
23681da177e4SLinus Torvalds 
23691da177e4SLinus Torvalds /*
23701da177e4SLinus Torvalds  * Encode an OPEN request with no attributes.
23711da177e4SLinus Torvalds  */
23729f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
23739f06c719SChuck Lever 				     struct xdr_stream *xdr,
2374fcc85819SChristoph Hellwig 				     const void *data)
23751da177e4SLinus Torvalds {
2376fcc85819SChristoph Hellwig 	const struct nfs_openargs *args = data;
23771da177e4SLinus Torvalds 	struct compound_hdr hdr = {
237866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23791da177e4SLinus Torvalds 	};
23801da177e4SLinus Torvalds 
23819f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23829f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23839f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23849f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
2385ae2bb032SWeston Andros Adamson 	if (args->access)
23866168f62cSWeston Andros Adamson 		encode_access(xdr, args->access, &hdr);
2387e23008ecSAndy Adamson 	encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
238856f487f8SFred Isaman 	if (args->lg_args) {
238956f487f8SFred Isaman 		encode_layoutget(xdr, args->lg_args, &hdr);
239056f487f8SFred Isaman 		xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
239156f487f8SFred Isaman 				 args->lg_args->layout.pages,
239256f487f8SFred Isaman 				 0, args->lg_args->layout.pglen);
239356f487f8SFred Isaman 	}
2394d017931cSAndy Adamson 	encode_nops(&hdr);
23951da177e4SLinus Torvalds }
23961da177e4SLinus Torvalds 
23971da177e4SLinus Torvalds /*
23981da177e4SLinus Torvalds  * Encode an OPEN_DOWNGRADE request
23991da177e4SLinus Torvalds  */
24009f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
24019f06c719SChuck Lever 					struct xdr_stream *xdr,
2402fcc85819SChristoph Hellwig 					const void *data)
24031da177e4SLinus Torvalds {
2404fcc85819SChristoph Hellwig 	const struct nfs_closeargs *args = data;
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);
2412b6808145STrond Myklebust 	if (args->lr_args)
2413b6808145STrond Myklebust 		encode_layoutreturn(xdr, args->lr_args, &hdr);
24149f06c719SChuck Lever 	encode_open_downgrade(xdr, args, &hdr);
2415d017931cSAndy Adamson 	encode_nops(&hdr);
24161da177e4SLinus Torvalds }
24171da177e4SLinus Torvalds 
24181da177e4SLinus Torvalds /*
24191da177e4SLinus Torvalds  * Encode a LOCK request
24201da177e4SLinus Torvalds  */
24219f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2422fcc85819SChristoph Hellwig 			      const void *data)
24231da177e4SLinus Torvalds {
2424fcc85819SChristoph Hellwig 	const struct nfs_lock_args *args = data;
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_lock(xdr, args, &hdr);
2433d017931cSAndy Adamson 	encode_nops(&hdr);
24341da177e4SLinus Torvalds }
24351da177e4SLinus Torvalds 
24361da177e4SLinus Torvalds /*
24371da177e4SLinus Torvalds  * Encode a LOCKT request
24381da177e4SLinus Torvalds  */
24399f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2440fcc85819SChristoph Hellwig 			       const void *data)
24411da177e4SLinus Torvalds {
2442fcc85819SChristoph Hellwig 	const struct nfs_lockt_args *args = data;
24431da177e4SLinus Torvalds 	struct compound_hdr hdr = {
244466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24451da177e4SLinus Torvalds 	};
24461da177e4SLinus Torvalds 
24479f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24489f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24499f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24509f06c719SChuck Lever 	encode_lockt(xdr, args, &hdr);
2451d017931cSAndy Adamson 	encode_nops(&hdr);
24521da177e4SLinus Torvalds }
24531da177e4SLinus Torvalds 
24541da177e4SLinus Torvalds /*
24551da177e4SLinus Torvalds  * Encode a LOCKU request
24561da177e4SLinus Torvalds  */
24579f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2458fcc85819SChristoph Hellwig 			       const void *data)
24591da177e4SLinus Torvalds {
2460fcc85819SChristoph Hellwig 	const struct nfs_locku_args *args = data;
24611da177e4SLinus Torvalds 	struct compound_hdr hdr = {
246266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24631da177e4SLinus Torvalds 	};
24641da177e4SLinus Torvalds 
24659f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24669f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24679f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24689f06c719SChuck Lever 	encode_locku(xdr, args, &hdr);
2469d017931cSAndy Adamson 	encode_nops(&hdr);
24701da177e4SLinus Torvalds }
24711da177e4SLinus Torvalds 
24729f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
24739f06c719SChuck Lever 					   struct xdr_stream *xdr,
2474fcc85819SChristoph Hellwig 					   const void *data)
2475d3c7b7ccSTrond Myklebust {
2476fcc85819SChristoph Hellwig 	const struct nfs_release_lockowner_args *args = data;
2477d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr = {
2478d3c7b7ccSTrond Myklebust 		.minorversion = 0,
2479d3c7b7ccSTrond Myklebust 	};
2480d3c7b7ccSTrond Myklebust 
24819f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24829f06c719SChuck Lever 	encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2483d3c7b7ccSTrond Myklebust 	encode_nops(&hdr);
2484d3c7b7ccSTrond Myklebust }
2485d3c7b7ccSTrond Myklebust 
24861da177e4SLinus Torvalds /*
24871da177e4SLinus Torvalds  * Encode a READLINK request
24881da177e4SLinus Torvalds  */
24899f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2490fcc85819SChristoph Hellwig 				  const void *data)
24911da177e4SLinus Torvalds {
2492fcc85819SChristoph Hellwig 	const struct nfs4_readlink *args = data;
24931da177e4SLinus Torvalds 	struct compound_hdr hdr = {
249466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24951da177e4SLinus Torvalds 	};
24961da177e4SLinus Torvalds 
24979f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24989f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24999f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25009f06c719SChuck Lever 	encode_readlink(xdr, args, req, &hdr);
2501e3a535e1STrond Myklebust 
250228f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2503e3a535e1STrond Myklebust 			args->pgbase, args->pglen);
2504d017931cSAndy Adamson 	encode_nops(&hdr);
25051da177e4SLinus Torvalds }
25061da177e4SLinus Torvalds 
25071da177e4SLinus Torvalds /*
25081da177e4SLinus Torvalds  * Encode a READDIR request
25091da177e4SLinus Torvalds  */
25109f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2511fcc85819SChristoph Hellwig 				 const void *data)
25121da177e4SLinus Torvalds {
2513fcc85819SChristoph Hellwig 	const struct nfs4_readdir_arg *args = data;
25141da177e4SLinus Torvalds 	struct compound_hdr hdr = {
251566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25161da177e4SLinus Torvalds 	};
25171da177e4SLinus Torvalds 
25189f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25199f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25209f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25219f06c719SChuck Lever 	encode_readdir(xdr, args, req, &hdr);
2522d6ac02dfSTrond Myklebust 
252328f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2524d6ac02dfSTrond Myklebust 			 args->pgbase, args->count);
2525d6ac02dfSTrond Myklebust 	dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
252628f56694SBenny Halevy 			__func__, hdr.replen << 2, args->pages,
2527d6ac02dfSTrond Myklebust 			args->pgbase, args->count);
2528d017931cSAndy Adamson 	encode_nops(&hdr);
25291da177e4SLinus Torvalds }
25301da177e4SLinus Torvalds 
25311da177e4SLinus Torvalds /*
25321da177e4SLinus Torvalds  * Encode a READ request
25331da177e4SLinus Torvalds  */
25349f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2535fcc85819SChristoph Hellwig 			      const void *data)
25361da177e4SLinus Torvalds {
2537fcc85819SChristoph Hellwig 	const struct nfs_pgio_args *args = data;
25381da177e4SLinus Torvalds 	struct compound_hdr hdr = {
253966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25401da177e4SLinus Torvalds 	};
25411da177e4SLinus Torvalds 
25429f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25439f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25449f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25459f06c719SChuck Lever 	encode_read(xdr, args, &hdr);
25461da177e4SLinus Torvalds 
254728f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
25481da177e4SLinus Torvalds 			 args->pages, args->pgbase, args->count);
25494f22ccc3S\"Talpey, Thomas\ 	req->rq_rcv_buf.flags |= XDRBUF_READ;
2550d017931cSAndy Adamson 	encode_nops(&hdr);
25511da177e4SLinus Torvalds }
25521da177e4SLinus Torvalds 
25531da177e4SLinus Torvalds /*
25541da177e4SLinus Torvalds  * Encode an SETATTR request
25551da177e4SLinus Torvalds  */
25569f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2557fcc85819SChristoph Hellwig 				 const void *data)
25581da177e4SLinus Torvalds {
2559fcc85819SChristoph Hellwig 	const struct nfs_setattrargs *args = data;
25601da177e4SLinus Torvalds 	struct compound_hdr hdr = {
256166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25621da177e4SLinus Torvalds 	};
25631da177e4SLinus Torvalds 
25649f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25659f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25669f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25679f06c719SChuck Lever 	encode_setattr(xdr, args, args->server, &hdr);
25689f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2569d017931cSAndy Adamson 	encode_nops(&hdr);
25701da177e4SLinus Torvalds }
25711da177e4SLinus Torvalds 
25721da177e4SLinus Torvalds /*
2573029d105eSJ. Bruce Fields  * Encode a GETACL request
2574029d105eSJ. Bruce Fields  */
25759f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2576fcc85819SChristoph Hellwig 				const void *data)
2577029d105eSJ. Bruce Fields {
2578fcc85819SChristoph Hellwig 	const struct nfs_getaclargs *args = data;
2579029d105eSJ. Bruce Fields 	struct compound_hdr hdr = {
258066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2581029d105eSJ. Bruce Fields 	};
258237c88763STrond Myklebust 	const __u32 nfs4_acl_bitmap[1] = {
258337c88763STrond Myklebust 		[0] = FATTR4_WORD0_ACL,
258437c88763STrond Myklebust 	};
258528f56694SBenny Halevy 	uint32_t replen;
2586029d105eSJ. Bruce Fields 
25879f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25889f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25899f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25906682c14bSJ. Bruce Fields 	replen = hdr.replen + op_decode_hdr_maxsz;
259137c88763STrond Myklebust 	encode_getattr(xdr, nfs4_acl_bitmap, NULL,
259237c88763STrond Myklebust 			ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
2593cf8cdbe5SAndy Adamson 
259428f56694SBenny Halevy 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
25958fbcf237SAndreas Gruenbacher 		args->acl_pages, 0, args->acl_len);
2596bf118a34SAndy Adamson 
2597d017931cSAndy Adamson 	encode_nops(&hdr);
2598029d105eSJ. Bruce Fields }
2599029d105eSJ. Bruce Fields 
2600029d105eSJ. Bruce Fields /*
26011da177e4SLinus Torvalds  * Encode a WRITE request
26021da177e4SLinus Torvalds  */
26039f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2604fcc85819SChristoph Hellwig 			       const void *data)
26051da177e4SLinus Torvalds {
2606fcc85819SChristoph Hellwig 	const struct nfs_pgio_args *args = data;
26071da177e4SLinus Torvalds 	struct compound_hdr hdr = {
260866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26091da177e4SLinus Torvalds 	};
26101da177e4SLinus Torvalds 
26119f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26129f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26139f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26149f06c719SChuck Lever 	encode_write(xdr, args, &hdr);
26154f22ccc3S\"Talpey, Thomas\ 	req->rq_snd_buf.flags |= XDRBUF_WRITE;
26167ffd1064SFred Isaman 	if (args->bitmask)
26179f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2618d017931cSAndy Adamson 	encode_nops(&hdr);
26191da177e4SLinus Torvalds }
26201da177e4SLinus Torvalds 
26211da177e4SLinus Torvalds /*
26221da177e4SLinus Torvalds  *  a COMMIT request
26231da177e4SLinus Torvalds  */
26249f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2625fcc85819SChristoph Hellwig 				const void *data)
26261da177e4SLinus Torvalds {
2627fcc85819SChristoph Hellwig 	const struct nfs_commitargs *args = data;
26281da177e4SLinus Torvalds 	struct compound_hdr hdr = {
262966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26301da177e4SLinus Torvalds 	};
26311da177e4SLinus Torvalds 
26329f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26339f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26349f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26359f06c719SChuck Lever 	encode_commit(xdr, args, &hdr);
2636d017931cSAndy Adamson 	encode_nops(&hdr);
26371da177e4SLinus Torvalds }
26381da177e4SLinus Torvalds 
26391da177e4SLinus Torvalds /*
26401da177e4SLinus Torvalds  * FSINFO request
26411da177e4SLinus Torvalds  */
26429f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2643fcc85819SChristoph Hellwig 				const void *data)
26441da177e4SLinus Torvalds {
2645fcc85819SChristoph Hellwig 	const struct nfs4_fsinfo_arg *args = data;
26461da177e4SLinus Torvalds 	struct compound_hdr hdr = {
264766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26481da177e4SLinus Torvalds 	};
26491da177e4SLinus Torvalds 
26509f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26519f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26529f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26539f06c719SChuck Lever 	encode_fsinfo(xdr, args->bitmask, &hdr);
2654d017931cSAndy Adamson 	encode_nops(&hdr);
26551da177e4SLinus Torvalds }
26561da177e4SLinus Torvalds 
26571da177e4SLinus Torvalds /*
26581da177e4SLinus Torvalds  * a PATHCONF request
26591da177e4SLinus Torvalds  */
26609f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2661fcc85819SChristoph Hellwig 				  const void *data)
26621da177e4SLinus Torvalds {
2663fcc85819SChristoph Hellwig 	const struct nfs4_pathconf_arg *args = data;
26641da177e4SLinus Torvalds 	struct compound_hdr hdr = {
266566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26661da177e4SLinus Torvalds 	};
26671da177e4SLinus Torvalds 
26689f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26699f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26709f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
267137c88763STrond Myklebust 	encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
267237c88763STrond Myklebust 			ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
2673d017931cSAndy Adamson 	encode_nops(&hdr);
26741da177e4SLinus Torvalds }
26751da177e4SLinus Torvalds 
26761da177e4SLinus Torvalds /*
26771da177e4SLinus Torvalds  * a STATFS request
26781da177e4SLinus Torvalds  */
26799f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2680fcc85819SChristoph Hellwig 				const void *data)
26811da177e4SLinus Torvalds {
2682fcc85819SChristoph Hellwig 	const struct nfs4_statfs_arg *args = data;
26831da177e4SLinus Torvalds 	struct compound_hdr hdr = {
268466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26851da177e4SLinus Torvalds 	};
26861da177e4SLinus Torvalds 
26879f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26889f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26899f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
269037c88763STrond Myklebust 	encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
269137c88763STrond Myklebust 			ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
2692d017931cSAndy Adamson 	encode_nops(&hdr);
26931da177e4SLinus Torvalds }
26941da177e4SLinus Torvalds 
26951da177e4SLinus Torvalds /*
26961da177e4SLinus Torvalds  * GETATTR_BITMAP request
26971da177e4SLinus Torvalds  */
26989f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
26999f06c719SChuck Lever 				     struct xdr_stream *xdr,
2700fcc85819SChristoph Hellwig 				     const void *data)
27011da177e4SLinus Torvalds {
2702fcc85819SChristoph Hellwig 	const struct nfs4_server_caps_arg *args = data;
27038c61282fSKinglong Mee 	const u32 *bitmask = args->bitmask;
27041da177e4SLinus Torvalds 	struct compound_hdr hdr = {
270566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
27061da177e4SLinus Torvalds 	};
27071da177e4SLinus Torvalds 
27089f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27099f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
27109f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
271137c88763STrond Myklebust 	encode_getattr(xdr, bitmask, NULL, 3, &hdr);
2712d017931cSAndy Adamson 	encode_nops(&hdr);
27131da177e4SLinus Torvalds }
27141da177e4SLinus Torvalds 
27151da177e4SLinus Torvalds /*
27161da177e4SLinus Torvalds  * a RENEW request
27171da177e4SLinus Torvalds  */
27189f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2719fcc85819SChristoph Hellwig 			       const void *data)
2720fcc85819SChristoph Hellwig 
27211da177e4SLinus Torvalds {
2722fcc85819SChristoph Hellwig 	const struct nfs_client *clp = data;
27231da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2724d017931cSAndy Adamson 		.nops	= 0,
27251da177e4SLinus Torvalds 	};
27261da177e4SLinus Torvalds 
27279f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
2728bb4dae5eSChuck Lever 	encode_renew(xdr, clp->cl_clientid, &hdr);
2729d017931cSAndy Adamson 	encode_nops(&hdr);
27301da177e4SLinus Torvalds }
27311da177e4SLinus Torvalds 
27321da177e4SLinus Torvalds /*
27331da177e4SLinus Torvalds  * a SETCLIENTID request
27341da177e4SLinus Torvalds  */
27359f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
27369f06c719SChuck Lever 				     struct xdr_stream *xdr,
2737fcc85819SChristoph Hellwig 				     const void *data)
27381da177e4SLinus Torvalds {
2739fcc85819SChristoph Hellwig 	const struct nfs4_setclientid *sc = data;
27401da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2741d017931cSAndy Adamson 		.nops	= 0,
27421da177e4SLinus Torvalds 	};
27431da177e4SLinus Torvalds 
27449f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27459f06c719SChuck Lever 	encode_setclientid(xdr, sc, &hdr);
2746d017931cSAndy Adamson 	encode_nops(&hdr);
27471da177e4SLinus Torvalds }
27481da177e4SLinus Torvalds 
27491da177e4SLinus Torvalds /*
27501da177e4SLinus Torvalds  * a SETCLIENTID_CONFIRM request
27511da177e4SLinus Torvalds  */
27529f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
27539f06c719SChuck Lever 					     struct xdr_stream *xdr,
2754fcc85819SChristoph Hellwig 					     const void *data)
27551da177e4SLinus Torvalds {
2756fcc85819SChristoph Hellwig 	const struct nfs4_setclientid_res *arg = data;
27571da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2758d017931cSAndy Adamson 		.nops	= 0,
27591da177e4SLinus Torvalds 	};
27601da177e4SLinus Torvalds 
27619f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27629f06c719SChuck Lever 	encode_setclientid_confirm(xdr, arg, &hdr);
2763d017931cSAndy Adamson 	encode_nops(&hdr);
27641da177e4SLinus Torvalds }
27651da177e4SLinus Torvalds 
27661da177e4SLinus Torvalds /*
27671da177e4SLinus Torvalds  * DELEGRETURN request
27681da177e4SLinus Torvalds  */
27699f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
27709f06c719SChuck Lever 				     struct xdr_stream *xdr,
2771fcc85819SChristoph Hellwig 				     const void *data)
27721da177e4SLinus Torvalds {
2773fcc85819SChristoph Hellwig 	const struct nfs4_delegreturnargs *args = data;
27741da177e4SLinus Torvalds 	struct compound_hdr hdr = {
277566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
27761da177e4SLinus Torvalds 	};
27771da177e4SLinus Torvalds 
27789f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27799f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
27809f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
2781586f1c39STrond Myklebust 	if (args->lr_args)
2782586f1c39STrond Myklebust 		encode_layoutreturn(xdr, args->lr_args, &hdr);
27838ac2b422STrond Myklebust 	if (args->bitmask)
27849f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2785e144cbccSTrond Myklebust 	encode_delegreturn(xdr, args->stateid, &hdr);
2786d017931cSAndy Adamson 	encode_nops(&hdr);
27871da177e4SLinus Torvalds }
27881da177e4SLinus Torvalds 
27891da177e4SLinus Torvalds /*
2790683b57b4STrond Myklebust  * Encode FS_LOCATIONS request
2791683b57b4STrond Myklebust  */
27929f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
27939f06c719SChuck Lever 				      struct xdr_stream *xdr,
2794fcc85819SChristoph Hellwig 				      const void *data)
2795683b57b4STrond Myklebust {
2796fcc85819SChristoph Hellwig 	const struct nfs4_fs_locations_arg *args = data;
2797683b57b4STrond Myklebust 	struct compound_hdr hdr = {
279866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2799683b57b4STrond Myklebust 	};
280028f56694SBenny Halevy 	uint32_t replen;
2801683b57b4STrond Myklebust 
28029f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28039f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
2804b03d735bSChuck Lever 	if (args->migration) {
2805b03d735bSChuck Lever 		encode_putfh(xdr, args->fh, &hdr);
2806b03d735bSChuck Lever 		replen = hdr.replen;
2807b03d735bSChuck Lever 		encode_fs_locations(xdr, args->bitmask, &hdr);
2808b03d735bSChuck Lever 		if (args->renew)
2809b03d735bSChuck Lever 			encode_renew(xdr, args->clientid, &hdr);
2810b03d735bSChuck Lever 	} else {
28119f06c719SChuck Lever 		encode_putfh(xdr, args->dir_fh, &hdr);
28129f06c719SChuck Lever 		encode_lookup(xdr, args->name, &hdr);
2813b03d735bSChuck Lever 		replen = hdr.replen;
28149f06c719SChuck Lever 		encode_fs_locations(xdr, args->bitmask, &hdr);
2815b03d735bSChuck Lever 	}
2816cf8cdbe5SAndy Adamson 
2817b03d735bSChuck Lever 	/* Set up reply kvec to capture returned fs_locations array. */
2818fcc85819SChristoph Hellwig 	xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2819fcc85819SChristoph Hellwig 			 (struct page **)&args->page, 0, PAGE_SIZE);
2820d017931cSAndy Adamson 	encode_nops(&hdr);
2821683b57b4STrond Myklebust }
2822683b57b4STrond Myklebust 
28235a5ea0d4SBryan Schumaker /*
28245a5ea0d4SBryan Schumaker  * Encode SECINFO request
28255a5ea0d4SBryan Schumaker  */
28265a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
28275a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
2828fcc85819SChristoph Hellwig 				const void *data)
28295a5ea0d4SBryan Schumaker {
2830fcc85819SChristoph Hellwig 	const struct nfs4_secinfo_arg *args = data;
28315a5ea0d4SBryan Schumaker 	struct compound_hdr hdr = {
28325a5ea0d4SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
28335a5ea0d4SBryan Schumaker 	};
28345a5ea0d4SBryan Schumaker 
28355a5ea0d4SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
28365a5ea0d4SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
28375a5ea0d4SBryan Schumaker 	encode_putfh(xdr, args->dir_fh, &hdr);
28385a5ea0d4SBryan Schumaker 	encode_secinfo(xdr, args->name, &hdr);
28395a5ea0d4SBryan Schumaker 	encode_nops(&hdr);
28405a5ea0d4SBryan Schumaker }
28415a5ea0d4SBryan Schumaker 
284244c99933SChuck Lever /*
284344c99933SChuck Lever  * Encode FSID_PRESENT request
284444c99933SChuck Lever  */
284544c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
284644c99933SChuck Lever 				      struct xdr_stream *xdr,
2847fcc85819SChristoph Hellwig 				      const void *data)
284844c99933SChuck Lever {
2849fcc85819SChristoph Hellwig 	const struct nfs4_fsid_present_arg *args = data;
285044c99933SChuck Lever 	struct compound_hdr hdr = {
285144c99933SChuck Lever 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
285244c99933SChuck Lever 	};
285344c99933SChuck Lever 
285444c99933SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
285544c99933SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
285644c99933SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
285744c99933SChuck Lever 	encode_getfh(xdr, &hdr);
285844c99933SChuck Lever 	if (args->renew)
285944c99933SChuck Lever 		encode_renew(xdr, args->clientid, &hdr);
286044c99933SChuck Lever 	encode_nops(&hdr);
286144c99933SChuck Lever }
286244c99933SChuck Lever 
286399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
286499fe60d0SBenny Halevy /*
28657c44f1aeSWeston Andros Adamson  * BIND_CONN_TO_SESSION request
28667c44f1aeSWeston Andros Adamson  */
28677c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
28687c44f1aeSWeston Andros Adamson 				struct xdr_stream *xdr,
2869fcc85819SChristoph Hellwig 				const void *data)
28707c44f1aeSWeston Andros Adamson {
2871fcc85819SChristoph Hellwig 	const struct nfs41_bind_conn_to_session_args *args = data;
28727c44f1aeSWeston Andros Adamson 	struct compound_hdr hdr = {
287371a097c6STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
28747c44f1aeSWeston Andros Adamson 	};
28757c44f1aeSWeston Andros Adamson 
28767c44f1aeSWeston Andros Adamson 	encode_compound_hdr(xdr, req, &hdr);
287771a097c6STrond Myklebust 	encode_bind_conn_to_session(xdr, args, &hdr);
28787c44f1aeSWeston Andros Adamson 	encode_nops(&hdr);
28797c44f1aeSWeston Andros Adamson }
28807c44f1aeSWeston Andros Adamson 
28817c44f1aeSWeston Andros Adamson /*
288299fe60d0SBenny Halevy  * EXCHANGE_ID request
288399fe60d0SBenny Halevy  */
28849f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
28859f06c719SChuck Lever 				     struct xdr_stream *xdr,
2886fcc85819SChristoph Hellwig 				     const void *data)
288799fe60d0SBenny Halevy {
2888fcc85819SChristoph Hellwig 	const struct nfs41_exchange_id_args *args = data;
288999fe60d0SBenny Halevy 	struct compound_hdr hdr = {
2890a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
289199fe60d0SBenny Halevy 	};
289299fe60d0SBenny Halevy 
28939f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28949f06c719SChuck Lever 	encode_exchange_id(xdr, args, &hdr);
289599fe60d0SBenny Halevy 	encode_nops(&hdr);
289699fe60d0SBenny Halevy }
28972050f0ccSAndy Adamson 
28982050f0ccSAndy Adamson /*
2899fc931582SAndy Adamson  * a CREATE_SESSION request
2900fc931582SAndy Adamson  */
29019f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
29029f06c719SChuck Lever 					struct xdr_stream *xdr,
2903fcc85819SChristoph Hellwig 					const void *data)
2904fc931582SAndy Adamson {
2905fcc85819SChristoph Hellwig 	const struct nfs41_create_session_args *args = data;
2906fc931582SAndy Adamson 	struct compound_hdr hdr = {
2907a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
2908fc931582SAndy Adamson 	};
2909fc931582SAndy Adamson 
29109f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29119f06c719SChuck Lever 	encode_create_session(xdr, args, &hdr);
2912fc931582SAndy Adamson 	encode_nops(&hdr);
2913fc931582SAndy Adamson }
2914fc931582SAndy Adamson 
2915fc931582SAndy Adamson /*
29160f3e66c6SAndy Adamson  * a DESTROY_SESSION request
29170f3e66c6SAndy Adamson  */
29189f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
29199f06c719SChuck Lever 					 struct xdr_stream *xdr,
2920fcc85819SChristoph Hellwig 					 const void *data)
29210f3e66c6SAndy Adamson {
2922fcc85819SChristoph Hellwig 	const struct nfs4_session *session = data;
29230f3e66c6SAndy Adamson 	struct compound_hdr hdr = {
2924a4432345STrond Myklebust 		.minorversion = session->clp->cl_mvops->minor_version,
29250f3e66c6SAndy Adamson 	};
29260f3e66c6SAndy Adamson 
29279f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29289f06c719SChuck Lever 	encode_destroy_session(xdr, session, &hdr);
29290f3e66c6SAndy Adamson 	encode_nops(&hdr);
29300f3e66c6SAndy Adamson }
29310f3e66c6SAndy Adamson 
29320f3e66c6SAndy Adamson /*
293366245539STrond Myklebust  * a DESTROY_CLIENTID request
293466245539STrond Myklebust  */
293566245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
293666245539STrond Myklebust 					 struct xdr_stream *xdr,
2937fcc85819SChristoph Hellwig 					 const void *data)
293866245539STrond Myklebust {
2939fcc85819SChristoph Hellwig 	const struct nfs_client *clp = data;
294066245539STrond Myklebust 	struct compound_hdr hdr = {
294166245539STrond Myklebust 		.minorversion = clp->cl_mvops->minor_version,
294266245539STrond Myklebust 	};
294366245539STrond Myklebust 
294466245539STrond Myklebust 	encode_compound_hdr(xdr, req, &hdr);
294566245539STrond Myklebust 	encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
294666245539STrond Myklebust 	encode_nops(&hdr);
294766245539STrond Myklebust }
294866245539STrond Myklebust 
294966245539STrond Myklebust /*
2950fc01cea9SAndy Adamson  * a SEQUENCE request
2951fc01cea9SAndy Adamson  */
29529f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2953fcc85819SChristoph Hellwig 				  const void *data)
2954fc01cea9SAndy Adamson {
2955fcc85819SChristoph Hellwig 	const struct nfs4_sequence_args *args = data;
2956fc01cea9SAndy Adamson 	struct compound_hdr hdr = {
2957fc01cea9SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(args),
2958fc01cea9SAndy Adamson 	};
2959fc01cea9SAndy Adamson 
29609f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29619f06c719SChuck Lever 	encode_sequence(xdr, args, &hdr);
2962fc01cea9SAndy Adamson 	encode_nops(&hdr);
2963fc01cea9SAndy Adamson }
2964fc01cea9SAndy Adamson 
2965fc01cea9SAndy Adamson /*
29662050f0ccSAndy Adamson  * a GET_LEASE_TIME request
29672050f0ccSAndy Adamson  */
29689f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
29699f06c719SChuck Lever 					struct xdr_stream *xdr,
2970fcc85819SChristoph Hellwig 					const void *data)
29712050f0ccSAndy Adamson {
2972fcc85819SChristoph Hellwig 	const struct nfs4_get_lease_time_args *args = data;
29732050f0ccSAndy Adamson 	struct compound_hdr hdr = {
29742050f0ccSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
29752050f0ccSAndy Adamson 	};
2976dae100c2SFred Isaman 	const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
29772050f0ccSAndy Adamson 
29789f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29799f06c719SChuck Lever 	encode_sequence(xdr, &args->la_seq_args, &hdr);
29809f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
29819f06c719SChuck Lever 	encode_fsinfo(xdr, lease_bitmap, &hdr);
29822050f0ccSAndy Adamson 	encode_nops(&hdr);
29832050f0ccSAndy Adamson }
298418019753SRicardo Labiaga 
298518019753SRicardo Labiaga /*
298618019753SRicardo Labiaga  * a RECLAIM_COMPLETE request
298718019753SRicardo Labiaga  */
29889f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
29899f06c719SChuck Lever 					  struct xdr_stream *xdr,
2990fcc85819SChristoph Hellwig 					  const void *data)
299118019753SRicardo Labiaga {
2992fcc85819SChristoph Hellwig 	const struct nfs41_reclaim_complete_args *args = data;
299318019753SRicardo Labiaga 	struct compound_hdr hdr = {
299418019753SRicardo Labiaga 		.minorversion = nfs4_xdr_minorversion(&args->seq_args)
299518019753SRicardo Labiaga 	};
299618019753SRicardo Labiaga 
29979f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29989f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
29999f06c719SChuck Lever 	encode_reclaim_complete(xdr, args, &hdr);
300018019753SRicardo Labiaga 	encode_nops(&hdr);
300118019753SRicardo Labiaga }
300218019753SRicardo Labiaga 
3003b1f69b75SAndy Adamson /*
3004b1f69b75SAndy Adamson  * Encode GETDEVICEINFO request
3005b1f69b75SAndy Adamson  */
30069f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
30079f06c719SChuck Lever 				       struct xdr_stream *xdr,
3008fcc85819SChristoph Hellwig 				       const void *data)
3009b1f69b75SAndy Adamson {
3010fcc85819SChristoph Hellwig 	const struct nfs4_getdeviceinfo_args *args = data;
3011b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
3012b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3013b1f69b75SAndy Adamson 	};
3014b1f69b75SAndy Adamson 
30159f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
30169f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
30179f06c719SChuck Lever 	encode_getdeviceinfo(xdr, args, &hdr);
3018b1f69b75SAndy Adamson 
3019b1f69b75SAndy Adamson 	/* set up reply kvec. Subtract notification bitmap max size (2)
3020b1f69b75SAndy Adamson 	 * so that notification bitmap is put in xdr_buf tail */
3021b1f69b75SAndy Adamson 	xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
3022b1f69b75SAndy Adamson 			 args->pdev->pages, args->pdev->pgbase,
3023b1f69b75SAndy Adamson 			 args->pdev->pglen);
3024b1f69b75SAndy Adamson 
3025b1f69b75SAndy Adamson 	encode_nops(&hdr);
3026b1f69b75SAndy Adamson }
3027b1f69b75SAndy Adamson 
3028b1f69b75SAndy Adamson /*
3029b1f69b75SAndy Adamson  *  Encode LAYOUTGET request
3030b1f69b75SAndy Adamson  */
30319f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
30329f06c719SChuck Lever 				   struct xdr_stream *xdr,
3033fcc85819SChristoph Hellwig 				   const void *data)
3034b1f69b75SAndy Adamson {
3035fcc85819SChristoph Hellwig 	const struct nfs4_layoutget_args *args = data;
3036b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
3037b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3038b1f69b75SAndy Adamson 	};
3039b1f69b75SAndy Adamson 
30409f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
30419f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
30429f06c719SChuck Lever 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
30439f06c719SChuck Lever 	encode_layoutget(xdr, args, &hdr);
304435124a09SWeston Andros Adamson 
304535124a09SWeston Andros Adamson 	xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
304635124a09SWeston Andros Adamson 	    args->layout.pages, 0, args->layout.pglen);
304735124a09SWeston Andros Adamson 
3048b1f69b75SAndy Adamson 	encode_nops(&hdr);
3049b1f69b75SAndy Adamson }
3050863a3c6cSAndy Adamson 
3051863a3c6cSAndy Adamson /*
3052863a3c6cSAndy Adamson  *  Encode LAYOUTCOMMIT request
3053863a3c6cSAndy Adamson  */
3054cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3055863a3c6cSAndy Adamson 				      struct xdr_stream *xdr,
3056fcc85819SChristoph Hellwig 				      const void *priv)
3057863a3c6cSAndy Adamson {
3058fcc85819SChristoph Hellwig 	const struct nfs4_layoutcommit_args *args = priv;
3059ac7db726SBenny Halevy 	struct nfs4_layoutcommit_data *data =
3060ac7db726SBenny Halevy 		container_of(args, struct nfs4_layoutcommit_data, args);
3061863a3c6cSAndy Adamson 	struct compound_hdr hdr = {
3062863a3c6cSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3063863a3c6cSAndy Adamson 	};
3064863a3c6cSAndy Adamson 
3065863a3c6cSAndy Adamson 	encode_compound_hdr(xdr, req, &hdr);
3066863a3c6cSAndy Adamson 	encode_sequence(xdr, &args->seq_args, &hdr);
3067863a3c6cSAndy Adamson 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3068ac7db726SBenny Halevy 	encode_layoutcommit(xdr, data->args.inode, args, &hdr);
3069863a3c6cSAndy Adamson 	encode_getfattr(xdr, args->bitmask, &hdr);
3070863a3c6cSAndy Adamson 	encode_nops(&hdr);
3071cbe82603SBenny Halevy }
3072cbe82603SBenny Halevy 
3073cbe82603SBenny Halevy /*
3074cbe82603SBenny Halevy  * Encode LAYOUTRETURN request
3075cbe82603SBenny Halevy  */
3076cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3077cbe82603SBenny Halevy 				      struct xdr_stream *xdr,
3078fcc85819SChristoph Hellwig 				      const void *data)
3079cbe82603SBenny Halevy {
3080fcc85819SChristoph Hellwig 	const struct nfs4_layoutreturn_args *args = data;
3081cbe82603SBenny Halevy 	struct compound_hdr hdr = {
3082cbe82603SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3083cbe82603SBenny Halevy 	};
3084cbe82603SBenny Halevy 
3085cbe82603SBenny Halevy 	encode_compound_hdr(xdr, req, &hdr);
3086cbe82603SBenny Halevy 	encode_sequence(xdr, &args->seq_args, &hdr);
3087cbe82603SBenny Halevy 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3088cbe82603SBenny Halevy 	encode_layoutreturn(xdr, args, &hdr);
3089cbe82603SBenny Halevy 	encode_nops(&hdr);
3090863a3c6cSAndy Adamson }
3091fca78d6dSBryan Schumaker 
3092fca78d6dSBryan Schumaker /*
3093fca78d6dSBryan Schumaker  * Encode SECINFO_NO_NAME request
3094fca78d6dSBryan Schumaker  */
3095fcc85819SChristoph Hellwig static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3096fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
3097fcc85819SChristoph Hellwig 					const void *data)
3098fca78d6dSBryan Schumaker {
3099fcc85819SChristoph Hellwig 	const struct nfs41_secinfo_no_name_args *args = data;
3100fca78d6dSBryan Schumaker 	struct compound_hdr hdr = {
3101fca78d6dSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3102fca78d6dSBryan Schumaker 	};
3103fca78d6dSBryan Schumaker 
3104fca78d6dSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
3105fca78d6dSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
3106fca78d6dSBryan Schumaker 	encode_putrootfh(xdr, &hdr);
3107fca78d6dSBryan Schumaker 	encode_secinfo_no_name(xdr, args, &hdr);
3108fca78d6dSBryan Schumaker 	encode_nops(&hdr);
3109fca78d6dSBryan Schumaker }
31107d974794SBryan Schumaker 
31117d974794SBryan Schumaker /*
31127d974794SBryan Schumaker  *  Encode TEST_STATEID request
31137d974794SBryan Schumaker  */
31147d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
31157d974794SBryan Schumaker 				      struct xdr_stream *xdr,
3116fcc85819SChristoph Hellwig 				      const void *data)
31177d974794SBryan Schumaker {
3118fcc85819SChristoph Hellwig 	const struct nfs41_test_stateid_args *args = data;
31197d974794SBryan Schumaker 	struct compound_hdr hdr = {
31207d974794SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
31217d974794SBryan Schumaker 	};
31227d974794SBryan Schumaker 
31237d974794SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
31247d974794SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
31257d974794SBryan Schumaker 	encode_test_stateid(xdr, args, &hdr);
31267d974794SBryan Schumaker 	encode_nops(&hdr);
31277d974794SBryan Schumaker }
31289aeda35fSBryan Schumaker 
31299aeda35fSBryan Schumaker /*
31309aeda35fSBryan Schumaker  *  Encode FREE_STATEID request
31319aeda35fSBryan Schumaker  */
31329aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
31339aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
3134fcc85819SChristoph Hellwig 				     const void *data)
31359aeda35fSBryan Schumaker {
3136fcc85819SChristoph Hellwig 	const struct nfs41_free_stateid_args *args = data;
31379aeda35fSBryan Schumaker 	struct compound_hdr hdr = {
31389aeda35fSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
31399aeda35fSBryan Schumaker 	};
31409aeda35fSBryan Schumaker 
31419aeda35fSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
31429aeda35fSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
31439aeda35fSBryan Schumaker 	encode_free_stateid(xdr, args, &hdr);
31449aeda35fSBryan Schumaker 	encode_nops(&hdr);
31459aeda35fSBryan Schumaker }
314699fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
314799fe60d0SBenny Halevy 
3148683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
31491da177e4SLinus Torvalds {
31506da59ce2STrond Myklebust 	ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
31516da59ce2STrond Myklebust 			NFS4_OPAQUE_LIMIT);
3152eb72f484SChuck Lever 	if (unlikely(ret < 0))
3153c0eae66eSBenny Halevy 		return -EIO;
31546da59ce2STrond Myklebust 	*len = ret;
31556da59ce2STrond Myklebust 	return 0;
31566da59ce2STrond Myklebust }
31571da177e4SLinus Torvalds 
31581da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
31591da177e4SLinus Torvalds {
31608687b63aSAl Viro 	__be32 *p;
31611da177e4SLinus Torvalds 
3162c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3163c0eae66eSBenny Halevy 	if (unlikely(!p))
3164eb72f484SChuck Lever 		return -EIO;
31656f723f77SBenny Halevy 	hdr->status = be32_to_cpup(p++);
3166cccddf4fSBenny Halevy 	hdr->taglen = be32_to_cpup(p);
31671da177e4SLinus Torvalds 
3168c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, hdr->taglen + 4);
3169c0eae66eSBenny Halevy 	if (unlikely(!p))
3170eb72f484SChuck Lever 		return -EIO;
31711da177e4SLinus Torvalds 	hdr->tag = (char *)p;
31721da177e4SLinus Torvalds 	p += XDR_QUADLEN(hdr->taglen);
3173cccddf4fSBenny Halevy 	hdr->nops = be32_to_cpup(p);
3174aadf6152SBenny Halevy 	if (unlikely(hdr->nops < 1))
3175aadf6152SBenny Halevy 		return nfs4_stat_to_errno(hdr->status);
31761da177e4SLinus Torvalds 	return 0;
31771da177e4SLinus Torvalds }
31781da177e4SLinus Torvalds 
3179c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3180c7848f69STrond Myklebust 		int *nfs_retval)
31811da177e4SLinus Torvalds {
31828687b63aSAl Viro 	__be32 *p;
31831da177e4SLinus Torvalds 	uint32_t opnum;
31841da177e4SLinus Torvalds 	int32_t nfserr;
31851da177e4SLinus Torvalds 
3186c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3187c0eae66eSBenny Halevy 	if (unlikely(!p))
3188c0eae66eSBenny Halevy 		goto out_overflow;
31896f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
3190c7848f69STrond Myklebust 	if (unlikely(opnum != expected))
3191c7848f69STrond Myklebust 		goto out_bad_operation;
3192f23f6584SChuck Lever 	if (unlikely(*p != cpu_to_be32(NFS_OK)))
3193f23f6584SChuck Lever 		goto out_status;
3194c7848f69STrond Myklebust 	*nfs_retval = 0;
3195f23f6584SChuck Lever 	return true;
3196f23f6584SChuck Lever out_status:
3197f23f6584SChuck Lever 	nfserr = be32_to_cpup(p);
3198f23f6584SChuck Lever 	trace_nfs4_xdr_status(opnum, nfserr);
3199c7848f69STrond Myklebust 	*nfs_retval = nfs4_stat_to_errno(nfserr);
3200c7848f69STrond Myklebust 	return true;
3201c7848f69STrond Myklebust out_bad_operation:
3202fe82a183SChuck Lever 	dprintk("nfs: Server returned operation"
32031da177e4SLinus Torvalds 		" %d but we issued a request for %d\n",
32041da177e4SLinus Torvalds 			opnum, expected);
3205c7848f69STrond Myklebust 	*nfs_retval = -EREMOTEIO;
3206c7848f69STrond Myklebust 	return false;
3207c0eae66eSBenny Halevy out_overflow:
3208c7848f69STrond Myklebust 	*nfs_retval = -EIO;
3209c7848f69STrond Myklebust 	return false;
3210c7848f69STrond Myklebust }
3211c7848f69STrond Myklebust 
3212c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3213c7848f69STrond Myklebust {
3214c7848f69STrond Myklebust 	int retval;
3215c7848f69STrond Myklebust 
3216c7848f69STrond Myklebust 	__decode_op_hdr(xdr, expected, &retval);
3217c7848f69STrond Myklebust 	return retval;
32181da177e4SLinus Torvalds }
32191da177e4SLinus Torvalds 
32201da177e4SLinus Torvalds /* Dummy routine */
32211bbe60ffSTrond Myklebust static int decode_ace(struct xdr_stream *xdr, void *ace)
32221da177e4SLinus Torvalds {
32238687b63aSAl Viro 	__be32 *p;
3224683b57b4STrond Myklebust 	unsigned int strlen;
32251da177e4SLinus Torvalds 	char *str;
32261da177e4SLinus Torvalds 
3227c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
3228eb72f484SChuck Lever 	if (unlikely(!p))
3229c0eae66eSBenny Halevy 		return -EIO;
3230eb72f484SChuck Lever 	return decode_opaque_inline(xdr, &strlen, &str);
32311da177e4SLinus Torvalds }
32321da177e4SLinus Torvalds 
323337c88763STrond Myklebust static ssize_t
323437c88763STrond Myklebust decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
32351da177e4SLinus Torvalds {
323637c88763STrond Myklebust 	ssize_t ret;
32371da177e4SLinus Torvalds 
323837c88763STrond Myklebust 	ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
323937c88763STrond Myklebust 	if (likely(ret >= 0))
324037c88763STrond Myklebust 		return ret;
3241eb72f484SChuck Lever 	if (ret != -EMSGSIZE)
3242c0eae66eSBenny Halevy 		return -EIO;
3243eb72f484SChuck Lever 	return sz;
32441da177e4SLinus Torvalds }
32451da177e4SLinus Torvalds 
324637c88763STrond Myklebust static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
324737c88763STrond Myklebust {
324837c88763STrond Myklebust 	ssize_t ret;
324937c88763STrond Myklebust 	ret = decode_bitmap4(xdr, bitmap, 3);
325037c88763STrond Myklebust 	return ret < 0 ? ret : 0;
325137c88763STrond Myklebust }
325237c88763STrond Myklebust 
3253256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
32541da177e4SLinus Torvalds {
32558687b63aSAl Viro 	__be32 *p;
32561da177e4SLinus Torvalds 
3257c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3258c0eae66eSBenny Halevy 	if (unlikely(!p))
3259eb72f484SChuck Lever 		return -EIO;
3260cccddf4fSBenny Halevy 	*attrlen = be32_to_cpup(p);
3261256e48bbSTrond Myklebust 	*savep = xdr_stream_pos(xdr);
32621da177e4SLinus Torvalds 	return 0;
32631da177e4SLinus Torvalds }
32641da177e4SLinus Torvalds 
32651da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
32661da177e4SLinus Torvalds {
32671da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
32683388bff5SRoman Borisov 		int ret;
32693388bff5SRoman Borisov 		ret = decode_attr_bitmap(xdr, bitmask);
32703388bff5SRoman Borisov 		if (unlikely(ret < 0))
32713388bff5SRoman Borisov 			return ret;
32721da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
32731da177e4SLinus Torvalds 	} else
3274dae100c2SFred Isaman 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
3275dae100c2SFred Isaman 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3276dae100c2SFred Isaman 		bitmask[0], bitmask[1], bitmask[2]);
32771da177e4SLinus Torvalds 	return 0;
32781da177e4SLinus Torvalds }
32791da177e4SLinus Torvalds 
32801da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
32811da177e4SLinus Torvalds {
32828687b63aSAl Viro 	__be32 *p;
3283409924e4STrond Myklebust 	int ret = 0;
32841da177e4SLinus Torvalds 
32851da177e4SLinus Torvalds 	*type = 0;
32861da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
32871da177e4SLinus Torvalds 		return -EIO;
32881da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3289c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3290c0eae66eSBenny Halevy 		if (unlikely(!p))
3291eb72f484SChuck Lever 			return -EIO;
3292cccddf4fSBenny Halevy 		*type = be32_to_cpup(p);
32931da177e4SLinus Torvalds 		if (*type < NF4REG || *type > NF4NAMEDATTR) {
32943110ff80SHarvey Harrison 			dprintk("%s: bad type %d\n", __func__, *type);
32951da177e4SLinus Torvalds 			return -EIO;
32961da177e4SLinus Torvalds 		}
32971da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_TYPE;
3298409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_TYPE;
32991da177e4SLinus Torvalds 	}
3300bca79478STrond Myklebust 	dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3301409924e4STrond Myklebust 	return ret;
33021da177e4SLinus Torvalds }
33031da177e4SLinus Torvalds 
3304264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3305264e6351SChuck Lever 				      uint32_t *bitmap, uint32_t *type)
3306264e6351SChuck Lever {
3307264e6351SChuck Lever 	__be32 *p;
3308264e6351SChuck Lever 
3309264e6351SChuck Lever 	*type = 0;
3310264e6351SChuck Lever 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3311264e6351SChuck Lever 		return -EIO;
3312264e6351SChuck Lever 	if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3313264e6351SChuck Lever 		p = xdr_inline_decode(xdr, 4);
3314264e6351SChuck Lever 		if (unlikely(!p))
3315eb72f484SChuck Lever 			return -EIO;
3316264e6351SChuck Lever 		*type = be32_to_cpup(p);
3317264e6351SChuck Lever 		bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3318264e6351SChuck Lever 	}
3319264e6351SChuck Lever 	dprintk("%s: expire type=0x%x\n", __func__, *type);
3320264e6351SChuck Lever 	return 0;
3321264e6351SChuck Lever }
3322264e6351SChuck Lever 
33231da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
33241da177e4SLinus Torvalds {
33258687b63aSAl Viro 	__be32 *p;
3326409924e4STrond Myklebust 	int ret = 0;
33271da177e4SLinus Torvalds 
33281da177e4SLinus Torvalds 	*change = 0;
33291da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
33301da177e4SLinus Torvalds 		return -EIO;
33311da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3332c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3333c0eae66eSBenny Halevy 		if (unlikely(!p))
3334eb72f484SChuck Lever 			return -EIO;
3335cccddf4fSBenny Halevy 		xdr_decode_hyper(p, change);
33361da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3337409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_CHANGE;
33381da177e4SLinus Torvalds 	}
33393110ff80SHarvey Harrison 	dprintk("%s: change attribute=%Lu\n", __func__,
33401da177e4SLinus Torvalds 			(unsigned long long)*change);
3341409924e4STrond Myklebust 	return ret;
33421da177e4SLinus Torvalds }
33431da177e4SLinus Torvalds 
33441da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
33451da177e4SLinus Torvalds {
33468687b63aSAl Viro 	__be32 *p;
3347409924e4STrond Myklebust 	int ret = 0;
33481da177e4SLinus Torvalds 
33491da177e4SLinus Torvalds 	*size = 0;
33501da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
33511da177e4SLinus Torvalds 		return -EIO;
33521da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3353c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3354c0eae66eSBenny Halevy 		if (unlikely(!p))
3355eb72f484SChuck Lever 			return -EIO;
3356cccddf4fSBenny Halevy 		xdr_decode_hyper(p, size);
33571da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SIZE;
3358409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SIZE;
33591da177e4SLinus Torvalds 	}
33603110ff80SHarvey Harrison 	dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3361409924e4STrond Myklebust 	return ret;
33621da177e4SLinus Torvalds }
33631da177e4SLinus Torvalds 
33641da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33651da177e4SLinus Torvalds {
33668687b63aSAl Viro 	__be32 *p;
33671da177e4SLinus Torvalds 
33681da177e4SLinus Torvalds 	*res = 0;
33691da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
33701da177e4SLinus Torvalds 		return -EIO;
33711da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3372c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3373c0eae66eSBenny Halevy 		if (unlikely(!p))
3374eb72f484SChuck Lever 			return -EIO;
3375cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33761da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
33771da177e4SLinus Torvalds 	}
33783110ff80SHarvey Harrison 	dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
33791da177e4SLinus Torvalds 	return 0;
33801da177e4SLinus Torvalds }
33811da177e4SLinus Torvalds 
33821da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33831da177e4SLinus Torvalds {
33848687b63aSAl Viro 	__be32 *p;
33851da177e4SLinus Torvalds 
33861da177e4SLinus Torvalds 	*res = 0;
33871da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
33881da177e4SLinus Torvalds 		return -EIO;
33891da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3390c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3391c0eae66eSBenny Halevy 		if (unlikely(!p))
3392eb72f484SChuck Lever 			return -EIO;
3393cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33941da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
33951da177e4SLinus Torvalds 	}
33963110ff80SHarvey Harrison 	dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
33971da177e4SLinus Torvalds 	return 0;
33981da177e4SLinus Torvalds }
33991da177e4SLinus Torvalds 
34008b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
34011da177e4SLinus Torvalds {
34028687b63aSAl Viro 	__be32 *p;
3403409924e4STrond Myklebust 	int ret = 0;
34041da177e4SLinus Torvalds 
34051da177e4SLinus Torvalds 	fsid->major = 0;
34061da177e4SLinus Torvalds 	fsid->minor = 0;
34071da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
34081da177e4SLinus Torvalds 		return -EIO;
34091da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3410c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 16);
3411c0eae66eSBenny Halevy 		if (unlikely(!p))
3412eb72f484SChuck Lever 			return -EIO;
34133ceb4dbbSBenny Halevy 		p = xdr_decode_hyper(p, &fsid->major);
3414cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &fsid->minor);
34151da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FSID;
3416409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FSID;
34171da177e4SLinus Torvalds 	}
34183110ff80SHarvey Harrison 	dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
34191da177e4SLinus Torvalds 			(unsigned long long)fsid->major,
34201da177e4SLinus Torvalds 			(unsigned long long)fsid->minor);
3421409924e4STrond Myklebust 	return ret;
34221da177e4SLinus Torvalds }
34231da177e4SLinus Torvalds 
34241da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
34251da177e4SLinus Torvalds {
34268687b63aSAl Viro 	__be32 *p;
34271da177e4SLinus Torvalds 
34281da177e4SLinus Torvalds 	*res = 60;
34291da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
34301da177e4SLinus Torvalds 		return -EIO;
34311da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3432c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3433c0eae66eSBenny Halevy 		if (unlikely(!p))
3434eb72f484SChuck Lever 			return -EIO;
3435cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
34361da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
34371da177e4SLinus Torvalds 	}
34383110ff80SHarvey Harrison 	dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
34391da177e4SLinus Torvalds 	return 0;
34401da177e4SLinus Torvalds }
34411da177e4SLinus Torvalds 
3442ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3443ae42c70aSBryan Schumaker {
3444ae42c70aSBryan Schumaker 	__be32 *p;
3445ae42c70aSBryan Schumaker 
3446ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3447ae42c70aSBryan Schumaker 		return -EIO;
3448ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3449ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3450ae42c70aSBryan Schumaker 		if (unlikely(!p))
3451eb72f484SChuck Lever 			return -EIO;
3452ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3453ee7b75fcSTrond Myklebust 		*res = -be32_to_cpup(p);
3454ae42c70aSBryan Schumaker 	}
3455ae42c70aSBryan Schumaker 	return 0;
3456ae42c70aSBryan Schumaker }
3457ae42c70aSBryan Schumaker 
34588c61282fSKinglong Mee static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
34598c61282fSKinglong Mee 				 uint32_t *bitmap, uint32_t *bitmask)
34608c61282fSKinglong Mee {
34618c61282fSKinglong Mee 	if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
34628c61282fSKinglong Mee 		int ret;
34638c61282fSKinglong Mee 		ret = decode_attr_bitmap(xdr, bitmask);
34648c61282fSKinglong Mee 		if (unlikely(ret < 0))
34658c61282fSKinglong Mee 			return ret;
34668c61282fSKinglong Mee 		bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
34678c61282fSKinglong Mee 	} else
34688c61282fSKinglong Mee 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
34698c61282fSKinglong Mee 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
34708c61282fSKinglong Mee 		bitmask[0], bitmask[1], bitmask[2]);
34718c61282fSKinglong Mee 	return 0;
34728c61282fSKinglong Mee }
34738c61282fSKinglong Mee 
3474ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3475ae42c70aSBryan Schumaker {
3476ae42c70aSBryan Schumaker 	__be32 *p;
347786bbd742SFrank Sorenson 	u32 len;
3478ae42c70aSBryan Schumaker 
34797ad07353STrond Myklebust 	if (fh != NULL)
3480ae42c70aSBryan Schumaker 		memset(fh, 0, sizeof(*fh));
3481ae42c70aSBryan Schumaker 
3482ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3483ae42c70aSBryan Schumaker 		return -EIO;
3484ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3485ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3486ae42c70aSBryan Schumaker 		if (unlikely(!p))
3487eb72f484SChuck Lever 			return -EIO;
3488ae42c70aSBryan Schumaker 		len = be32_to_cpup(p);
3489ae42c70aSBryan Schumaker 		if (len > NFS4_FHSIZE)
3490ae42c70aSBryan Schumaker 			return -EIO;
3491ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, len);
3492ae42c70aSBryan Schumaker 		if (unlikely(!p))
3493eb72f484SChuck Lever 			return -EIO;
34947ad07353STrond Myklebust 		if (fh != NULL) {
3495ae42c70aSBryan Schumaker 			memcpy(fh->data, p, len);
34967ad07353STrond Myklebust 			fh->size = len;
34977ad07353STrond Myklebust 		}
3498ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3499ae42c70aSBryan Schumaker 	}
3500ae42c70aSBryan Schumaker 	return 0;
3501ae42c70aSBryan Schumaker }
3502ae42c70aSBryan Schumaker 
35031da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
35041da177e4SLinus Torvalds {
35058687b63aSAl Viro 	__be32 *p;
35061da177e4SLinus Torvalds 
3507a1800acaSMalahal Naineni 	*res = 0;
35081da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
35091da177e4SLinus Torvalds 		return -EIO;
35101da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3511c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3512c0eae66eSBenny Halevy 		if (unlikely(!p))
3513eb72f484SChuck Lever 			return -EIO;
3514cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
35151da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
35161da177e4SLinus Torvalds 	}
35173110ff80SHarvey Harrison 	dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
35181da177e4SLinus Torvalds 	return 0;
35191da177e4SLinus Torvalds }
35201da177e4SLinus Torvalds 
35211da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
35221da177e4SLinus Torvalds {
35238687b63aSAl Viro 	__be32 *p;
3524409924e4STrond Myklebust 	int ret = 0;
35251da177e4SLinus Torvalds 
35261da177e4SLinus Torvalds 	*fileid = 0;
35271da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
35281da177e4SLinus Torvalds 		return -EIO;
35291da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3530c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3531c0eae66eSBenny Halevy 		if (unlikely(!p))
3532eb72f484SChuck Lever 			return -EIO;
3533cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
35341da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILEID;
3535409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FILEID;
35361da177e4SLinus Torvalds 	}
35373110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3538409924e4STrond Myklebust 	return ret;
35391da177e4SLinus Torvalds }
35401da177e4SLinus Torvalds 
354199baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
354299baf625SManoj Naik {
35438687b63aSAl Viro 	__be32 *p;
3544409924e4STrond Myklebust 	int ret = 0;
354599baf625SManoj Naik 
354699baf625SManoj Naik 	*fileid = 0;
354799baf625SManoj Naik 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
354899baf625SManoj Naik 		return -EIO;
354999baf625SManoj Naik 	if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3550c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3551c0eae66eSBenny Halevy 		if (unlikely(!p))
3552eb72f484SChuck Lever 			return -EIO;
3553cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
355499baf625SManoj Naik 		bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
355528331a46STrond Myklebust 		ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
355699baf625SManoj Naik 	}
35573110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3558409924e4STrond Myklebust 	return ret;
355999baf625SManoj Naik }
356099baf625SManoj Naik 
35611da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35621da177e4SLinus Torvalds {
35638687b63aSAl Viro 	__be32 *p;
35641da177e4SLinus Torvalds 	int status = 0;
35651da177e4SLinus Torvalds 
35661da177e4SLinus Torvalds 	*res = 0;
35671da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
35681da177e4SLinus Torvalds 		return -EIO;
35691da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3570c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3571c0eae66eSBenny Halevy 		if (unlikely(!p))
3572eb72f484SChuck Lever 			return -EIO;
3573cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35741da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
35751da177e4SLinus Torvalds 	}
35763110ff80SHarvey Harrison 	dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
35771da177e4SLinus Torvalds 	return status;
35781da177e4SLinus Torvalds }
35791da177e4SLinus Torvalds 
35801da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35811da177e4SLinus Torvalds {
35828687b63aSAl Viro 	__be32 *p;
35831da177e4SLinus Torvalds 	int status = 0;
35841da177e4SLinus Torvalds 
35851da177e4SLinus Torvalds 	*res = 0;
35861da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
35871da177e4SLinus Torvalds 		return -EIO;
35881da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3589c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3590c0eae66eSBenny Halevy 		if (unlikely(!p))
3591eb72f484SChuck Lever 			return -EIO;
3592cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35931da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
35941da177e4SLinus Torvalds 	}
35953110ff80SHarvey Harrison 	dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
35961da177e4SLinus Torvalds 	return status;
35971da177e4SLinus Torvalds }
35981da177e4SLinus Torvalds 
35991da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
36001da177e4SLinus Torvalds {
36018687b63aSAl Viro 	__be32 *p;
36021da177e4SLinus Torvalds 	int status = 0;
36031da177e4SLinus Torvalds 
36041da177e4SLinus Torvalds 	*res = 0;
36051da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
36061da177e4SLinus Torvalds 		return -EIO;
36071da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3608c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3609c0eae66eSBenny Halevy 		if (unlikely(!p))
3610eb72f484SChuck Lever 			return -EIO;
3611cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
36121da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
36131da177e4SLinus Torvalds 	}
36143110ff80SHarvey Harrison 	dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
36151da177e4SLinus Torvalds 	return status;
36161da177e4SLinus Torvalds }
36171da177e4SLinus Torvalds 
36187aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
36197aaa0b3bSManoj Naik {
3620464ad6b1SChuck Lever 	u32 n;
36218687b63aSAl Viro 	__be32 *p;
36227aaa0b3bSManoj Naik 	int status = 0;
36237aaa0b3bSManoj Naik 
3624c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3625c0eae66eSBenny Halevy 	if (unlikely(!p))
3626eb72f484SChuck Lever 		return -EIO;
3627cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
362833a43f28SAndy Adamson 	if (n == 0)
362933a43f28SAndy Adamson 		goto root_path;
363002a2976cSChuck Lever 	dprintk("pathname4: ");
3631809b426cSTrond Myklebust 	if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3632809b426cSTrond Myklebust 		dprintk("cannot parse %d components in path\n", n);
3633809b426cSTrond Myklebust 		goto out_eio;
3634809b426cSTrond Myklebust 	}
3635809b426cSTrond Myklebust 	for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
36367aaa0b3bSManoj Naik 		struct nfs4_string *component = &path->components[path->ncomponents];
36377aaa0b3bSManoj Naik 		status = decode_opaque_inline(xdr, &component->len, &component->data);
36387aaa0b3bSManoj Naik 		if (unlikely(status != 0))
36397aaa0b3bSManoj Naik 			goto out_eio;
364095a13f7bSTrond Myklebust 		ifdebug (XDR)
364102a2976cSChuck Lever 			pr_cont("%s%.*s ",
364202a2976cSChuck Lever 				(path->ncomponents != n ? "/ " : ""),
364302a2976cSChuck Lever 				component->len, component->data);
36447aaa0b3bSManoj Naik 	}
36457aaa0b3bSManoj Naik out:
36467aaa0b3bSManoj Naik 	return status;
364733a43f28SAndy Adamson root_path:
364833a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */
364933a43f28SAndy Adamson 	path->ncomponents = 1;
365033a43f28SAndy Adamson 	path->components[0].len=0;
365133a43f28SAndy Adamson 	path->components[0].data=NULL;
365202a2976cSChuck Lever 	dprintk("pathname4: /\n");
365333a43f28SAndy Adamson 	goto out;
36547aaa0b3bSManoj Naik out_eio:
36557aaa0b3bSManoj Naik 	dprintk(" status %d", status);
36567aaa0b3bSManoj Naik 	status = -EIO;
36577aaa0b3bSManoj Naik 	goto out;
36587aaa0b3bSManoj Naik }
36597aaa0b3bSManoj Naik 
36607aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3661683b57b4STrond Myklebust {
3662683b57b4STrond Myklebust 	int n;
36638687b63aSAl Viro 	__be32 *p;
3664683b57b4STrond Myklebust 	int status = -EIO;
3665683b57b4STrond Myklebust 
3666683b57b4STrond Myklebust 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3667683b57b4STrond Myklebust 		goto out;
3668683b57b4STrond Myklebust 	status = 0;
3669683b57b4STrond Myklebust 	if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3670683b57b4STrond Myklebust 		goto out;
3671f54423a1SKinglong Mee 	bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
36728b7e3f49STrond Myklebust 	status = -EIO;
36738b7e3f49STrond Myklebust 	/* Ignore borken servers that return unrequested attrs */
36748b7e3f49STrond Myklebust 	if (unlikely(res == NULL))
36758b7e3f49STrond Myklebust 		goto out;
367602a2976cSChuck Lever 	dprintk("%s: fsroot:\n", __func__);
36777aaa0b3bSManoj Naik 	status = decode_pathname(xdr, &res->fs_path);
3678683b57b4STrond Myklebust 	if (unlikely(status != 0))
3679683b57b4STrond Myklebust 		goto out;
3680c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3681c0eae66eSBenny Halevy 	if (unlikely(!p))
3682eb72f484SChuck Lever 		goto out_eio;
3683cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
3684683b57b4STrond Myklebust 	if (n <= 0)
3685683b57b4STrond Myklebust 		goto out_eio;
3686809b426cSTrond Myklebust 	for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3687464ad6b1SChuck Lever 		u32 m;
3688809b426cSTrond Myklebust 		struct nfs4_fs_location *loc;
3689683b57b4STrond Myklebust 
3690809b426cSTrond Myklebust 		if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3691809b426cSTrond Myklebust 			break;
3692809b426cSTrond Myklebust 		loc = &res->locations[res->nlocations];
3693c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3694c0eae66eSBenny Halevy 		if (unlikely(!p))
3695eb72f484SChuck Lever 			goto out_eio;
3696cccddf4fSBenny Halevy 		m = be32_to_cpup(p);
36977aaa0b3bSManoj Naik 
369802a2976cSChuck Lever 		dprintk("%s: servers:\n", __func__);
3699809b426cSTrond Myklebust 		for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3700809b426cSTrond Myklebust 			struct nfs4_string *server;
3701809b426cSTrond Myklebust 
3702809b426cSTrond Myklebust 			if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3703464ad6b1SChuck Lever 				unsigned int i;
3704464ad6b1SChuck Lever 				dprintk("%s: using first %u of %u servers "
3705464ad6b1SChuck Lever 					"returned for location %u\n",
37063110ff80SHarvey Harrison 						__func__,
3707464ad6b1SChuck Lever 						NFS4_FS_LOCATION_MAXSERVERS,
3708464ad6b1SChuck Lever 						m, res->nlocations);
37097aaa0b3bSManoj Naik 				for (i = loc->nservers; i < m; i++) {
37102e42c3e2STrond Myklebust 					unsigned int len;
37117aaa0b3bSManoj Naik 					char *data;
37127aaa0b3bSManoj Naik 					status = decode_opaque_inline(xdr, &len, &data);
3713683b57b4STrond Myklebust 					if (unlikely(status != 0))
3714683b57b4STrond Myklebust 						goto out_eio;
37157aaa0b3bSManoj Naik 				}
3716809b426cSTrond Myklebust 				break;
37177aaa0b3bSManoj Naik 			}
3718809b426cSTrond Myklebust 			server = &loc->servers[loc->nservers];
3719809b426cSTrond Myklebust 			status = decode_opaque_inline(xdr, &server->len, &server->data);
3720809b426cSTrond Myklebust 			if (unlikely(status != 0))
3721809b426cSTrond Myklebust 				goto out_eio;
3722809b426cSTrond Myklebust 			dprintk("%s ", server->data);
37237aaa0b3bSManoj Naik 		}
37247aaa0b3bSManoj Naik 		status = decode_pathname(xdr, &loc->rootpath);
37257aaa0b3bSManoj Naik 		if (unlikely(status != 0))
37267aaa0b3bSManoj Naik 			goto out_eio;
3727683b57b4STrond Myklebust 	}
3728409924e4STrond Myklebust 	if (res->nlocations != 0)
372981934ddbSChuck Lever 		status = NFS_ATTR_FATTR_V4_LOCATIONS;
3730683b57b4STrond Myklebust out:
37313110ff80SHarvey Harrison 	dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3732683b57b4STrond Myklebust 	return status;
3733683b57b4STrond Myklebust out_eio:
3734683b57b4STrond Myklebust 	status = -EIO;
3735683b57b4STrond Myklebust 	goto out;
3736683b57b4STrond Myklebust }
3737683b57b4STrond Myklebust 
37381da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
37391da177e4SLinus Torvalds {
37408687b63aSAl Viro 	__be32 *p;
37411da177e4SLinus Torvalds 	int status = 0;
37421da177e4SLinus Torvalds 
37431da177e4SLinus Torvalds 	*res = 0;
37441da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
37451da177e4SLinus Torvalds 		return -EIO;
37461da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3747c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3748c0eae66eSBenny Halevy 		if (unlikely(!p))
3749eb72f484SChuck Lever 			return -EIO;
3750cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
37511da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
37521da177e4SLinus Torvalds 	}
37533110ff80SHarvey Harrison 	dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
37541da177e4SLinus Torvalds 	return status;
37551da177e4SLinus Torvalds }
37561da177e4SLinus Torvalds 
37571da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
37581da177e4SLinus Torvalds {
37598687b63aSAl Viro 	__be32 *p;
37601da177e4SLinus Torvalds 	int status = 0;
37611da177e4SLinus Torvalds 
37621da177e4SLinus Torvalds 	*maxlink = 1;
37631da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
37641da177e4SLinus Torvalds 		return -EIO;
37651da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3766c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3767c0eae66eSBenny Halevy 		if (unlikely(!p))
3768eb72f484SChuck Lever 			return -EIO;
3769cccddf4fSBenny Halevy 		*maxlink = be32_to_cpup(p);
37701da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
37711da177e4SLinus Torvalds 	}
37723110ff80SHarvey Harrison 	dprintk("%s: maxlink=%u\n", __func__, *maxlink);
37731da177e4SLinus Torvalds 	return status;
37741da177e4SLinus Torvalds }
37751da177e4SLinus Torvalds 
37761da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
37771da177e4SLinus Torvalds {
37788687b63aSAl Viro 	__be32 *p;
37791da177e4SLinus Torvalds 	int status = 0;
37801da177e4SLinus Torvalds 
37811da177e4SLinus Torvalds 	*maxname = 1024;
37821da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
37831da177e4SLinus Torvalds 		return -EIO;
37841da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3785c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3786c0eae66eSBenny Halevy 		if (unlikely(!p))
3787eb72f484SChuck Lever 			return -EIO;
3788cccddf4fSBenny Halevy 		*maxname = be32_to_cpup(p);
37891da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
37901da177e4SLinus Torvalds 	}
37913110ff80SHarvey Harrison 	dprintk("%s: maxname=%u\n", __func__, *maxname);
37921da177e4SLinus Torvalds 	return status;
37931da177e4SLinus Torvalds }
37941da177e4SLinus Torvalds 
37951da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
37961da177e4SLinus Torvalds {
37978687b63aSAl Viro 	__be32 *p;
37981da177e4SLinus Torvalds 	int status = 0;
37991da177e4SLinus Torvalds 
38001da177e4SLinus Torvalds 	*res = 1024;
38011da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
38021da177e4SLinus Torvalds 		return -EIO;
38031da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
38041da177e4SLinus Torvalds 		uint64_t maxread;
3805c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3806c0eae66eSBenny Halevy 		if (unlikely(!p))
3807eb72f484SChuck Lever 			return -EIO;
3808cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxread);
38091da177e4SLinus Torvalds 		if (maxread > 0x7FFFFFFF)
38101da177e4SLinus Torvalds 			maxread = 0x7FFFFFFF;
38111da177e4SLinus Torvalds 		*res = (uint32_t)maxread;
38121da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
38131da177e4SLinus Torvalds 	}
38143110ff80SHarvey Harrison 	dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
38151da177e4SLinus Torvalds 	return status;
38161da177e4SLinus Torvalds }
38171da177e4SLinus Torvalds 
38181da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
38191da177e4SLinus Torvalds {
38208687b63aSAl Viro 	__be32 *p;
38211da177e4SLinus Torvalds 	int status = 0;
38221da177e4SLinus Torvalds 
38231da177e4SLinus Torvalds 	*res = 1024;
38241da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
38251da177e4SLinus Torvalds 		return -EIO;
38261da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
38271da177e4SLinus Torvalds 		uint64_t maxwrite;
3828c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3829c0eae66eSBenny Halevy 		if (unlikely(!p))
3830eb72f484SChuck Lever 			return -EIO;
3831cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxwrite);
38321da177e4SLinus Torvalds 		if (maxwrite > 0x7FFFFFFF)
38331da177e4SLinus Torvalds 			maxwrite = 0x7FFFFFFF;
38341da177e4SLinus Torvalds 		*res = (uint32_t)maxwrite;
38351da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
38361da177e4SLinus Torvalds 	}
38373110ff80SHarvey Harrison 	dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
38381da177e4SLinus Torvalds 	return status;
38391da177e4SLinus Torvalds }
38401da177e4SLinus Torvalds 
3841bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
38421da177e4SLinus Torvalds {
3843bca79478STrond Myklebust 	uint32_t tmp;
38448687b63aSAl Viro 	__be32 *p;
3845409924e4STrond Myklebust 	int ret = 0;
38461da177e4SLinus Torvalds 
38471da177e4SLinus Torvalds 	*mode = 0;
38481da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
38491da177e4SLinus Torvalds 		return -EIO;
38501da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3851c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3852c0eae66eSBenny Halevy 		if (unlikely(!p))
3853eb72f484SChuck Lever 			return -EIO;
3854cccddf4fSBenny Halevy 		tmp = be32_to_cpup(p);
3855bca79478STrond Myklebust 		*mode = tmp & ~S_IFMT;
38561da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_MODE;
3857409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_MODE;
38581da177e4SLinus Torvalds 	}
38593110ff80SHarvey Harrison 	dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3860409924e4STrond Myklebust 	return ret;
38611da177e4SLinus Torvalds }
38621da177e4SLinus Torvalds 
38631da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
38641da177e4SLinus Torvalds {
38658687b63aSAl Viro 	__be32 *p;
3866409924e4STrond Myklebust 	int ret = 0;
38671da177e4SLinus Torvalds 
38681da177e4SLinus Torvalds 	*nlink = 1;
38691da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
38701da177e4SLinus Torvalds 		return -EIO;
38711da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3872c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3873c0eae66eSBenny Halevy 		if (unlikely(!p))
3874eb72f484SChuck Lever 			return -EIO;
3875cccddf4fSBenny Halevy 		*nlink = be32_to_cpup(p);
38761da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3877409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_NLINK;
38781da177e4SLinus Torvalds 	}
38793110ff80SHarvey Harrison 	dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3880409924e4STrond Myklebust 	return ret;
38811da177e4SLinus Torvalds }
38821da177e4SLinus Torvalds 
3883686a816aSTrond Myklebust static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3884686a816aSTrond Myklebust 		struct nfs4_string *name, gfp_t gfp_flags)
3885686a816aSTrond Myklebust {
3886686a816aSTrond Myklebust 	ssize_t ret;
3887686a816aSTrond Myklebust 
3888686a816aSTrond Myklebust 	ret = xdr_stream_decode_string_dup(xdr, &name->data,
3889686a816aSTrond Myklebust 			XDR_MAX_NETOBJ, gfp_flags);
3890686a816aSTrond Myklebust 	name->len = 0;
3891686a816aSTrond Myklebust 	if (ret > 0)
3892686a816aSTrond Myklebust 		name->len = ret;
3893686a816aSTrond Myklebust 	return ret;
3894686a816aSTrond Myklebust }
3895686a816aSTrond Myklebust 
389680e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3897e5782076SEric W. Biederman 		const struct nfs_server *server, kuid_t *uid,
38986926afd1STrond Myklebust 		struct nfs4_string *owner_name)
38991da177e4SLinus Torvalds {
3900686a816aSTrond Myklebust 	ssize_t len;
3901686a816aSTrond Myklebust 	char *p;
39021da177e4SLinus Torvalds 
3903e5782076SEric W. Biederman 	*uid = make_kuid(&init_user_ns, -2);
39041da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
39051da177e4SLinus Torvalds 		return -EIO;
3906686a816aSTrond Myklebust 	if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3907686a816aSTrond Myklebust 		return 0;
39081da177e4SLinus Torvalds 	bitmap[1] &= ~FATTR4_WORD1_OWNER;
3909686a816aSTrond Myklebust 
3910686a816aSTrond Myklebust 	if (owner_name != NULL) {
3911e8d8aa46STrond Myklebust 		len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
3912686a816aSTrond Myklebust 		if (len <= 0)
3913686a816aSTrond Myklebust 			goto out;
3914686a816aSTrond Myklebust 		dprintk("%s: name=%s\n", __func__, owner_name->data);
3915686a816aSTrond Myklebust 		return NFS_ATTR_FATTR_OWNER_NAME;
3916686a816aSTrond Myklebust 	} else {
3917686a816aSTrond Myklebust 		len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3918686a816aSTrond Myklebust 				XDR_MAX_NETOBJ);
3919686a816aSTrond Myklebust 		if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3920686a816aSTrond Myklebust 			goto out;
3921e5782076SEric W. Biederman 		dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3922686a816aSTrond Myklebust 		return NFS_ATTR_FATTR_OWNER;
3923686a816aSTrond Myklebust 	}
3924686a816aSTrond Myklebust out:
3925eb72f484SChuck Lever 	if (len == -EBADMSG)
3926c0eae66eSBenny Halevy 		return -EIO;
3927eb72f484SChuck Lever 	return 0;
39281da177e4SLinus Torvalds }
39291da177e4SLinus Torvalds 
393080e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3931e5782076SEric W. Biederman 		const struct nfs_server *server, kgid_t *gid,
39326926afd1STrond Myklebust 		struct nfs4_string *group_name)
39331da177e4SLinus Torvalds {
3934686a816aSTrond Myklebust 	ssize_t len;
3935686a816aSTrond Myklebust 	char *p;
39361da177e4SLinus Torvalds 
3937e5782076SEric W. Biederman 	*gid = make_kgid(&init_user_ns, -2);
39381da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
39391da177e4SLinus Torvalds 		return -EIO;
3940686a816aSTrond Myklebust 	if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
3941686a816aSTrond Myklebust 		return 0;
39421da177e4SLinus Torvalds 	bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3943686a816aSTrond Myklebust 
3944686a816aSTrond Myklebust 	if (group_name != NULL) {
3945e8d8aa46STrond Myklebust 		len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
3946686a816aSTrond Myklebust 		if (len <= 0)
3947686a816aSTrond Myklebust 			goto out;
3948686a816aSTrond Myklebust 		dprintk("%s: name=%s\n", __func__, group_name->data);
39496f1f6220SKinglong Mee 		return NFS_ATTR_FATTR_GROUP_NAME;
3950686a816aSTrond Myklebust 	} else {
3951686a816aSTrond Myklebust 		len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3952686a816aSTrond Myklebust 				XDR_MAX_NETOBJ);
3953686a816aSTrond Myklebust 		if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
3954686a816aSTrond Myklebust 			goto out;
3955e5782076SEric W. Biederman 		dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3956686a816aSTrond Myklebust 		return NFS_ATTR_FATTR_GROUP;
3957686a816aSTrond Myklebust 	}
3958686a816aSTrond Myklebust out:
3959eb72f484SChuck Lever 	if (len == -EBADMSG)
3960c0eae66eSBenny Halevy 		return -EIO;
3961eb72f484SChuck Lever 	return 0;
39621da177e4SLinus Torvalds }
39631da177e4SLinus Torvalds 
39641da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
39651da177e4SLinus Torvalds {
39668687b63aSAl Viro 	uint32_t major = 0, minor = 0;
39678687b63aSAl Viro 	__be32 *p;
3968409924e4STrond Myklebust 	int ret = 0;
39691da177e4SLinus Torvalds 
39701da177e4SLinus Torvalds 	*rdev = MKDEV(0,0);
39711da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
39721da177e4SLinus Torvalds 		return -EIO;
39731da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
39741da177e4SLinus Torvalds 		dev_t tmp;
39751da177e4SLinus Torvalds 
3976c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3977c0eae66eSBenny Halevy 		if (unlikely(!p))
3978eb72f484SChuck Lever 			return -EIO;
39796f723f77SBenny Halevy 		major = be32_to_cpup(p++);
3980cccddf4fSBenny Halevy 		minor = be32_to_cpup(p);
39811da177e4SLinus Torvalds 		tmp = MKDEV(major, minor);
39821da177e4SLinus Torvalds 		if (MAJOR(tmp) == major && MINOR(tmp) == minor)
39831da177e4SLinus Torvalds 			*rdev = tmp;
39841da177e4SLinus Torvalds 		bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3985409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_RDEV;
39861da177e4SLinus Torvalds 	}
39873110ff80SHarvey Harrison 	dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3988409924e4STrond Myklebust 	return ret;
39891da177e4SLinus Torvalds }
39901da177e4SLinus Torvalds 
39911da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
39921da177e4SLinus Torvalds {
39938687b63aSAl Viro 	__be32 *p;
39941da177e4SLinus Torvalds 	int status = 0;
39951da177e4SLinus Torvalds 
39961da177e4SLinus Torvalds 	*res = 0;
39971da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
39981da177e4SLinus Torvalds 		return -EIO;
39991da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
4000c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4001c0eae66eSBenny Halevy 		if (unlikely(!p))
4002eb72f484SChuck Lever 			return -EIO;
4003cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40041da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
40051da177e4SLinus Torvalds 	}
40063110ff80SHarvey Harrison 	dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
40071da177e4SLinus Torvalds 	return status;
40081da177e4SLinus Torvalds }
40091da177e4SLinus Torvalds 
40101da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40111da177e4SLinus Torvalds {
40128687b63aSAl Viro 	__be32 *p;
40131da177e4SLinus Torvalds 	int status = 0;
40141da177e4SLinus Torvalds 
40151da177e4SLinus Torvalds 	*res = 0;
40161da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
40171da177e4SLinus Torvalds 		return -EIO;
40181da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
4019c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4020c0eae66eSBenny Halevy 		if (unlikely(!p))
4021eb72f484SChuck Lever 			return -EIO;
4022cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40231da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
40241da177e4SLinus Torvalds 	}
40253110ff80SHarvey Harrison 	dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
40261da177e4SLinus Torvalds 	return status;
40271da177e4SLinus Torvalds }
40281da177e4SLinus Torvalds 
40291da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40301da177e4SLinus Torvalds {
40318687b63aSAl Viro 	__be32 *p;
40321da177e4SLinus Torvalds 	int status = 0;
40331da177e4SLinus Torvalds 
40341da177e4SLinus Torvalds 	*res = 0;
40351da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
40361da177e4SLinus Torvalds 		return -EIO;
40371da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4038c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4039c0eae66eSBenny Halevy 		if (unlikely(!p))
4040eb72f484SChuck Lever 			return -EIO;
4041cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40421da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
40431da177e4SLinus Torvalds 	}
40443110ff80SHarvey Harrison 	dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
40451da177e4SLinus Torvalds 	return status;
40461da177e4SLinus Torvalds }
40471da177e4SLinus Torvalds 
40481da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
40491da177e4SLinus Torvalds {
40508687b63aSAl Viro 	__be32 *p;
4051409924e4STrond Myklebust 	int ret = 0;
40521da177e4SLinus Torvalds 
40531da177e4SLinus Torvalds 	*used = 0;
40541da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
40551da177e4SLinus Torvalds 		return -EIO;
40561da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4057c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4058c0eae66eSBenny Halevy 		if (unlikely(!p))
4059eb72f484SChuck Lever 			return -EIO;
4060cccddf4fSBenny Halevy 		xdr_decode_hyper(p, used);
40611da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4062409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SPACE_USED;
40631da177e4SLinus Torvalds 	}
40643110ff80SHarvey Harrison 	dprintk("%s: space used=%Lu\n", __func__,
40651da177e4SLinus Torvalds 			(unsigned long long)*used);
4066409924e4STrond Myklebust 	return ret;
40671da177e4SLinus Torvalds }
40681da177e4SLinus Torvalds 
406936b3743fSTrond Myklebust static __be32 *
407036b3743fSTrond Myklebust xdr_decode_nfstime4(__be32 *p, struct timespec *t)
407136b3743fSTrond Myklebust {
407236b3743fSTrond Myklebust 	__u64 sec;
407336b3743fSTrond Myklebust 
407436b3743fSTrond Myklebust 	p = xdr_decode_hyper(p, &sec);
407536b3743fSTrond Myklebust 	t-> tv_sec = (time_t)sec;
407636b3743fSTrond Myklebust 	t->tv_nsec = be32_to_cpup(p++);
407736b3743fSTrond Myklebust 	return p;
407836b3743fSTrond Myklebust }
407936b3743fSTrond Myklebust 
40801da177e4SLinus Torvalds static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
40811da177e4SLinus Torvalds {
40828687b63aSAl Viro 	__be32 *p;
40831da177e4SLinus Torvalds 
408436b3743fSTrond Myklebust 	p = xdr_inline_decode(xdr, nfstime4_maxsz << 2);
4085c0eae66eSBenny Halevy 	if (unlikely(!p))
4086eb72f484SChuck Lever 		return -EIO;
408736b3743fSTrond Myklebust 	xdr_decode_nfstime4(p, time);
40881da177e4SLinus Torvalds 	return 0;
40891da177e4SLinus Torvalds }
40901da177e4SLinus Torvalds 
40911da177e4SLinus Torvalds static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
40921da177e4SLinus Torvalds {
40931da177e4SLinus Torvalds 	int status = 0;
40941da177e4SLinus Torvalds 
40951da177e4SLinus Torvalds 	time->tv_sec = 0;
40961da177e4SLinus Torvalds 	time->tv_nsec = 0;
40971da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
40981da177e4SLinus Torvalds 		return -EIO;
40991da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
41001da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4101409924e4STrond Myklebust 		if (status == 0)
4102409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_ATIME;
41031da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
41041da177e4SLinus Torvalds 	}
41053110ff80SHarvey Harrison 	dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
41061da177e4SLinus Torvalds 	return status;
41071da177e4SLinus Torvalds }
41081da177e4SLinus Torvalds 
41091da177e4SLinus Torvalds static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
41101da177e4SLinus Torvalds {
41111da177e4SLinus Torvalds 	int status = 0;
41121da177e4SLinus Torvalds 
41131da177e4SLinus Torvalds 	time->tv_sec = 0;
41141da177e4SLinus Torvalds 	time->tv_nsec = 0;
41151da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
41161da177e4SLinus Torvalds 		return -EIO;
41171da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
41181da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4119409924e4STrond Myklebust 		if (status == 0)
4120409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_CTIME;
41211da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
41221da177e4SLinus Torvalds 	}
41233110ff80SHarvey Harrison 	dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
41241da177e4SLinus Torvalds 	return status;
41251da177e4SLinus Torvalds }
41261da177e4SLinus Torvalds 
412755b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
412855b6e774SRicardo Labiaga 				  struct timespec *time)
412955b6e774SRicardo Labiaga {
413055b6e774SRicardo Labiaga 	int status = 0;
413155b6e774SRicardo Labiaga 
413255b6e774SRicardo Labiaga 	time->tv_sec = 0;
413355b6e774SRicardo Labiaga 	time->tv_nsec = 0;
413455b6e774SRicardo Labiaga 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
413555b6e774SRicardo Labiaga 		return -EIO;
413655b6e774SRicardo Labiaga 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
413755b6e774SRicardo Labiaga 		status = decode_attr_time(xdr, time);
413855b6e774SRicardo Labiaga 		bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
413955b6e774SRicardo Labiaga 	}
414055b6e774SRicardo Labiaga 	dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
414155b6e774SRicardo Labiaga 		(long)time->tv_nsec);
414255b6e774SRicardo Labiaga 	return status;
414355b6e774SRicardo Labiaga }
414455b6e774SRicardo Labiaga 
4145aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4146aa9c2669SDavid Quigley 					struct nfs4_label *label)
4147aa9c2669SDavid Quigley {
4148aa9c2669SDavid Quigley 	uint32_t pi = 0;
4149aa9c2669SDavid Quigley 	uint32_t lfs = 0;
4150aa9c2669SDavid Quigley 	__u32 len;
4151aa9c2669SDavid Quigley 	__be32 *p;
4152aa9c2669SDavid Quigley 	int status = 0;
4153aa9c2669SDavid Quigley 
4154aa9c2669SDavid Quigley 	if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4155aa9c2669SDavid Quigley 		return -EIO;
4156aa9c2669SDavid Quigley 	if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4157aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4158aa9c2669SDavid Quigley 		if (unlikely(!p))
4159eb72f484SChuck Lever 			return -EIO;
4160aa9c2669SDavid Quigley 		lfs = be32_to_cpup(p++);
4161aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4162aa9c2669SDavid Quigley 		if (unlikely(!p))
4163eb72f484SChuck Lever 			return -EIO;
4164aa9c2669SDavid Quigley 		pi = be32_to_cpup(p++);
4165aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4166aa9c2669SDavid Quigley 		if (unlikely(!p))
4167eb72f484SChuck Lever 			return -EIO;
4168aa9c2669SDavid Quigley 		len = be32_to_cpup(p++);
4169aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, len);
4170aa9c2669SDavid Quigley 		if (unlikely(!p))
4171eb72f484SChuck Lever 			return -EIO;
4172aa9c2669SDavid Quigley 		if (len < NFS4_MAXLABELLEN) {
4173aa9c2669SDavid Quigley 			if (label) {
4174aa9c2669SDavid Quigley 				memcpy(label->label, p, len);
4175aa9c2669SDavid Quigley 				label->len = len;
4176aa9c2669SDavid Quigley 				label->pi = pi;
4177aa9c2669SDavid Quigley 				label->lfs = lfs;
4178aa9c2669SDavid Quigley 				status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4179aa9c2669SDavid Quigley 			}
4180aa9c2669SDavid Quigley 			bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4181aa9c2669SDavid Quigley 		} else
4182aa9c2669SDavid Quigley 			printk(KERN_WARNING "%s: label too long (%u)!\n",
4183aa9c2669SDavid Quigley 					__func__, len);
4184aa9c2669SDavid Quigley 	}
4185aa9c2669SDavid Quigley 	if (label && label->label)
4186aa9c2669SDavid Quigley 		dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4187aa9c2669SDavid Quigley 			(char *)label->label, label->len, label->pi, label->lfs);
4188aa9c2669SDavid Quigley 	return status;
4189aa9c2669SDavid Quigley }
4190aa9c2669SDavid Quigley 
41911da177e4SLinus Torvalds static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
41921da177e4SLinus Torvalds {
41931da177e4SLinus Torvalds 	int status = 0;
41941da177e4SLinus Torvalds 
41951da177e4SLinus Torvalds 	time->tv_sec = 0;
41961da177e4SLinus Torvalds 	time->tv_nsec = 0;
41971da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
41981da177e4SLinus Torvalds 		return -EIO;
41991da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
42001da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4201409924e4STrond Myklebust 		if (status == 0)
4202409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_MTIME;
42031da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
42041da177e4SLinus Torvalds 	}
42053110ff80SHarvey Harrison 	dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
42061da177e4SLinus Torvalds 	return status;
42071da177e4SLinus Torvalds }
42081da177e4SLinus Torvalds 
4209256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
42101da177e4SLinus Torvalds {
42111da177e4SLinus Torvalds 	unsigned int attrwords = XDR_QUADLEN(attrlen);
4212256e48bbSTrond Myklebust 	unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
42131da177e4SLinus Torvalds 
42141da177e4SLinus Torvalds 	if (unlikely(attrwords != nwords)) {
4215fe82a183SChuck Lever 		dprintk("%s: server returned incorrect attribute length: "
4216fe82a183SChuck Lever 			"%u %c %u\n",
42173110ff80SHarvey Harrison 				__func__,
42181da177e4SLinus Torvalds 				attrwords << 2,
42191da177e4SLinus Torvalds 				(attrwords < nwords) ? '<' : '>',
42201da177e4SLinus Torvalds 				nwords << 2);
42211da177e4SLinus Torvalds 		return -EIO;
42221da177e4SLinus Torvalds 	}
42231da177e4SLinus Torvalds 	return 0;
42241da177e4SLinus Torvalds }
42251da177e4SLinus Torvalds 
42261da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
42271da177e4SLinus Torvalds {
42288687b63aSAl Viro 	__be32 *p;
42291da177e4SLinus Torvalds 
4230c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
4231c0eae66eSBenny Halevy 	if (unlikely(!p))
4232eb72f484SChuck Lever 		return -EIO;
42336f723f77SBenny Halevy 	cinfo->atomic = be32_to_cpup(p++);
42343ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &cinfo->before);
4235cccddf4fSBenny Halevy 	xdr_decode_hyper(p, &cinfo->after);
42361da177e4SLinus Torvalds 	return 0;
42371da177e4SLinus Torvalds }
42381da177e4SLinus Torvalds 
42396168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
42401da177e4SLinus Torvalds {
42418687b63aSAl Viro 	__be32 *p;
42421da177e4SLinus Torvalds 	uint32_t supp, acc;
42431da177e4SLinus Torvalds 	int status;
42441da177e4SLinus Torvalds 
42451da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_ACCESS);
42461da177e4SLinus Torvalds 	if (status)
42471da177e4SLinus Torvalds 		return status;
4248c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
4249c0eae66eSBenny Halevy 	if (unlikely(!p))
4250eb72f484SChuck Lever 		return -EIO;
42516f723f77SBenny Halevy 	supp = be32_to_cpup(p++);
4252cccddf4fSBenny Halevy 	acc = be32_to_cpup(p);
42536168f62cSWeston Andros Adamson 	*supported = supp;
42546168f62cSWeston Andros Adamson 	*access = acc;
42551da177e4SLinus Torvalds 	return 0;
42561da177e4SLinus Torvalds }
42571da177e4SLinus Torvalds 
425807d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
42591da177e4SLinus Torvalds {
4260ab6e9aafSTrond Myklebust 	ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4261eb72f484SChuck Lever 	if (unlikely(ret < 0))
426207d30434SBenny Halevy 		return -EIO;
4263ab6e9aafSTrond Myklebust 	return 0;
4264ab6e9aafSTrond Myklebust }
426507d30434SBenny Halevy 
426607d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
426707d30434SBenny Halevy {
42682d2f24adSTrond Myklebust 	return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
42691da177e4SLinus Torvalds }
42701da177e4SLinus Torvalds 
427193b717fdSTrond Myklebust static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
427293b717fdSTrond Myklebust {
427393b717fdSTrond Myklebust 	stateid->type = NFS4_OPEN_STATEID_TYPE;
427493b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
427593b717fdSTrond Myklebust }
427693b717fdSTrond Myklebust 
427793b717fdSTrond Myklebust static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
427893b717fdSTrond Myklebust {
427993b717fdSTrond Myklebust 	stateid->type = NFS4_LOCK_STATEID_TYPE;
428093b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
428193b717fdSTrond Myklebust }
428293b717fdSTrond Myklebust 
428393b717fdSTrond Myklebust static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
428493b717fdSTrond Myklebust {
428593b717fdSTrond Myklebust 	stateid->type = NFS4_DELEGATION_STATEID_TYPE;
428693b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
428793b717fdSTrond Myklebust }
428893b717fdSTrond Myklebust 
4289fcd8843cSTrond Myklebust static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4290fcd8843cSTrond Myklebust {
4291fcd8843cSTrond Myklebust 	nfs4_stateid dummy;
4292fcd8843cSTrond Myklebust 
4293fcd8843cSTrond Myklebust 	nfs4_stateid_copy(stateid, &invalid_stateid);
4294fcd8843cSTrond Myklebust 	return decode_stateid(xdr, &dummy);
4295fcd8843cSTrond Myklebust }
4296fcd8843cSTrond Myklebust 
42971da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
42981da177e4SLinus Torvalds {
42991da177e4SLinus Torvalds 	int status;
43001da177e4SLinus Torvalds 
43011da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CLOSE);
4302c1d51931STrond Myklebust 	if (status != -EIO)
4303c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
430407d30434SBenny Halevy 	if (!status)
4305fcd8843cSTrond Myklebust 		status = decode_invalid_stateid(xdr, &res->stateid);
43061da177e4SLinus Torvalds 	return status;
43071da177e4SLinus Torvalds }
43081da177e4SLinus Torvalds 
4309db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4310db942bbdSBenny Halevy {
4311cd93710eSChuck Lever 	return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
43121da177e4SLinus Torvalds }
43131da177e4SLinus Torvalds 
43142f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
43152f2c63bcSTrond Myklebust {
43162f2c63bcSTrond Myklebust 	return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
43172f2c63bcSTrond Myklebust }
43182f2c63bcSTrond Myklebust 
43190b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
43201da177e4SLinus Torvalds {
43211da177e4SLinus Torvalds 	int status;
43221da177e4SLinus Torvalds 
43231da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_COMMIT);
4324db942bbdSBenny Halevy 	if (!status)
43252f2c63bcSTrond Myklebust 		status = decode_write_verifier(xdr, &res->verf->verifier);
43261da177e4SLinus Torvalds 	return status;
43271da177e4SLinus Torvalds }
43281da177e4SLinus Torvalds 
43291da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
43301da177e4SLinus Torvalds {
43318687b63aSAl Viro 	__be32 *p;
43321da177e4SLinus Torvalds 	uint32_t bmlen;
43331da177e4SLinus Torvalds 	int status;
43341da177e4SLinus Torvalds 
43351da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CREATE);
43361da177e4SLinus Torvalds 	if (status)
43371da177e4SLinus Torvalds 		return status;
43381da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, cinfo)))
43391da177e4SLinus Torvalds 		return status;
4340c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4341c0eae66eSBenny Halevy 	if (unlikely(!p))
4342eb72f484SChuck Lever 		return -EIO;
4343cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
4344c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
4345c0eae66eSBenny Halevy 	if (likely(p))
43461da177e4SLinus Torvalds 		return 0;
4347c0eae66eSBenny Halevy 	return -EIO;
43481da177e4SLinus Torvalds }
43491da177e4SLinus Torvalds 
43501da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
43511da177e4SLinus Torvalds {
4352256e48bbSTrond Myklebust 	unsigned int savep;
4353dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
43541da177e4SLinus Torvalds 	int status;
43551da177e4SLinus Torvalds 
43561da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
43571da177e4SLinus Torvalds 		goto xdr_error;
43581da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
43591da177e4SLinus Torvalds 		goto xdr_error;
43601da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
43611da177e4SLinus Torvalds 		goto xdr_error;
43621da177e4SLinus Torvalds 	if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
43631da177e4SLinus Torvalds 		goto xdr_error;
4364264e6351SChuck Lever 	if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4365264e6351SChuck Lever 						 &res->fh_expire_type)) != 0)
4366264e6351SChuck Lever 		goto xdr_error;
43671da177e4SLinus Torvalds 	if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
43681da177e4SLinus Torvalds 		goto xdr_error;
43691da177e4SLinus Torvalds 	if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
43701da177e4SLinus Torvalds 		goto xdr_error;
43711da177e4SLinus Torvalds 	if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
43721da177e4SLinus Torvalds 		goto xdr_error;
43738c61282fSKinglong Mee 	if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
43748c61282fSKinglong Mee 				res->exclcreat_bitmask)) != 0)
43758c61282fSKinglong Mee 		goto xdr_error;
43761da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
43771da177e4SLinus Torvalds xdr_error:
43783110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
43791da177e4SLinus Torvalds 	return status;
43801da177e4SLinus Torvalds }
43811da177e4SLinus Torvalds 
43821da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
43831da177e4SLinus Torvalds {
4384256e48bbSTrond Myklebust 	unsigned int savep;
4385dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
43861da177e4SLinus Torvalds 	int status;
43871da177e4SLinus Torvalds 
43881da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
43891da177e4SLinus Torvalds 		goto xdr_error;
43901da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
43911da177e4SLinus Torvalds 		goto xdr_error;
43921da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
43931da177e4SLinus Torvalds 		goto xdr_error;
43941da177e4SLinus Torvalds 
43951da177e4SLinus Torvalds 	if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
43961da177e4SLinus Torvalds 		goto xdr_error;
43971da177e4SLinus Torvalds 	if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
43981da177e4SLinus Torvalds 		goto xdr_error;
43991da177e4SLinus Torvalds 	if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
44001da177e4SLinus Torvalds 		goto xdr_error;
44011ca843a2SAndreas Gruenbacher 
44021ca843a2SAndreas Gruenbacher 	status = -EIO;
44031ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[0]))
44041ca843a2SAndreas Gruenbacher 		goto xdr_error;
44051ca843a2SAndreas Gruenbacher 
44061da177e4SLinus Torvalds 	if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
44071da177e4SLinus Torvalds 		goto xdr_error;
44081da177e4SLinus Torvalds 	if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
44091da177e4SLinus Torvalds 		goto xdr_error;
44101da177e4SLinus Torvalds 	if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
44111da177e4SLinus Torvalds 		goto xdr_error;
44121da177e4SLinus Torvalds 
44131da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
44141da177e4SLinus Torvalds xdr_error:
44153110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
44161da177e4SLinus Torvalds 	return status;
44171da177e4SLinus Torvalds }
44181da177e4SLinus Torvalds 
44191da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
44201da177e4SLinus Torvalds {
4421256e48bbSTrond Myklebust 	unsigned int savep;
4422dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
44231da177e4SLinus Torvalds 	int status;
44241da177e4SLinus Torvalds 
44251da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
44261da177e4SLinus Torvalds 		goto xdr_error;
44271da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
44281da177e4SLinus Torvalds 		goto xdr_error;
44291da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
44301da177e4SLinus Torvalds 		goto xdr_error;
44311da177e4SLinus Torvalds 
44321da177e4SLinus Torvalds 	if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
44331da177e4SLinus Torvalds 		goto xdr_error;
44341da177e4SLinus Torvalds 	if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
44351da177e4SLinus Torvalds 		goto xdr_error;
44361da177e4SLinus Torvalds 
44371da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
44381da177e4SLinus Torvalds xdr_error:
44393110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
44401da177e4SLinus Torvalds 	return status;
44411da177e4SLinus Torvalds }
44421da177e4SLinus Torvalds 
444388034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr,
444488034c3dSAndy Adamson 				  uint32_t *bitmap,
444588034c3dSAndy Adamson 				  uint64_t *res,
444688034c3dSAndy Adamson 				  uint32_t hint_bit)
444788034c3dSAndy Adamson {
444888034c3dSAndy Adamson 	__be32 *p;
444988034c3dSAndy Adamson 
445088034c3dSAndy Adamson 	*res = 0;
445188034c3dSAndy Adamson 	if (likely(bitmap[0] & hint_bit)) {
445288034c3dSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
445388034c3dSAndy Adamson 		if (unlikely(!p))
4454eb72f484SChuck Lever 			return -EIO;
445588034c3dSAndy Adamson 		xdr_decode_hyper(p, res);
445688034c3dSAndy Adamson 	}
445788034c3dSAndy Adamson 	return 0;
445888034c3dSAndy Adamson }
445988034c3dSAndy Adamson 
446088034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr,
446188034c3dSAndy Adamson 					struct nfs4_threshold *res)
446288034c3dSAndy Adamson {
4463256e48bbSTrond Myklebust 	__be32 *p;
4464256e48bbSTrond Myklebust 	unsigned int savep;
446588034c3dSAndy Adamson 	uint32_t bitmap[3] = {0,}, attrlen;
446688034c3dSAndy Adamson 	int status;
446788034c3dSAndy Adamson 
446888034c3dSAndy Adamson 	/* layout type */
446988034c3dSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
4470eb72f484SChuck Lever 	if (unlikely(!p))
447188034c3dSAndy Adamson 		return -EIO;
447288034c3dSAndy Adamson 	res->l_type = be32_to_cpup(p);
447388034c3dSAndy Adamson 
447488034c3dSAndy Adamson 	/* thi_hintset bitmap */
447588034c3dSAndy Adamson 	status = decode_attr_bitmap(xdr, bitmap);
447688034c3dSAndy Adamson 	if (status < 0)
447788034c3dSAndy Adamson 		goto xdr_error;
447888034c3dSAndy Adamson 
447988034c3dSAndy Adamson 	/* thi_hintlist length */
448088034c3dSAndy Adamson 	status = decode_attr_length(xdr, &attrlen, &savep);
448188034c3dSAndy Adamson 	if (status < 0)
448288034c3dSAndy Adamson 		goto xdr_error;
448388034c3dSAndy Adamson 	/* thi_hintlist */
448488034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
448588034c3dSAndy Adamson 	if (status < 0)
448688034c3dSAndy Adamson 		goto xdr_error;
448788034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
448888034c3dSAndy Adamson 	if (status < 0)
448988034c3dSAndy Adamson 		goto xdr_error;
449088034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
449188034c3dSAndy Adamson 				       THRESHOLD_RD_IO);
449288034c3dSAndy Adamson 	if (status < 0)
449388034c3dSAndy Adamson 		goto xdr_error;
449488034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
449588034c3dSAndy Adamson 				       THRESHOLD_WR_IO);
449688034c3dSAndy Adamson 	if (status < 0)
449788034c3dSAndy Adamson 		goto xdr_error;
449888034c3dSAndy Adamson 
449988034c3dSAndy Adamson 	status = verify_attr_len(xdr, savep, attrlen);
450088034c3dSAndy Adamson 	res->bm = bitmap[0];
450188034c3dSAndy Adamson 
450288034c3dSAndy Adamson 	dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
450388034c3dSAndy Adamson 		 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
450488034c3dSAndy Adamson 		res->wr_io_sz);
450588034c3dSAndy Adamson xdr_error:
450688034c3dSAndy Adamson 	dprintk("%s ret=%d!\n", __func__, status);
450788034c3dSAndy Adamson 	return status;
450888034c3dSAndy Adamson }
450988034c3dSAndy Adamson 
451088034c3dSAndy Adamson /*
451188034c3dSAndy Adamson  * Thresholds on pNFS direct I/O vrs MDS I/O
451288034c3dSAndy Adamson  */
451388034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
451488034c3dSAndy Adamson 				    uint32_t *bitmap,
451588034c3dSAndy Adamson 				    struct nfs4_threshold *res)
451688034c3dSAndy Adamson {
451788034c3dSAndy Adamson 	__be32 *p;
451888034c3dSAndy Adamson 	int status = 0;
451988034c3dSAndy Adamson 	uint32_t num;
452088034c3dSAndy Adamson 
452188034c3dSAndy Adamson 	if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
452288034c3dSAndy Adamson 		return -EIO;
4523029c5347STrond Myklebust 	if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
45241549210fSTrond Myklebust 		/* Did the server return an unrequested attribute? */
45251549210fSTrond Myklebust 		if (unlikely(res == NULL))
45261549210fSTrond Myklebust 			return -EREMOTEIO;
452788034c3dSAndy Adamson 		p = xdr_inline_decode(xdr, 4);
452888034c3dSAndy Adamson 		if (unlikely(!p))
4529eb72f484SChuck Lever 			return -EIO;
453088034c3dSAndy Adamson 		num = be32_to_cpup(p);
453188034c3dSAndy Adamson 		if (num == 0)
453288034c3dSAndy Adamson 			return 0;
453388034c3dSAndy Adamson 		if (num > 1)
453488034c3dSAndy Adamson 			printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
453588034c3dSAndy Adamson 				"drivers per filesystem not supported\n",
453688034c3dSAndy Adamson 				__func__);
453788034c3dSAndy Adamson 
453888034c3dSAndy Adamson 		status = decode_first_threshold_item4(xdr, res);
4539029c5347STrond Myklebust 		bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
454088034c3dSAndy Adamson 	}
454188034c3dSAndy Adamson 	return status;
454288034c3dSAndy Adamson }
454388034c3dSAndy Adamson 
4544ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4545ae42c70aSBryan Schumaker 		struct nfs_fattr *fattr, struct nfs_fh *fh,
4546aa9c2669SDavid Quigley 		struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
45476926afd1STrond Myklebust 		const struct nfs_server *server)
45481da177e4SLinus Torvalds {
4549bca79478STrond Myklebust 	int status;
4550bca79478STrond Myklebust 	umode_t fmode = 0;
4551ae42c70aSBryan Schumaker 	uint32_t type;
4552ee7b75fcSTrond Myklebust 	int32_t err;
45531da177e4SLinus Torvalds 
4554f26c7a78STrond Myklebust 	status = decode_attr_type(xdr, bitmap, &type);
4555f26c7a78STrond Myklebust 	if (status < 0)
45561da177e4SLinus Torvalds 		goto xdr_error;
4557409924e4STrond Myklebust 	fattr->mode = 0;
4558409924e4STrond Myklebust 	if (status != 0) {
4559409924e4STrond Myklebust 		fattr->mode |= nfs_type2fmt[type];
4560409924e4STrond Myklebust 		fattr->valid |= status;
4561409924e4STrond Myklebust 	}
45621da177e4SLinus Torvalds 
4563f26c7a78STrond Myklebust 	status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4564f26c7a78STrond Myklebust 	if (status < 0)
45651da177e4SLinus Torvalds 		goto xdr_error;
4566409924e4STrond Myklebust 	fattr->valid |= status;
4567f26c7a78STrond Myklebust 
4568f26c7a78STrond Myklebust 	status = decode_attr_size(xdr, bitmap, &fattr->size);
4569f26c7a78STrond Myklebust 	if (status < 0)
45701da177e4SLinus Torvalds 		goto xdr_error;
4571409924e4STrond Myklebust 	fattr->valid |= status;
4572f26c7a78STrond Myklebust 
4573f26c7a78STrond Myklebust 	status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4574f26c7a78STrond Myklebust 	if (status < 0)
45751da177e4SLinus Torvalds 		goto xdr_error;
4576409924e4STrond Myklebust 	fattr->valid |= status;
4577f26c7a78STrond Myklebust 
4578ee7b75fcSTrond Myklebust 	err = 0;
4579ee7b75fcSTrond Myklebust 	status = decode_attr_error(xdr, bitmap, &err);
4580ae42c70aSBryan Schumaker 	if (status < 0)
4581ae42c70aSBryan Schumaker 		goto xdr_error;
4582ae42c70aSBryan Schumaker 
4583ae42c70aSBryan Schumaker 	status = decode_attr_filehandle(xdr, bitmap, fh);
4584ae42c70aSBryan Schumaker 	if (status < 0)
4585ae42c70aSBryan Schumaker 		goto xdr_error;
4586ae42c70aSBryan Schumaker 
4587f26c7a78STrond Myklebust 	status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4588f26c7a78STrond Myklebust 	if (status < 0)
45891da177e4SLinus Torvalds 		goto xdr_error;
4590409924e4STrond Myklebust 	fattr->valid |= status;
4591f26c7a78STrond Myklebust 
45928b7e3f49STrond Myklebust 	status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4593f26c7a78STrond Myklebust 	if (status < 0)
4594683b57b4STrond Myklebust 		goto xdr_error;
4595409924e4STrond Myklebust 	fattr->valid |= status;
4596f26c7a78STrond Myklebust 
45971ca843a2SAndreas Gruenbacher 	status = -EIO;
45981ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[0]))
45991ca843a2SAndreas Gruenbacher 		goto xdr_error;
46001ca843a2SAndreas Gruenbacher 
4601f26c7a78STrond Myklebust 	status = decode_attr_mode(xdr, bitmap, &fmode);
4602f26c7a78STrond Myklebust 	if (status < 0)
46031da177e4SLinus Torvalds 		goto xdr_error;
4604409924e4STrond Myklebust 	if (status != 0) {
46051da177e4SLinus Torvalds 		fattr->mode |= fmode;
4606409924e4STrond Myklebust 		fattr->valid |= status;
4607409924e4STrond Myklebust 	}
4608f26c7a78STrond Myklebust 
4609f26c7a78STrond Myklebust 	status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4610f26c7a78STrond Myklebust 	if (status < 0)
46111da177e4SLinus Torvalds 		goto xdr_error;
4612409924e4STrond Myklebust 	fattr->valid |= status;
4613f26c7a78STrond Myklebust 
46146926afd1STrond Myklebust 	status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4615f26c7a78STrond Myklebust 	if (status < 0)
46161da177e4SLinus Torvalds 		goto xdr_error;
4617409924e4STrond Myklebust 	fattr->valid |= status;
4618f26c7a78STrond Myklebust 
46196926afd1STrond Myklebust 	status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4620f26c7a78STrond Myklebust 	if (status < 0)
46211da177e4SLinus Torvalds 		goto xdr_error;
4622409924e4STrond Myklebust 	fattr->valid |= status;
4623f26c7a78STrond Myklebust 
4624f26c7a78STrond Myklebust 	status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4625f26c7a78STrond Myklebust 	if (status < 0)
46261da177e4SLinus Torvalds 		goto xdr_error;
4627409924e4STrond Myklebust 	fattr->valid |= status;
4628f26c7a78STrond Myklebust 
4629f26c7a78STrond Myklebust 	status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4630f26c7a78STrond Myklebust 	if (status < 0)
46311da177e4SLinus Torvalds 		goto xdr_error;
4632409924e4STrond Myklebust 	fattr->valid |= status;
4633f26c7a78STrond Myklebust 
4634f26c7a78STrond Myklebust 	status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4635f26c7a78STrond Myklebust 	if (status < 0)
46361da177e4SLinus Torvalds 		goto xdr_error;
4637409924e4STrond Myklebust 	fattr->valid |= status;
4638f26c7a78STrond Myklebust 
4639f26c7a78STrond Myklebust 	status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4640f26c7a78STrond Myklebust 	if (status < 0)
46411da177e4SLinus Torvalds 		goto xdr_error;
4642409924e4STrond Myklebust 	fattr->valid |= status;
4643f26c7a78STrond Myklebust 
4644f26c7a78STrond Myklebust 	status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4645f26c7a78STrond Myklebust 	if (status < 0)
46461da177e4SLinus Torvalds 		goto xdr_error;
4647409924e4STrond Myklebust 	fattr->valid |= status;
4648f26c7a78STrond Myklebust 
464928331a46STrond Myklebust 	status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4650f26c7a78STrond Myklebust 	if (status < 0)
465199baf625SManoj Naik 		goto xdr_error;
4652409924e4STrond Myklebust 	fattr->valid |= status;
4653f26c7a78STrond Myklebust 
46541ca843a2SAndreas Gruenbacher 	status = -EIO;
46551ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[1]))
46561ca843a2SAndreas Gruenbacher 		goto xdr_error;
46571ca843a2SAndreas Gruenbacher 
465888034c3dSAndy Adamson 	status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
465988034c3dSAndy Adamson 	if (status < 0)
466088034c3dSAndy Adamson 		goto xdr_error;
466188034c3dSAndy Adamson 
4662aa9c2669SDavid Quigley 	if (label) {
4663aa9c2669SDavid Quigley 		status = decode_attr_security_label(xdr, bitmap, label);
4664aa9c2669SDavid Quigley 		if (status < 0)
4665aa9c2669SDavid Quigley 			goto xdr_error;
4666aa9c2669SDavid Quigley 		fattr->valid |= status;
4667aa9c2669SDavid Quigley 	}
4668aa9c2669SDavid Quigley 
4669ae42c70aSBryan Schumaker xdr_error:
4670ae42c70aSBryan Schumaker 	dprintk("%s: xdr returned %d\n", __func__, -status);
4671ae42c70aSBryan Schumaker 	return status;
4672ae42c70aSBryan Schumaker }
4673ae42c70aSBryan Schumaker 
4674ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
46758b7e3f49STrond Myklebust 		struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4676aa9c2669SDavid Quigley 		struct nfs4_label *label, const struct nfs_server *server)
4677ae42c70aSBryan Schumaker {
4678256e48bbSTrond Myklebust 	unsigned int savep;
4679ae42c70aSBryan Schumaker 	uint32_t attrlen,
4680dae100c2SFred Isaman 		 bitmap[3] = {0};
4681ae42c70aSBryan Schumaker 	int status;
4682ae42c70aSBryan Schumaker 
4683ae42c70aSBryan Schumaker 	status = decode_op_hdr(xdr, OP_GETATTR);
4684ae42c70aSBryan Schumaker 	if (status < 0)
4685ae42c70aSBryan Schumaker 		goto xdr_error;
4686ae42c70aSBryan Schumaker 
4687ae42c70aSBryan Schumaker 	status = decode_attr_bitmap(xdr, bitmap);
4688ae42c70aSBryan Schumaker 	if (status < 0)
4689ae42c70aSBryan Schumaker 		goto xdr_error;
4690ae42c70aSBryan Schumaker 
4691ae42c70aSBryan Schumaker 	status = decode_attr_length(xdr, &attrlen, &savep);
4692ae42c70aSBryan Schumaker 	if (status < 0)
4693ae42c70aSBryan Schumaker 		goto xdr_error;
4694ae42c70aSBryan Schumaker 
4695aa9c2669SDavid Quigley 	status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4696aa9c2669SDavid Quigley 					label, server);
4697ae42c70aSBryan Schumaker 	if (status < 0)
4698ae42c70aSBryan Schumaker 		goto xdr_error;
4699ae42c70aSBryan Schumaker 
4700f26c7a78STrond Myklebust 	status = verify_attr_len(xdr, savep, attrlen);
47011da177e4SLinus Torvalds xdr_error:
47023110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d\n", __func__, -status);
47031da177e4SLinus Torvalds 	return status;
47041da177e4SLinus Torvalds }
47051da177e4SLinus Torvalds 
4706aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4707aa9c2669SDavid Quigley 		struct nfs4_label *label, const struct nfs_server *server)
4708aa9c2669SDavid Quigley {
4709aa9c2669SDavid Quigley 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4710aa9c2669SDavid Quigley }
4711aa9c2669SDavid Quigley 
4712ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
47136926afd1STrond Myklebust 		const struct nfs_server *server)
4714ae42c70aSBryan Schumaker {
4715aa9c2669SDavid Quigley 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
4716ae42c70aSBryan Schumaker }
47171da177e4SLinus Torvalds 
4718504913fbSAndy Adamson /*
47193132e49eSJeff Layton  * Decode potentially multiple layout types.
4720504913fbSAndy Adamson  */
47213132e49eSJeff Layton static int decode_pnfs_layout_types(struct xdr_stream *xdr,
4722ca440c38SJeff Layton 				    struct nfs_fsinfo *fsinfo)
4723504913fbSAndy Adamson {
4724b8a8a0ddSTrond Myklebust 	__be32 *p;
4725ca440c38SJeff Layton 	uint32_t i;
4726504913fbSAndy Adamson 
4727504913fbSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
4728504913fbSAndy Adamson 	if (unlikely(!p))
4729eb72f484SChuck Lever 		return -EIO;
4730ca440c38SJeff Layton 	fsinfo->nlayouttypes = be32_to_cpup(p);
4731504913fbSAndy Adamson 
4732504913fbSAndy Adamson 	/* pNFS is not supported by the underlying file system */
4733ca440c38SJeff Layton 	if (fsinfo->nlayouttypes == 0)
4734504913fbSAndy Adamson 		return 0;
4735504913fbSAndy Adamson 
4736504913fbSAndy Adamson 	/* Decode and set first layout type, move xdr->p past unused types */
4737ca440c38SJeff Layton 	p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
4738504913fbSAndy Adamson 	if (unlikely(!p))
4739eb72f484SChuck Lever 		return -EIO;
4740ca440c38SJeff Layton 
4741ca440c38SJeff Layton 	/* If we get too many, then just cap it at the max */
4742ca440c38SJeff Layton 	if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4743ca440c38SJeff Layton 		printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4744ca440c38SJeff Layton 			__func__, fsinfo->nlayouttypes);
4745ca440c38SJeff Layton 		fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4746ca440c38SJeff Layton 	}
4747ca440c38SJeff Layton 
4748ca440c38SJeff Layton 	for(i = 0; i < fsinfo->nlayouttypes; ++i)
4749ca440c38SJeff Layton 		fsinfo->layouttype[i] = be32_to_cpup(p++);
4750504913fbSAndy Adamson 	return 0;
4751504913fbSAndy Adamson }
4752504913fbSAndy Adamson 
4753504913fbSAndy Adamson /*
4754504913fbSAndy Adamson  * The type of file system exported.
4755504913fbSAndy Adamson  * Note we must ensure that layouttype is set in any non-error case.
4756504913fbSAndy Adamson  */
4757504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4758ca440c38SJeff Layton 				struct nfs_fsinfo *fsinfo)
4759504913fbSAndy Adamson {
4760504913fbSAndy Adamson 	int status = 0;
4761504913fbSAndy Adamson 
4762504913fbSAndy Adamson 	dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4763504913fbSAndy Adamson 	if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4764504913fbSAndy Adamson 		return -EIO;
4765504913fbSAndy Adamson 	if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4766ca440c38SJeff Layton 		status = decode_pnfs_layout_types(xdr, fsinfo);
4767504913fbSAndy Adamson 		bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
47683132e49eSJeff Layton 	}
4769504913fbSAndy Adamson 	return status;
4770504913fbSAndy Adamson }
4771504913fbSAndy Adamson 
4772dae100c2SFred Isaman /*
4773dae100c2SFred Isaman  * The prefered block size for layout directed io
4774dae100c2SFred Isaman  */
4775dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4776dae100c2SFred Isaman 				      uint32_t *res)
4777dae100c2SFred Isaman {
4778dae100c2SFred Isaman 	__be32 *p;
4779dae100c2SFred Isaman 
4780dae100c2SFred Isaman 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4781dae100c2SFred Isaman 	*res = 0;
4782dae100c2SFred Isaman 	if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4783dae100c2SFred Isaman 		p = xdr_inline_decode(xdr, 4);
4784eb72f484SChuck Lever 		if (unlikely(!p))
4785dae100c2SFred Isaman 			return -EIO;
4786dae100c2SFred Isaman 		*res = be32_to_cpup(p);
4787dae100c2SFred Isaman 		bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4788dae100c2SFred Isaman 	}
4789dae100c2SFred Isaman 	return 0;
4790dae100c2SFred Isaman }
4791dae100c2SFred Isaman 
47922a92ee92SPeng Tao /*
47932a92ee92SPeng Tao  * The granularity of a CLONE operation.
47942a92ee92SPeng Tao  */
47952a92ee92SPeng Tao static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
47962a92ee92SPeng Tao 				     uint32_t *res)
47972a92ee92SPeng Tao {
47982a92ee92SPeng Tao 	__be32 *p;
47992a92ee92SPeng Tao 
48002a92ee92SPeng Tao 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
48012a92ee92SPeng Tao 	*res = 0;
48022a92ee92SPeng Tao 	if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
48032a92ee92SPeng Tao 		p = xdr_inline_decode(xdr, 4);
4804eb72f484SChuck Lever 		if (unlikely(!p))
48052a92ee92SPeng Tao 			return -EIO;
48062a92ee92SPeng Tao 		*res = be32_to_cpup(p);
48072a92ee92SPeng Tao 		bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
48082a92ee92SPeng Tao 	}
48092a92ee92SPeng Tao 	return 0;
48102a92ee92SPeng Tao }
48112a92ee92SPeng Tao 
48121da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
48131da177e4SLinus Torvalds {
4814256e48bbSTrond Myklebust 	unsigned int savep;
4815dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3];
48161da177e4SLinus Torvalds 	int status;
48171da177e4SLinus Torvalds 
48181da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
48191da177e4SLinus Torvalds 		goto xdr_error;
48201da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
48211da177e4SLinus Torvalds 		goto xdr_error;
48221da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
48231da177e4SLinus Torvalds 		goto xdr_error;
48241da177e4SLinus Torvalds 
48251da177e4SLinus Torvalds 	fsinfo->rtmult = fsinfo->wtmult = 512;	/* ??? */
48261da177e4SLinus Torvalds 
48271da177e4SLinus Torvalds 	if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
48281da177e4SLinus Torvalds 		goto xdr_error;
48291da177e4SLinus Torvalds 	if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
48301da177e4SLinus Torvalds 		goto xdr_error;
48311da177e4SLinus Torvalds 	if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
48321da177e4SLinus Torvalds 		goto xdr_error;
48331da177e4SLinus Torvalds 	fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
48341da177e4SLinus Torvalds 	if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
48351da177e4SLinus Torvalds 		goto xdr_error;
48361da177e4SLinus Torvalds 	fsinfo->wtpref = fsinfo->wtmax;
48371ca843a2SAndreas Gruenbacher 
48381ca843a2SAndreas Gruenbacher 	status = -EIO;
48391ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[0]))
48401ca843a2SAndreas Gruenbacher 		goto xdr_error;
48411ca843a2SAndreas Gruenbacher 
484255b6e774SRicardo Labiaga 	status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
484355b6e774SRicardo Labiaga 	if (status != 0)
484455b6e774SRicardo Labiaga 		goto xdr_error;
4845ca440c38SJeff Layton 	status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
4846504913fbSAndy Adamson 	if (status != 0)
4847504913fbSAndy Adamson 		goto xdr_error;
48481ca843a2SAndreas Gruenbacher 
48491ca843a2SAndreas Gruenbacher 	status = -EIO;
48501ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[1]))
48511ca843a2SAndreas Gruenbacher 		goto xdr_error;
48521ca843a2SAndreas Gruenbacher 
4853dae100c2SFred Isaman 	status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4854dae100c2SFred Isaman 	if (status)
4855dae100c2SFred Isaman 		goto xdr_error;
48562a92ee92SPeng Tao 	status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
48572a92ee92SPeng Tao 	if (status)
48582a92ee92SPeng Tao 		goto xdr_error;
48591da177e4SLinus Torvalds 
48601da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
48611da177e4SLinus Torvalds xdr_error:
48623110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
48631da177e4SLinus Torvalds 	return status;
48641da177e4SLinus Torvalds }
48651da177e4SLinus Torvalds 
48661da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
48671da177e4SLinus Torvalds {
48688687b63aSAl Viro 	__be32 *p;
48691da177e4SLinus Torvalds 	uint32_t len;
48701da177e4SLinus Torvalds 	int status;
48711da177e4SLinus Torvalds 
48729936781dSTrond Myklebust 	/* Zero handle first to allow comparisons */
48739936781dSTrond Myklebust 	memset(fh, 0, sizeof(*fh));
48749936781dSTrond Myklebust 
48751da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_GETFH);
48761da177e4SLinus Torvalds 	if (status)
48771da177e4SLinus Torvalds 		return status;
48781da177e4SLinus Torvalds 
4879c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4880c0eae66eSBenny Halevy 	if (unlikely(!p))
4881eb72f484SChuck Lever 		return -EIO;
4882cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
48831da177e4SLinus Torvalds 	if (len > NFS4_FHSIZE)
48841da177e4SLinus Torvalds 		return -EIO;
48851da177e4SLinus Torvalds 	fh->size = len;
4886c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, len);
4887c0eae66eSBenny Halevy 	if (unlikely(!p))
4888eb72f484SChuck Lever 		return -EIO;
488999398d06SBenny Halevy 	memcpy(fh->data, p, len);
48901da177e4SLinus Torvalds 	return 0;
48911da177e4SLinus Torvalds }
48921da177e4SLinus Torvalds 
48931da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
48941da177e4SLinus Torvalds {
48951da177e4SLinus Torvalds 	int status;
48961da177e4SLinus Torvalds 
48971da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LINK);
48981da177e4SLinus Torvalds 	if (status)
48991da177e4SLinus Torvalds 		return status;
49001da177e4SLinus Torvalds 	return decode_change_info(xdr, cinfo);
49011da177e4SLinus Torvalds }
49021da177e4SLinus Torvalds 
49031da177e4SLinus Torvalds /*
49041da177e4SLinus Torvalds  * We create the owner, so we know a proper owner.id length is 4.
49051da177e4SLinus Torvalds  */
4906911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
49071da177e4SLinus Torvalds {
4908911d1aafSTrond Myklebust 	uint64_t offset, length, clientid;
49098687b63aSAl Viro 	__be32 *p;
4910911d1aafSTrond Myklebust 	uint32_t namelen, type;
49111da177e4SLinus Torvalds 
4912babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4913c0eae66eSBenny Halevy 	if (unlikely(!p))
4914eb72f484SChuck Lever 		return -EIO;
4915babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
49163ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &length);
4917babddc72SBryan Schumaker 	type = be32_to_cpup(p++); /* 4 byte read */
4918babddc72SBryan Schumaker 	if (fl != NULL) { /* manipulate file lock */
4919911d1aafSTrond Myklebust 		fl->fl_start = (loff_t)offset;
4920911d1aafSTrond Myklebust 		fl->fl_end = fl->fl_start + (loff_t)length - 1;
4921911d1aafSTrond Myklebust 		if (length == ~(uint64_t)0)
4922911d1aafSTrond Myklebust 			fl->fl_end = OFFSET_MAX;
4923911d1aafSTrond Myklebust 		fl->fl_type = F_WRLCK;
4924911d1aafSTrond Myklebust 		if (type & 1)
4925911d1aafSTrond Myklebust 			fl->fl_type = F_RDLCK;
4926911d1aafSTrond Myklebust 		fl->fl_pid = 0;
4927911d1aafSTrond Myklebust 	}
4928babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4929babddc72SBryan Schumaker 	namelen = be32_to_cpup(p); /* read 4 bytes */  /* have read all 32 bytes now */
4930babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, namelen); /* variable size field */
4931eb72f484SChuck Lever 	if (likely(!p))
4932c0eae66eSBenny Halevy 		return -EIO;
4933eb72f484SChuck Lever 	return -NFS4ERR_DENIED;
49341da177e4SLinus Torvalds }
49351da177e4SLinus Torvalds 
4936911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
49371da177e4SLinus Torvalds {
49381da177e4SLinus Torvalds 	int status;
49391da177e4SLinus Torvalds 
49401da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCK);
4941c1d51931STrond Myklebust 	if (status == -EIO)
4942c1d51931STrond Myklebust 		goto out;
49431da177e4SLinus Torvalds 	if (status == 0) {
494493b717fdSTrond Myklebust 		status = decode_lock_stateid(xdr, &res->stateid);
494507d30434SBenny Halevy 		if (unlikely(status))
494607d30434SBenny Halevy 			goto out;
49471da177e4SLinus Torvalds 	} else if (status == -NFS4ERR_DENIED)
4948c1d51931STrond Myklebust 		status = decode_lock_denied(xdr, NULL);
4949c1d51931STrond Myklebust 	if (res->open_seqid != NULL)
4950c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->open_seqid);
4951c1d51931STrond Myklebust 	nfs_increment_lock_seqid(status, res->lock_seqid);
4952c1d51931STrond Myklebust out:
49531da177e4SLinus Torvalds 	return status;
49541da177e4SLinus Torvalds }
49551da177e4SLinus Torvalds 
4956911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
49571da177e4SLinus Torvalds {
49581da177e4SLinus Torvalds 	int status;
49591da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKT);
49601da177e4SLinus Torvalds 	if (status == -NFS4ERR_DENIED)
4961911d1aafSTrond Myklebust 		return decode_lock_denied(xdr, res->denied);
49621da177e4SLinus Torvalds 	return status;
49631da177e4SLinus Torvalds }
49641da177e4SLinus Torvalds 
4965911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
49661da177e4SLinus Torvalds {
49671da177e4SLinus Torvalds 	int status;
49681da177e4SLinus Torvalds 
49691da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKU);
4970c1d51931STrond Myklebust 	if (status != -EIO)
4971c1d51931STrond Myklebust 		nfs_increment_lock_seqid(status, res->seqid);
497207d30434SBenny Halevy 	if (status == 0)
497393b717fdSTrond Myklebust 		status = decode_lock_stateid(xdr, &res->stateid);
49741da177e4SLinus Torvalds 	return status;
49751da177e4SLinus Torvalds }
49761da177e4SLinus Torvalds 
4977d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr)
4978d3c7b7ccSTrond Myklebust {
4979d3c7b7ccSTrond Myklebust 	return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4980d3c7b7ccSTrond Myklebust }
4981d3c7b7ccSTrond Myklebust 
49821da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr)
49831da177e4SLinus Torvalds {
49841da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_LOOKUP);
49851da177e4SLinus Torvalds }
49861da177e4SLinus Torvalds 
49875b5faaf6SJeff Layton static int decode_lookupp(struct xdr_stream *xdr)
49885b5faaf6SJeff Layton {
49895b5faaf6SJeff Layton 	return decode_op_hdr(xdr, OP_LOOKUPP);
49905b5faaf6SJeff Layton }
49915b5faaf6SJeff Layton 
49921da177e4SLinus Torvalds /* This is too sick! */
49937d160a6cSTrond Myklebust static int decode_space_limit(struct xdr_stream *xdr,
49947d160a6cSTrond Myklebust 		unsigned long *pagemod_limit)
49951da177e4SLinus Torvalds {
49968687b63aSAl Viro 	__be32 *p;
49971da177e4SLinus Torvalds 	uint32_t limit_type, nblocks, blocksize;
49987d160a6cSTrond Myklebust 	u64 maxsize = 0;
49991da177e4SLinus Torvalds 
5000c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
5001c0eae66eSBenny Halevy 	if (unlikely(!p))
5002eb72f484SChuck Lever 		return -EIO;
50036f723f77SBenny Halevy 	limit_type = be32_to_cpup(p++);
50041da177e4SLinus Torvalds 	switch (limit_type) {
50057d160a6cSTrond Myklebust 	case NFS4_LIMIT_SIZE:
50067d160a6cSTrond Myklebust 		xdr_decode_hyper(p, &maxsize);
50071da177e4SLinus Torvalds 		break;
50087d160a6cSTrond Myklebust 	case NFS4_LIMIT_BLOCKS:
50096f723f77SBenny Halevy 		nblocks = be32_to_cpup(p++);
5010cccddf4fSBenny Halevy 		blocksize = be32_to_cpup(p);
50117d160a6cSTrond Myklebust 		maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
50121da177e4SLinus Torvalds 	}
501309cbfeafSKirill A. Shutemov 	maxsize >>= PAGE_SHIFT;
50147d160a6cSTrond Myklebust 	*pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
50151da177e4SLinus Torvalds 	return 0;
50161da177e4SLinus Torvalds }
50171da177e4SLinus Torvalds 
50186ae37339STrond Myklebust static int decode_rw_delegation(struct xdr_stream *xdr,
50196ae37339STrond Myklebust 		uint32_t delegation_type,
50206ae37339STrond Myklebust 		struct nfs_openres *res)
50211da177e4SLinus Torvalds {
50228687b63aSAl Viro 	__be32 *p;
502307d30434SBenny Halevy 	int status;
50241da177e4SLinus Torvalds 
502593b717fdSTrond Myklebust 	status = decode_delegation_stateid(xdr, &res->delegation);
502607d30434SBenny Halevy 	if (unlikely(status))
502707d30434SBenny Halevy 		return status;
5028c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5029c0eae66eSBenny Halevy 	if (unlikely(!p))
5030eb72f484SChuck Lever 		return -EIO;
5031cccddf4fSBenny Halevy 	res->do_recall = be32_to_cpup(p);
503205d564feSAndy Adamson 
50331da177e4SLinus Torvalds 	switch (delegation_type) {
50341da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_READ:
50351da177e4SLinus Torvalds 		res->delegation_type = FMODE_READ;
50361da177e4SLinus Torvalds 		break;
50371da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_WRITE:
50381da177e4SLinus Torvalds 		res->delegation_type = FMODE_WRITE|FMODE_READ;
50397d160a6cSTrond Myklebust 		if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
50401da177e4SLinus Torvalds 				return -EIO;
50411da177e4SLinus Torvalds 	}
50421bbe60ffSTrond Myklebust 	return decode_ace(xdr, NULL);
50431da177e4SLinus Torvalds }
50441da177e4SLinus Torvalds 
50456ae37339STrond Myklebust static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
50466ae37339STrond Myklebust {
50476ae37339STrond Myklebust 	__be32 *p;
50486ae37339STrond Myklebust 	uint32_t why_no_delegation;
50496ae37339STrond Myklebust 
50506ae37339STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
50516ae37339STrond Myklebust 	if (unlikely(!p))
5052eb72f484SChuck Lever 		return -EIO;
50536ae37339STrond Myklebust 	why_no_delegation = be32_to_cpup(p);
50546ae37339STrond Myklebust 	switch (why_no_delegation) {
50556ae37339STrond Myklebust 		case WND4_CONTENTION:
50566ae37339STrond Myklebust 		case WND4_RESOURCE:
50576ae37339STrond Myklebust 			xdr_inline_decode(xdr, 4);
50586ae37339STrond Myklebust 			/* Ignore for now */
50596ae37339STrond Myklebust 	}
50606ae37339STrond Myklebust 	return 0;
50616ae37339STrond Myklebust }
50626ae37339STrond Myklebust 
50636ae37339STrond Myklebust static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
50646ae37339STrond Myklebust {
50656ae37339STrond Myklebust 	__be32 *p;
50666ae37339STrond Myklebust 	uint32_t delegation_type;
50676ae37339STrond Myklebust 
50686ae37339STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
50696ae37339STrond Myklebust 	if (unlikely(!p))
5070eb72f484SChuck Lever 		return -EIO;
50716ae37339STrond Myklebust 	delegation_type = be32_to_cpup(p);
50726ae37339STrond Myklebust 	res->delegation_type = 0;
50736ae37339STrond Myklebust 	switch (delegation_type) {
50746ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_NONE:
50756ae37339STrond Myklebust 		return 0;
50766ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_READ:
50776ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_WRITE:
50786ae37339STrond Myklebust 		return decode_rw_delegation(xdr, delegation_type, res);
50796ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_NONE_EXT:
50806ae37339STrond Myklebust 		return decode_no_delegation(xdr, res);
50816ae37339STrond Myklebust 	}
50826ae37339STrond Myklebust 	return -EIO;
50836ae37339STrond Myklebust }
50846ae37339STrond Myklebust 
50851da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
50861da177e4SLinus Torvalds {
50878687b63aSAl Viro 	__be32 *p;
5088aa53ed54SJeff Layton 	uint32_t savewords, bmlen, i;
50891da177e4SLinus Torvalds 	int status;
50901da177e4SLinus Torvalds 
5091c7848f69STrond Myklebust 	if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5092c7848f69STrond Myklebust 		return status;
5093c1d51931STrond Myklebust 	nfs_increment_open_seqid(status, res->seqid);
5094c7848f69STrond Myklebust 	if (status)
5095c7848f69STrond Myklebust 		return status;
509693b717fdSTrond Myklebust 	status = decode_open_stateid(xdr, &res->stateid);
509707d30434SBenny Halevy 	if (unlikely(status))
50981da177e4SLinus Torvalds 		return status;
50991da177e4SLinus Torvalds 
51001da177e4SLinus Torvalds 	decode_change_info(xdr, &res->cinfo);
51011da177e4SLinus Torvalds 
5102c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5103c0eae66eSBenny Halevy 	if (unlikely(!p))
5104eb72f484SChuck Lever 		return -EIO;
51056f723f77SBenny Halevy 	res->rflags = be32_to_cpup(p++);
5106cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
51071da177e4SLinus Torvalds 	if (bmlen > 10)
51081da177e4SLinus Torvalds 		goto xdr_error;
51091da177e4SLinus Torvalds 
5110c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
5111c0eae66eSBenny Halevy 	if (unlikely(!p))
5112eb72f484SChuck Lever 		return -EIO;
5113aa53ed54SJeff Layton 	savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5114aa53ed54SJeff Layton 	for (i = 0; i < savewords; ++i)
51156f723f77SBenny Halevy 		res->attrset[i] = be32_to_cpup(p++);
5116aa53ed54SJeff Layton 	for (; i < NFS4_BITMAP_SIZE; i++)
5117aa53ed54SJeff Layton 		res->attrset[i] = 0;
5118aa53ed54SJeff Layton 
51191da177e4SLinus Torvalds 	return decode_delegation(xdr, res);
51201da177e4SLinus Torvalds xdr_error:
51213110ff80SHarvey Harrison 	dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
51221da177e4SLinus Torvalds 	return -EIO;
51231da177e4SLinus Torvalds }
51241da177e4SLinus Torvalds 
51251da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
51261da177e4SLinus Torvalds {
51271da177e4SLinus Torvalds 	int status;
51281da177e4SLinus Torvalds 
51291da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5130c1d51931STrond Myklebust 	if (status != -EIO)
5131c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
513207d30434SBenny Halevy 	if (!status)
513393b717fdSTrond Myklebust 		status = decode_open_stateid(xdr, &res->stateid);
51341da177e4SLinus Torvalds 	return status;
51351da177e4SLinus Torvalds }
51361da177e4SLinus Torvalds 
51371da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
51381da177e4SLinus Torvalds {
51391da177e4SLinus Torvalds 	int status;
51401da177e4SLinus Torvalds 
51411da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5142c1d51931STrond Myklebust 	if (status != -EIO)
5143c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
514407d30434SBenny Halevy 	if (!status)
514593b717fdSTrond Myklebust 		status = decode_open_stateid(xdr, &res->stateid);
51461da177e4SLinus Torvalds 	return status;
51471da177e4SLinus Torvalds }
51481da177e4SLinus Torvalds 
51491da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr)
51501da177e4SLinus Torvalds {
51511da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTFH);
51521da177e4SLinus Torvalds }
51531da177e4SLinus Torvalds 
51541da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr)
51551da177e4SLinus Torvalds {
51561da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTROOTFH);
51571da177e4SLinus Torvalds }
51581da177e4SLinus Torvalds 
51599137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
51609137bdf3SAnna Schumaker 		       struct nfs_pgio_res *res)
51611da177e4SLinus Torvalds {
51628687b63aSAl Viro 	__be32 *p;
516364bd577eSTrond Myklebust 	uint32_t count, eof, recvd;
51641da177e4SLinus Torvalds 	int status;
51651da177e4SLinus Torvalds 
51661da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READ);
51671da177e4SLinus Torvalds 	if (status)
51681da177e4SLinus Torvalds 		return status;
5169c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5170c0eae66eSBenny Halevy 	if (unlikely(!p))
5171eb72f484SChuck Lever 		return -EIO;
51726f723f77SBenny Halevy 	eof = be32_to_cpup(p++);
5173cccddf4fSBenny Halevy 	count = be32_to_cpup(p);
517464bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, count);
51751da177e4SLinus Torvalds 	if (count > recvd) {
5176fe82a183SChuck Lever 		dprintk("NFS: server cheating in read reply: "
51771da177e4SLinus Torvalds 				"count %u > recvd %u\n", count, recvd);
51781da177e4SLinus Torvalds 		count = recvd;
51791da177e4SLinus Torvalds 		eof = 0;
51801da177e4SLinus Torvalds 	}
51811da177e4SLinus Torvalds 	res->eof = eof;
51821da177e4SLinus Torvalds 	res->count = count;
51831da177e4SLinus Torvalds 	return 0;
51841da177e4SLinus Torvalds }
51851da177e4SLinus Torvalds 
51861da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
51871da177e4SLinus Torvalds {
5188bcecff77SChuck Lever 	int		status;
5189cd93710eSChuck Lever 	__be32		verf[2];
51901da177e4SLinus Torvalds 
51911da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READDIR);
5192db942bbdSBenny Halevy 	if (!status)
5193db942bbdSBenny Halevy 		status = decode_verifier(xdr, readdir->verifier.data);
5194db942bbdSBenny Halevy 	if (unlikely(status))
51951da177e4SLinus Torvalds 		return status;
5196cd93710eSChuck Lever 	memcpy(verf, readdir->verifier.data, sizeof(verf));
519744109241SFred Isaman 	dprintk("%s: verifier = %08x:%08x\n",
5198cd93710eSChuck Lever 			__func__, verf[0], verf[1]);
519964bd577eSTrond Myklebust 	return xdr_read_pages(xdr, xdr->buf->page_len);
52001da177e4SLinus Torvalds }
52011da177e4SLinus Torvalds 
52021da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
52031da177e4SLinus Torvalds {
52041da177e4SLinus Torvalds 	struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5205bcecff77SChuck Lever 	u32 len, recvd;
52068687b63aSAl Viro 	__be32 *p;
52071da177e4SLinus Torvalds 	int status;
52081da177e4SLinus Torvalds 
52091da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READLINK);
52101da177e4SLinus Torvalds 	if (status)
52111da177e4SLinus Torvalds 		return status;
52121da177e4SLinus Torvalds 
52131da177e4SLinus Torvalds 	/* Convert length of symlink */
5214c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5215c0eae66eSBenny Halevy 	if (unlikely(!p))
5216eb72f484SChuck Lever 		return -EIO;
5217cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
52181da177e4SLinus Torvalds 	if (len >= rcvbuf->page_len || len <= 0) {
5219fe82a183SChuck Lever 		dprintk("nfs: server returned giant symlink!\n");
52201da177e4SLinus Torvalds 		return -ENAMETOOLONG;
52211da177e4SLinus Torvalds 	}
522264bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, len);
52231da177e4SLinus Torvalds 	if (recvd < len) {
5224fe82a183SChuck Lever 		dprintk("NFS: server cheating in readlink reply: "
52251da177e4SLinus Torvalds 				"count %u > recvd %u\n", len, recvd);
52261da177e4SLinus Torvalds 		return -EIO;
52271da177e4SLinus Torvalds 	}
52281da177e4SLinus Torvalds 	/*
52291da177e4SLinus Torvalds 	 * The XDR encode routine has set things up so that
52301da177e4SLinus Torvalds 	 * the link text will be copied directly into the
52311da177e4SLinus Torvalds 	 * buffer.  We just have to do overflow-checking,
52321da177e4SLinus Torvalds 	 * and and null-terminate the text (the VFS expects
52331da177e4SLinus Torvalds 	 * null-termination).
52341da177e4SLinus Torvalds 	 */
5235b4687da7SChuck Lever 	xdr_terminate_string(rcvbuf, len);
52361da177e4SLinus Torvalds 	return 0;
52371da177e4SLinus Torvalds }
52381da177e4SLinus Torvalds 
52391da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
52401da177e4SLinus Torvalds {
52411da177e4SLinus Torvalds 	int status;
52421da177e4SLinus Torvalds 
52431da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_REMOVE);
52441da177e4SLinus Torvalds 	if (status)
52451da177e4SLinus Torvalds 		goto out;
52461da177e4SLinus Torvalds 	status = decode_change_info(xdr, cinfo);
52471da177e4SLinus Torvalds out:
52481da177e4SLinus Torvalds 	return status;
52491da177e4SLinus Torvalds }
52501da177e4SLinus Torvalds 
52511da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
52521da177e4SLinus Torvalds 	      struct nfs4_change_info *new_cinfo)
52531da177e4SLinus Torvalds {
52541da177e4SLinus Torvalds 	int status;
52551da177e4SLinus Torvalds 
52561da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_RENAME);
52571da177e4SLinus Torvalds 	if (status)
52581da177e4SLinus Torvalds 		goto out;
52591da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, old_cinfo)))
52601da177e4SLinus Torvalds 		goto out;
52611da177e4SLinus Torvalds 	status = decode_change_info(xdr, new_cinfo);
52621da177e4SLinus Torvalds out:
52631da177e4SLinus Torvalds 	return status;
52641da177e4SLinus Torvalds }
52651da177e4SLinus Torvalds 
52661da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr)
52671da177e4SLinus Torvalds {
52681da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_RENEW);
52691da177e4SLinus Torvalds }
52701da177e4SLinus Torvalds 
527156ae19f3STrond Myklebust static int
527256ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr)
527356ae19f3STrond Myklebust {
527456ae19f3STrond Myklebust 	return decode_op_hdr(xdr, OP_RESTOREFH);
527556ae19f3STrond Myklebust }
527656ae19f3STrond Myklebust 
5277029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5278bf118a34SAndy Adamson 			 struct nfs_getaclres *res)
5279029d105eSJ. Bruce Fields {
5280256e48bbSTrond Myklebust 	unsigned int savep;
5281029d105eSJ. Bruce Fields 	uint32_t attrlen,
5282dae100c2SFred Isaman 		 bitmap[3] = {0};
5283029d105eSJ. Bruce Fields 	int status;
5284cff298c7STrond Myklebust 	unsigned int pg_offset;
5285029d105eSJ. Bruce Fields 
5286bf118a34SAndy Adamson 	res->acl_len = 0;
5287029d105eSJ. Bruce Fields 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5288029d105eSJ. Bruce Fields 		goto out;
52895a006899SSachin Prabhu 
5290519d3959STrond Myklebust 	xdr_enter_page(xdr, xdr->buf->page_len);
5291519d3959STrond Myklebust 
5292cff298c7STrond Myklebust 	/* Calculate the offset of the page data */
5293cff298c7STrond Myklebust 	pg_offset = xdr->buf->head[0].iov_len;
52945a006899SSachin Prabhu 
5295029d105eSJ. Bruce Fields 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5296029d105eSJ. Bruce Fields 		goto out;
5297029d105eSJ. Bruce Fields 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5298029d105eSJ. Bruce Fields 		goto out;
5299029d105eSJ. Bruce Fields 
5300029d105eSJ. Bruce Fields 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5301029d105eSJ. Bruce Fields 		return -EIO;
5302029d105eSJ. Bruce Fields 	if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5303029d105eSJ. Bruce Fields 
5304bf118a34SAndy Adamson 		/* The bitmap (xdr len + bitmaps) and the attr xdr len words
5305bf118a34SAndy Adamson 		 * are stored with the acl data to handle the problem of
5306bf118a34SAndy Adamson 		 * variable length bitmaps.*/
5307cff298c7STrond Myklebust 		res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
5308519d3959STrond Myklebust 		res->acl_len = attrlen;
53091f1ea6c2STrond Myklebust 
53101f1ea6c2STrond Myklebust 		/* Check for receive buffer overflow */
53111f1ea6c2STrond Myklebust 		if (res->acl_len > (xdr->nwords << 2) ||
53121f1ea6c2STrond Myklebust 		    res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
53131f1ea6c2STrond Myklebust 			res->acl_flags |= NFS4_ACL_TRUNC;
5314519d3959STrond Myklebust 			dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5315cff298c7STrond Myklebust 					attrlen, xdr->nwords << 2);
5316029d105eSJ. Bruce Fields 		}
53178c233cf9SJ. Bruce Fields 	} else
53188c233cf9SJ. Bruce Fields 		status = -EOPNOTSUPP;
5319029d105eSJ. Bruce Fields 
5320029d105eSJ. Bruce Fields out:
5321029d105eSJ. Bruce Fields 	return status;
5322029d105eSJ. Bruce Fields }
5323029d105eSJ. Bruce Fields 
53241da177e4SLinus Torvalds static int
53251da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr)
53261da177e4SLinus Torvalds {
53271da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SAVEFH);
53281da177e4SLinus Torvalds }
53291da177e4SLinus Torvalds 
53309e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr)
53311da177e4SLinus Torvalds {
53321da177e4SLinus Torvalds 	int status;
53331da177e4SLinus Torvalds 
53341da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_SETATTR);
53351da177e4SLinus Torvalds 	if (status)
53361da177e4SLinus Torvalds 		return status;
533737c88763STrond Myklebust 	if (decode_bitmap4(xdr, NULL, 0) >= 0)
53381da177e4SLinus Torvalds 		return 0;
5339c0eae66eSBenny Halevy 	return -EIO;
53401da177e4SLinus Torvalds }
53411da177e4SLinus Torvalds 
5342bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
53431da177e4SLinus Torvalds {
53448687b63aSAl Viro 	__be32 *p;
53451da177e4SLinus Torvalds 	uint32_t opnum;
53461da177e4SLinus Torvalds 	int32_t nfserr;
53471da177e4SLinus Torvalds 
5348c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5349c0eae66eSBenny Halevy 	if (unlikely(!p))
5350eb72f484SChuck Lever 		return -EIO;
53516f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
53521da177e4SLinus Torvalds 	if (opnum != OP_SETCLIENTID) {
5353fe82a183SChuck Lever 		dprintk("nfs: decode_setclientid: Server returned operation"
53541da177e4SLinus Torvalds 			" %d\n", opnum);
53551da177e4SLinus Torvalds 		return -EIO;
53561da177e4SLinus Torvalds 	}
5357cccddf4fSBenny Halevy 	nfserr = be32_to_cpup(p);
53581da177e4SLinus Torvalds 	if (nfserr == NFS_OK) {
5359c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5360c0eae66eSBenny Halevy 		if (unlikely(!p))
5361eb72f484SChuck Lever 			return -EIO;
5362bb8b27e5STrond Myklebust 		p = xdr_decode_hyper(p, &res->clientid);
5363bb8b27e5STrond Myklebust 		memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
53641da177e4SLinus Torvalds 	} else if (nfserr == NFSERR_CLID_INUSE) {
53651da177e4SLinus Torvalds 		uint32_t len;
53661da177e4SLinus Torvalds 
53671da177e4SLinus Torvalds 		/* skip netid string */
5368c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5369c0eae66eSBenny Halevy 		if (unlikely(!p))
5370eb72f484SChuck Lever 			return -EIO;
5371cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5372c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5373c0eae66eSBenny Halevy 		if (unlikely(!p))
5374eb72f484SChuck Lever 			return -EIO;
53751da177e4SLinus Torvalds 
53761da177e4SLinus Torvalds 		/* skip uaddr string */
5377c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5378c0eae66eSBenny Halevy 		if (unlikely(!p))
5379eb72f484SChuck Lever 			return -EIO;
5380cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5381c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5382c0eae66eSBenny Halevy 		if (unlikely(!p))
5383eb72f484SChuck Lever 			return -EIO;
53841da177e4SLinus Torvalds 		return -NFSERR_CLID_INUSE;
53851da177e4SLinus Torvalds 	} else
5386856dff3dSBenny Halevy 		return nfs4_stat_to_errno(nfserr);
53871da177e4SLinus Torvalds 
53881da177e4SLinus Torvalds 	return 0;
53891da177e4SLinus Torvalds }
53901da177e4SLinus Torvalds 
53911da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr)
53921da177e4SLinus Torvalds {
53931da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
53941da177e4SLinus Torvalds }
53951da177e4SLinus Torvalds 
53969137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
53971da177e4SLinus Torvalds {
53988687b63aSAl Viro 	__be32 *p;
53991da177e4SLinus Torvalds 	int status;
54001da177e4SLinus Torvalds 
54011da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_WRITE);
54021da177e4SLinus Torvalds 	if (status)
54031da177e4SLinus Torvalds 		return status;
54041da177e4SLinus Torvalds 
54052f2c63bcSTrond Myklebust 	p = xdr_inline_decode(xdr, 8);
5406c0eae66eSBenny Halevy 	if (unlikely(!p))
5407eb72f484SChuck Lever 		return -EIO;
54086f723f77SBenny Halevy 	res->count = be32_to_cpup(p++);
54096f723f77SBenny Halevy 	res->verf->committed = be32_to_cpup(p++);
54102f2c63bcSTrond Myklebust 	return decode_write_verifier(xdr, &res->verf->verifier);
54111da177e4SLinus Torvalds }
54121da177e4SLinus Torvalds 
54131da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr)
54141da177e4SLinus Torvalds {
54151da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_DELEGRETURN);
54161da177e4SLinus Torvalds }
54171da177e4SLinus Torvalds 
5418fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr,
5419fb15b26fSChuck Lever 			      struct nfs4_secinfo4 *flavor)
54205a5ea0d4SBryan Schumaker {
5421fb15b26fSChuck Lever 	u32 oid_len;
54225a5ea0d4SBryan Schumaker 	__be32 *p;
54235a5ea0d4SBryan Schumaker 
54245a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
54255a5ea0d4SBryan Schumaker 	if (unlikely(!p))
5426eb72f484SChuck Lever 		return -EIO;
5427fb15b26fSChuck Lever 	oid_len = be32_to_cpup(p);
5428fb15b26fSChuck Lever 	if (oid_len > GSS_OID_MAX_LEN)
5429eb72f484SChuck Lever 		return -EINVAL;
54305a5ea0d4SBryan Schumaker 
5431fb15b26fSChuck Lever 	p = xdr_inline_decode(xdr, oid_len);
54325a5ea0d4SBryan Schumaker 	if (unlikely(!p))
5433eb72f484SChuck Lever 		return -EIO;
5434fb15b26fSChuck Lever 	memcpy(flavor->flavor_info.oid.data, p, oid_len);
5435fb15b26fSChuck Lever 	flavor->flavor_info.oid.len = oid_len;
54365a5ea0d4SBryan Schumaker 
54375a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 8);
54385a5ea0d4SBryan Schumaker 	if (unlikely(!p))
5439eb72f484SChuck Lever 		return -EIO;
5440fb15b26fSChuck Lever 	flavor->flavor_info.qop = be32_to_cpup(p++);
5441fb15b26fSChuck Lever 	flavor->flavor_info.service = be32_to_cpup(p);
54425a5ea0d4SBryan Schumaker 
54435a5ea0d4SBryan Schumaker 	return 0;
54445a5ea0d4SBryan Schumaker }
54455a5ea0d4SBryan Schumaker 
544631e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
54475a5ea0d4SBryan Schumaker {
5448fb15b26fSChuck Lever 	struct nfs4_secinfo4 *sec_flavor;
5449fb15b26fSChuck Lever 	unsigned int i, num_flavors;
54505a5ea0d4SBryan Schumaker 	int status;
54515a5ea0d4SBryan Schumaker 	__be32 *p;
54525a5ea0d4SBryan Schumaker 
54535a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
54545a5ea0d4SBryan Schumaker 	if (unlikely(!p))
5455eb72f484SChuck Lever 		return -EIO;
54565a5ea0d4SBryan Schumaker 
5457c3dfc280SBryan Schumaker 	res->flavors->num_flavors = 0;
5458c3dfc280SBryan Schumaker 	num_flavors = be32_to_cpup(p);
5459c3dfc280SBryan Schumaker 
5460c3dfc280SBryan Schumaker 	for (i = 0; i < num_flavors; i++) {
54615a5ea0d4SBryan Schumaker 		sec_flavor = &res->flavors->flavors[i];
5462c3dfc280SBryan Schumaker 		if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
54635a5ea0d4SBryan Schumaker 			break;
54645a5ea0d4SBryan Schumaker 
54655a5ea0d4SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
54665a5ea0d4SBryan Schumaker 		if (unlikely(!p))
5467eb72f484SChuck Lever 			return -EIO;
54685a5ea0d4SBryan Schumaker 		sec_flavor->flavor = be32_to_cpup(p);
54695a5ea0d4SBryan Schumaker 
54705a5ea0d4SBryan Schumaker 		if (sec_flavor->flavor == RPC_AUTH_GSS) {
5471613e901eSBryan Schumaker 			status = decode_secinfo_gss(xdr, sec_flavor);
5472613e901eSBryan Schumaker 			if (status)
5473613e901eSBryan Schumaker 				goto out;
54745a5ea0d4SBryan Schumaker 		}
5475c3dfc280SBryan Schumaker 		res->flavors->num_flavors++;
54765a5ea0d4SBryan Schumaker 	}
54775a5ea0d4SBryan Schumaker 
547831e4dda4SBryan Schumaker 	status = 0;
5479613e901eSBryan Schumaker out:
5480613e901eSBryan Schumaker 	return status;
54815a5ea0d4SBryan Schumaker }
54825a5ea0d4SBryan Schumaker 
548331e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
548431e4dda4SBryan Schumaker {
548531e4dda4SBryan Schumaker 	int status = decode_op_hdr(xdr, OP_SECINFO);
548631e4dda4SBryan Schumaker 	if (status)
548731e4dda4SBryan Schumaker 		return status;
548831e4dda4SBryan Schumaker 	return decode_secinfo_common(xdr, res);
548931e4dda4SBryan Schumaker }
549031e4dda4SBryan Schumaker 
549199fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
549231e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
549331e4dda4SBryan Schumaker {
549431e4dda4SBryan Schumaker 	int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
549531e4dda4SBryan Schumaker 	if (status)
549631e4dda4SBryan Schumaker 		return status;
549731e4dda4SBryan Schumaker 	return decode_secinfo_common(xdr, res);
549831e4dda4SBryan Schumaker }
549931e4dda4SBryan Schumaker 
55002031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
55012031cd1aSWeston Andros Adamson {
55022031cd1aSWeston Andros Adamson 	__be32 *p;
55032031cd1aSWeston Andros Adamson 	uint32_t bitmap_words;
55042031cd1aSWeston Andros Adamson 	unsigned int i;
55052031cd1aSWeston Andros Adamson 
55062031cd1aSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4);
55074edabfd7SPan Bian 	if (!p)
55084edabfd7SPan Bian 		return -EIO;
55092031cd1aSWeston Andros Adamson 	bitmap_words = be32_to_cpup(p++);
55102031cd1aSWeston Andros Adamson 	if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
55112031cd1aSWeston Andros Adamson 		return -EIO;
55122031cd1aSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4 * bitmap_words);
55132031cd1aSWeston Andros Adamson 	for (i = 0; i < bitmap_words; i++)
55142031cd1aSWeston Andros Adamson 		op_map->u.words[i] = be32_to_cpup(p++);
55152031cd1aSWeston Andros Adamson 
55162031cd1aSWeston Andros Adamson 	return 0;
55172031cd1aSWeston Andros Adamson }
55182031cd1aSWeston Andros Adamson 
551999fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr,
552099fe60d0SBenny Halevy 			      struct nfs41_exchange_id_res *res)
552199fe60d0SBenny Halevy {
552299fe60d0SBenny Halevy 	__be32 *p;
552399fe60d0SBenny Halevy 	uint32_t dummy;
55242460ba57SBenny Halevy 	char *dummy_str;
552599fe60d0SBenny Halevy 	int status;
55267d2ed9acSWeston Andros Adamson 	uint32_t impl_id_count;
552799fe60d0SBenny Halevy 
552899fe60d0SBenny Halevy 	status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
552999fe60d0SBenny Halevy 	if (status)
553099fe60d0SBenny Halevy 		return status;
553199fe60d0SBenny Halevy 
5532c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5533c0eae66eSBenny Halevy 	if (unlikely(!p))
5534eb72f484SChuck Lever 		return -EIO;
553532b01310STrond Myklebust 	xdr_decode_hyper(p, &res->clientid);
5536c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
5537c0eae66eSBenny Halevy 	if (unlikely(!p))
5538eb72f484SChuck Lever 		return -EIO;
553932b01310STrond Myklebust 	res->seqid = be32_to_cpup(p++);
554032b01310STrond Myklebust 	res->flags = be32_to_cpup(p++);
554199fe60d0SBenny Halevy 
55422031cd1aSWeston Andros Adamson 	res->state_protect.how = be32_to_cpup(p);
55432031cd1aSWeston Andros Adamson 	switch (res->state_protect.how) {
55442031cd1aSWeston Andros Adamson 	case SP4_NONE:
55452031cd1aSWeston Andros Adamson 		break;
55462031cd1aSWeston Andros Adamson 	case SP4_MACH_CRED:
55472031cd1aSWeston Andros Adamson 		status = decode_op_map(xdr, &res->state_protect.enforce);
55482031cd1aSWeston Andros Adamson 		if (status)
55492031cd1aSWeston Andros Adamson 			return status;
55502031cd1aSWeston Andros Adamson 		status = decode_op_map(xdr, &res->state_protect.allow);
55512031cd1aSWeston Andros Adamson 		if (status)
55522031cd1aSWeston Andros Adamson 			return status;
55532031cd1aSWeston Andros Adamson 		break;
55542031cd1aSWeston Andros Adamson 	default:
55552031cd1aSWeston Andros Adamson 		WARN_ON_ONCE(1);
555699fe60d0SBenny Halevy 		return -EIO;
55572031cd1aSWeston Andros Adamson 	}
555899fe60d0SBenny Halevy 
5559acdeb69dSChuck Lever 	/* server_owner4.so_minor_id */
5560c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5561c0eae66eSBenny Halevy 	if (unlikely(!p))
5562eb72f484SChuck Lever 		return -EIO;
5563acdeb69dSChuck Lever 	p = xdr_decode_hyper(p, &res->server_owner->minor_id);
556499fe60d0SBenny Halevy 
5565acdeb69dSChuck Lever 	/* server_owner4.so_major_id */
55662460ba57SBenny Halevy 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
55672460ba57SBenny Halevy 	if (unlikely(status))
55682460ba57SBenny Halevy 		return status;
5569acdeb69dSChuck Lever 	memcpy(res->server_owner->major_id, dummy_str, dummy);
5570acdeb69dSChuck Lever 	res->server_owner->major_id_sz = dummy;
557178fe0f41SWeston Andros Adamson 
5572acdeb69dSChuck Lever 	/* server_scope4 */
5573acdeb69dSChuck Lever 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5574acdeb69dSChuck Lever 	if (unlikely(status))
5575acdeb69dSChuck Lever 		return status;
557678fe0f41SWeston Andros Adamson 	memcpy(res->server_scope->server_scope, dummy_str, dummy);
557778fe0f41SWeston Andros Adamson 	res->server_scope->server_scope_sz = dummy;
557878fe0f41SWeston Andros Adamson 
55797d2ed9acSWeston Andros Adamson 	/* Implementation Id */
55807d2ed9acSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4);
55817d2ed9acSWeston Andros Adamson 	if (unlikely(!p))
5582eb72f484SChuck Lever 		return -EIO;
55837d2ed9acSWeston Andros Adamson 	impl_id_count = be32_to_cpup(p++);
55847d2ed9acSWeston Andros Adamson 
55857d2ed9acSWeston Andros Adamson 	if (impl_id_count) {
55867d2ed9acSWeston Andros Adamson 		/* nii_domain */
55872460ba57SBenny Halevy 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
55882460ba57SBenny Halevy 		if (unlikely(status))
55892460ba57SBenny Halevy 			return status;
55907d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->domain, dummy_str, dummy);
559199fe60d0SBenny Halevy 
55927d2ed9acSWeston Andros Adamson 		/* nii_name */
55937d2ed9acSWeston Andros Adamson 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
55947d2ed9acSWeston Andros Adamson 		if (unlikely(status))
55957d2ed9acSWeston Andros Adamson 			return status;
55967d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->name, dummy_str, dummy);
55977d2ed9acSWeston Andros Adamson 
55987d2ed9acSWeston Andros Adamson 		/* nii_date */
55997d2ed9acSWeston Andros Adamson 		p = xdr_inline_decode(xdr, 12);
56007d2ed9acSWeston Andros Adamson 		if (unlikely(!p))
5601eb72f484SChuck Lever 			return -EIO;
56027d2ed9acSWeston Andros Adamson 		p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
56037d2ed9acSWeston Andros Adamson 		res->impl_id->date.nseconds = be32_to_cpup(p);
56047d2ed9acSWeston Andros Adamson 
56057d2ed9acSWeston Andros Adamson 		/* if there's more than one entry, ignore the rest */
56067d2ed9acSWeston Andros Adamson 	}
560799fe60d0SBenny Halevy 	return 0;
560899fe60d0SBenny Halevy }
5609fc931582SAndy Adamson 
5610fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr,
5611fc931582SAndy Adamson 			     struct nfs4_channel_attrs *attrs)
5612fc931582SAndy Adamson {
5613fc931582SAndy Adamson 	__be32 *p;
5614c9c30dd5SBenny Halevy 	u32 nr_attrs, val;
5615fc931582SAndy Adamson 
5616c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 28);
5617c0eae66eSBenny Halevy 	if (unlikely(!p))
5618eb72f484SChuck Lever 		return -EIO;
5619c9c30dd5SBenny Halevy 	val = be32_to_cpup(p++);	/* headerpadsz */
5620c9c30dd5SBenny Halevy 	if (val)
5621c9c30dd5SBenny Halevy 		return -EINVAL;		/* no support for header padding yet */
56226f723f77SBenny Halevy 	attrs->max_rqst_sz = be32_to_cpup(p++);
56236f723f77SBenny Halevy 	attrs->max_resp_sz = be32_to_cpup(p++);
56246f723f77SBenny Halevy 	attrs->max_resp_sz_cached = be32_to_cpup(p++);
56256f723f77SBenny Halevy 	attrs->max_ops = be32_to_cpup(p++);
56266f723f77SBenny Halevy 	attrs->max_reqs = be32_to_cpup(p++);
5627cccddf4fSBenny Halevy 	nr_attrs = be32_to_cpup(p);
5628fc931582SAndy Adamson 	if (unlikely(nr_attrs > 1)) {
5629a030889aSWeston Andros Adamson 		printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5630a030889aSWeston Andros Adamson 			"count %u\n", __func__, nr_attrs);
5631fc931582SAndy Adamson 		return -EINVAL;
5632fc931582SAndy Adamson 	}
5633c0eae66eSBenny Halevy 	if (nr_attrs == 1) {
5634c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5635c0eae66eSBenny Halevy 		if (unlikely(!p))
5636eb72f484SChuck Lever 			return -EIO;
5637c0eae66eSBenny Halevy 	}
5638fc931582SAndy Adamson 	return 0;
5639fc931582SAndy Adamson }
5640fc931582SAndy Adamson 
5641e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5642e78291e4SBenny Halevy {
5643e78291e4SBenny Halevy 	return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5644fc931582SAndy Adamson }
5645fc931582SAndy Adamson 
56467c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr,
56477c44f1aeSWeston Andros Adamson 				struct nfs41_bind_conn_to_session_res *res)
56487c44f1aeSWeston Andros Adamson {
56497c44f1aeSWeston Andros Adamson 	__be32 *p;
56507c44f1aeSWeston Andros Adamson 	int status;
56517c44f1aeSWeston Andros Adamson 
56527c44f1aeSWeston Andros Adamson 	status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
56537c44f1aeSWeston Andros Adamson 	if (!status)
565471a097c6STrond Myklebust 		status = decode_sessionid(xdr, &res->sessionid);
56557c44f1aeSWeston Andros Adamson 	if (unlikely(status))
56567c44f1aeSWeston Andros Adamson 		return status;
56577c44f1aeSWeston Andros Adamson 
56587c44f1aeSWeston Andros Adamson 	/* dir flags, rdma mode bool */
56597c44f1aeSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 8);
56607c44f1aeSWeston Andros Adamson 	if (unlikely(!p))
5661eb72f484SChuck Lever 		return -EIO;
56627c44f1aeSWeston Andros Adamson 
56637c44f1aeSWeston Andros Adamson 	res->dir = be32_to_cpup(p++);
56647c44f1aeSWeston Andros Adamson 	if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
56657c44f1aeSWeston Andros Adamson 		return -EIO;
56667c44f1aeSWeston Andros Adamson 	if (be32_to_cpup(p) == 0)
56677c44f1aeSWeston Andros Adamson 		res->use_conn_in_rdma_mode = false;
56687c44f1aeSWeston Andros Adamson 	else
56697c44f1aeSWeston Andros Adamson 		res->use_conn_in_rdma_mode = true;
56707c44f1aeSWeston Andros Adamson 
56717c44f1aeSWeston Andros Adamson 	return 0;
56727c44f1aeSWeston Andros Adamson }
56737c44f1aeSWeston Andros Adamson 
5674fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr,
5675fc931582SAndy Adamson 				 struct nfs41_create_session_res *res)
5676fc931582SAndy Adamson {
5677fc931582SAndy Adamson 	__be32 *p;
5678fc931582SAndy Adamson 	int status;
5679fc931582SAndy Adamson 
5680fc931582SAndy Adamson 	status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5681e78291e4SBenny Halevy 	if (!status)
568279969dd1STrond Myklebust 		status = decode_sessionid(xdr, &res->sessionid);
5683e78291e4SBenny Halevy 	if (unlikely(status))
5684fc931582SAndy Adamson 		return status;
5685fc931582SAndy Adamson 
5686fc931582SAndy Adamson 	/* seqid, flags */
5687c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5688c0eae66eSBenny Halevy 	if (unlikely(!p))
5689eb72f484SChuck Lever 		return -EIO;
569079969dd1STrond Myklebust 	res->seqid = be32_to_cpup(p++);
569179969dd1STrond Myklebust 	res->flags = be32_to_cpup(p);
5692fc931582SAndy Adamson 
5693fc931582SAndy Adamson 	/* Channel attributes */
569479969dd1STrond Myklebust 	status = decode_chan_attrs(xdr, &res->fc_attrs);
5695fc931582SAndy Adamson 	if (!status)
569679969dd1STrond Myklebust 		status = decode_chan_attrs(xdr, &res->bc_attrs);
5697fc931582SAndy Adamson 	return status;
5698fc931582SAndy Adamson }
56990f3e66c6SAndy Adamson 
57000f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
57010f3e66c6SAndy Adamson {
57020f3e66c6SAndy Adamson 	return decode_op_hdr(xdr, OP_DESTROY_SESSION);
57030f3e66c6SAndy Adamson }
570418019753SRicardo Labiaga 
570566245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
570666245539STrond Myklebust {
570766245539STrond Myklebust 	return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
570866245539STrond Myklebust }
570966245539STrond Myklebust 
571018019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
571118019753SRicardo Labiaga {
571218019753SRicardo Labiaga 	return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
571318019753SRicardo Labiaga }
571499fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
571599fe60d0SBenny Halevy 
57169b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr,
57179b7b9fccSAndy Adamson 			   struct nfs4_sequence_res *res,
57189b7b9fccSAndy Adamson 			   struct rpc_rqst *rqstp)
57199b7b9fccSAndy Adamson {
57209b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
5721e3725ec0STrond Myklebust 	struct nfs4_session *session;
5722fc01cea9SAndy Adamson 	struct nfs4_sessionid id;
5723fc01cea9SAndy Adamson 	u32 dummy;
5724fc01cea9SAndy Adamson 	int status;
5725fc01cea9SAndy Adamson 	__be32 *p;
5726fc01cea9SAndy Adamson 
5727e3725ec0STrond Myklebust 	if (res->sr_slot == NULL)
57289b7b9fccSAndy Adamson 		return 0;
57293bd2384aSChuck Lever 	if (!res->sr_slot->table->session)
57303bd2384aSChuck Lever 		return 0;
57319b7b9fccSAndy Adamson 
5732fc01cea9SAndy Adamson 	status = decode_op_hdr(xdr, OP_SEQUENCE);
5733e78291e4SBenny Halevy 	if (!status)
5734e78291e4SBenny Halevy 		status = decode_sessionid(xdr, &id);
5735e78291e4SBenny Halevy 	if (unlikely(status))
5736fc01cea9SAndy Adamson 		goto out_err;
57379b7b9fccSAndy Adamson 
5738fc01cea9SAndy Adamson 	/*
5739fc01cea9SAndy Adamson 	 * If the server returns different values for sessionID, slotID or
5740fc01cea9SAndy Adamson 	 * sequence number, the server is looney tunes.
5741fc01cea9SAndy Adamson 	 */
5742fdcb4577STrond Myklebust 	status = -EREMOTEIO;
5743e3725ec0STrond Myklebust 	session = res->sr_slot->table->session;
5744fc01cea9SAndy Adamson 
5745e3725ec0STrond Myklebust 	if (memcmp(id.data, session->sess_id.data,
5746fc01cea9SAndy Adamson 		   NFS4_MAX_SESSIONID_LEN)) {
5747fc01cea9SAndy Adamson 		dprintk("%s Invalid session id\n", __func__);
5748fc01cea9SAndy Adamson 		goto out_err;
5749fc01cea9SAndy Adamson 	}
5750e78291e4SBenny Halevy 
5751c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
5752c0eae66eSBenny Halevy 	if (unlikely(!p))
5753c0eae66eSBenny Halevy 		goto out_overflow;
5754e78291e4SBenny Halevy 
5755fc01cea9SAndy Adamson 	/* seqid */
57566f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5757dfb4f309SBenny Halevy 	if (dummy != res->sr_slot->seq_nr) {
5758fc01cea9SAndy Adamson 		dprintk("%s Invalid sequence number\n", __func__);
5759fc01cea9SAndy Adamson 		goto out_err;
5760fc01cea9SAndy Adamson 	}
5761fc01cea9SAndy Adamson 	/* slot id */
57626f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5763df2fabffSTrond Myklebust 	if (dummy != res->sr_slot->slot_nr) {
5764fc01cea9SAndy Adamson 		dprintk("%s Invalid slot id\n", __func__);
5765fc01cea9SAndy Adamson 		goto out_err;
5766fc01cea9SAndy Adamson 	}
5767da0507b7STrond Myklebust 	/* highest slot id */
5768da0507b7STrond Myklebust 	res->sr_highest_slotid = be32_to_cpup(p++);
5769464ee9f9STrond Myklebust 	/* target highest slot id */
5770464ee9f9STrond Myklebust 	res->sr_target_highest_slotid = be32_to_cpup(p++);
57710629e370SAlexandros Batsakis 	/* result flags */
57720629e370SAlexandros Batsakis 	res->sr_status_flags = be32_to_cpup(p);
5773fc01cea9SAndy Adamson 	status = 0;
5774fc01cea9SAndy Adamson out_err:
5775fc01cea9SAndy Adamson 	res->sr_status = status;
5776fc01cea9SAndy Adamson 	return status;
5777c0eae66eSBenny Halevy out_overflow:
5778c0eae66eSBenny Halevy 	status = -EIO;
5779c0eae66eSBenny Halevy 	goto out_err;
5780fc01cea9SAndy Adamson #else  /* CONFIG_NFS_V4_1 */
57819b7b9fccSAndy Adamson 	return 0;
5782fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
57839b7b9fccSAndy Adamson }
57849b7b9fccSAndy Adamson 
5785b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1)
578693b717fdSTrond Myklebust static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
578793b717fdSTrond Myklebust {
578893b717fdSTrond Myklebust 	stateid->type = NFS4_LAYOUT_STATEID_TYPE;
578993b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
579093b717fdSTrond Myklebust }
579193b717fdSTrond Myklebust 
5792b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr,
57934e590803STrond Myklebust 				struct nfs4_getdeviceinfo_res *res)
5794b1f69b75SAndy Adamson {
57954e590803STrond Myklebust 	struct pnfs_device *pdev = res->pdev;
5796b1f69b75SAndy Adamson 	__be32 *p;
5797b1f69b75SAndy Adamson 	uint32_t len, type;
5798b1f69b75SAndy Adamson 	int status;
5799b1f69b75SAndy Adamson 
5800b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5801b1f69b75SAndy Adamson 	if (status) {
5802b1f69b75SAndy Adamson 		if (status == -ETOOSMALL) {
5803b1f69b75SAndy Adamson 			p = xdr_inline_decode(xdr, 4);
5804b1f69b75SAndy Adamson 			if (unlikely(!p))
5805eb72f484SChuck Lever 				return -EIO;
5806b1f69b75SAndy Adamson 			pdev->mincount = be32_to_cpup(p);
5807b1f69b75SAndy Adamson 			dprintk("%s: Min count too small. mincnt = %u\n",
5808b1f69b75SAndy Adamson 				__func__, pdev->mincount);
5809b1f69b75SAndy Adamson 		}
5810b1f69b75SAndy Adamson 		return status;
5811b1f69b75SAndy Adamson 	}
5812b1f69b75SAndy Adamson 
5813b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 8);
5814b1f69b75SAndy Adamson 	if (unlikely(!p))
5815eb72f484SChuck Lever 		return -EIO;
5816b1f69b75SAndy Adamson 	type = be32_to_cpup(p++);
5817b1f69b75SAndy Adamson 	if (type != pdev->layout_type) {
5818b1f69b75SAndy Adamson 		dprintk("%s: layout mismatch req: %u pdev: %u\n",
5819b1f69b75SAndy Adamson 			__func__, pdev->layout_type, type);
5820b1f69b75SAndy Adamson 		return -EINVAL;
5821b1f69b75SAndy Adamson 	}
5822b1f69b75SAndy Adamson 	/*
5823b1f69b75SAndy Adamson 	 * Get the length of the opaque device_addr4. xdr_read_pages places
5824b1f69b75SAndy Adamson 	 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5825b1f69b75SAndy Adamson 	 * and places the remaining xdr data in xdr_buf->tail
5826b1f69b75SAndy Adamson 	 */
5827b1f69b75SAndy Adamson 	pdev->mincount = be32_to_cpup(p);
582813fe4ba1STrond Myklebust 	if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5829eb72f484SChuck Lever 		return -EIO;
5830b1f69b75SAndy Adamson 
5831b1f69b75SAndy Adamson 	/* Parse notification bitmap, verifying that it is zero. */
5832b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 4);
5833b1f69b75SAndy Adamson 	if (unlikely(!p))
5834eb72f484SChuck Lever 		return -EIO;
5835b1f69b75SAndy Adamson 	len = be32_to_cpup(p);
5836b1f69b75SAndy Adamson 	if (len) {
5837ead00597SChuck Lever 		uint32_t i;
5838b1f69b75SAndy Adamson 
5839b1f69b75SAndy Adamson 		p = xdr_inline_decode(xdr, 4 * len);
5840b1f69b75SAndy Adamson 		if (unlikely(!p))
5841eb72f484SChuck Lever 			return -EIO;
584284c9dee3SChristoph Hellwig 
58434e590803STrond Myklebust 		res->notification = be32_to_cpup(p++);
584484c9dee3SChristoph Hellwig 		for (i = 1; i < len; i++) {
584584c9dee3SChristoph Hellwig 			if (be32_to_cpup(p++)) {
584684c9dee3SChristoph Hellwig 				dprintk("%s: unsupported notification\n",
5847b1f69b75SAndy Adamson 					__func__);
5848b1f69b75SAndy Adamson 				return -EIO;
5849b1f69b75SAndy Adamson 			}
5850b1f69b75SAndy Adamson 		}
5851b1f69b75SAndy Adamson 	}
5852b1f69b75SAndy Adamson 	return 0;
5853b1f69b75SAndy Adamson }
5854b1f69b75SAndy Adamson 
5855b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5856b1f69b75SAndy Adamson 			    struct nfs4_layoutget_res *res)
5857b1f69b75SAndy Adamson {
5858b1f69b75SAndy Adamson 	__be32 *p;
5859b1f69b75SAndy Adamson 	int status;
5860b1f69b75SAndy Adamson 	u32 layout_count;
586164bd577eSTrond Myklebust 	u32 recvd;
5862b1f69b75SAndy Adamson 
5863b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTGET);
5864b1f69b75SAndy Adamson 	if (status)
5865808ba32aSFred Isaman 		goto out;
5866ea9d23f5STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
5867b1f69b75SAndy Adamson 	if (unlikely(!p))
5868b1f69b75SAndy Adamson 		goto out_overflow;
5869ea9d23f5STrond Myklebust 	res->return_on_close = be32_to_cpup(p);
587093b717fdSTrond Myklebust 	decode_layout_stateid(xdr, &res->stateid);
5871ea9d23f5STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
5872ea9d23f5STrond Myklebust 	if (unlikely(!p))
5873ea9d23f5STrond Myklebust 		goto out_overflow;
5874b1f69b75SAndy Adamson 	layout_count = be32_to_cpup(p);
5875b1f69b75SAndy Adamson 	if (!layout_count) {
5876b1f69b75SAndy Adamson 		dprintk("%s: server responded with empty layout array\n",
5877b1f69b75SAndy Adamson 			__func__);
5878808ba32aSFred Isaman 		status = -EINVAL;
5879808ba32aSFred Isaman 		goto out;
5880b1f69b75SAndy Adamson 	}
5881b1f69b75SAndy Adamson 
588235124a09SWeston Andros Adamson 	p = xdr_inline_decode(xdr, 28);
5883b1f69b75SAndy Adamson 	if (unlikely(!p))
5884b1f69b75SAndy Adamson 		goto out_overflow;
5885b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.offset);
5886b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.length);
5887b1f69b75SAndy Adamson 	res->range.iomode = be32_to_cpup(p++);
5888b1f69b75SAndy Adamson 	res->type = be32_to_cpup(p++);
588935124a09SWeston Andros Adamson 	res->layoutp->len = be32_to_cpup(p);
5890b1f69b75SAndy Adamson 
5891b1f69b75SAndy Adamson 	dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5892b1f69b75SAndy Adamson 		__func__,
5893b1f69b75SAndy Adamson 		(unsigned long)res->range.offset,
5894b1f69b75SAndy Adamson 		(unsigned long)res->range.length,
5895b1f69b75SAndy Adamson 		res->range.iomode,
5896b1f69b75SAndy Adamson 		res->type,
589735124a09SWeston Andros Adamson 		res->layoutp->len);
5898b1f69b75SAndy Adamson 
589964bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, res->layoutp->len);
590035124a09SWeston Andros Adamson 	if (res->layoutp->len > recvd) {
590135124a09SWeston Andros Adamson 		dprintk("NFS: server cheating in layoutget reply: "
590235124a09SWeston Andros Adamson 				"layout len %u > recvd %u\n",
590335124a09SWeston Andros Adamson 				res->layoutp->len, recvd);
5904808ba32aSFred Isaman 		status = -EINVAL;
5905808ba32aSFred Isaman 		goto out;
590635124a09SWeston Andros Adamson 	}
590735124a09SWeston Andros Adamson 
5908b1f69b75SAndy Adamson 	if (layout_count > 1) {
5909b1f69b75SAndy Adamson 		/* We only handle a length one array at the moment.  Any
5910b1f69b75SAndy Adamson 		 * further entries are just ignored.  Note that this means
5911b1f69b75SAndy Adamson 		 * the client may see a response that is less than the
5912b1f69b75SAndy Adamson 		 * minimum it requested.
5913b1f69b75SAndy Adamson 		 */
5914b1f69b75SAndy Adamson 		dprintk("%s: server responded with %d layouts, dropping tail\n",
5915b1f69b75SAndy Adamson 			__func__, layout_count);
5916b1f69b75SAndy Adamson 	}
5917b1f69b75SAndy Adamson 
5918808ba32aSFred Isaman out:
5919808ba32aSFred Isaman 	res->status = status;
5920808ba32aSFred Isaman 	return status;
5921b1f69b75SAndy Adamson out_overflow:
5922808ba32aSFred Isaman 	status = -EIO;
5923808ba32aSFred Isaman 	goto out;
5924b1f69b75SAndy Adamson }
5925863a3c6cSAndy Adamson 
5926cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr,
5927cbe82603SBenny Halevy 			       struct nfs4_layoutreturn_res *res)
5928cbe82603SBenny Halevy {
5929cbe82603SBenny Halevy 	__be32 *p;
5930cbe82603SBenny Halevy 	int status;
5931cbe82603SBenny Halevy 
5932cbe82603SBenny Halevy 	status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5933cbe82603SBenny Halevy 	if (status)
5934cbe82603SBenny Halevy 		return status;
5935cbe82603SBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5936cbe82603SBenny Halevy 	if (unlikely(!p))
5937eb72f484SChuck Lever 		return -EIO;
5938cbe82603SBenny Halevy 	res->lrs_present = be32_to_cpup(p);
5939cbe82603SBenny Halevy 	if (res->lrs_present)
594093b717fdSTrond Myklebust 		status = decode_layout_stateid(xdr, &res->stateid);
5941fcd8843cSTrond Myklebust 	else
5942fcd8843cSTrond Myklebust 		nfs4_stateid_copy(&res->stateid, &invalid_stateid);
5943cbe82603SBenny Halevy 	return status;
5944cbe82603SBenny Halevy }
5945cbe82603SBenny Halevy 
5946863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr,
5947863a3c6cSAndy Adamson 			       struct rpc_rqst *req,
5948863a3c6cSAndy Adamson 			       struct nfs4_layoutcommit_res *res)
5949863a3c6cSAndy Adamson {
5950863a3c6cSAndy Adamson 	__be32 *p;
5951863a3c6cSAndy Adamson 	__u32 sizechanged;
5952863a3c6cSAndy Adamson 	int status;
5953863a3c6cSAndy Adamson 
5954863a3c6cSAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5955db29c089SAndy Adamson 	res->status = status;
5956863a3c6cSAndy Adamson 	if (status)
5957863a3c6cSAndy Adamson 		return status;
5958863a3c6cSAndy Adamson 
5959863a3c6cSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
5960863a3c6cSAndy Adamson 	if (unlikely(!p))
5961eb72f484SChuck Lever 		return -EIO;
5962863a3c6cSAndy Adamson 	sizechanged = be32_to_cpup(p);
5963863a3c6cSAndy Adamson 
5964863a3c6cSAndy Adamson 	if (sizechanged) {
5965863a3c6cSAndy Adamson 		/* throw away new size */
5966863a3c6cSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
5967863a3c6cSAndy Adamson 		if (unlikely(!p))
5968eb72f484SChuck Lever 			return -EIO;
5969863a3c6cSAndy Adamson 	}
5970863a3c6cSAndy Adamson 	return 0;
5971863a3c6cSAndy Adamson }
59727d974794SBryan Schumaker 
59737d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr,
59747d974794SBryan Schumaker 			       struct nfs41_test_stateid_res *res)
59757d974794SBryan Schumaker {
59767d974794SBryan Schumaker 	__be32 *p;
59777d974794SBryan Schumaker 	int status;
59787d974794SBryan Schumaker 	int num_res;
59797d974794SBryan Schumaker 
59807d974794SBryan Schumaker 	status = decode_op_hdr(xdr, OP_TEST_STATEID);
59817d974794SBryan Schumaker 	if (status)
59827d974794SBryan Schumaker 		return status;
59837d974794SBryan Schumaker 
59847d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
59857d974794SBryan Schumaker 	if (unlikely(!p))
5986eb72f484SChuck Lever 		return -EIO;
59877d974794SBryan Schumaker 	num_res = be32_to_cpup(p++);
59887d974794SBryan Schumaker 	if (num_res != 1)
5989eb72f484SChuck Lever 		return -EIO;
59907d974794SBryan Schumaker 
59917d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
59927d974794SBryan Schumaker 	if (unlikely(!p))
5993eb72f484SChuck Lever 		return -EIO;
59947d974794SBryan Schumaker 	res->status = be32_to_cpup(p++);
59951cab0652SBryan Schumaker 
59961cab0652SBryan Schumaker 	return status;
59977d974794SBryan Schumaker }
59989aeda35fSBryan Schumaker 
59999aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr,
60009aeda35fSBryan Schumaker 			       struct nfs41_free_stateid_res *res)
60019aeda35fSBryan Schumaker {
60029f79fb48SAndy Adamson 	res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
60039aeda35fSBryan Schumaker 	return res->status;
60049aeda35fSBryan Schumaker }
6005cf805165STrond Myklebust #else
6006cf805165STrond Myklebust static inline
6007cf805165STrond Myklebust int decode_layoutreturn(struct xdr_stream *xdr,
6008cf805165STrond Myklebust 			       struct nfs4_layoutreturn_res *res)
6009cf805165STrond Myklebust {
6010cf805165STrond Myklebust 	return 0;
6011cf805165STrond Myklebust }
601256f487f8SFred Isaman 
601356f487f8SFred Isaman static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
601456f487f8SFred Isaman 			    struct nfs4_layoutget_res *res)
601556f487f8SFred Isaman {
601656f487f8SFred Isaman 	return 0;
601756f487f8SFred Isaman }
601856f487f8SFred Isaman 
6019b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
6020b1f69b75SAndy Adamson 
60211da177e4SLinus Torvalds /*
602249c2559eSBenny Halevy  * END OF "GENERIC" DECODE ROUTINES.
602349c2559eSBenny Halevy  */
602449c2559eSBenny Halevy 
602549c2559eSBenny Halevy /*
60261da177e4SLinus Torvalds  * Decode OPEN_DOWNGRADE response
60271da177e4SLinus Torvalds  */
6028bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6029bf269551SChuck Lever 				       struct xdr_stream *xdr,
6030fc016483SChristoph Hellwig 				       void *data)
60311da177e4SLinus Torvalds {
6032fc016483SChristoph Hellwig 	struct nfs_closeres *res = data;
60331da177e4SLinus Torvalds 	struct compound_hdr hdr;
60341da177e4SLinus Torvalds 	int status;
60351da177e4SLinus Torvalds 
6036bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
60371da177e4SLinus Torvalds 	if (status)
60381da177e4SLinus Torvalds 		goto out;
6039bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
60409b7b9fccSAndy Adamson 	if (status)
60419b7b9fccSAndy Adamson 		goto out;
6042bf269551SChuck Lever 	status = decode_putfh(xdr);
60431da177e4SLinus Torvalds 	if (status)
60441da177e4SLinus Torvalds 		goto out;
6045b6808145STrond Myklebust 	if (res->lr_res) {
6046b6808145STrond Myklebust 		status = decode_layoutreturn(xdr, res->lr_res);
6047b6808145STrond Myklebust 		res->lr_ret = status;
6048b6808145STrond Myklebust 		if (status)
6049b6808145STrond Myklebust 			goto out;
6050b6808145STrond Myklebust 	}
6051bf269551SChuck Lever 	status = decode_open_downgrade(xdr, res);
60521da177e4SLinus Torvalds out:
60531da177e4SLinus Torvalds 	return status;
60541da177e4SLinus Torvalds }
60551da177e4SLinus Torvalds 
60561da177e4SLinus Torvalds /*
60571da177e4SLinus Torvalds  * Decode ACCESS response
60581da177e4SLinus Torvalds  */
6059bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6060fc016483SChristoph Hellwig 			       void *data)
60611da177e4SLinus Torvalds {
6062fc016483SChristoph Hellwig 	struct nfs4_accessres *res = data;
60631da177e4SLinus Torvalds 	struct compound_hdr hdr;
60641da177e4SLinus Torvalds 	int status;
60651da177e4SLinus Torvalds 
6066bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
60679b7b9fccSAndy Adamson 	if (status)
60689b7b9fccSAndy Adamson 		goto out;
6069bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
60709b7b9fccSAndy Adamson 	if (status)
60711da177e4SLinus Torvalds 		goto out;
6072bf269551SChuck Lever 	status = decode_putfh(xdr);
607376b32999STrond Myklebust 	if (status != 0)
607476b32999STrond Myklebust 		goto out;
60756168f62cSWeston Andros Adamson 	status = decode_access(xdr, &res->supported, &res->access);
607676b32999STrond Myklebust 	if (status != 0)
607776b32999STrond Myklebust 		goto out;
60788bcbe7d9STrond Myklebust 	if (res->fattr)
60796926afd1STrond Myklebust 		decode_getfattr(xdr, res->fattr, res->server);
60801da177e4SLinus Torvalds out:
60811da177e4SLinus Torvalds 	return status;
60821da177e4SLinus Torvalds }
60831da177e4SLinus Torvalds 
60841da177e4SLinus Torvalds /*
60851da177e4SLinus Torvalds  * Decode LOOKUP response
60861da177e4SLinus Torvalds  */
6087bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6088fc016483SChristoph Hellwig 			       void *data)
60891da177e4SLinus Torvalds {
6090fc016483SChristoph Hellwig 	struct nfs4_lookup_res *res = data;
60911da177e4SLinus Torvalds 	struct compound_hdr hdr;
60921da177e4SLinus Torvalds 	int status;
60931da177e4SLinus Torvalds 
6094bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
60959b7b9fccSAndy Adamson 	if (status)
60969b7b9fccSAndy Adamson 		goto out;
6097bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
60989b7b9fccSAndy Adamson 	if (status)
60991da177e4SLinus Torvalds 		goto out;
6100bf269551SChuck Lever 	status = decode_putfh(xdr);
6101bf269551SChuck Lever 	if (status)
61021da177e4SLinus Torvalds 		goto out;
6103bf269551SChuck Lever 	status = decode_lookup(xdr);
6104bf269551SChuck Lever 	if (status)
61051da177e4SLinus Torvalds 		goto out;
6106bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6107bf269551SChuck Lever 	if (status)
61081da177e4SLinus Torvalds 		goto out;
6109aa9c2669SDavid Quigley 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
61101da177e4SLinus Torvalds out:
61111da177e4SLinus Torvalds 	return status;
61121da177e4SLinus Torvalds }
61131da177e4SLinus Torvalds 
61141da177e4SLinus Torvalds /*
61155b5faaf6SJeff Layton  * Decode LOOKUPP response
61165b5faaf6SJeff Layton  */
61175b5faaf6SJeff Layton static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
61185b5faaf6SJeff Layton 		void *data)
61195b5faaf6SJeff Layton {
61205b5faaf6SJeff Layton 	struct nfs4_lookupp_res *res = data;
61215b5faaf6SJeff Layton 	struct compound_hdr hdr;
61225b5faaf6SJeff Layton 	int status;
61235b5faaf6SJeff Layton 
61245b5faaf6SJeff Layton 	status = decode_compound_hdr(xdr, &hdr);
61255b5faaf6SJeff Layton 	if (status)
61265b5faaf6SJeff Layton 		goto out;
61275b5faaf6SJeff Layton 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61285b5faaf6SJeff Layton 	if (status)
61295b5faaf6SJeff Layton 		goto out;
61305b5faaf6SJeff Layton 	status = decode_putfh(xdr);
61315b5faaf6SJeff Layton 	if (status)
61325b5faaf6SJeff Layton 		goto out;
61335b5faaf6SJeff Layton 	status = decode_lookupp(xdr);
61345b5faaf6SJeff Layton 	if (status)
61355b5faaf6SJeff Layton 		goto out;
61365b5faaf6SJeff Layton 	status = decode_getfh(xdr, res->fh);
61375b5faaf6SJeff Layton 	if (status)
61385b5faaf6SJeff Layton 		goto out;
61395b5faaf6SJeff Layton 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
61405b5faaf6SJeff Layton out:
61415b5faaf6SJeff Layton 	return status;
61425b5faaf6SJeff Layton }
61435b5faaf6SJeff Layton 
61445b5faaf6SJeff Layton /*
61451da177e4SLinus Torvalds  * Decode LOOKUP_ROOT response
61461da177e4SLinus Torvalds  */
6147bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6148bf269551SChuck Lever 				    struct xdr_stream *xdr,
6149fc016483SChristoph Hellwig 				    void *data)
61501da177e4SLinus Torvalds {
6151fc016483SChristoph Hellwig 	struct nfs4_lookup_res *res = data;
61521da177e4SLinus Torvalds 	struct compound_hdr hdr;
61531da177e4SLinus Torvalds 	int status;
61541da177e4SLinus Torvalds 
6155bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61569b7b9fccSAndy Adamson 	if (status)
61579b7b9fccSAndy Adamson 		goto out;
6158bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61599b7b9fccSAndy Adamson 	if (status)
61601da177e4SLinus Torvalds 		goto out;
6161bf269551SChuck Lever 	status = decode_putrootfh(xdr);
6162bf269551SChuck Lever 	if (status)
61631da177e4SLinus Torvalds 		goto out;
6164bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6165bf269551SChuck Lever 	if (status == 0)
6166aa9c2669SDavid Quigley 		status = decode_getfattr_label(xdr, res->fattr,
6167aa9c2669SDavid Quigley 						res->label, res->server);
61681da177e4SLinus Torvalds out:
61691da177e4SLinus Torvalds 	return status;
61701da177e4SLinus Torvalds }
61711da177e4SLinus Torvalds 
61721da177e4SLinus Torvalds /*
61731da177e4SLinus Torvalds  * Decode REMOVE response
61741da177e4SLinus Torvalds  */
6175bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6176fc016483SChristoph Hellwig 			       void *data)
61771da177e4SLinus Torvalds {
6178fc016483SChristoph Hellwig 	struct nfs_removeres *res = data;
61791da177e4SLinus Torvalds 	struct compound_hdr hdr;
61801da177e4SLinus Torvalds 	int status;
61811da177e4SLinus Torvalds 
6182bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61839b7b9fccSAndy Adamson 	if (status)
61849b7b9fccSAndy Adamson 		goto out;
6185bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61869b7b9fccSAndy Adamson 	if (status)
61871da177e4SLinus Torvalds 		goto out;
6188bf269551SChuck Lever 	status = decode_putfh(xdr);
6189bf269551SChuck Lever 	if (status)
619016e42959STrond Myklebust 		goto out;
6191bf269551SChuck Lever 	status = decode_remove(xdr, &res->cinfo);
61921da177e4SLinus Torvalds out:
61931da177e4SLinus Torvalds 	return status;
61941da177e4SLinus Torvalds }
61951da177e4SLinus Torvalds 
61961da177e4SLinus Torvalds /*
61971da177e4SLinus Torvalds  * Decode RENAME response
61981da177e4SLinus Torvalds  */
6199bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6200fc016483SChristoph Hellwig 			       void *data)
62011da177e4SLinus Torvalds {
6202fc016483SChristoph Hellwig 	struct nfs_renameres *res = data;
62031da177e4SLinus Torvalds 	struct compound_hdr hdr;
62041da177e4SLinus Torvalds 	int status;
62051da177e4SLinus Torvalds 
6206bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62079b7b9fccSAndy Adamson 	if (status)
62089b7b9fccSAndy Adamson 		goto out;
6209bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62109b7b9fccSAndy Adamson 	if (status)
62111da177e4SLinus Torvalds 		goto out;
6212bf269551SChuck Lever 	status = decode_putfh(xdr);
6213bf269551SChuck Lever 	if (status)
62141da177e4SLinus Torvalds 		goto out;
6215bf269551SChuck Lever 	status = decode_savefh(xdr);
6216bf269551SChuck Lever 	if (status)
62171da177e4SLinus Torvalds 		goto out;
6218bf269551SChuck Lever 	status = decode_putfh(xdr);
6219bf269551SChuck Lever 	if (status)
62201da177e4SLinus Torvalds 		goto out;
6221bf269551SChuck Lever 	status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
62221da177e4SLinus Torvalds out:
62231da177e4SLinus Torvalds 	return status;
62241da177e4SLinus Torvalds }
62251da177e4SLinus Torvalds 
62261da177e4SLinus Torvalds /*
62271da177e4SLinus Torvalds  * Decode LINK response
62281da177e4SLinus Torvalds  */
6229bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6230fc016483SChristoph Hellwig 			     void *data)
62311da177e4SLinus Torvalds {
6232fc016483SChristoph Hellwig 	struct nfs4_link_res *res = data;
62331da177e4SLinus Torvalds 	struct compound_hdr hdr;
62341da177e4SLinus Torvalds 	int status;
62351da177e4SLinus Torvalds 
6236bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62379b7b9fccSAndy Adamson 	if (status)
62389b7b9fccSAndy Adamson 		goto out;
6239bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62409b7b9fccSAndy Adamson 	if (status)
62411da177e4SLinus Torvalds 		goto out;
6242bf269551SChuck Lever 	status = decode_putfh(xdr);
6243bf269551SChuck Lever 	if (status)
62441da177e4SLinus Torvalds 		goto out;
6245bf269551SChuck Lever 	status = decode_savefh(xdr);
6246bf269551SChuck Lever 	if (status)
62471da177e4SLinus Torvalds 		goto out;
6248bf269551SChuck Lever 	status = decode_putfh(xdr);
6249bf269551SChuck Lever 	if (status)
62501da177e4SLinus Torvalds 		goto out;
6251bf269551SChuck Lever 	status = decode_link(xdr, &res->cinfo);
6252bf269551SChuck Lever 	if (status)
625391ba2eeeSTrond Myklebust 		goto out;
625491ba2eeeSTrond Myklebust 	/*
625591ba2eeeSTrond Myklebust 	 * Note order: OP_LINK leaves the directory as the current
625691ba2eeeSTrond Myklebust 	 *             filehandle.
625791ba2eeeSTrond Myklebust 	 */
6258bf269551SChuck Lever 	status = decode_restorefh(xdr);
6259bf269551SChuck Lever 	if (status)
626091ba2eeeSTrond Myklebust 		goto out;
6261aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
62621da177e4SLinus Torvalds out:
62631da177e4SLinus Torvalds 	return status;
62641da177e4SLinus Torvalds }
62651da177e4SLinus Torvalds 
62661da177e4SLinus Torvalds /*
62671da177e4SLinus Torvalds  * Decode CREATE response
62681da177e4SLinus Torvalds  */
6269bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6270fc016483SChristoph Hellwig 			       void *data)
62711da177e4SLinus Torvalds {
6272fc016483SChristoph Hellwig 	struct nfs4_create_res *res = data;
62731da177e4SLinus Torvalds 	struct compound_hdr hdr;
62741da177e4SLinus Torvalds 	int status;
62751da177e4SLinus Torvalds 
6276bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62779b7b9fccSAndy Adamson 	if (status)
62789b7b9fccSAndy Adamson 		goto out;
6279bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62809b7b9fccSAndy Adamson 	if (status)
62811da177e4SLinus Torvalds 		goto out;
6282bf269551SChuck Lever 	status = decode_putfh(xdr);
6283bf269551SChuck Lever 	if (status)
62841da177e4SLinus Torvalds 		goto out;
6285bf269551SChuck Lever 	status = decode_create(xdr, &res->dir_cinfo);
6286bf269551SChuck Lever 	if (status)
62871da177e4SLinus Torvalds 		goto out;
6288bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6289bf269551SChuck Lever 	if (status)
62901da177e4SLinus Torvalds 		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 SYMLINK response
62981da177e4SLinus Torvalds  */
6299bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6300fc016483SChristoph Hellwig 				void *res)
63011da177e4SLinus Torvalds {
6302bf269551SChuck Lever 	return nfs4_xdr_dec_create(rqstp, xdr, res);
63031da177e4SLinus Torvalds }
63041da177e4SLinus Torvalds 
63051da177e4SLinus Torvalds /*
63061da177e4SLinus Torvalds  * Decode GETATTR response
63071da177e4SLinus Torvalds  */
6308bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6309fc016483SChristoph Hellwig 				void *data)
63101da177e4SLinus Torvalds {
6311fc016483SChristoph Hellwig 	struct nfs4_getattr_res *res = data;
63121da177e4SLinus Torvalds 	struct compound_hdr hdr;
63131da177e4SLinus Torvalds 	int status;
63141da177e4SLinus Torvalds 
6315bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63161da177e4SLinus Torvalds 	if (status)
63171da177e4SLinus Torvalds 		goto out;
6318bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63199b7b9fccSAndy Adamson 	if (status)
63209b7b9fccSAndy Adamson 		goto out;
6321bf269551SChuck Lever 	status = decode_putfh(xdr);
63221da177e4SLinus Torvalds 	if (status)
63231da177e4SLinus Torvalds 		goto out;
6324aa9c2669SDavid Quigley 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
63251da177e4SLinus Torvalds out:
63261da177e4SLinus Torvalds 	return status;
63271da177e4SLinus Torvalds }
63281da177e4SLinus Torvalds 
632923ec6965SJ. Bruce Fields /*
633023ec6965SJ. Bruce Fields  * Encode an SETACL request
633123ec6965SJ. Bruce Fields  */
63329f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6333fcc85819SChristoph Hellwig 				const void *data)
633423ec6965SJ. Bruce Fields {
6335fcc85819SChristoph Hellwig 	const struct nfs_setaclargs *args = data;
633623ec6965SJ. Bruce Fields 	struct compound_hdr hdr = {
633766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
633823ec6965SJ. Bruce Fields 	};
633923ec6965SJ. Bruce Fields 
63409f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
63419f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
63429f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
63439f06c719SChuck Lever 	encode_setacl(xdr, args, &hdr);
6344d017931cSAndy Adamson 	encode_nops(&hdr);
634523ec6965SJ. Bruce Fields }
634605d564feSAndy Adamson 
634723ec6965SJ. Bruce Fields /*
634823ec6965SJ. Bruce Fields  * Decode SETACL response
634923ec6965SJ. Bruce Fields  */
635023ec6965SJ. Bruce Fields static int
6351bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6352fc016483SChristoph Hellwig 		    void *data)
635323ec6965SJ. Bruce Fields {
6354fc016483SChristoph Hellwig 	struct nfs_setaclres *res = data;
635523ec6965SJ. Bruce Fields 	struct compound_hdr hdr;
635623ec6965SJ. Bruce Fields 	int status;
635723ec6965SJ. Bruce Fields 
6358bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
635923ec6965SJ. Bruce Fields 	if (status)
636023ec6965SJ. Bruce Fields 		goto out;
6361bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63629b7b9fccSAndy Adamson 	if (status)
63639b7b9fccSAndy Adamson 		goto out;
6364bf269551SChuck Lever 	status = decode_putfh(xdr);
636523ec6965SJ. Bruce Fields 	if (status)
636623ec6965SJ. Bruce Fields 		goto out;
6367bf269551SChuck Lever 	status = decode_setattr(xdr);
636823ec6965SJ. Bruce Fields out:
636923ec6965SJ. Bruce Fields 	return status;
637023ec6965SJ. Bruce Fields }
63711da177e4SLinus Torvalds 
63721da177e4SLinus Torvalds /*
6373029d105eSJ. Bruce Fields  * Decode GETACL response
6374029d105eSJ. Bruce Fields  */
6375029d105eSJ. Bruce Fields static int
6376bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6377fc016483SChristoph Hellwig 		    void *data)
6378029d105eSJ. Bruce Fields {
6379fc016483SChristoph Hellwig 	struct nfs_getaclres *res = data;
6380029d105eSJ. Bruce Fields 	struct compound_hdr hdr;
6381029d105eSJ. Bruce Fields 	int status;
6382029d105eSJ. Bruce Fields 
6383331818f1STrond Myklebust 	if (res->acl_scratch != NULL) {
6384331818f1STrond Myklebust 		void *p = page_address(res->acl_scratch);
6385331818f1STrond Myklebust 		xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6386331818f1STrond Myklebust 	}
6387bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6388029d105eSJ. Bruce Fields 	if (status)
6389029d105eSJ. Bruce Fields 		goto out;
6390bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63919b7b9fccSAndy Adamson 	if (status)
63929b7b9fccSAndy Adamson 		goto out;
6393bf269551SChuck Lever 	status = decode_putfh(xdr);
6394029d105eSJ. Bruce Fields 	if (status)
6395029d105eSJ. Bruce Fields 		goto out;
6396bf118a34SAndy Adamson 	status = decode_getacl(xdr, rqstp, res);
6397029d105eSJ. Bruce Fields 
6398029d105eSJ. Bruce Fields out:
6399029d105eSJ. Bruce Fields 	return status;
6400029d105eSJ. Bruce Fields }
6401029d105eSJ. Bruce Fields 
6402029d105eSJ. Bruce Fields /*
64031da177e4SLinus Torvalds  * Decode CLOSE response
64041da177e4SLinus Torvalds  */
6405bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6406fc016483SChristoph Hellwig 			      void *data)
64071da177e4SLinus Torvalds {
6408fc016483SChristoph Hellwig 	struct nfs_closeres *res = data;
64091da177e4SLinus Torvalds 	struct compound_hdr hdr;
64101da177e4SLinus Torvalds 	int status;
64111da177e4SLinus Torvalds 
6412bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64131da177e4SLinus Torvalds 	if (status)
64141da177e4SLinus Torvalds 		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);
64191da177e4SLinus Torvalds 	if (status)
64201da177e4SLinus Torvalds 		goto out;
6421cf805165STrond Myklebust 	if (res->lr_res) {
6422cf805165STrond Myklebust 		status = decode_layoutreturn(xdr, res->lr_res);
6423cf805165STrond Myklebust 		res->lr_ret = status;
6424cf805165STrond Myklebust 		if (status)
6425cf805165STrond Myklebust 			goto out;
6426cf805165STrond Myklebust 	}
6427d8d84983STrond Myklebust 	if (res->fattr != NULL) {
6428d8d84983STrond Myklebust 		status = decode_getfattr(xdr, res->fattr, res->server);
6429516a6af6STrond Myklebust 		if (status != 0)
6430516a6af6STrond Myklebust 			goto out;
6431d8d84983STrond Myklebust 	}
6432d8d84983STrond Myklebust 	status = decode_close(xdr, res);
64331da177e4SLinus Torvalds out:
64341da177e4SLinus Torvalds 	return status;
64351da177e4SLinus Torvalds }
64361da177e4SLinus Torvalds 
64371da177e4SLinus Torvalds /*
64381da177e4SLinus Torvalds  * Decode OPEN response
64391da177e4SLinus Torvalds  */
6440bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6441fc016483SChristoph Hellwig 			     void *data)
64421da177e4SLinus Torvalds {
6443fc016483SChristoph Hellwig 	struct nfs_openres *res = data;
64441da177e4SLinus Torvalds 	struct compound_hdr hdr;
64451da177e4SLinus Torvalds 	int status;
64461da177e4SLinus Torvalds 
6447bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64481da177e4SLinus Torvalds 	if (status)
64491da177e4SLinus Torvalds 		goto out;
6450bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64519b7b9fccSAndy Adamson 	if (status)
64529b7b9fccSAndy Adamson 		goto out;
6453bf269551SChuck Lever 	status = decode_putfh(xdr);
64541da177e4SLinus Torvalds 	if (status)
64551da177e4SLinus Torvalds 		goto out;
6456bf269551SChuck Lever 	status = decode_open(xdr, res);
64571da177e4SLinus Torvalds 	if (status)
64581da177e4SLinus Torvalds 		goto out;
645901913b49SWeston Andros Adamson 	status = decode_getfh(xdr, &res->fh);
646001913b49SWeston Andros Adamson 	if (status)
64611da177e4SLinus Torvalds 		goto out;
6462ae2bb032SWeston Andros Adamson 	if (res->access_request)
64636168f62cSWeston Andros Adamson 		decode_access(xdr, &res->access_supported, &res->access_result);
6464aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
646556f487f8SFred Isaman 	if (res->lg_res)
646656f487f8SFred Isaman 		decode_layoutget(xdr, rqstp, res->lg_res);
64671da177e4SLinus Torvalds out:
64681da177e4SLinus Torvalds 	return status;
64691da177e4SLinus Torvalds }
64701da177e4SLinus Torvalds 
64711da177e4SLinus Torvalds /*
64721da177e4SLinus Torvalds  * Decode OPEN_CONFIRM response
64731da177e4SLinus Torvalds  */
6474bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6475bf269551SChuck Lever 				     struct xdr_stream *xdr,
6476fc016483SChristoph Hellwig 				     void *data)
64771da177e4SLinus Torvalds {
6478fc016483SChristoph Hellwig 	struct nfs_open_confirmres *res = data;
64791da177e4SLinus Torvalds 	struct compound_hdr hdr;
64801da177e4SLinus Torvalds 	int status;
64811da177e4SLinus Torvalds 
6482bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64831da177e4SLinus Torvalds 	if (status)
64841da177e4SLinus Torvalds 		goto out;
6485bf269551SChuck Lever 	status = decode_putfh(xdr);
64861da177e4SLinus Torvalds 	if (status)
64871da177e4SLinus Torvalds 		goto out;
6488bf269551SChuck Lever 	status = decode_open_confirm(xdr, res);
64891da177e4SLinus Torvalds out:
64901da177e4SLinus Torvalds 	return status;
64911da177e4SLinus Torvalds }
64921da177e4SLinus Torvalds 
64931da177e4SLinus Torvalds /*
64941da177e4SLinus Torvalds  * Decode OPEN response
64951da177e4SLinus Torvalds  */
6496bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6497bf269551SChuck Lever 				    struct xdr_stream *xdr,
6498fc016483SChristoph Hellwig 				    void *data)
64991da177e4SLinus Torvalds {
6500fc016483SChristoph Hellwig 	struct nfs_openres *res = data;
65011da177e4SLinus Torvalds 	struct compound_hdr hdr;
65021da177e4SLinus Torvalds 	int status;
65031da177e4SLinus Torvalds 
6504bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65051da177e4SLinus Torvalds 	if (status)
65061da177e4SLinus Torvalds 		goto out;
6507bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65089b7b9fccSAndy Adamson 	if (status)
65099b7b9fccSAndy Adamson 		goto out;
6510bf269551SChuck Lever 	status = decode_putfh(xdr);
65111da177e4SLinus Torvalds 	if (status)
65121da177e4SLinus Torvalds 		goto out;
6513bf269551SChuck Lever 	status = decode_open(xdr, res);
6514864472e9STrond Myklebust 	if (status)
6515864472e9STrond Myklebust 		goto out;
6516ae2bb032SWeston Andros Adamson 	if (res->access_request)
65176168f62cSWeston Andros Adamson 		decode_access(xdr, &res->access_supported, &res->access_result);
65186926afd1STrond Myklebust 	decode_getfattr(xdr, res->f_attr, res->server);
651956f487f8SFred Isaman 	if (res->lg_res)
652056f487f8SFred Isaman 		decode_layoutget(xdr, rqstp, res->lg_res);
65211da177e4SLinus Torvalds out:
65221da177e4SLinus Torvalds 	return status;
65231da177e4SLinus Torvalds }
65241da177e4SLinus Torvalds 
65251da177e4SLinus Torvalds /*
65261da177e4SLinus Torvalds  * Decode SETATTR response
65271da177e4SLinus Torvalds  */
6528bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6529bf269551SChuck Lever 				struct xdr_stream *xdr,
6530fc016483SChristoph Hellwig 				void *data)
65311da177e4SLinus Torvalds {
6532fc016483SChristoph Hellwig 	struct nfs_setattrres *res = data;
65331da177e4SLinus Torvalds 	struct compound_hdr hdr;
65341da177e4SLinus Torvalds 	int status;
65351da177e4SLinus Torvalds 
6536bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65371da177e4SLinus Torvalds 	if (status)
65381da177e4SLinus Torvalds 		goto out;
6539bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65409b7b9fccSAndy Adamson 	if (status)
65419b7b9fccSAndy Adamson 		goto out;
6542bf269551SChuck Lever 	status = decode_putfh(xdr);
65431da177e4SLinus Torvalds 	if (status)
65441da177e4SLinus Torvalds 		goto out;
6545bf269551SChuck Lever 	status = decode_setattr(xdr);
65461da177e4SLinus Torvalds 	if (status)
65471da177e4SLinus Torvalds 		goto out;
6548aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
65491da177e4SLinus Torvalds out:
65501da177e4SLinus Torvalds 	return status;
65511da177e4SLinus Torvalds }
65521da177e4SLinus Torvalds 
65531da177e4SLinus Torvalds /*
65541da177e4SLinus Torvalds  * Decode LOCK response
65551da177e4SLinus Torvalds  */
6556bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6557fc016483SChristoph Hellwig 			     void *data)
65581da177e4SLinus Torvalds {
6559fc016483SChristoph Hellwig 	struct nfs_lock_res *res = data;
65601da177e4SLinus Torvalds 	struct compound_hdr hdr;
65611da177e4SLinus Torvalds 	int status;
65621da177e4SLinus Torvalds 
6563bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65641da177e4SLinus Torvalds 	if (status)
65651da177e4SLinus Torvalds 		goto out;
6566bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65679b7b9fccSAndy Adamson 	if (status)
65689b7b9fccSAndy Adamson 		goto out;
6569bf269551SChuck Lever 	status = decode_putfh(xdr);
65701da177e4SLinus Torvalds 	if (status)
65711da177e4SLinus Torvalds 		goto out;
6572bf269551SChuck Lever 	status = decode_lock(xdr, res);
65731da177e4SLinus Torvalds out:
65741da177e4SLinus Torvalds 	return status;
65751da177e4SLinus Torvalds }
65761da177e4SLinus Torvalds 
65771da177e4SLinus Torvalds /*
65781da177e4SLinus Torvalds  * Decode LOCKT response
65791da177e4SLinus Torvalds  */
6580bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6581fc016483SChristoph Hellwig 			      void *data)
65821da177e4SLinus Torvalds {
6583fc016483SChristoph Hellwig 	struct nfs_lockt_res *res = data;
65841da177e4SLinus Torvalds 	struct compound_hdr hdr;
65851da177e4SLinus Torvalds 	int status;
65861da177e4SLinus Torvalds 
6587bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65881da177e4SLinus Torvalds 	if (status)
65891da177e4SLinus Torvalds 		goto out;
6590bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65919b7b9fccSAndy Adamson 	if (status)
65929b7b9fccSAndy Adamson 		goto out;
6593bf269551SChuck Lever 	status = decode_putfh(xdr);
65941da177e4SLinus Torvalds 	if (status)
65951da177e4SLinus Torvalds 		goto out;
6596bf269551SChuck Lever 	status = decode_lockt(xdr, res);
65971da177e4SLinus Torvalds out:
65981da177e4SLinus Torvalds 	return status;
65991da177e4SLinus Torvalds }
66001da177e4SLinus Torvalds 
66011da177e4SLinus Torvalds /*
66021da177e4SLinus Torvalds  * Decode LOCKU response
66031da177e4SLinus Torvalds  */
6604bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6605fc016483SChristoph Hellwig 			      void *data)
66061da177e4SLinus Torvalds {
6607fc016483SChristoph Hellwig 	struct nfs_locku_res *res = data;
66081da177e4SLinus Torvalds 	struct compound_hdr hdr;
66091da177e4SLinus Torvalds 	int status;
66101da177e4SLinus Torvalds 
6611bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66121da177e4SLinus Torvalds 	if (status)
66131da177e4SLinus Torvalds 		goto out;
6614bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66159b7b9fccSAndy Adamson 	if (status)
66169b7b9fccSAndy Adamson 		goto out;
6617bf269551SChuck Lever 	status = decode_putfh(xdr);
66181da177e4SLinus Torvalds 	if (status)
66191da177e4SLinus Torvalds 		goto out;
6620bf269551SChuck Lever 	status = decode_locku(xdr, res);
66211da177e4SLinus Torvalds out:
66221da177e4SLinus Torvalds 	return status;
66231da177e4SLinus Torvalds }
66241da177e4SLinus Torvalds 
6625bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6626bf269551SChuck Lever 					  struct xdr_stream *xdr, void *dummy)
6627d3c7b7ccSTrond Myklebust {
6628d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr;
6629d3c7b7ccSTrond Myklebust 	int status;
6630d3c7b7ccSTrond Myklebust 
6631bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6632d3c7b7ccSTrond Myklebust 	if (!status)
6633bf269551SChuck Lever 		status = decode_release_lockowner(xdr);
6634d3c7b7ccSTrond Myklebust 	return status;
6635d3c7b7ccSTrond Myklebust }
6636d3c7b7ccSTrond Myklebust 
66371da177e4SLinus Torvalds /*
66381da177e4SLinus Torvalds  * Decode READLINK response
66391da177e4SLinus Torvalds  */
6640bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6641bf269551SChuck Lever 				 struct xdr_stream *xdr,
6642fc016483SChristoph Hellwig 				 void *data)
66431da177e4SLinus Torvalds {
6644fc016483SChristoph Hellwig 	struct nfs4_readlink_res *res = data;
66451da177e4SLinus Torvalds 	struct compound_hdr hdr;
66461da177e4SLinus Torvalds 	int status;
66471da177e4SLinus Torvalds 
6648bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66491da177e4SLinus Torvalds 	if (status)
66501da177e4SLinus Torvalds 		goto out;
6651bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66529b7b9fccSAndy Adamson 	if (status)
66539b7b9fccSAndy Adamson 		goto out;
6654bf269551SChuck Lever 	status = decode_putfh(xdr);
66551da177e4SLinus Torvalds 	if (status)
66561da177e4SLinus Torvalds 		goto out;
6657bf269551SChuck Lever 	status = decode_readlink(xdr, rqstp);
66581da177e4SLinus Torvalds out:
66591da177e4SLinus Torvalds 	return status;
66601da177e4SLinus Torvalds }
66611da177e4SLinus Torvalds 
66621da177e4SLinus Torvalds /*
66631da177e4SLinus Torvalds  * Decode READDIR response
66641da177e4SLinus Torvalds  */
6665bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6666fc016483SChristoph Hellwig 				void *data)
66671da177e4SLinus Torvalds {
6668fc016483SChristoph Hellwig 	struct nfs4_readdir_res *res = data;
66691da177e4SLinus Torvalds 	struct compound_hdr hdr;
66701da177e4SLinus Torvalds 	int status;
66711da177e4SLinus Torvalds 
6672bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66731da177e4SLinus Torvalds 	if (status)
66741da177e4SLinus Torvalds 		goto out;
6675bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66769b7b9fccSAndy Adamson 	if (status)
66779b7b9fccSAndy Adamson 		goto out;
6678bf269551SChuck Lever 	status = decode_putfh(xdr);
66791da177e4SLinus Torvalds 	if (status)
66801da177e4SLinus Torvalds 		goto out;
6681bf269551SChuck Lever 	status = decode_readdir(xdr, rqstp, res);
66821da177e4SLinus Torvalds out:
66831da177e4SLinus Torvalds 	return status;
66841da177e4SLinus Torvalds }
66851da177e4SLinus Torvalds 
66861da177e4SLinus Torvalds /*
66871da177e4SLinus Torvalds  * Decode Read response
66881da177e4SLinus Torvalds  */
6689bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6690fc016483SChristoph Hellwig 			     void *data)
66911da177e4SLinus Torvalds {
6692fc016483SChristoph Hellwig 	struct nfs_pgio_res *res = data;
66931da177e4SLinus Torvalds 	struct compound_hdr hdr;
66941da177e4SLinus Torvalds 	int status;
66951da177e4SLinus Torvalds 
6696bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6697aabff4ddSPeng Tao 	res->op_status = hdr.status;
66981da177e4SLinus Torvalds 	if (status)
66991da177e4SLinus Torvalds 		goto out;
6700bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67019b7b9fccSAndy Adamson 	if (status)
67029b7b9fccSAndy Adamson 		goto out;
6703bf269551SChuck Lever 	status = decode_putfh(xdr);
67041da177e4SLinus Torvalds 	if (status)
67051da177e4SLinus Torvalds 		goto out;
6706bf269551SChuck Lever 	status = decode_read(xdr, rqstp, res);
67071da177e4SLinus Torvalds 	if (!status)
67081da177e4SLinus Torvalds 		status = res->count;
67091da177e4SLinus Torvalds out:
67101da177e4SLinus Torvalds 	return status;
67111da177e4SLinus Torvalds }
67121da177e4SLinus Torvalds 
67131da177e4SLinus Torvalds /*
67141da177e4SLinus Torvalds  * Decode WRITE response
67151da177e4SLinus Torvalds  */
6716bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6717fc016483SChristoph Hellwig 			      void *data)
67181da177e4SLinus Torvalds {
6719fc016483SChristoph Hellwig 	struct nfs_pgio_res *res = data;
67201da177e4SLinus Torvalds 	struct compound_hdr hdr;
67211da177e4SLinus Torvalds 	int status;
67221da177e4SLinus Torvalds 
6723bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6724aabff4ddSPeng Tao 	res->op_status = hdr.status;
67251da177e4SLinus Torvalds 	if (status)
67261da177e4SLinus Torvalds 		goto out;
6727bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67289b7b9fccSAndy Adamson 	if (status)
67299b7b9fccSAndy Adamson 		goto out;
6730bf269551SChuck Lever 	status = decode_putfh(xdr);
67311da177e4SLinus Torvalds 	if (status)
67321da177e4SLinus Torvalds 		goto out;
6733bf269551SChuck Lever 	status = decode_write(xdr, res);
67344f9838c7STrond Myklebust 	if (status)
67354f9838c7STrond Myklebust 		goto out;
67367ffd1064SFred Isaman 	if (res->fattr)
67376926afd1STrond Myklebust 		decode_getfattr(xdr, res->fattr, res->server);
67381da177e4SLinus Torvalds 	if (!status)
67391da177e4SLinus Torvalds 		status = res->count;
67401da177e4SLinus Torvalds out:
67411da177e4SLinus Torvalds 	return status;
67421da177e4SLinus Torvalds }
67431da177e4SLinus Torvalds 
67441da177e4SLinus Torvalds /*
67451da177e4SLinus Torvalds  * Decode COMMIT response
67461da177e4SLinus Torvalds  */
6747bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6748fc016483SChristoph Hellwig 			       void *data)
67491da177e4SLinus Torvalds {
6750fc016483SChristoph Hellwig 	struct nfs_commitres *res = data;
67511da177e4SLinus Torvalds 	struct compound_hdr hdr;
67521da177e4SLinus Torvalds 	int status;
67531da177e4SLinus Torvalds 
6754bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6755aabff4ddSPeng Tao 	res->op_status = hdr.status;
67561da177e4SLinus Torvalds 	if (status)
67571da177e4SLinus Torvalds 		goto out;
6758bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67599b7b9fccSAndy Adamson 	if (status)
67609b7b9fccSAndy Adamson 		goto out;
6761bf269551SChuck Lever 	status = decode_putfh(xdr);
67621da177e4SLinus Torvalds 	if (status)
67631da177e4SLinus Torvalds 		goto out;
6764bf269551SChuck Lever 	status = decode_commit(xdr, res);
67651da177e4SLinus Torvalds out:
67661da177e4SLinus Torvalds 	return status;
67671da177e4SLinus Torvalds }
67681da177e4SLinus Torvalds 
67691da177e4SLinus Torvalds /*
67708b173218SRicardo Labiaga  * Decode FSINFO response
67711da177e4SLinus Torvalds  */
6772bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6773fc016483SChristoph Hellwig 			       void *data)
67741da177e4SLinus Torvalds {
6775fc016483SChristoph Hellwig 	struct nfs4_fsinfo_res *res = data;
67761da177e4SLinus Torvalds 	struct compound_hdr hdr;
67771da177e4SLinus Torvalds 	int status;
67781da177e4SLinus Torvalds 
6779bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67801da177e4SLinus Torvalds 	if (!status)
6781bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
67829b7b9fccSAndy Adamson 	if (!status)
6783bf269551SChuck Lever 		status = decode_putfh(xdr);
67841da177e4SLinus Torvalds 	if (!status)
6785bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->fsinfo);
67861da177e4SLinus Torvalds 	return status;
67871da177e4SLinus Torvalds }
67881da177e4SLinus Torvalds 
67891da177e4SLinus Torvalds /*
67908b173218SRicardo Labiaga  * Decode PATHCONF response
67911da177e4SLinus Torvalds  */
6792bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6793fc016483SChristoph Hellwig 				 void *data)
67941da177e4SLinus Torvalds {
6795fc016483SChristoph Hellwig 	struct nfs4_pathconf_res *res = data;
67961da177e4SLinus Torvalds 	struct compound_hdr hdr;
67971da177e4SLinus Torvalds 	int status;
67981da177e4SLinus Torvalds 
6799bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68001da177e4SLinus Torvalds 	if (!status)
6801bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
68029b7b9fccSAndy Adamson 	if (!status)
6803bf269551SChuck Lever 		status = decode_putfh(xdr);
68041da177e4SLinus Torvalds 	if (!status)
6805bf269551SChuck Lever 		status = decode_pathconf(xdr, res->pathconf);
68061da177e4SLinus Torvalds 	return status;
68071da177e4SLinus Torvalds }
68081da177e4SLinus Torvalds 
68091da177e4SLinus Torvalds /*
68108b173218SRicardo Labiaga  * Decode STATFS response
68111da177e4SLinus Torvalds  */
6812bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6813fc016483SChristoph Hellwig 			       void *data)
68141da177e4SLinus Torvalds {
6815fc016483SChristoph Hellwig 	struct nfs4_statfs_res *res = data;
68161da177e4SLinus Torvalds 	struct compound_hdr hdr;
68171da177e4SLinus Torvalds 	int status;
68181da177e4SLinus Torvalds 
6819bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68201da177e4SLinus Torvalds 	if (!status)
6821bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
68229b7b9fccSAndy Adamson 	if (!status)
6823bf269551SChuck Lever 		status = decode_putfh(xdr);
68241da177e4SLinus Torvalds 	if (!status)
6825bf269551SChuck Lever 		status = decode_statfs(xdr, res->fsstat);
68261da177e4SLinus Torvalds 	return status;
68271da177e4SLinus Torvalds }
68281da177e4SLinus Torvalds 
68291da177e4SLinus Torvalds /*
68308b173218SRicardo Labiaga  * Decode GETATTR_BITMAP response
68311da177e4SLinus Torvalds  */
6832bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6833bf269551SChuck Lever 				    struct xdr_stream *xdr,
6834fc016483SChristoph Hellwig 				    void *data)
68351da177e4SLinus Torvalds {
6836fc016483SChristoph Hellwig 	struct nfs4_server_caps_res *res = data;
68371da177e4SLinus Torvalds 	struct compound_hdr hdr;
68381da177e4SLinus Torvalds 	int status;
68391da177e4SLinus Torvalds 
6840bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68419b7b9fccSAndy Adamson 	if (status)
68429b7b9fccSAndy Adamson 		goto out;
6843bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
68449b7b9fccSAndy Adamson 	if (status)
68451da177e4SLinus Torvalds 		goto out;
6846bf269551SChuck Lever 	status = decode_putfh(xdr);
6847bf269551SChuck Lever 	if (status)
68481da177e4SLinus Torvalds 		goto out;
6849bf269551SChuck Lever 	status = decode_server_caps(xdr, res);
68501da177e4SLinus Torvalds out:
68511da177e4SLinus Torvalds 	return status;
68521da177e4SLinus Torvalds }
68531da177e4SLinus Torvalds 
68541da177e4SLinus Torvalds /*
68551da177e4SLinus Torvalds  * Decode RENEW response
68561da177e4SLinus Torvalds  */
6857bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6858bf269551SChuck Lever 			      void *__unused)
68591da177e4SLinus Torvalds {
68601da177e4SLinus Torvalds 	struct compound_hdr hdr;
68611da177e4SLinus Torvalds 	int status;
68621da177e4SLinus Torvalds 
6863bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68641da177e4SLinus Torvalds 	if (!status)
6865bf269551SChuck Lever 		status = decode_renew(xdr);
68661da177e4SLinus Torvalds 	return status;
68671da177e4SLinus Torvalds }
68681da177e4SLinus Torvalds 
68691da177e4SLinus Torvalds /*
68708b173218SRicardo Labiaga  * Decode SETCLIENTID response
68711da177e4SLinus Torvalds  */
6872bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6873bf269551SChuck Lever 				    struct xdr_stream *xdr,
6874fc016483SChristoph Hellwig 				    void *data)
68751da177e4SLinus Torvalds {
6876fc016483SChristoph Hellwig 	struct nfs4_setclientid_res *res = data;
68771da177e4SLinus Torvalds 	struct compound_hdr hdr;
68781da177e4SLinus Torvalds 	int status;
68791da177e4SLinus Torvalds 
6880bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68811da177e4SLinus Torvalds 	if (!status)
6882bf269551SChuck Lever 		status = decode_setclientid(xdr, res);
68831da177e4SLinus Torvalds 	return status;
68841da177e4SLinus Torvalds }
68851da177e4SLinus Torvalds 
68861da177e4SLinus Torvalds /*
68878b173218SRicardo Labiaga  * Decode SETCLIENTID_CONFIRM response
68881da177e4SLinus Torvalds  */
6889bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6890fc016483SChristoph Hellwig 					    struct xdr_stream *xdr,
6891fc016483SChristoph Hellwig 					    void *data)
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,
6907fc016483SChristoph Hellwig 				    void *data)
69081da177e4SLinus Torvalds {
6909fc016483SChristoph Hellwig 	struct nfs4_delegreturnres *res = data;
69101da177e4SLinus Torvalds 	struct compound_hdr hdr;
69111da177e4SLinus Torvalds 	int status;
69121da177e4SLinus Torvalds 
6913bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
69149b7b9fccSAndy Adamson 	if (status)
69159b7b9fccSAndy Adamson 		goto out;
6916bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
69179b7b9fccSAndy Adamson 	if (status)
6918fa178f29STrond Myklebust 		goto out;
6919bf269551SChuck Lever 	status = decode_putfh(xdr);
6920fa178f29STrond Myklebust 	if (status != 0)
6921fa178f29STrond Myklebust 		goto out;
6922586f1c39STrond Myklebust 	if (res->lr_res) {
6923586f1c39STrond Myklebust 		status = decode_layoutreturn(xdr, res->lr_res);
6924586f1c39STrond Myklebust 		res->lr_ret = status;
6925586f1c39STrond Myklebust 		if (status)
6926586f1c39STrond Myklebust 			goto out;
6927586f1c39STrond Myklebust 	}
69288ac2b422STrond Myklebust 	if (res->fattr) {
6929e144cbccSTrond Myklebust 		status = decode_getfattr(xdr, res->fattr, res->server);
6930556ae3bbSJeff Layton 		if (status != 0)
6931556ae3bbSJeff Layton 			goto out;
69328ac2b422STrond Myklebust 	}
6933e144cbccSTrond Myklebust 	status = decode_delegreturn(xdr);
6934fa178f29STrond Myklebust out:
69351da177e4SLinus Torvalds 	return status;
69361da177e4SLinus Torvalds }
69371da177e4SLinus Torvalds 
6938683b57b4STrond Myklebust /*
69398b173218SRicardo Labiaga  * Decode FS_LOCATIONS response
6940683b57b4STrond Myklebust  */
6941bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6942bf269551SChuck Lever 				     struct xdr_stream *xdr,
6943fc016483SChristoph Hellwig 				     void *data)
6944683b57b4STrond Myklebust {
6945fc016483SChristoph Hellwig 	struct nfs4_fs_locations_res *res = data;
6946683b57b4STrond Myklebust 	struct compound_hdr hdr;
6947683b57b4STrond Myklebust 	int status;
6948683b57b4STrond Myklebust 
6949bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
69509b7b9fccSAndy Adamson 	if (status)
69519b7b9fccSAndy Adamson 		goto out;
6952bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
69539b7b9fccSAndy Adamson 	if (status)
6954683b57b4STrond Myklebust 		goto out;
6955bf269551SChuck Lever 	status = decode_putfh(xdr);
6956bf269551SChuck Lever 	if (status)
6957683b57b4STrond Myklebust 		goto out;
6958b03d735bSChuck Lever 	if (res->migration) {
6959b03d735bSChuck Lever 		xdr_enter_page(xdr, PAGE_SIZE);
6960b03d735bSChuck Lever 		status = decode_getfattr_generic(xdr,
6961b03d735bSChuck Lever 					&res->fs_locations->fattr,
6962b03d735bSChuck Lever 					 NULL, res->fs_locations,
6963b03d735bSChuck Lever 					 NULL, res->fs_locations->server);
6964b03d735bSChuck Lever 		if (status)
6965b03d735bSChuck Lever 			goto out;
6966b03d735bSChuck Lever 		if (res->renew)
6967b03d735bSChuck Lever 			status = decode_renew(xdr);
6968b03d735bSChuck Lever 	} else {
6969bf269551SChuck Lever 		status = decode_lookup(xdr);
6970bf269551SChuck Lever 		if (status)
6971683b57b4STrond Myklebust 			goto out;
6972bf269551SChuck Lever 		xdr_enter_page(xdr, PAGE_SIZE);
6973b03d735bSChuck Lever 		status = decode_getfattr_generic(xdr,
6974b03d735bSChuck Lever 					&res->fs_locations->fattr,
69758b7e3f49STrond Myklebust 					 NULL, res->fs_locations,
6976aa9c2669SDavid Quigley 					 NULL, res->fs_locations->server);
6977b03d735bSChuck Lever 	}
6978683b57b4STrond Myklebust out:
6979683b57b4STrond Myklebust 	return status;
6980683b57b4STrond Myklebust }
6981683b57b4STrond Myklebust 
69825a5ea0d4SBryan Schumaker /*
69835a5ea0d4SBryan Schumaker  * Decode SECINFO response
69845a5ea0d4SBryan Schumaker  */
69855a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
69865a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
6987fc016483SChristoph Hellwig 				void *data)
69885a5ea0d4SBryan Schumaker {
6989fc016483SChristoph Hellwig 	struct nfs4_secinfo_res *res = data;
69905a5ea0d4SBryan Schumaker 	struct compound_hdr hdr;
69915a5ea0d4SBryan Schumaker 	int status;
69925a5ea0d4SBryan Schumaker 
69935a5ea0d4SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
69945a5ea0d4SBryan Schumaker 	if (status)
69955a5ea0d4SBryan Schumaker 		goto out;
69965a5ea0d4SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
69975a5ea0d4SBryan Schumaker 	if (status)
69985a5ea0d4SBryan Schumaker 		goto out;
69995a5ea0d4SBryan Schumaker 	status = decode_putfh(xdr);
70005a5ea0d4SBryan Schumaker 	if (status)
70015a5ea0d4SBryan Schumaker 		goto out;
70025a5ea0d4SBryan Schumaker 	status = decode_secinfo(xdr, res);
70035a5ea0d4SBryan Schumaker out:
70045a5ea0d4SBryan Schumaker 	return status;
70055a5ea0d4SBryan Schumaker }
70065a5ea0d4SBryan Schumaker 
700744c99933SChuck Lever /*
700844c99933SChuck Lever  * Decode FSID_PRESENT response
700944c99933SChuck Lever  */
701044c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
701144c99933SChuck Lever 				     struct xdr_stream *xdr,
7012fc016483SChristoph Hellwig 				     void *data)
701344c99933SChuck Lever {
7014fc016483SChristoph Hellwig 	struct nfs4_fsid_present_res *res = data;
701544c99933SChuck Lever 	struct compound_hdr hdr;
701644c99933SChuck Lever 	int status;
701744c99933SChuck Lever 
701844c99933SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
701944c99933SChuck Lever 	if (status)
702044c99933SChuck Lever 		goto out;
702144c99933SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
702244c99933SChuck Lever 	if (status)
702344c99933SChuck Lever 		goto out;
702444c99933SChuck Lever 	status = decode_putfh(xdr);
702544c99933SChuck Lever 	if (status)
702644c99933SChuck Lever 		goto out;
702744c99933SChuck Lever 	status = decode_getfh(xdr, res->fh);
702844c99933SChuck Lever 	if (status)
702944c99933SChuck Lever 		goto out;
703044c99933SChuck Lever 	if (res->renew)
703144c99933SChuck Lever 		status = decode_renew(xdr);
703244c99933SChuck Lever out:
703344c99933SChuck Lever 	return status;
703444c99933SChuck Lever }
703544c99933SChuck Lever 
703699fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
703799fe60d0SBenny Halevy /*
70387c44f1aeSWeston Andros Adamson  * Decode BIND_CONN_TO_SESSION response
70397c44f1aeSWeston Andros Adamson  */
70407c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
70417c44f1aeSWeston Andros Adamson 					struct xdr_stream *xdr,
70427c44f1aeSWeston Andros Adamson 					void *res)
70437c44f1aeSWeston Andros Adamson {
70447c44f1aeSWeston Andros Adamson 	struct compound_hdr hdr;
70457c44f1aeSWeston Andros Adamson 	int status;
70467c44f1aeSWeston Andros Adamson 
70477c44f1aeSWeston Andros Adamson 	status = decode_compound_hdr(xdr, &hdr);
70487c44f1aeSWeston Andros Adamson 	if (!status)
70497c44f1aeSWeston Andros Adamson 		status = decode_bind_conn_to_session(xdr, res);
70507c44f1aeSWeston Andros Adamson 	return status;
70517c44f1aeSWeston Andros Adamson }
70527c44f1aeSWeston Andros Adamson 
70537c44f1aeSWeston Andros Adamson /*
70548b173218SRicardo Labiaga  * Decode EXCHANGE_ID response
705599fe60d0SBenny Halevy  */
7056bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7057bf269551SChuck Lever 				    struct xdr_stream *xdr,
705899fe60d0SBenny Halevy 				    void *res)
705999fe60d0SBenny Halevy {
706099fe60d0SBenny Halevy 	struct compound_hdr hdr;
706199fe60d0SBenny Halevy 	int status;
706299fe60d0SBenny Halevy 
7063bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
706499fe60d0SBenny Halevy 	if (!status)
7065bf269551SChuck Lever 		status = decode_exchange_id(xdr, res);
706699fe60d0SBenny Halevy 	return status;
706799fe60d0SBenny Halevy }
70682050f0ccSAndy Adamson 
70692050f0ccSAndy Adamson /*
70708b173218SRicardo Labiaga  * Decode CREATE_SESSION response
7071fc931582SAndy Adamson  */
7072bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7073bf269551SChuck Lever 				       struct xdr_stream *xdr,
7074fc016483SChristoph Hellwig 				       void *res)
7075fc931582SAndy Adamson {
7076fc931582SAndy Adamson 	struct compound_hdr hdr;
7077fc931582SAndy Adamson 	int status;
7078fc931582SAndy Adamson 
7079bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7080fc931582SAndy Adamson 	if (!status)
7081bf269551SChuck Lever 		status = decode_create_session(xdr, res);
7082fc931582SAndy Adamson 	return status;
7083fc931582SAndy Adamson }
7084fc931582SAndy Adamson 
7085fc931582SAndy Adamson /*
70868b173218SRicardo Labiaga  * Decode DESTROY_SESSION response
70870f3e66c6SAndy Adamson  */
7088bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7089bf269551SChuck Lever 					struct xdr_stream *xdr,
7090bf269551SChuck Lever 					void *res)
70910f3e66c6SAndy Adamson {
70920f3e66c6SAndy Adamson 	struct compound_hdr hdr;
70930f3e66c6SAndy Adamson 	int status;
70940f3e66c6SAndy Adamson 
7095bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
70960f3e66c6SAndy Adamson 	if (!status)
7097bf269551SChuck Lever 		status = decode_destroy_session(xdr, res);
70980f3e66c6SAndy Adamson 	return status;
70990f3e66c6SAndy Adamson }
71000f3e66c6SAndy Adamson 
71010f3e66c6SAndy Adamson /*
710266245539STrond Myklebust  * Decode DESTROY_CLIENTID response
710366245539STrond Myklebust  */
710466245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
710566245539STrond Myklebust 					struct xdr_stream *xdr,
710666245539STrond Myklebust 					void *res)
710766245539STrond Myklebust {
710866245539STrond Myklebust 	struct compound_hdr hdr;
710966245539STrond Myklebust 	int status;
711066245539STrond Myklebust 
711166245539STrond Myklebust 	status = decode_compound_hdr(xdr, &hdr);
711266245539STrond Myklebust 	if (!status)
711366245539STrond Myklebust 		status = decode_destroy_clientid(xdr, res);
711466245539STrond Myklebust 	return status;
711566245539STrond Myklebust }
711666245539STrond Myklebust 
711766245539STrond Myklebust /*
71188b173218SRicardo Labiaga  * Decode SEQUENCE response
7119fc01cea9SAndy Adamson  */
7120bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7121bf269551SChuck Lever 				 struct xdr_stream *xdr,
7122fc016483SChristoph Hellwig 				 void *res)
7123fc01cea9SAndy Adamson {
7124fc01cea9SAndy Adamson 	struct compound_hdr hdr;
7125fc01cea9SAndy Adamson 	int status;
7126fc01cea9SAndy Adamson 
7127bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7128fc01cea9SAndy Adamson 	if (!status)
7129bf269551SChuck Lever 		status = decode_sequence(xdr, res, rqstp);
7130fc01cea9SAndy Adamson 	return status;
7131fc01cea9SAndy Adamson }
7132fc01cea9SAndy Adamson 
7133fc01cea9SAndy Adamson /*
71348b173218SRicardo Labiaga  * Decode GET_LEASE_TIME response
71352050f0ccSAndy Adamson  */
7136bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7137bf269551SChuck Lever 				       struct xdr_stream *xdr,
7138fc016483SChristoph Hellwig 				       void *data)
71392050f0ccSAndy Adamson {
7140fc016483SChristoph Hellwig 	struct nfs4_get_lease_time_res *res = data;
71412050f0ccSAndy Adamson 	struct compound_hdr hdr;
71422050f0ccSAndy Adamson 	int status;
71432050f0ccSAndy Adamson 
7144bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
71452050f0ccSAndy Adamson 	if (!status)
7146bf269551SChuck Lever 		status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
71472050f0ccSAndy Adamson 	if (!status)
7148bf269551SChuck Lever 		status = decode_putrootfh(xdr);
71492050f0ccSAndy Adamson 	if (!status)
7150bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->lr_fsinfo);
71512050f0ccSAndy Adamson 	return status;
71522050f0ccSAndy Adamson }
715318019753SRicardo Labiaga 
715418019753SRicardo Labiaga /*
715518019753SRicardo Labiaga  * Decode RECLAIM_COMPLETE response
715618019753SRicardo Labiaga  */
7157bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7158bf269551SChuck Lever 					 struct xdr_stream *xdr,
7159fc016483SChristoph Hellwig 					 void *data)
716018019753SRicardo Labiaga {
7161fc016483SChristoph Hellwig 	struct nfs41_reclaim_complete_res *res = data;
716218019753SRicardo Labiaga 	struct compound_hdr hdr;
716318019753SRicardo Labiaga 	int status;
716418019753SRicardo Labiaga 
7165bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
716618019753SRicardo Labiaga 	if (!status)
7167bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, rqstp);
716818019753SRicardo Labiaga 	if (!status)
71698ee2b78aSHimangi Saraogi 		status = decode_reclaim_complete(xdr, NULL);
717018019753SRicardo Labiaga 	return status;
717118019753SRicardo Labiaga }
7172b1f69b75SAndy Adamson 
7173b1f69b75SAndy Adamson /*
7174b1f69b75SAndy Adamson  * Decode GETDEVINFO response
7175b1f69b75SAndy Adamson  */
7176bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7177bf269551SChuck Lever 				      struct xdr_stream *xdr,
7178fc016483SChristoph Hellwig 				      void *data)
7179b1f69b75SAndy Adamson {
7180fc016483SChristoph Hellwig 	struct nfs4_getdeviceinfo_res *res = data;
7181b1f69b75SAndy Adamson 	struct compound_hdr hdr;
7182b1f69b75SAndy Adamson 	int status;
7183b1f69b75SAndy Adamson 
7184bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7185b1f69b75SAndy Adamson 	if (status != 0)
7186b1f69b75SAndy Adamson 		goto out;
7187bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7188b1f69b75SAndy Adamson 	if (status != 0)
7189b1f69b75SAndy Adamson 		goto out;
71904e590803STrond Myklebust 	status = decode_getdeviceinfo(xdr, res);
7191b1f69b75SAndy Adamson out:
7192b1f69b75SAndy Adamson 	return status;
7193b1f69b75SAndy Adamson }
7194b1f69b75SAndy Adamson 
7195b1f69b75SAndy Adamson /*
7196b1f69b75SAndy Adamson  * Decode LAYOUTGET response
7197b1f69b75SAndy Adamson  */
7198bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7199bf269551SChuck Lever 				  struct xdr_stream *xdr,
7200fc016483SChristoph Hellwig 				  void *data)
7201b1f69b75SAndy Adamson {
7202fc016483SChristoph Hellwig 	struct nfs4_layoutget_res *res = data;
7203b1f69b75SAndy Adamson 	struct compound_hdr hdr;
7204b1f69b75SAndy Adamson 	int status;
7205b1f69b75SAndy Adamson 
7206bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7207b1f69b75SAndy Adamson 	if (status)
7208b1f69b75SAndy Adamson 		goto out;
7209bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7210b1f69b75SAndy Adamson 	if (status)
7211b1f69b75SAndy Adamson 		goto out;
7212bf269551SChuck Lever 	status = decode_putfh(xdr);
7213b1f69b75SAndy Adamson 	if (status)
7214b1f69b75SAndy Adamson 		goto out;
7215bf269551SChuck Lever 	status = decode_layoutget(xdr, rqstp, res);
7216b1f69b75SAndy Adamson out:
7217b1f69b75SAndy Adamson 	return status;
7218b1f69b75SAndy Adamson }
7219863a3c6cSAndy Adamson 
7220863a3c6cSAndy Adamson /*
7221cbe82603SBenny Halevy  * Decode LAYOUTRETURN response
7222cbe82603SBenny Halevy  */
7223cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7224cbe82603SBenny Halevy 				     struct xdr_stream *xdr,
7225fc016483SChristoph Hellwig 				     void *data)
7226cbe82603SBenny Halevy {
7227fc016483SChristoph Hellwig 	struct nfs4_layoutreturn_res *res = data;
7228cbe82603SBenny Halevy 	struct compound_hdr hdr;
7229cbe82603SBenny Halevy 	int status;
7230cbe82603SBenny Halevy 
7231cbe82603SBenny Halevy 	status = decode_compound_hdr(xdr, &hdr);
7232cbe82603SBenny Halevy 	if (status)
7233cbe82603SBenny Halevy 		goto out;
7234cbe82603SBenny Halevy 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7235cbe82603SBenny Halevy 	if (status)
7236cbe82603SBenny Halevy 		goto out;
7237cbe82603SBenny Halevy 	status = decode_putfh(xdr);
7238cbe82603SBenny Halevy 	if (status)
7239cbe82603SBenny Halevy 		goto out;
7240cbe82603SBenny Halevy 	status = decode_layoutreturn(xdr, res);
7241cbe82603SBenny Halevy out:
7242cbe82603SBenny Halevy 	return status;
7243cbe82603SBenny Halevy }
7244cbe82603SBenny Halevy 
7245cbe82603SBenny Halevy /*
7246863a3c6cSAndy Adamson  * Decode LAYOUTCOMMIT response
7247863a3c6cSAndy Adamson  */
7248863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7249863a3c6cSAndy Adamson 				     struct xdr_stream *xdr,
7250fc016483SChristoph Hellwig 				     void *data)
7251863a3c6cSAndy Adamson {
7252fc016483SChristoph Hellwig 	struct nfs4_layoutcommit_res *res = data;
7253863a3c6cSAndy Adamson 	struct compound_hdr hdr;
7254863a3c6cSAndy Adamson 	int status;
7255863a3c6cSAndy Adamson 
7256863a3c6cSAndy Adamson 	status = decode_compound_hdr(xdr, &hdr);
7257863a3c6cSAndy Adamson 	if (status)
7258863a3c6cSAndy Adamson 		goto out;
7259863a3c6cSAndy Adamson 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7260863a3c6cSAndy Adamson 	if (status)
7261863a3c6cSAndy Adamson 		goto out;
7262863a3c6cSAndy Adamson 	status = decode_putfh(xdr);
7263863a3c6cSAndy Adamson 	if (status)
7264863a3c6cSAndy Adamson 		goto out;
7265863a3c6cSAndy Adamson 	status = decode_layoutcommit(xdr, rqstp, res);
7266863a3c6cSAndy Adamson 	if (status)
7267863a3c6cSAndy Adamson 		goto out;
72686926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
7269863a3c6cSAndy Adamson out:
7270863a3c6cSAndy Adamson 	return status;
7271863a3c6cSAndy Adamson }
7272fca78d6dSBryan Schumaker 
7273fca78d6dSBryan Schumaker /*
7274fca78d6dSBryan Schumaker  * Decode SECINFO_NO_NAME response
7275fca78d6dSBryan Schumaker  */
7276fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7277fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
7278fc016483SChristoph Hellwig 					void *data)
7279fca78d6dSBryan Schumaker {
7280fc016483SChristoph Hellwig 	struct nfs4_secinfo_res *res = data;
7281fca78d6dSBryan Schumaker 	struct compound_hdr hdr;
7282fca78d6dSBryan Schumaker 	int status;
7283fca78d6dSBryan Schumaker 
7284fca78d6dSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
7285fca78d6dSBryan Schumaker 	if (status)
7286fca78d6dSBryan Schumaker 		goto out;
7287fca78d6dSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7288fca78d6dSBryan Schumaker 	if (status)
7289fca78d6dSBryan Schumaker 		goto out;
7290fca78d6dSBryan Schumaker 	status = decode_putrootfh(xdr);
7291fca78d6dSBryan Schumaker 	if (status)
7292fca78d6dSBryan Schumaker 		goto out;
729331e4dda4SBryan Schumaker 	status = decode_secinfo_no_name(xdr, res);
7294fca78d6dSBryan Schumaker out:
7295fca78d6dSBryan Schumaker 	return status;
7296fca78d6dSBryan Schumaker }
72977d974794SBryan Schumaker 
72987d974794SBryan Schumaker /*
72997d974794SBryan Schumaker  * Decode TEST_STATEID response
73007d974794SBryan Schumaker  */
73017d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
73027d974794SBryan Schumaker 				     struct xdr_stream *xdr,
7303fc016483SChristoph Hellwig 				     void *data)
73047d974794SBryan Schumaker {
7305fc016483SChristoph Hellwig 	struct nfs41_test_stateid_res *res = data;
73067d974794SBryan Schumaker 	struct compound_hdr hdr;
73077d974794SBryan Schumaker 	int status;
73087d974794SBryan Schumaker 
73097d974794SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
73107d974794SBryan Schumaker 	if (status)
73117d974794SBryan Schumaker 		goto out;
73127d974794SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
73137d974794SBryan Schumaker 	if (status)
73147d974794SBryan Schumaker 		goto out;
73157d974794SBryan Schumaker 	status = decode_test_stateid(xdr, res);
73167d974794SBryan Schumaker out:
73177d974794SBryan Schumaker 	return status;
73187d974794SBryan Schumaker }
73199aeda35fSBryan Schumaker 
73209aeda35fSBryan Schumaker /*
73219aeda35fSBryan Schumaker  * Decode FREE_STATEID response
73229aeda35fSBryan Schumaker  */
73239aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
73249aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
7325fc016483SChristoph Hellwig 				     void *data)
73269aeda35fSBryan Schumaker {
7327fc016483SChristoph Hellwig 	struct nfs41_free_stateid_res *res = data;
73289aeda35fSBryan Schumaker 	struct compound_hdr hdr;
73299aeda35fSBryan Schumaker 	int status;
73309aeda35fSBryan Schumaker 
73319aeda35fSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
73329aeda35fSBryan Schumaker 	if (status)
73339aeda35fSBryan Schumaker 		goto out;
73349aeda35fSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
73359aeda35fSBryan Schumaker 	if (status)
73369aeda35fSBryan Schumaker 		goto out;
73379aeda35fSBryan Schumaker 	status = decode_free_stateid(xdr, res);
73389aeda35fSBryan Schumaker out:
73399aeda35fSBryan Schumaker 	return status;
73409aeda35fSBryan Schumaker }
734199fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
734299fe60d0SBenny Halevy 
7343573c4e1eSChuck Lever /**
7344573c4e1eSChuck Lever  * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7345573c4e1eSChuck Lever  *                      the local page cache.
7346573c4e1eSChuck Lever  * @xdr: XDR stream where entry resides
7347573c4e1eSChuck Lever  * @entry: buffer to fill in with entry data
7348573c4e1eSChuck Lever  * @plus: boolean indicating whether this should be a readdirplus entry
7349573c4e1eSChuck Lever  *
7350573c4e1eSChuck Lever  * Returns zero if successful, otherwise a negative errno value is
7351573c4e1eSChuck Lever  * returned.
7352573c4e1eSChuck Lever  *
7353573c4e1eSChuck Lever  * This function is not invoked during READDIR reply decoding, but
7354573c4e1eSChuck Lever  * rather whenever an application invokes the getdents(2) system call
7355573c4e1eSChuck Lever  * on a directory already in our cache.
7356573c4e1eSChuck Lever  */
7357573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7358a7a3b1e9SBenjamin Coddington 		       bool plus)
73591da177e4SLinus Torvalds {
7360256e48bbSTrond Myklebust 	unsigned int savep;
7361dae100c2SFred Isaman 	uint32_t bitmap[3] = {0};
73621da177e4SLinus Torvalds 	uint32_t len;
736398de9ce6SFrank Sorenson 	uint64_t new_cookie;
7364babddc72SBryan Schumaker 	__be32 *p = xdr_inline_decode(xdr, 4);
7365babddc72SBryan Schumaker 	if (unlikely(!p))
7366eb72f484SChuck Lever 		return -EAGAIN;
7367c08e76d0SChuck Lever 	if (*p == xdr_zero) {
7368babddc72SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
7369babddc72SBryan Schumaker 		if (unlikely(!p))
7370eb72f484SChuck Lever 			return -EAGAIN;
7371c08e76d0SChuck Lever 		if (*p == xdr_zero)
7372573c4e1eSChuck Lever 			return -EAGAIN;
73731da177e4SLinus Torvalds 		entry->eof = 1;
7374573c4e1eSChuck Lever 		return -EBADCOOKIE;
73751da177e4SLinus Torvalds 	}
73761da177e4SLinus Torvalds 
7377babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 12);
7378babddc72SBryan Schumaker 	if (unlikely(!p))
7379eb72f484SChuck Lever 		return -EAGAIN;
738098de9ce6SFrank Sorenson 	p = xdr_decode_hyper(p, &new_cookie);
7381c08e76d0SChuck Lever 	entry->len = be32_to_cpup(p);
7382babddc72SBryan Schumaker 
73839af8c222STrond Myklebust 	p = xdr_inline_decode(xdr, entry->len);
7384babddc72SBryan Schumaker 	if (unlikely(!p))
7385eb72f484SChuck Lever 		return -EAGAIN;
73861da177e4SLinus Torvalds 	entry->name = (const char *) p;
73871da177e4SLinus Torvalds 
73881da177e4SLinus Torvalds 	/*
73891da177e4SLinus Torvalds 	 * In case the server doesn't return an inode number,
73901da177e4SLinus Torvalds 	 * we fake one here.  (We don't use inode number 0,
73911da177e4SLinus Torvalds 	 * since glibc seems to choke on it...)
73921da177e4SLinus Torvalds 	 */
73931da177e4SLinus Torvalds 	entry->ino = 1;
73944f082222STrond Myklebust 	entry->fattr->valid = 0;
73951da177e4SLinus Torvalds 
73969af8c222STrond Myklebust 	if (decode_attr_bitmap(xdr, bitmap) < 0)
7397eb72f484SChuck Lever 		return -EAGAIN;
73989af8c222STrond Myklebust 
7399256e48bbSTrond Myklebust 	if (decode_attr_length(xdr, &len, &savep) < 0)
7400eb72f484SChuck Lever 		return -EAGAIN;
74019af8c222STrond Myklebust 
7402573c4e1eSChuck Lever 	if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7403aa9c2669SDavid Quigley 			NULL, entry->label, entry->server) < 0)
7404eb72f484SChuck Lever 		return -EAGAIN;
740528331a46STrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
740628331a46STrond Myklebust 		entry->ino = entry->fattr->mounted_on_fileid;
740728331a46STrond Myklebust 	else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
740882f2e547SBryan Schumaker 		entry->ino = entry->fattr->fileid;
74099af8c222STrond Myklebust 
74100b26a0bfSTrond Myklebust 	entry->d_type = DT_UNKNOWN;
74110b26a0bfSTrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
74120b26a0bfSTrond Myklebust 		entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
74130b26a0bfSTrond Myklebust 
741498de9ce6SFrank Sorenson 	entry->prev_cookie = entry->cookie;
741598de9ce6SFrank Sorenson 	entry->cookie = new_cookie;
741698de9ce6SFrank Sorenson 
7417573c4e1eSChuck Lever 	return 0;
74181da177e4SLinus Torvalds }
74191da177e4SLinus Torvalds 
74201da177e4SLinus Torvalds /*
74211da177e4SLinus Torvalds  * We need to translate between nfs status return values and
74221da177e4SLinus Torvalds  * the local errno values which may not be the same.
74231da177e4SLinus Torvalds  */
74241da177e4SLinus Torvalds static struct {
74251da177e4SLinus Torvalds 	int stat;
74261da177e4SLinus Torvalds 	int errno;
74271da177e4SLinus Torvalds } nfs_errtbl[] = {
74281da177e4SLinus Torvalds 	{ NFS4_OK,		0		},
7429856dff3dSBenny Halevy 	{ NFS4ERR_PERM,		-EPERM		},
7430856dff3dSBenny Halevy 	{ NFS4ERR_NOENT,	-ENOENT		},
7431856dff3dSBenny Halevy 	{ NFS4ERR_IO,		-errno_NFSERR_IO},
7432856dff3dSBenny Halevy 	{ NFS4ERR_NXIO,		-ENXIO		},
7433856dff3dSBenny Halevy 	{ NFS4ERR_ACCESS,	-EACCES		},
7434856dff3dSBenny Halevy 	{ NFS4ERR_EXIST,	-EEXIST		},
7435856dff3dSBenny Halevy 	{ NFS4ERR_XDEV,		-EXDEV		},
7436856dff3dSBenny Halevy 	{ NFS4ERR_NOTDIR,	-ENOTDIR	},
7437856dff3dSBenny Halevy 	{ NFS4ERR_ISDIR,	-EISDIR		},
7438856dff3dSBenny Halevy 	{ NFS4ERR_INVAL,	-EINVAL		},
7439856dff3dSBenny Halevy 	{ NFS4ERR_FBIG,		-EFBIG		},
7440856dff3dSBenny Halevy 	{ NFS4ERR_NOSPC,	-ENOSPC		},
7441856dff3dSBenny Halevy 	{ NFS4ERR_ROFS,		-EROFS		},
7442856dff3dSBenny Halevy 	{ NFS4ERR_MLINK,	-EMLINK		},
7443856dff3dSBenny Halevy 	{ NFS4ERR_NAMETOOLONG,	-ENAMETOOLONG	},
7444856dff3dSBenny Halevy 	{ NFS4ERR_NOTEMPTY,	-ENOTEMPTY	},
7445856dff3dSBenny Halevy 	{ NFS4ERR_DQUOT,	-EDQUOT		},
7446856dff3dSBenny Halevy 	{ NFS4ERR_STALE,	-ESTALE		},
7447856dff3dSBenny Halevy 	{ NFS4ERR_BADHANDLE,	-EBADHANDLE	},
7448856dff3dSBenny Halevy 	{ NFS4ERR_BAD_COOKIE,	-EBADCOOKIE	},
7449856dff3dSBenny Halevy 	{ NFS4ERR_NOTSUPP,	-ENOTSUPP	},
7450856dff3dSBenny Halevy 	{ NFS4ERR_TOOSMALL,	-ETOOSMALL	},
7451fdcb4577STrond Myklebust 	{ NFS4ERR_SERVERFAULT,	-EREMOTEIO	},
7452856dff3dSBenny Halevy 	{ NFS4ERR_BADTYPE,	-EBADTYPE	},
7453856dff3dSBenny Halevy 	{ NFS4ERR_LOCKED,	-EAGAIN		},
7454856dff3dSBenny Halevy 	{ NFS4ERR_SYMLINK,	-ELOOP		},
7455856dff3dSBenny Halevy 	{ NFS4ERR_OP_ILLEGAL,	-EOPNOTSUPP	},
7456856dff3dSBenny Halevy 	{ NFS4ERR_DEADLOCK,	-EDEADLK	},
7457856dff3dSBenny Halevy 	{ -1,			-EIO		}
74581da177e4SLinus Torvalds };
74591da177e4SLinus Torvalds 
74601da177e4SLinus Torvalds /*
74611da177e4SLinus Torvalds  * Convert an NFS error code to a local one.
74621da177e4SLinus Torvalds  * This one is used jointly by NFSv2 and NFSv3.
74631da177e4SLinus Torvalds  */
74641da177e4SLinus Torvalds static int
74650a8ea437SDavid Howells nfs4_stat_to_errno(int stat)
74661da177e4SLinus Torvalds {
74671da177e4SLinus Torvalds 	int i;
74681da177e4SLinus Torvalds 	for (i = 0; nfs_errtbl[i].stat != -1; i++) {
74691da177e4SLinus Torvalds 		if (nfs_errtbl[i].stat == stat)
74701da177e4SLinus Torvalds 			return nfs_errtbl[i].errno;
74711da177e4SLinus Torvalds 	}
74721da177e4SLinus Torvalds 	if (stat <= 10000 || stat > 10100) {
74731da177e4SLinus Torvalds 		/* The server is looney tunes. */
7474fdcb4577STrond Myklebust 		return -EREMOTEIO;
74751da177e4SLinus Torvalds 	}
74761da177e4SLinus Torvalds 	/* If we cannot translate the error, the recovery routines should
74771da177e4SLinus Torvalds 	 * handle it.
74781da177e4SLinus Torvalds 	 * Note: remaining NFSv4 error codes have values > 10000, so should
74791da177e4SLinus Torvalds 	 * not conflict with native Linux error codes.
74801da177e4SLinus Torvalds 	 */
7481856dff3dSBenny Halevy 	return -stat;
74821da177e4SLinus Torvalds }
74831da177e4SLinus Torvalds 
74841c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2
74851c6dcbe5SAnna Schumaker #include "nfs42xdr.c"
74861c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */
74871c6dcbe5SAnna Schumaker 
74881da177e4SLinus Torvalds #define PROC(proc, argtype, restype)				\
74891da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = {					\
74901da177e4SLinus Torvalds 	.p_proc   = NFSPROC4_COMPOUND,				\
7491fcc85819SChristoph Hellwig 	.p_encode = nfs4_xdr_##argtype,				\
7492fc016483SChristoph Hellwig 	.p_decode = nfs4_xdr_##restype,				\
74932bea90d4SChuck Lever 	.p_arglen = NFS4_##argtype##_sz,			\
74942bea90d4SChuck Lever 	.p_replen = NFS4_##restype##_sz,			\
7495cc0175c1SChuck Lever 	.p_statidx = NFSPROC4_CLNT_##proc,			\
7496cc0175c1SChuck Lever 	.p_name   = #proc,					\
74971da177e4SLinus Torvalds }
74981da177e4SLinus Torvalds 
74997c61f0d3SAnna Schumaker #define STUB(proc)		\
75007c61f0d3SAnna Schumaker [NFSPROC4_CLNT_##proc] = {	\
75017c61f0d3SAnna Schumaker 	.p_name = #proc,	\
75027c61f0d3SAnna Schumaker }
75037c61f0d3SAnna Schumaker 
75048634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_1)
75058634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype)				\
75068634ef5eSTrond Myklebust 	PROC(proc, argtype, restype)
75078634ef5eSTrond Myklebust #else
75088634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype)				\
75098634ef5eSTrond Myklebust 	STUB(proc)
75108634ef5eSTrond Myklebust #endif
75118634ef5eSTrond Myklebust 
75128634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_2)
75138634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype)				\
75148634ef5eSTrond Myklebust 	PROC(proc, argtype, restype)
75158634ef5eSTrond Myklebust #else
75168634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype)				\
75178634ef5eSTrond Myklebust 	STUB(proc)
75188634ef5eSTrond Myklebust #endif
75198634ef5eSTrond Myklebust 
7520511e936bSChristoph Hellwig const struct rpc_procinfo nfs4_procedures[] = {
75211da177e4SLinus Torvalds 	PROC(READ,		enc_read,		dec_read),
75221da177e4SLinus Torvalds 	PROC(WRITE,		enc_write,		dec_write),
75231da177e4SLinus Torvalds 	PROC(COMMIT,		enc_commit,		dec_commit),
75241da177e4SLinus Torvalds 	PROC(OPEN,		enc_open,		dec_open),
75251da177e4SLinus Torvalds 	PROC(OPEN_CONFIRM,	enc_open_confirm,	dec_open_confirm),
75261da177e4SLinus Torvalds 	PROC(OPEN_NOATTR,	enc_open_noattr,	dec_open_noattr),
75271da177e4SLinus Torvalds 	PROC(OPEN_DOWNGRADE,	enc_open_downgrade,	dec_open_downgrade),
75281da177e4SLinus Torvalds 	PROC(CLOSE,		enc_close,		dec_close),
75291da177e4SLinus Torvalds 	PROC(SETATTR,		enc_setattr,		dec_setattr),
75301da177e4SLinus Torvalds 	PROC(FSINFO,		enc_fsinfo,		dec_fsinfo),
75311da177e4SLinus Torvalds 	PROC(RENEW,		enc_renew,		dec_renew),
75321da177e4SLinus Torvalds 	PROC(SETCLIENTID,	enc_setclientid,	dec_setclientid),
75331da177e4SLinus Torvalds 	PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
75341da177e4SLinus Torvalds 	PROC(LOCK,		enc_lock,		dec_lock),
75351da177e4SLinus Torvalds 	PROC(LOCKT,		enc_lockt,		dec_lockt),
75361da177e4SLinus Torvalds 	PROC(LOCKU,		enc_locku,		dec_locku),
75371da177e4SLinus Torvalds 	PROC(ACCESS,		enc_access,		dec_access),
75381da177e4SLinus Torvalds 	PROC(GETATTR,		enc_getattr,		dec_getattr),
75391da177e4SLinus Torvalds 	PROC(LOOKUP,		enc_lookup,		dec_lookup),
75401da177e4SLinus Torvalds 	PROC(LOOKUP_ROOT,	enc_lookup_root,	dec_lookup_root),
75411da177e4SLinus Torvalds 	PROC(REMOVE,		enc_remove,		dec_remove),
75421da177e4SLinus Torvalds 	PROC(RENAME,		enc_rename,		dec_rename),
75431da177e4SLinus Torvalds 	PROC(LINK,		enc_link,		dec_link),
75441da177e4SLinus Torvalds 	PROC(SYMLINK,		enc_symlink,		dec_symlink),
75451da177e4SLinus Torvalds 	PROC(CREATE,		enc_create,		dec_create),
75461da177e4SLinus Torvalds 	PROC(PATHCONF,		enc_pathconf,		dec_pathconf),
75471da177e4SLinus Torvalds 	PROC(STATFS,		enc_statfs,		dec_statfs),
75481da177e4SLinus Torvalds 	PROC(READLINK,		enc_readlink,		dec_readlink),
75491da177e4SLinus Torvalds 	PROC(READDIR,		enc_readdir,		dec_readdir),
75501da177e4SLinus Torvalds 	PROC(SERVER_CAPS,	enc_server_caps,	dec_server_caps),
75511da177e4SLinus Torvalds 	PROC(DELEGRETURN,	enc_delegreturn,	dec_delegreturn),
7552029d105eSJ. Bruce Fields 	PROC(GETACL,		enc_getacl,		dec_getacl),
755323ec6965SJ. Bruce Fields 	PROC(SETACL,		enc_setacl,		dec_setacl),
7554683b57b4STrond Myklebust 	PROC(FS_LOCATIONS,	enc_fs_locations,	dec_fs_locations),
7555d3c7b7ccSTrond Myklebust 	PROC(RELEASE_LOCKOWNER,	enc_release_lockowner,	dec_release_lockowner),
75565a5ea0d4SBryan Schumaker 	PROC(SECINFO,		enc_secinfo,		dec_secinfo),
755744c99933SChuck Lever 	PROC(FSID_PRESENT,	enc_fsid_present,	dec_fsid_present),
75588634ef5eSTrond Myklebust 	PROC41(EXCHANGE_ID,	enc_exchange_id,	dec_exchange_id),
75598634ef5eSTrond Myklebust 	PROC41(CREATE_SESSION,	enc_create_session,	dec_create_session),
75608634ef5eSTrond Myklebust 	PROC41(DESTROY_SESSION,	enc_destroy_session,	dec_destroy_session),
75618634ef5eSTrond Myklebust 	PROC41(SEQUENCE,	enc_sequence,		dec_sequence),
75628634ef5eSTrond Myklebust 	PROC41(GET_LEASE_TIME,	enc_get_lease_time,	dec_get_lease_time),
75638634ef5eSTrond Myklebust 	PROC41(RECLAIM_COMPLETE,enc_reclaim_complete,	dec_reclaim_complete),
75648634ef5eSTrond Myklebust 	PROC41(GETDEVICEINFO,	enc_getdeviceinfo,	dec_getdeviceinfo),
75658634ef5eSTrond Myklebust 	PROC41(LAYOUTGET,	enc_layoutget,		dec_layoutget),
75668634ef5eSTrond Myklebust 	PROC41(LAYOUTCOMMIT,	enc_layoutcommit,	dec_layoutcommit),
75678634ef5eSTrond Myklebust 	PROC41(LAYOUTRETURN,	enc_layoutreturn,	dec_layoutreturn),
75688634ef5eSTrond Myklebust 	PROC41(SECINFO_NO_NAME,	enc_secinfo_no_name,	dec_secinfo_no_name),
75698634ef5eSTrond Myklebust 	PROC41(TEST_STATEID,	enc_test_stateid,	dec_test_stateid),
75708634ef5eSTrond Myklebust 	PROC41(FREE_STATEID,	enc_free_stateid,	dec_free_stateid),
75717c61f0d3SAnna Schumaker 	STUB(GETDEVICELIST),
75728634ef5eSTrond Myklebust 	PROC41(BIND_CONN_TO_SESSION,
7573ad24ecfbSTrond Myklebust 			enc_bind_conn_to_session, dec_bind_conn_to_session),
75748634ef5eSTrond Myklebust 	PROC41(DESTROY_CLIENTID,enc_destroy_clientid,	dec_destroy_clientid),
75758634ef5eSTrond Myklebust 	PROC42(SEEK,		enc_seek,		dec_seek),
75768634ef5eSTrond Myklebust 	PROC42(ALLOCATE,	enc_allocate,		dec_allocate),
75778634ef5eSTrond Myklebust 	PROC42(DEALLOCATE,	enc_deallocate,		dec_deallocate),
75788634ef5eSTrond Myklebust 	PROC42(LAYOUTSTATS,	enc_layoutstats,	dec_layoutstats),
75798634ef5eSTrond Myklebust 	PROC42(CLONE,		enc_clone,		dec_clone),
75808634ef5eSTrond Myklebust 	PROC42(COPY,		enc_copy,		dec_copy),
7581cb95deeaSOlga Kornievskaia 	PROC42(OFFLOAD_CANCEL,	enc_offload_cancel,	dec_offload_cancel),
75828634ef5eSTrond Myklebust 	PROC(LOOKUPP,		enc_lookupp,		dec_lookupp),
75831da177e4SLinus Torvalds };
75841da177e4SLinus Torvalds 
7585c551858aSChristoph Hellwig static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
7586a613fa16STrond Myklebust const struct rpc_version nfs_version4 = {
75871da177e4SLinus Torvalds 	.number			= 4,
7588e8c96f8cSTobias Klauser 	.nrprocs		= ARRAY_SIZE(nfs4_procedures),
7589c551858aSChristoph Hellwig 	.procs			= nfs4_procedures,
7590c551858aSChristoph Hellwig 	.counts			= nfs_version4_counts,
75911da177e4SLinus Torvalds };
75921da177e4SLinus Torvalds 
75931da177e4SLinus Torvalds /*
75941da177e4SLinus Torvalds  * Local variables:
75951da177e4SLinus Torvalds  *  c-basic-offset: 8
75961da177e4SLinus Torvalds  * End:
75971da177e4SLinus Torvalds  */
7598