xref: /openbmc/linux/fs/nfs/nfs4xdr.c (revision ae08483c)
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)
21802ef04e4SChuck Lever #define decode_read_maxsz	(op_decode_hdr_maxsz + 2 + 1)
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 + \
22302ef04e4SChuck Lever 				 decode_verifier_maxsz + 1)
2249104a55dSTrond Myklebust #define encode_readlink_maxsz	(op_encode_hdr_maxsz)
22502ef04e4SChuck Lever #define decode_readlink_maxsz	(op_decode_hdr_maxsz + 1 + 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 + \
28702ef04e4SChuck Lever 				 nfs4_fattr_bitmap_maxsz + 1 + 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 \
29402ef04e4SChuck Lever 				(1)
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 */ + \
39502ef04e4SChuck Lever 				1 /* notification bitmap, word 0 */ + \
39602ef04e4SChuck Lever 				1 /* possible XDR padding */)
397b1f69b75SAndy Adamson #define encode_layoutget_maxsz	(op_encode_hdr_maxsz + 10 + \
398b1f69b75SAndy Adamson 				encode_stateid_maxsz)
399b1f69b75SAndy Adamson #define decode_layoutget_maxsz	(op_decode_hdr_maxsz + 8 + \
400b1f69b75SAndy Adamson 				decode_stateid_maxsz + \
40102ef04e4SChuck Lever 				XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
402863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
403863a3c6cSAndy Adamson 				2 /* offset */ + \
404863a3c6cSAndy Adamson 				2 /* length */ + \
405863a3c6cSAndy Adamson 				1 /* reclaim */ + \
406863a3c6cSAndy Adamson 				encode_stateid_maxsz + \
407863a3c6cSAndy Adamson 				1 /* new offset (true) */ + \
408863a3c6cSAndy Adamson 				2 /* last byte written */ + \
409863a3c6cSAndy Adamson 				1 /* nt_timechanged (false) */ + \
410863a3c6cSAndy Adamson 				1 /* layoutupdate4 layout type */ + \
4115f919c9fSChristoph Hellwig 				1 /* layoutupdate4 opaqueue len */)
4125f919c9fSChristoph Hellwig 				  /* the actual content of layoutupdate4 should
4135f919c9fSChristoph Hellwig 				     be allocated by drivers and spliced in
4145f919c9fSChristoph Hellwig 				     using xdr_write_pages */
415863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
416cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
417cbe82603SBenny Halevy 				encode_stateid_maxsz + \
4186669cb8bSTrond Myklebust 				1 + \
4196669cb8bSTrond Myklebust 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
420cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
421cbe82603SBenny Halevy 				1 + decode_stateid_maxsz)
422fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
423fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
4247d974794SBryan Schumaker #define encode_test_stateid_maxsz	(op_encode_hdr_maxsz + 2 + \
4257d974794SBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
4267d974794SBryan Schumaker #define decode_test_stateid_maxsz	(op_decode_hdr_maxsz + 2 + 1)
4279aeda35fSBryan Schumaker #define encode_free_stateid_maxsz	(op_encode_hdr_maxsz + 1 + \
4289aeda35fSBryan Schumaker 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
4299f79fb48SAndy Adamson #define decode_free_stateid_maxsz	(op_decode_hdr_maxsz)
4309b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */
4319b7b9fccSAndy Adamson #define encode_sequence_maxsz	0
4329b7b9fccSAndy Adamson #define decode_sequence_maxsz	0
433cf805165STrond Myklebust #define encode_layoutreturn_maxsz 0
434cf805165STrond Myklebust #define decode_layoutreturn_maxsz 0
43556f487f8SFred Isaman #define encode_layoutget_maxsz	0
43656f487f8SFred Isaman #define decode_layoutget_maxsz	0
4379b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
4389b7b9fccSAndy Adamson 
4391da177e4SLinus Torvalds #define NFS4_enc_compound_sz	(1024)  /* XXX: large enough? */
4401da177e4SLinus Torvalds #define NFS4_dec_compound_sz	(1024)  /* XXX: large enough? */
4411da177e4SLinus Torvalds #define NFS4_enc_read_sz	(compound_encode_hdr_maxsz + \
4429b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4431da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4449104a55dSTrond Myklebust 				encode_read_maxsz)
4451da177e4SLinus Torvalds #define NFS4_dec_read_sz	(compound_decode_hdr_maxsz + \
4469b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4471da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4489104a55dSTrond Myklebust 				decode_read_maxsz)
4491da177e4SLinus Torvalds #define NFS4_enc_readlink_sz	(compound_encode_hdr_maxsz + \
4509b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4511da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4529104a55dSTrond Myklebust 				encode_readlink_maxsz)
4531da177e4SLinus Torvalds #define NFS4_dec_readlink_sz	(compound_decode_hdr_maxsz + \
4549b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4551da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4569104a55dSTrond Myklebust 				decode_readlink_maxsz)
4571da177e4SLinus Torvalds #define NFS4_enc_readdir_sz	(compound_encode_hdr_maxsz + \
4589b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4591da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4609104a55dSTrond Myklebust 				encode_readdir_maxsz)
4611da177e4SLinus Torvalds #define NFS4_dec_readdir_sz	(compound_decode_hdr_maxsz + \
4629b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4631da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4649104a55dSTrond Myklebust 				decode_readdir_maxsz)
4651da177e4SLinus Torvalds #define NFS4_enc_write_sz	(compound_encode_hdr_maxsz + \
4669b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4671da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4689104a55dSTrond Myklebust 				encode_write_maxsz + \
4694f9838c7STrond Myklebust 				encode_getattr_maxsz)
4701da177e4SLinus Torvalds #define NFS4_dec_write_sz	(compound_decode_hdr_maxsz + \
4719b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4721da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4739104a55dSTrond Myklebust 				decode_write_maxsz + \
4744f9838c7STrond Myklebust 				decode_getattr_maxsz)
4751da177e4SLinus Torvalds #define NFS4_enc_commit_sz	(compound_encode_hdr_maxsz + \
4769b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4771da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4788582715eSTrond Myklebust 				encode_commit_maxsz)
4791da177e4SLinus Torvalds #define NFS4_dec_commit_sz	(compound_decode_hdr_maxsz + \
4809b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4811da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4828582715eSTrond Myklebust 				decode_commit_maxsz)
4831da177e4SLinus Torvalds #define NFS4_enc_open_sz        (compound_encode_hdr_maxsz + \
4849b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
4851da177e4SLinus Torvalds 				encode_putfh_maxsz + \
4862cebf828STrond Myklebust 				encode_open_maxsz + \
4876168f62cSWeston Andros Adamson 				encode_access_maxsz + \
4882cebf828STrond Myklebust 				encode_getfh_maxsz + \
48956f487f8SFred Isaman 				encode_getattr_maxsz + \
49056f487f8SFred Isaman 				encode_layoutget_maxsz)
4911da177e4SLinus Torvalds #define NFS4_dec_open_sz        (compound_decode_hdr_maxsz + \
4929b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
4931da177e4SLinus Torvalds 				decode_putfh_maxsz + \
4942cebf828STrond Myklebust 				decode_open_maxsz + \
4956168f62cSWeston Andros Adamson 				decode_access_maxsz + \
4962cebf828STrond Myklebust 				decode_getfh_maxsz + \
49756f487f8SFred Isaman 				decode_getattr_maxsz + \
49856f487f8SFred Isaman 				decode_layoutget_maxsz)
4991da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \
5001da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
5011da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
5029104a55dSTrond Myklebust 				 encode_open_confirm_maxsz)
5039104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \
5049104a55dSTrond Myklebust 				(compound_decode_hdr_maxsz + \
5051da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
5069104a55dSTrond Myklebust 				 decode_open_confirm_maxsz)
5071da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz	(compound_encode_hdr_maxsz + \
5089b7b9fccSAndy Adamson 					encode_sequence_maxsz + \
5091da177e4SLinus Torvalds 					encode_putfh_maxsz + \
5102cebf828STrond Myklebust 					encode_open_maxsz + \
5116168f62cSWeston Andros Adamson 					encode_access_maxsz + \
51256f487f8SFred Isaman 					encode_getattr_maxsz + \
51356f487f8SFred Isaman 					encode_layoutget_maxsz)
5141da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz	(compound_decode_hdr_maxsz + \
5159b7b9fccSAndy Adamson 					decode_sequence_maxsz + \
5161da177e4SLinus Torvalds 					decode_putfh_maxsz + \
5172cebf828STrond Myklebust 					decode_open_maxsz + \
5186168f62cSWeston Andros Adamson 					decode_access_maxsz + \
51956f487f8SFred Isaman 					decode_getattr_maxsz + \
52056f487f8SFred Isaman 					decode_layoutget_maxsz)
5211da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \
5221da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
5239b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5241da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
525b6808145STrond Myklebust 				 encode_layoutreturn_maxsz + \
5263947b74dSTrond Myklebust 				 encode_open_downgrade_maxsz)
5271da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \
5281da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
5299b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5301da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
531b6808145STrond Myklebust 				 decode_layoutreturn_maxsz + \
5323947b74dSTrond Myklebust 				 decode_open_downgrade_maxsz)
5331da177e4SLinus Torvalds #define NFS4_enc_close_sz	(compound_encode_hdr_maxsz + \
5349b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5351da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
536cf805165STrond Myklebust 				 encode_layoutreturn_maxsz + \
5379104a55dSTrond Myklebust 				 encode_close_maxsz + \
538516a6af6STrond Myklebust 				 encode_getattr_maxsz)
5391da177e4SLinus Torvalds #define NFS4_dec_close_sz	(compound_decode_hdr_maxsz + \
5409b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5411da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
542cf805165STrond Myklebust 				 decode_layoutreturn_maxsz + \
5439104a55dSTrond Myklebust 				 decode_close_maxsz + \
544516a6af6STrond Myklebust 				 decode_getattr_maxsz)
5451da177e4SLinus Torvalds #define NFS4_enc_setattr_sz	(compound_encode_hdr_maxsz + \
5469b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
5471da177e4SLinus Torvalds 				 encode_putfh_maxsz + \
5489104a55dSTrond Myklebust 				 encode_setattr_maxsz + \
5491da177e4SLinus Torvalds 				 encode_getattr_maxsz)
5501da177e4SLinus Torvalds #define NFS4_dec_setattr_sz	(compound_decode_hdr_maxsz + \
5519b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5521da177e4SLinus Torvalds 				 decode_putfh_maxsz + \
5539104a55dSTrond Myklebust 				 decode_setattr_maxsz + \
5549104a55dSTrond Myklebust 				 decode_getattr_maxsz)
5551da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz	(compound_encode_hdr_maxsz + \
5569b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5571da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5581da177e4SLinus Torvalds 				encode_fsinfo_maxsz)
5591da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz	(compound_decode_hdr_maxsz + \
5609b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5611da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5621da177e4SLinus Torvalds 				decode_fsinfo_maxsz)
5631da177e4SLinus Torvalds #define NFS4_enc_renew_sz	(compound_encode_hdr_maxsz + \
5641da177e4SLinus Torvalds 				encode_renew_maxsz)
5651da177e4SLinus Torvalds #define NFS4_dec_renew_sz	(compound_decode_hdr_maxsz + \
5661da177e4SLinus Torvalds 				decode_renew_maxsz)
5671da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz	(compound_encode_hdr_maxsz + \
5681da177e4SLinus Torvalds 				encode_setclientid_maxsz)
5691da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz	(compound_decode_hdr_maxsz + \
5701da177e4SLinus Torvalds 				decode_setclientid_maxsz)
5711da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \
5721da177e4SLinus Torvalds 				(compound_encode_hdr_maxsz + \
57383ca7f5aSChuck Lever 				encode_setclientid_confirm_maxsz)
5741da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \
5751da177e4SLinus Torvalds 				(compound_decode_hdr_maxsz + \
57683ca7f5aSChuck Lever 				decode_setclientid_confirm_maxsz)
5771da177e4SLinus Torvalds #define NFS4_enc_lock_sz        (compound_encode_hdr_maxsz + \
5789b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5791da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5809104a55dSTrond Myklebust 				encode_lock_maxsz)
5811da177e4SLinus Torvalds #define NFS4_dec_lock_sz        (compound_decode_hdr_maxsz + \
5829b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5831da177e4SLinus Torvalds 				decode_putfh_maxsz + \
5849104a55dSTrond Myklebust 				decode_lock_maxsz)
5851da177e4SLinus Torvalds #define NFS4_enc_lockt_sz       (compound_encode_hdr_maxsz + \
5869b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5871da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5889104a55dSTrond Myklebust 				encode_lockt_maxsz)
5899104a55dSTrond Myklebust #define NFS4_dec_lockt_sz       (compound_decode_hdr_maxsz + \
5909b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
5919104a55dSTrond Myklebust 				 decode_putfh_maxsz + \
5929104a55dSTrond Myklebust 				 decode_lockt_maxsz)
5931da177e4SLinus Torvalds #define NFS4_enc_locku_sz       (compound_encode_hdr_maxsz + \
5949b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
5951da177e4SLinus Torvalds 				encode_putfh_maxsz + \
5969104a55dSTrond Myklebust 				encode_locku_maxsz)
5971da177e4SLinus Torvalds #define NFS4_dec_locku_sz       (compound_decode_hdr_maxsz + \
5989b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
5991da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6009104a55dSTrond Myklebust 				decode_locku_maxsz)
601d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \
602d3c7b7ccSTrond Myklebust 				(compound_encode_hdr_maxsz + \
603d3c7b7ccSTrond Myklebust 				 encode_lockowner_maxsz)
604d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \
605d3c7b7ccSTrond Myklebust 				(compound_decode_hdr_maxsz + \
606d3c7b7ccSTrond Myklebust 				 decode_lockowner_maxsz)
6071da177e4SLinus Torvalds #define NFS4_enc_access_sz	(compound_encode_hdr_maxsz + \
6089b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6091da177e4SLinus Torvalds 				encode_putfh_maxsz + \
61076b32999STrond Myklebust 				encode_access_maxsz + \
61176b32999STrond Myklebust 				encode_getattr_maxsz)
6121da177e4SLinus Torvalds #define NFS4_dec_access_sz	(compound_decode_hdr_maxsz + \
6139b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6141da177e4SLinus Torvalds 				decode_putfh_maxsz + \
61576b32999STrond Myklebust 				decode_access_maxsz + \
61676b32999STrond Myklebust 				decode_getattr_maxsz)
6171da177e4SLinus Torvalds #define NFS4_enc_getattr_sz	(compound_encode_hdr_maxsz + \
6189b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6191da177e4SLinus Torvalds 				encode_putfh_maxsz + \
62044c99933SChuck Lever 				encode_getattr_maxsz + \
62144c99933SChuck Lever 				encode_renew_maxsz)
6221da177e4SLinus Torvalds #define NFS4_dec_getattr_sz	(compound_decode_hdr_maxsz + \
6239b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6241da177e4SLinus Torvalds 				decode_putfh_maxsz + \
62544c99933SChuck Lever 				decode_getattr_maxsz + \
62644c99933SChuck Lever 				decode_renew_maxsz)
6271da177e4SLinus Torvalds #define NFS4_enc_lookup_sz	(compound_encode_hdr_maxsz + \
6289b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6291da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6301da177e4SLinus Torvalds 				encode_lookup_maxsz + \
6311da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6321da177e4SLinus Torvalds 				encode_getfh_maxsz)
6331da177e4SLinus Torvalds #define NFS4_dec_lookup_sz	(compound_decode_hdr_maxsz + \
6349b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6351da177e4SLinus Torvalds 				decode_putfh_maxsz + \
636e6889620STrond Myklebust 				decode_lookup_maxsz + \
6371da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6381da177e4SLinus Torvalds 				decode_getfh_maxsz)
6395b5faaf6SJeff Layton #define NFS4_enc_lookupp_sz	(compound_encode_hdr_maxsz + \
6405b5faaf6SJeff Layton 				encode_sequence_maxsz + \
6415b5faaf6SJeff Layton 				encode_putfh_maxsz + \
6425b5faaf6SJeff Layton 				encode_lookupp_maxsz + \
6435b5faaf6SJeff Layton 				encode_getattr_maxsz + \
6445b5faaf6SJeff Layton 				encode_getfh_maxsz)
6455b5faaf6SJeff Layton #define NFS4_dec_lookupp_sz	(compound_decode_hdr_maxsz + \
6465b5faaf6SJeff Layton 				decode_sequence_maxsz + \
6475b5faaf6SJeff Layton 				decode_putfh_maxsz + \
6485b5faaf6SJeff Layton 				decode_lookupp_maxsz + \
6495b5faaf6SJeff Layton 				decode_getattr_maxsz + \
6505b5faaf6SJeff Layton 				decode_getfh_maxsz)
6511da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
6529b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6531da177e4SLinus Torvalds 				encode_putrootfh_maxsz + \
6541da177e4SLinus Torvalds 				encode_getattr_maxsz + \
6551da177e4SLinus Torvalds 				encode_getfh_maxsz)
6561da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
6579b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6581da177e4SLinus Torvalds 				decode_putrootfh_maxsz + \
6591da177e4SLinus Torvalds 				decode_getattr_maxsz + \
6601da177e4SLinus Torvalds 				decode_getfh_maxsz)
6611da177e4SLinus Torvalds #define NFS4_enc_remove_sz	(compound_encode_hdr_maxsz + \
6629b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6631da177e4SLinus Torvalds 				encode_putfh_maxsz + \
664778d2817STrond Myklebust 				encode_remove_maxsz)
6651da177e4SLinus Torvalds #define NFS4_dec_remove_sz	(compound_decode_hdr_maxsz + \
6669b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6671da177e4SLinus Torvalds 				decode_putfh_maxsz + \
668778d2817STrond Myklebust 				decode_remove_maxsz)
6691da177e4SLinus Torvalds #define NFS4_enc_rename_sz	(compound_encode_hdr_maxsz + \
6709b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6711da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6721da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6731da177e4SLinus Torvalds 				encode_putfh_maxsz + \
674778d2817STrond Myklebust 				encode_rename_maxsz)
6751da177e4SLinus Torvalds #define NFS4_dec_rename_sz	(compound_decode_hdr_maxsz + \
6769b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6771da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6781da177e4SLinus Torvalds 				decode_savefh_maxsz + \
6791da177e4SLinus Torvalds 				decode_putfh_maxsz + \
680778d2817STrond Myklebust 				decode_rename_maxsz)
6811da177e4SLinus Torvalds #define NFS4_enc_link_sz	(compound_encode_hdr_maxsz + \
6829b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6831da177e4SLinus Torvalds 				encode_putfh_maxsz + \
6841da177e4SLinus Torvalds 				encode_savefh_maxsz + \
6851da177e4SLinus Torvalds 				encode_putfh_maxsz + \
68691ba2eeeSTrond Myklebust 				encode_link_maxsz + \
68791ba2eeeSTrond Myklebust 				encode_restorefh_maxsz + \
688a9f6991bSTrond Myklebust 				encode_getattr_maxsz)
6891da177e4SLinus Torvalds #define NFS4_dec_link_sz	(compound_decode_hdr_maxsz + \
6909b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
6911da177e4SLinus Torvalds 				decode_putfh_maxsz + \
6921da177e4SLinus Torvalds 				decode_savefh_maxsz + \
6931da177e4SLinus Torvalds 				decode_putfh_maxsz + \
69491ba2eeeSTrond Myklebust 				decode_link_maxsz + \
69591ba2eeeSTrond Myklebust 				decode_restorefh_maxsz + \
69691ba2eeeSTrond Myklebust 				decode_getattr_maxsz)
6971da177e4SLinus Torvalds #define NFS4_enc_symlink_sz	(compound_encode_hdr_maxsz + \
6989b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
6991da177e4SLinus Torvalds 				encode_putfh_maxsz + \
7001da177e4SLinus Torvalds 				encode_symlink_maxsz + \
7011da177e4SLinus Torvalds 				encode_getattr_maxsz + \
7021da177e4SLinus Torvalds 				encode_getfh_maxsz)
7031da177e4SLinus Torvalds #define NFS4_dec_symlink_sz	(compound_decode_hdr_maxsz + \
7049b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
7051da177e4SLinus Torvalds 				decode_putfh_maxsz + \
7061da177e4SLinus Torvalds 				decode_symlink_maxsz + \
7071da177e4SLinus Torvalds 				decode_getattr_maxsz + \
7081da177e4SLinus Torvalds 				decode_getfh_maxsz)
7091da177e4SLinus Torvalds #define NFS4_enc_create_sz	(compound_encode_hdr_maxsz + \
7109b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
7111da177e4SLinus Torvalds 				encode_putfh_maxsz + \
7121da177e4SLinus Torvalds 				encode_create_maxsz + \
71356ae19f3STrond Myklebust 				encode_getfh_maxsz + \
71456ae19f3STrond Myklebust 				encode_getattr_maxsz)
7151da177e4SLinus Torvalds #define NFS4_dec_create_sz	(compound_decode_hdr_maxsz + \
7169b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
7171da177e4SLinus Torvalds 				decode_putfh_maxsz + \
7181da177e4SLinus Torvalds 				decode_create_maxsz + \
71956ae19f3STrond Myklebust 				decode_getfh_maxsz + \
72056ae19f3STrond Myklebust 				decode_getattr_maxsz)
7211da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz	(compound_encode_hdr_maxsz + \
7229b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
7231da177e4SLinus Torvalds 				encode_putfh_maxsz + \
7241da177e4SLinus Torvalds 				encode_getattr_maxsz)
7251da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz	(compound_decode_hdr_maxsz + \
7269b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
7271da177e4SLinus Torvalds 				decode_putfh_maxsz + \
7281da177e4SLinus Torvalds 				decode_getattr_maxsz)
7291da177e4SLinus Torvalds #define NFS4_enc_statfs_sz	(compound_encode_hdr_maxsz + \
7309b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
7311da177e4SLinus Torvalds 				encode_putfh_maxsz + \
7329104a55dSTrond Myklebust 				encode_statfs_maxsz)
7331da177e4SLinus Torvalds #define NFS4_dec_statfs_sz	(compound_decode_hdr_maxsz + \
7349b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
7351da177e4SLinus Torvalds 				decode_putfh_maxsz + \
7369104a55dSTrond Myklebust 				decode_statfs_maxsz)
7371da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
7389b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
739ab91f264STrond Myklebust 				encode_putfh_maxsz + \
7401da177e4SLinus Torvalds 				encode_getattr_maxsz)
7411da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
7429b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
743ab91f264STrond Myklebust 				decode_putfh_maxsz + \
7441da177e4SLinus Torvalds 				decode_getattr_maxsz)
7451da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz	(compound_encode_hdr_maxsz + \
7469b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
7471da177e4SLinus Torvalds 				encode_putfh_maxsz + \
748586f1c39STrond Myklebust 				encode_layoutreturn_maxsz + \
749fa178f29STrond Myklebust 				encode_delegreturn_maxsz + \
750fa178f29STrond Myklebust 				encode_getattr_maxsz)
7511da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
7529b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
753d8434d4cSTrond Myklebust 				decode_putfh_maxsz + \
754586f1c39STrond Myklebust 				decode_layoutreturn_maxsz + \
755fa178f29STrond Myklebust 				decode_delegreturn_maxsz + \
756fa178f29STrond Myklebust 				decode_getattr_maxsz)
757029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz	(compound_encode_hdr_maxsz + \
7589b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
759029d105eSJ. Bruce Fields 				encode_putfh_maxsz + \
7609104a55dSTrond Myklebust 				encode_getacl_maxsz)
761029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz	(compound_decode_hdr_maxsz + \
7629b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
763029d105eSJ. Bruce Fields 				decode_putfh_maxsz + \
7649104a55dSTrond Myklebust 				decode_getacl_maxsz)
76523ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz	(compound_encode_hdr_maxsz + \
7669b7b9fccSAndy Adamson 				encode_sequence_maxsz + \
76723ec6965SJ. Bruce Fields 				encode_putfh_maxsz + \
7689104a55dSTrond Myklebust 				encode_setacl_maxsz)
76923ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz	(compound_decode_hdr_maxsz + \
7709b7b9fccSAndy Adamson 				decode_sequence_maxsz + \
77123ec6965SJ. Bruce Fields 				decode_putfh_maxsz + \
7729104a55dSTrond Myklebust 				decode_setacl_maxsz)
773683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \
774683b57b4STrond Myklebust 				(compound_encode_hdr_maxsz + \
7759b7b9fccSAndy Adamson 				 encode_sequence_maxsz + \
776683b57b4STrond Myklebust 				 encode_putfh_maxsz + \
777e6889620STrond Myklebust 				 encode_lookup_maxsz + \
778b03d735bSChuck Lever 				 encode_fs_locations_maxsz + \
779b03d735bSChuck Lever 				 encode_renew_maxsz)
780683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \
781683b57b4STrond Myklebust 				(compound_decode_hdr_maxsz + \
7829b7b9fccSAndy Adamson 				 decode_sequence_maxsz + \
783683b57b4STrond Myklebust 				 decode_putfh_maxsz + \
784e6889620STrond Myklebust 				 decode_lookup_maxsz + \
785b03d735bSChuck Lever 				 decode_fs_locations_maxsz + \
786b03d735bSChuck Lever 				 decode_renew_maxsz)
7875a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz 	(compound_encode_hdr_maxsz + \
7885a5ea0d4SBryan Schumaker 				encode_sequence_maxsz + \
7895a5ea0d4SBryan Schumaker 				encode_putfh_maxsz + \
7905a5ea0d4SBryan Schumaker 				encode_secinfo_maxsz)
7915a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz	(compound_decode_hdr_maxsz + \
7925a5ea0d4SBryan Schumaker 				decode_sequence_maxsz + \
7935a5ea0d4SBryan Schumaker 				decode_putfh_maxsz + \
7945a5ea0d4SBryan Schumaker 				decode_secinfo_maxsz)
79544c99933SChuck Lever #define NFS4_enc_fsid_present_sz \
79644c99933SChuck Lever 				(compound_encode_hdr_maxsz + \
79744c99933SChuck Lever 				 encode_sequence_maxsz + \
79844c99933SChuck Lever 				 encode_putfh_maxsz + \
79944c99933SChuck Lever 				 encode_getfh_maxsz + \
80044c99933SChuck Lever 				 encode_renew_maxsz)
80144c99933SChuck Lever #define NFS4_dec_fsid_present_sz \
80244c99933SChuck Lever 				(compound_decode_hdr_maxsz + \
80344c99933SChuck Lever 				 decode_sequence_maxsz + \
80444c99933SChuck Lever 				 decode_putfh_maxsz + \
80544c99933SChuck Lever 				 decode_getfh_maxsz + \
80644c99933SChuck Lever 				 decode_renew_maxsz)
80799fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
8087c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \
8097c44f1aeSWeston Andros Adamson 				(compound_encode_hdr_maxsz + \
8107c44f1aeSWeston Andros Adamson 				 encode_bind_conn_to_session_maxsz)
8117c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \
8127c44f1aeSWeston Andros Adamson 				(compound_decode_hdr_maxsz + \
8137c44f1aeSWeston Andros Adamson 				 decode_bind_conn_to_session_maxsz)
81499fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \
81599fe60d0SBenny Halevy 				(compound_encode_hdr_maxsz + \
81699fe60d0SBenny Halevy 				 encode_exchange_id_maxsz)
81799fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \
81899fe60d0SBenny Halevy 				(compound_decode_hdr_maxsz + \
81999fe60d0SBenny Halevy 				 decode_exchange_id_maxsz)
820fc931582SAndy Adamson #define NFS4_enc_create_session_sz \
821fc931582SAndy Adamson 				(compound_encode_hdr_maxsz + \
822fc931582SAndy Adamson 				 encode_create_session_maxsz)
823fc931582SAndy Adamson #define NFS4_dec_create_session_sz \
824fc931582SAndy Adamson 				(compound_decode_hdr_maxsz + \
825fc931582SAndy Adamson 				 decode_create_session_maxsz)
8260f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz	(compound_encode_hdr_maxsz + \
8270f3e66c6SAndy Adamson 					 encode_destroy_session_maxsz)
8280f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz	(compound_decode_hdr_maxsz + \
8290f3e66c6SAndy Adamson 					 decode_destroy_session_maxsz)
83066245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz	(compound_encode_hdr_maxsz + \
83166245539STrond Myklebust 					 encode_destroy_clientid_maxsz)
83266245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz	(compound_decode_hdr_maxsz + \
83366245539STrond Myklebust 					 decode_destroy_clientid_maxsz)
834fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \
835fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
836fc01cea9SAndy Adamson 				 encode_sequence_maxsz)
837fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \
838fc01cea9SAndy Adamson 				(compound_decode_hdr_maxsz + \
839fc01cea9SAndy Adamson 				 decode_sequence_maxsz)
8400efb01b2SDonald Buczek #endif
8412050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz	(compound_encode_hdr_maxsz + \
8422050f0ccSAndy Adamson 					 encode_sequence_maxsz + \
8432050f0ccSAndy Adamson 					 encode_putrootfh_maxsz + \
8442050f0ccSAndy Adamson 					 encode_fsinfo_maxsz)
8452050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz	(compound_decode_hdr_maxsz + \
8462050f0ccSAndy Adamson 					 decode_sequence_maxsz + \
8472050f0ccSAndy Adamson 					 decode_putrootfh_maxsz + \
8482050f0ccSAndy Adamson 					 decode_fsinfo_maxsz)
8490efb01b2SDonald Buczek #if defined(CONFIG_NFS_V4_1)
85018019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz	(compound_encode_hdr_maxsz + \
85118019753SRicardo Labiaga 					 encode_sequence_maxsz + \
85218019753SRicardo Labiaga 					 encode_reclaim_complete_maxsz)
85318019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz	(compound_decode_hdr_maxsz + \
85418019753SRicardo Labiaga 					 decode_sequence_maxsz + \
85518019753SRicardo Labiaga 					 decode_reclaim_complete_maxsz)
856b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz +    \
857b1f69b75SAndy Adamson 				encode_sequence_maxsz +\
858b1f69b75SAndy Adamson 				encode_getdeviceinfo_maxsz)
859b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz +    \
860b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
861b1f69b75SAndy Adamson 				decode_getdeviceinfo_maxsz)
862b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz	(compound_encode_hdr_maxsz + \
863b1f69b75SAndy Adamson 				encode_sequence_maxsz + \
864b1f69b75SAndy Adamson 				encode_putfh_maxsz +        \
865b1f69b75SAndy Adamson 				encode_layoutget_maxsz)
866b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz	(compound_decode_hdr_maxsz + \
867b1f69b75SAndy Adamson 				decode_sequence_maxsz + \
868b1f69b75SAndy Adamson 				decode_putfh_maxsz +        \
869b1f69b75SAndy Adamson 				decode_layoutget_maxsz)
870863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
871863a3c6cSAndy Adamson 				encode_sequence_maxsz +\
872863a3c6cSAndy Adamson 				encode_putfh_maxsz + \
873863a3c6cSAndy Adamson 				encode_layoutcommit_maxsz + \
874863a3c6cSAndy Adamson 				encode_getattr_maxsz)
875863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
876863a3c6cSAndy Adamson 				decode_sequence_maxsz + \
877863a3c6cSAndy Adamson 				decode_putfh_maxsz + \
878863a3c6cSAndy Adamson 				decode_layoutcommit_maxsz + \
879863a3c6cSAndy Adamson 				decode_getattr_maxsz)
880cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
881cbe82603SBenny Halevy 				encode_sequence_maxsz + \
882cbe82603SBenny Halevy 				encode_putfh_maxsz + \
883cbe82603SBenny Halevy 				encode_layoutreturn_maxsz)
884cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
885cbe82603SBenny Halevy 				decode_sequence_maxsz + \
886cbe82603SBenny Halevy 				decode_putfh_maxsz + \
887cbe82603SBenny Halevy 				decode_layoutreturn_maxsz)
888fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz	(compound_encode_hdr_maxsz + \
889fca78d6dSBryan Schumaker 					encode_sequence_maxsz + \
890fca78d6dSBryan Schumaker 					encode_putrootfh_maxsz +\
891fca78d6dSBryan Schumaker 					encode_secinfo_no_name_maxsz)
892fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz	(compound_decode_hdr_maxsz + \
893fca78d6dSBryan Schumaker 					decode_sequence_maxsz + \
894fca78d6dSBryan Schumaker 					decode_putrootfh_maxsz + \
895fca78d6dSBryan Schumaker 					decode_secinfo_no_name_maxsz)
8967d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz	(compound_encode_hdr_maxsz + \
8977d974794SBryan Schumaker 					 encode_sequence_maxsz + \
8987d974794SBryan Schumaker 					 encode_test_stateid_maxsz)
8997d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz	(compound_decode_hdr_maxsz + \
9007d974794SBryan Schumaker 					 decode_sequence_maxsz + \
9017d974794SBryan Schumaker 					 decode_test_stateid_maxsz)
9029aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz	(compound_encode_hdr_maxsz + \
9039aeda35fSBryan Schumaker 					 encode_sequence_maxsz + \
9049aeda35fSBryan Schumaker 					 encode_free_stateid_maxsz)
9059aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz	(compound_decode_hdr_maxsz + \
9069aeda35fSBryan Schumaker 					 decode_sequence_maxsz + \
9079aeda35fSBryan Schumaker 					 decode_free_stateid_maxsz)
9082449ea2eSAlexandros Batsakis 
9092449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
9102449ea2eSAlexandros Batsakis 				      compound_encode_hdr_maxsz +
9112449ea2eSAlexandros Batsakis 				      encode_sequence_maxsz +
9122449ea2eSAlexandros Batsakis 				      encode_putfh_maxsz +
9132449ea2eSAlexandros Batsakis 				      encode_getattr_maxsz) *
9142449ea2eSAlexandros Batsakis 				     XDR_UNIT);
9152449ea2eSAlexandros Batsakis 
9162449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
9172449ea2eSAlexandros Batsakis 				     compound_decode_hdr_maxsz +
9182449ea2eSAlexandros Batsakis 				     decode_sequence_maxsz +
9192449ea2eSAlexandros Batsakis 				     decode_putfh_maxsz) *
9202449ea2eSAlexandros Batsakis 				    XDR_UNIT);
921f1c097beSAndy Adamson 
922f1c097beSAndy Adamson const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
923f1c097beSAndy Adamson 					   compound_decode_hdr_maxsz +
924f1c097beSAndy Adamson 					   decode_sequence_maxsz) *
925f1c097beSAndy Adamson 					  XDR_UNIT);
926f1c097beSAndy Adamson EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
92799fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
9281da177e4SLinus Torvalds 
929bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = {
930bca79478STrond Myklebust 	[NF4BAD] = 0,
931bca79478STrond Myklebust 	[NF4REG] = S_IFREG,
932bca79478STrond Myklebust 	[NF4DIR] = S_IFDIR,
933bca79478STrond Myklebust 	[NF4BLK] = S_IFBLK,
934bca79478STrond Myklebust 	[NF4CHR] = S_IFCHR,
935bca79478STrond Myklebust 	[NF4LNK] = S_IFLNK,
936bca79478STrond Myklebust 	[NF4SOCK] = S_IFSOCK,
937bca79478STrond Myklebust 	[NF4FIFO] = S_IFIFO,
938bca79478STrond Myklebust 	[NF4ATTRDIR] = 0,
939bca79478STrond Myklebust 	[NF4NAMEDATTR] = 0,
9401da177e4SLinus Torvalds };
9411da177e4SLinus Torvalds 
9421da177e4SLinus Torvalds struct compound_hdr {
9431da177e4SLinus Torvalds 	int32_t		status;
9441da177e4SLinus Torvalds 	uint32_t	nops;
945d017931cSAndy Adamson 	__be32 *	nops_p;
9461da177e4SLinus Torvalds 	uint32_t	taglen;
9471da177e4SLinus Torvalds 	char *		tag;
9480c4e8c18SBenny Halevy 	uint32_t	replen;		/* expected reply words */
94966cc0429SBenny Halevy 	u32		minorversion;
9501da177e4SLinus Torvalds };
9511da177e4SLinus Torvalds 
95213c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
95313c65ce9SBenny Halevy {
95413c65ce9SBenny Halevy 	__be32 *p = xdr_reserve_space(xdr, nbytes);
95513c65ce9SBenny Halevy 	BUG_ON(!p);
95613c65ce9SBenny Halevy 	return p;
95713c65ce9SBenny Halevy }
9581da177e4SLinus Torvalds 
959cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
960cb17e556STrond Myklebust {
961ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
962cb17e556STrond Myklebust }
963cb17e556STrond Myklebust 
9641da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
9651da177e4SLinus Torvalds {
966ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
9671da177e4SLinus Torvalds }
9681da177e4SLinus Torvalds 
9694ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n)
9704ade9821STrond Myklebust {
971ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
9724ade9821STrond Myklebust }
9734ade9821STrond Myklebust 
974ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n)
975ff2eb681STrond Myklebust {
976ab6e9aafSTrond Myklebust 	WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
977ff2eb681STrond Myklebust }
978ff2eb681STrond Myklebust 
97937c88763STrond Myklebust static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
98037c88763STrond Myklebust 		const __u32 *bitmap, size_t len)
98137c88763STrond Myklebust {
98237c88763STrond Myklebust 	ssize_t ret;
98337c88763STrond Myklebust 
98437c88763STrond Myklebust 	/* Trim empty words */
98537c88763STrond Myklebust 	while (len > 0 && bitmap[len-1] == 0)
98637c88763STrond Myklebust 		len--;
98737c88763STrond Myklebust 	ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
98837c88763STrond Myklebust 	if (WARN_ON_ONCE(ret < 0))
98937c88763STrond Myklebust 		return ret;
99037c88763STrond Myklebust 	return len;
99137c88763STrond Myklebust }
99237c88763STrond Myklebust 
99337c88763STrond Myklebust static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
99437c88763STrond Myklebust 		__u32 *res, size_t len)
99537c88763STrond Myklebust {
99637c88763STrond Myklebust 	size_t i;
99737c88763STrond Myklebust 	__u32 tmp;
99837c88763STrond Myklebust 
99937c88763STrond Myklebust 	while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
100037c88763STrond Myklebust 		len--;
100137c88763STrond Myklebust 	for (i = len; i-- > 0;) {
100237c88763STrond Myklebust 		tmp = bitmap[i] & mask[i];
100337c88763STrond Myklebust 		res[i] = tmp;
100437c88763STrond Myklebust 	}
100537c88763STrond Myklebust 	return len;
100637c88763STrond Myklebust }
100737c88763STrond Myklebust 
10084ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr,
10094ade9821STrond Myklebust 		const struct nfs_seqid *seqid)
10104ade9821STrond Myklebust {
1011a6796419STrond Myklebust 	if (seqid != NULL)
10124ade9821STrond Myklebust 		encode_uint32(xdr, seqid->sequence->counter);
1013a6796419STrond Myklebust 	else
1014a6796419STrond Myklebust 		encode_uint32(xdr, 0);
10154ade9821STrond Myklebust }
10164ade9821STrond Myklebust 
10170c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr,
10180c4e8c18SBenny Halevy 				struct rpc_rqst *req,
10190c4e8c18SBenny Halevy 				struct compound_hdr *hdr)
10201da177e4SLinus Torvalds {
10218687b63aSAl Viro 	__be32 *p;
10220c4e8c18SBenny Halevy 
10230c4e8c18SBenny Halevy 	/* initialize running count of expected bytes in reply.
10240c4e8c18SBenny Halevy 	 * NOTE: the replied tag SHOULD be the same is the one sent,
10250c4e8c18SBenny Halevy 	 * but this is not required as a MUST for the server to do so. */
1026cf500bacSChuck Lever 	hdr->replen = 3 + hdr->taglen;
10271da177e4SLinus Torvalds 
10287fc38846STrond Myklebust 	WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
10296fdfb0bcSTrond Myklebust 	encode_string(xdr, hdr->taglen, hdr->tag);
10306fdfb0bcSTrond Myklebust 	p = reserve_space(xdr, 8);
1031e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(hdr->minorversion);
1032d017931cSAndy Adamson 	hdr->nops_p = p;
103334558513SBenny Halevy 	*p = cpu_to_be32(hdr->nops);
1034d017931cSAndy Adamson }
1035d017931cSAndy Adamson 
1036ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
1037ab19b481STrond Myklebust 		uint32_t replen,
1038ab19b481STrond Myklebust 		struct compound_hdr *hdr)
1039ab19b481STrond Myklebust {
1040ab19b481STrond Myklebust 	encode_uint32(xdr, op);
1041ab19b481STrond Myklebust 	hdr->nops++;
1042ab19b481STrond Myklebust 	hdr->replen += replen;
1043ab19b481STrond Myklebust }
1044ab19b481STrond Myklebust 
1045d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr)
1046d017931cSAndy Adamson {
10477fc38846STrond Myklebust 	WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
1048d017931cSAndy Adamson 	*hdr->nops_p = htonl(hdr->nops);
10491da177e4SLinus Torvalds }
10501da177e4SLinus Torvalds 
1051ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1052ea9d23f5STrond Myklebust {
10532d2f24adSTrond Myklebust 	encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
1054ea9d23f5STrond Myklebust }
1055ea9d23f5STrond Myklebust 
10561da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
10571da177e4SLinus Torvalds {
1058cb17e556STrond Myklebust 	encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
10591da177e4SLinus Torvalds }
10601da177e4SLinus Torvalds 
106136b3743fSTrond Myklebust static __be32 *
1062e7d4b05cSTrond Myklebust xdr_encode_nfstime4(__be32 *p, const struct timespec64 *t)
106336b3743fSTrond Myklebust {
106436b3743fSTrond Myklebust 	p = xdr_encode_hyper(p, (__s64)t->tv_sec);
106536b3743fSTrond Myklebust 	*p++ = cpu_to_be32(t->tv_nsec);
106636b3743fSTrond Myklebust 	return p;
106736b3743fSTrond Myklebust }
106836b3743fSTrond Myklebust 
1069aa9c2669SDavid Quigley static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1070aa9c2669SDavid Quigley 				const struct nfs4_label *label,
107128cf22d0STrond Myklebust 				const umode_t *umask,
10725334c5bdSKinglong Mee 				const struct nfs_server *server,
107328cf22d0STrond Myklebust 				const uint32_t attrmask[])
10741da177e4SLinus Torvalds {
10751da177e4SLinus Torvalds 	char owner_name[IDMAP_NAMESZ];
10761da177e4SLinus Torvalds 	char owner_group[IDMAP_NAMESZ];
10771da177e4SLinus Torvalds 	int owner_namelen = 0;
10781da177e4SLinus Torvalds 	int owner_grouplen = 0;
10798687b63aSAl Viro 	__be32 *p;
1080d7067b2dSTrond Myklebust 	uint32_t len = 0;
1081d7067b2dSTrond Myklebust 	uint32_t bmval[3] = { 0 };
10821da177e4SLinus Torvalds 
10831da177e4SLinus Torvalds 	/*
10841da177e4SLinus Torvalds 	 * We reserve enough space to write the entire attribute buffer at once.
10851da177e4SLinus Torvalds 	 */
108628cf22d0STrond Myklebust 	if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
1087d7067b2dSTrond Myklebust 		bmval[0] |= FATTR4_WORD0_SIZE;
10881da177e4SLinus Torvalds 		len += 8;
1089d7067b2dSTrond Myklebust 	}
1090d7067b2dSTrond Myklebust 	if (iap->ia_valid & ATTR_MODE) {
109128cf22d0STrond Myklebust 		if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
1092dff25ddbSAndreas Gruenbacher 			bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1093dff25ddbSAndreas Gruenbacher 			len += 8;
109428cf22d0STrond Myklebust 		} else if (attrmask[1] & FATTR4_WORD1_MODE) {
1095d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_MODE;
10961da177e4SLinus Torvalds 			len += 4;
1097d7067b2dSTrond Myklebust 		}
1098dff25ddbSAndreas Gruenbacher 	}
109928cf22d0STrond Myklebust 	if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
1100e4fd72a1STrond Myklebust 		owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
11011da177e4SLinus Torvalds 		if (owner_namelen < 0) {
1102fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve uid %d to string\n",
1103e5782076SEric W. Biederman 					from_kuid(&init_user_ns, iap->ia_uid));
11041da177e4SLinus Torvalds 			/* XXX */
11051da177e4SLinus Torvalds 			strcpy(owner_name, "nobody");
11061da177e4SLinus Torvalds 			owner_namelen = sizeof("nobody") - 1;
11071da177e4SLinus Torvalds 			/* goto out; */
11081da177e4SLinus Torvalds 		}
1109d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_OWNER;
11101da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
11111da177e4SLinus Torvalds 	}
111228cf22d0STrond Myklebust 	if ((iap->ia_valid & ATTR_GID) &&
111328cf22d0STrond Myklebust 	   (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
1114e4fd72a1STrond Myklebust 		owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
11151da177e4SLinus Torvalds 		if (owner_grouplen < 0) {
1116fe82a183SChuck Lever 			dprintk("nfs: couldn't resolve gid %d to string\n",
1117e5782076SEric W. Biederman 					from_kgid(&init_user_ns, iap->ia_gid));
11181da177e4SLinus Torvalds 			strcpy(owner_group, "nobody");
11191da177e4SLinus Torvalds 			owner_grouplen = sizeof("nobody") - 1;
11201da177e4SLinus Torvalds 			/* goto out; */
11211da177e4SLinus Torvalds 		}
1122d7067b2dSTrond Myklebust 		bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
11231da177e4SLinus Torvalds 		len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
11241da177e4SLinus Torvalds 	}
112528cf22d0STrond Myklebust 	if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1126d7067b2dSTrond Myklebust 		if (iap->ia_valid & ATTR_ATIME_SET) {
1127d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
112836b3743fSTrond Myklebust 			len += 4 + (nfstime4_maxsz << 2);
1129d7067b2dSTrond Myklebust 		} else if (iap->ia_valid & ATTR_ATIME) {
1130d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
11311da177e4SLinus Torvalds 			len += 4;
1132d7067b2dSTrond Myklebust 		}
113328cf22d0STrond Myklebust 	}
113428cf22d0STrond Myklebust 	if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1135d7067b2dSTrond Myklebust 		if (iap->ia_valid & ATTR_MTIME_SET) {
1136d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
113736b3743fSTrond Myklebust 			len += 4 + (nfstime4_maxsz << 2);
1138d7067b2dSTrond Myklebust 		} else if (iap->ia_valid & ATTR_MTIME) {
1139d7067b2dSTrond Myklebust 			bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
11401da177e4SLinus Torvalds 			len += 4;
1141d7067b2dSTrond Myklebust 		}
11425334c5bdSKinglong Mee 	}
11435334c5bdSKinglong Mee 
114428cf22d0STrond Myklebust 	if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
1145b4a2cf76STrond Myklebust 		len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1146d7067b2dSTrond Myklebust 		bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1147d7067b2dSTrond Myklebust 	}
1148d7067b2dSTrond Myklebust 
114940a3426cSTrond Myklebust 	xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
115040a3426cSTrond Myklebust 	xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
11511da177e4SLinus Torvalds 
1152d7067b2dSTrond Myklebust 	if (bmval[0] & FATTR4_WORD0_SIZE)
1153b95be5a9SBenny Halevy 		p = xdr_encode_hyper(p, iap->ia_size);
1154d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_MODE)
1155e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1156d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_OWNER)
1157811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_name, owner_namelen);
1158d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1159811652bdSBenny Halevy 		p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1160d7067b2dSTrond Myklebust 	if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
11611da177e4SLinus Torvalds 		if (iap->ia_valid & ATTR_ATIME_SET) {
1162e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1163e7d4b05cSTrond Myklebust 			p = xdr_encode_nfstime4(p, &iap->ia_atime);
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);
1170e7d4b05cSTrond Myklebust 			p = xdr_encode_nfstime4(p, &iap->ia_mtime);
1171d7067b2dSTrond Myklebust 		} else
1172e75bc1c8SBenny Halevy 			*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
11731da177e4SLinus Torvalds 	}
1174e2751463SJia-Ju Bai 	if (label && (bmval[2] & FATTR4_WORD2_SECURITY_LABEL)) {
1175aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->lfs);
1176aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->pi);
1177aa9c2669SDavid Quigley 		*p++ = cpu_to_be32(label->len);
1178aa9c2669SDavid Quigley 		p = xdr_encode_opaque_fixed(p, label->label, label->len);
1179aa9c2669SDavid Quigley 	}
1180dff25ddbSAndreas Gruenbacher 	if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1181dff25ddbSAndreas Gruenbacher 		*p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1182dff25ddbSAndreas Gruenbacher 		*p++ = cpu_to_be32(*umask);
1183dff25ddbSAndreas Gruenbacher 	}
11841da177e4SLinus Torvalds 
11851da177e4SLinus Torvalds /* out: */
11861da177e4SLinus Torvalds }
11871da177e4SLinus Torvalds 
1188cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
11891da177e4SLinus Torvalds {
1190475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1191475d4ba0STrond Myklebust 	encode_uint32(xdr, access);
11921da177e4SLinus Torvalds }
11931da177e4SLinus Torvalds 
1194cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
11951da177e4SLinus Torvalds {
1196ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
11974ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
1198566fcec6STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
11991da177e4SLinus Torvalds }
12001da177e4SLinus Torvalds 
12010b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
12021da177e4SLinus Torvalds {
12038687b63aSAl Viro 	__be32 *p;
12041da177e4SLinus Torvalds 
1205475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1206475d4ba0STrond Myklebust 	p = reserve_space(xdr, 12);
1207b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
120834558513SBenny Halevy 	*p = cpu_to_be32(args->count);
12091da177e4SLinus Torvalds }
12101da177e4SLinus Torvalds 
1211cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
12121da177e4SLinus Torvalds {
12138687b63aSAl Viro 	__be32 *p;
12141da177e4SLinus Torvalds 
1215475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1216475d4ba0STrond Myklebust 	encode_uint32(xdr, create->ftype);
12171da177e4SLinus Torvalds 
12181da177e4SLinus Torvalds 	switch (create->ftype) {
12191da177e4SLinus Torvalds 	case NF4LNK:
122013c65ce9SBenny Halevy 		p = reserve_space(xdr, 4);
122134558513SBenny Halevy 		*p = cpu_to_be32(create->u.symlink.len);
12222fcc213aSChuck Lever 		xdr_write_pages(xdr, create->u.symlink.pages, 0,
12232fcc213aSChuck Lever 				create->u.symlink.len);
12242fcc213aSChuck Lever 		xdr->buf->flags |= XDRBUF_WRITE;
12251da177e4SLinus Torvalds 		break;
12261da177e4SLinus Torvalds 
12271da177e4SLinus Torvalds 	case NF4BLK: case NF4CHR:
122813c65ce9SBenny Halevy 		p = reserve_space(xdr, 8);
1229e75bc1c8SBenny Halevy 		*p++ = cpu_to_be32(create->u.device.specdata1);
123034558513SBenny Halevy 		*p = cpu_to_be32(create->u.device.specdata2);
12311da177e4SLinus Torvalds 		break;
12321da177e4SLinus Torvalds 
12331da177e4SLinus Torvalds 	default:
12341da177e4SLinus Torvalds 		break;
12351da177e4SLinus Torvalds 	}
12361da177e4SLinus Torvalds 
1237811652bdSBenny Halevy 	encode_string(xdr, create->name->len, create->name->name);
123828cf22d0STrond Myklebust 	encode_attrs(xdr, create->attrs, create->label, &create->umask,
123928cf22d0STrond Myklebust 			create->server, create->server->attr_bitmask);
12401da177e4SLinus Torvalds }
12411da177e4SLinus Torvalds 
124237c88763STrond Myklebust static void encode_getattr(struct xdr_stream *xdr,
124337c88763STrond Myklebust 		const __u32 *bitmap, const __u32 *mask, size_t len,
1244dae100c2SFred Isaman 		struct compound_hdr *hdr)
1245dae100c2SFred Isaman {
124637c88763STrond Myklebust 	__u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
1247dae100c2SFred Isaman 
1248ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
124937c88763STrond Myklebust 	if (mask) {
125037c88763STrond Myklebust 		if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
125137c88763STrond Myklebust 			len = ARRAY_SIZE(masked_bitmap);
125237c88763STrond Myklebust 		len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
125337c88763STrond Myklebust 		bitmap = masked_bitmap;
1254dae100c2SFred Isaman 	}
125537c88763STrond Myklebust 	xdr_encode_bitmap4(xdr, bitmap, len);
1256dae100c2SFred Isaman }
1257dae100c2SFred Isaman 
1258cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
12591da177e4SLinus Torvalds {
126037c88763STrond Myklebust 	encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
126137c88763STrond Myklebust 			ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
12621da177e4SLinus Torvalds }
12631da177e4SLinus Torvalds 
126488034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
12651549210fSTrond Myklebust 				 const u32 *open_bitmap,
126688034c3dSAndy Adamson 				 struct compound_hdr *hdr)
126788034c3dSAndy Adamson {
126837c88763STrond Myklebust 	encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
126988034c3dSAndy Adamson }
127088034c3dSAndy Adamson 
1271cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
12721da177e4SLinus Torvalds {
127337c88763STrond Myklebust 	encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
127437c88763STrond Myklebust 			ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
12751da177e4SLinus Torvalds }
12761da177e4SLinus Torvalds 
1277cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1278830b8e33SManoj Naik {
127937c88763STrond Myklebust 	encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
128037c88763STrond Myklebust 			ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
1281830b8e33SManoj Naik }
1282830b8e33SManoj Naik 
1283cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
12841da177e4SLinus Torvalds {
1285ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
12861da177e4SLinus Torvalds }
12871da177e4SLinus Torvalds 
1288cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
12891da177e4SLinus Torvalds {
1290ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
12916fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
12921da177e4SLinus Torvalds }
12931da177e4SLinus Torvalds 
1294911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block)
1295911d1aafSTrond Myklebust {
1296f44106e2SJeff Layton 	if (fl->fl_type == F_RDLCK)
1297911d1aafSTrond Myklebust 		return block ? NFS4_READW_LT : NFS4_READ_LT;
1298911d1aafSTrond Myklebust 	return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1299911d1aafSTrond Myklebust }
1300911d1aafSTrond Myklebust 
1301911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1302911d1aafSTrond Myklebust {
1303911d1aafSTrond Myklebust 	if (fl->fl_end == OFFSET_MAX)
1304911d1aafSTrond Myklebust 		return ~(uint64_t)0;
1305911d1aafSTrond Myklebust 	return fl->fl_end - fl->fl_start + 1;
1306911d1aafSTrond Myklebust }
1307911d1aafSTrond Myklebust 
1308daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1309daccbdedSTrond Myklebust {
1310daccbdedSTrond Myklebust 	__be32 *p;
1311daccbdedSTrond Myklebust 
1312d035c36cSTrond Myklebust 	p = reserve_space(xdr, 32);
1313daccbdedSTrond Myklebust 	p = xdr_encode_hyper(p, lowner->clientid);
1314d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(20);
1315daccbdedSTrond Myklebust 	p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1316d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(lowner->s_dev);
1317daccbdedSTrond Myklebust 	xdr_encode_hyper(p, lowner->id);
1318daccbdedSTrond Myklebust }
1319daccbdedSTrond Myklebust 
13201da177e4SLinus Torvalds /*
13211da177e4SLinus Torvalds  * opcode,type,reclaim,offset,length,new_lock_owner = 32
13221da177e4SLinus Torvalds  * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
13231da177e4SLinus Torvalds  */
1324cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
13251da177e4SLinus Torvalds {
13268687b63aSAl Viro 	__be32 *p;
13271da177e4SLinus Torvalds 
1328475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1329475d4ba0STrond Myklebust 	p = reserve_space(xdr, 28);
1330e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1331e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->reclaim);
1332b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1333b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
133434558513SBenny Halevy 	*p = cpu_to_be32(args->new_lock_owner);
1335911d1aafSTrond Myklebust 	if (args->new_lock_owner){
13364ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->open_seqid);
1337425c1d4eSTrond Myklebust 		encode_nfs4_stateid(xdr, &args->open_stateid);
13384ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->lock_seqid);
1339daccbdedSTrond Myklebust 		encode_lockowner(xdr, &args->lock_owner);
13401da177e4SLinus Torvalds 	}
13411da177e4SLinus Torvalds 	else {
1342425c1d4eSTrond Myklebust 		encode_nfs4_stateid(xdr, &args->lock_stateid);
13434ade9821STrond Myklebust 		encode_nfs4_seqid(xdr, args->lock_seqid);
13441da177e4SLinus Torvalds 	}
13451da177e4SLinus Torvalds }
13461da177e4SLinus Torvalds 
1347cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
13481da177e4SLinus Torvalds {
13498687b63aSAl Viro 	__be32 *p;
13501da177e4SLinus Torvalds 
1351475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1352475d4ba0STrond Myklebust 	p = reserve_space(xdr, 20);
1353e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1354b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
1355b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1356daccbdedSTrond Myklebust 	encode_lockowner(xdr, &args->lock_owner);
13571da177e4SLinus Torvalds }
13581da177e4SLinus Torvalds 
1359cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
13601da177e4SLinus Torvalds {
13618687b63aSAl Viro 	__be32 *p;
13621da177e4SLinus Torvalds 
1363475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1364475d4ba0STrond Myklebust 	encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
13654ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, args->seqid);
1366425c1d4eSTrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
1367ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 16);
1368b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->fl->fl_start);
136934558513SBenny Halevy 	xdr_encode_hyper(p, nfs4_lock_length(args->fl));
13701da177e4SLinus Torvalds }
13711da177e4SLinus Torvalds 
1372d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1373d3c7b7ccSTrond Myklebust {
1374ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1375d3c7b7ccSTrond Myklebust 	encode_lockowner(xdr, lowner);
1376d3c7b7ccSTrond Myklebust }
1377d3c7b7ccSTrond Myklebust 
1378cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
13791da177e4SLinus Torvalds {
1380ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
13816fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
13821da177e4SLinus Torvalds }
13831da177e4SLinus Torvalds 
13845b5faaf6SJeff Layton static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
13855b5faaf6SJeff Layton {
13865b5faaf6SJeff Layton 	encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
13875b5faaf6SJeff Layton }
13885b5faaf6SJeff Layton 
13896ae37339STrond Myklebust static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
13901da177e4SLinus Torvalds {
13918687b63aSAl Viro 	__be32 *p;
13921da177e4SLinus Torvalds 
139313c65ce9SBenny Halevy 	p = reserve_space(xdr, 8);
13946ae37339STrond Myklebust 	*p++ = cpu_to_be32(share_access);
139534558513SBenny Halevy 	*p = cpu_to_be32(0);		/* for linux, share_deny = 0 always */
13961da177e4SLinus Torvalds }
13971da177e4SLinus Torvalds 
13981da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
13991da177e4SLinus Torvalds {
14008687b63aSAl Viro 	__be32 *p;
14011da177e4SLinus Torvalds  /*
14021da177e4SLinus Torvalds  * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
14031da177e4SLinus Torvalds  * owner 4 = 32
14041da177e4SLinus Torvalds  */
14054ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
14066ae37339STrond Myklebust 	encode_share_access(xdr, arg->share_access);
140795b72eb0STrond Myklebust 	p = reserve_space(xdr, 36);
1408b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, arg->clientid);
140995b72eb0STrond Myklebust 	*p++ = cpu_to_be32(24);
141093f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, "open id:", 8);
1411d035c36cSTrond Myklebust 	*p++ = cpu_to_be32(arg->server->s_dev);
141295b72eb0STrond Myklebust 	*p++ = cpu_to_be32(arg->id.uniquifier);
141395b72eb0STrond Myklebust 	xdr_encode_hyper(p, arg->id.create_time);
14141da177e4SLinus Torvalds }
14151da177e4SLinus Torvalds 
14161da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14171da177e4SLinus Torvalds {
14188687b63aSAl Viro 	__be32 *p;
14191da177e4SLinus Torvalds 
142013c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
1421549b19ccSTrond Myklebust 	switch(arg->createmode) {
1422549b19ccSTrond Myklebust 	case NFS4_CREATE_UNCHECKED:
142334558513SBenny Halevy 		*p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
142428cf22d0STrond Myklebust 		encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
142528cf22d0STrond Myklebust 				arg->server, arg->server->attr_bitmask);
14261da177e4SLinus Torvalds 		break;
1427549b19ccSTrond Myklebust 	case NFS4_CREATE_GUARDED:
14284882ef72SAlexandros Batsakis 		*p = cpu_to_be32(NFS4_CREATE_GUARDED);
142928cf22d0STrond Myklebust 		encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
143028cf22d0STrond Myklebust 				arg->server, arg->server->attr_bitmask);
1431549b19ccSTrond Myklebust 		break;
1432549b19ccSTrond Myklebust 	case NFS4_CREATE_EXCLUSIVE:
1433549b19ccSTrond Myklebust 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1434549b19ccSTrond Myklebust 		encode_nfs4_verifier(xdr, &arg->u.verifier);
1435549b19ccSTrond Myklebust 		break;
1436549b19ccSTrond Myklebust 	case NFS4_CREATE_EXCLUSIVE4_1:
14374882ef72SAlexandros Batsakis 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
14384882ef72SAlexandros Batsakis 		encode_nfs4_verifier(xdr, &arg->u.verifier);
143928cf22d0STrond Myklebust 		encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
144028cf22d0STrond Myklebust 				arg->server, arg->server->exclcreat_bitmask);
14414882ef72SAlexandros Batsakis 	}
14424882ef72SAlexandros Batsakis }
14431da177e4SLinus Torvalds 
14441da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14451da177e4SLinus Torvalds {
14468687b63aSAl Viro 	__be32 *p;
14471da177e4SLinus Torvalds 
144813c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14491da177e4SLinus Torvalds 	switch (arg->open_flags & O_CREAT) {
14501da177e4SLinus Torvalds 	case 0:
145134558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_NOCREATE);
14521da177e4SLinus Torvalds 		break;
14531da177e4SLinus Torvalds 	default:
145434558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_CREATE);
14551da177e4SLinus Torvalds 		encode_createmode(xdr, arg);
14561da177e4SLinus Torvalds 	}
14571da177e4SLinus Torvalds }
14581da177e4SLinus Torvalds 
1459bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
14601da177e4SLinus Torvalds {
14618687b63aSAl Viro 	__be32 *p;
14621da177e4SLinus Torvalds 
146313c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
14641da177e4SLinus Torvalds 	switch (delegation_type) {
14651da177e4SLinus Torvalds 	case 0:
146634558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
14671da177e4SLinus Torvalds 		break;
14681da177e4SLinus Torvalds 	case FMODE_READ:
146934558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
14701da177e4SLinus Torvalds 		break;
14711da177e4SLinus Torvalds 	case FMODE_WRITE|FMODE_READ:
147234558513SBenny Halevy 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
14731da177e4SLinus Torvalds 		break;
14741da177e4SLinus Torvalds 	default:
14751da177e4SLinus Torvalds 		BUG();
14761da177e4SLinus Torvalds 	}
14771da177e4SLinus Torvalds }
14781da177e4SLinus Torvalds 
14791da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
14801da177e4SLinus Torvalds {
14818687b63aSAl Viro 	__be32 *p;
14821da177e4SLinus Torvalds 
148313c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
148434558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
14851da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
14861da177e4SLinus Torvalds }
14871da177e4SLinus Torvalds 
1488bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
14891da177e4SLinus Torvalds {
14908687b63aSAl Viro 	__be32 *p;
14911da177e4SLinus Torvalds 
149213c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
149334558513SBenny Halevy 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
14941da177e4SLinus Torvalds 	encode_delegation_type(xdr, type);
14951da177e4SLinus Torvalds }
14961da177e4SLinus Torvalds 
14971da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
14981da177e4SLinus Torvalds {
14998687b63aSAl Viro 	__be32 *p;
15001da177e4SLinus Torvalds 
1501ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 4);
1502ea9d23f5STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1503ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
15041da177e4SLinus Torvalds 	encode_string(xdr, name->len, name->name);
15051da177e4SLinus Torvalds }
15061da177e4SLinus Torvalds 
1507d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr)
1508d9fc6619STrond Myklebust {
1509d9fc6619STrond Myklebust 	__be32 *p;
1510d9fc6619STrond Myklebust 
1511d9fc6619STrond Myklebust 	p = reserve_space(xdr, 4);
1512d9fc6619STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1513d9fc6619STrond Myklebust }
1514d9fc6619STrond Myklebust 
1515d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1516d9fc6619STrond Myklebust {
1517d9fc6619STrond Myklebust 	__be32 *p;
1518d9fc6619STrond Myklebust 
1519d9fc6619STrond Myklebust 	p = reserve_space(xdr, 4);
1520d9fc6619STrond Myklebust 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1521d9fc6619STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
1522d9fc6619STrond Myklebust }
1523d9fc6619STrond Myklebust 
1524cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
15251da177e4SLinus Torvalds {
1526ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
15271da177e4SLinus Torvalds 	encode_openhdr(xdr, arg);
15281da177e4SLinus Torvalds 	encode_opentype(xdr, arg);
15291da177e4SLinus Torvalds 	switch (arg->claim) {
15301da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_NULL:
15311da177e4SLinus Torvalds 		encode_claim_null(xdr, arg->name);
15321da177e4SLinus Torvalds 		break;
15331da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_PREVIOUS:
15341da177e4SLinus Torvalds 		encode_claim_previous(xdr, arg->u.delegation_type);
15351da177e4SLinus Torvalds 		break;
15361da177e4SLinus Torvalds 	case NFS4_OPEN_CLAIM_DELEGATE_CUR:
15371da177e4SLinus Torvalds 		encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
15381da177e4SLinus Torvalds 		break;
1539d9fc6619STrond Myklebust 	case NFS4_OPEN_CLAIM_FH:
1540d9fc6619STrond Myklebust 		encode_claim_fh(xdr);
1541d9fc6619STrond Myklebust 		break;
1542d9fc6619STrond Myklebust 	case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1543d9fc6619STrond Myklebust 		encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1544d9fc6619STrond Myklebust 		break;
15451da177e4SLinus Torvalds 	default:
15461da177e4SLinus Torvalds 		BUG();
15471da177e4SLinus Torvalds 	}
15481da177e4SLinus Torvalds }
15491da177e4SLinus Torvalds 
1550cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
15511da177e4SLinus Torvalds {
1552ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1553ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, arg->stateid);
15544ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
15551da177e4SLinus Torvalds }
15561da177e4SLinus Torvalds 
1557cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
15581da177e4SLinus Torvalds {
1559ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1560566fcec6STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
15614ade9821STrond Myklebust 	encode_nfs4_seqid(xdr, arg->seqid);
15626ae37339STrond Myklebust 	encode_share_access(xdr, arg->share_access);
15631da177e4SLinus Torvalds }
15641da177e4SLinus Torvalds 
1565cf8cdbe5SAndy Adamson static void
1566d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
15671da177e4SLinus Torvalds {
1568ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
15696fdfb0bcSTrond Myklebust 	encode_string(xdr, fh->size, fh->data);
15701da177e4SLinus Torvalds }
15711da177e4SLinus Torvalds 
1572cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
15731da177e4SLinus Torvalds {
1574ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
15751da177e4SLinus Torvalds }
15761da177e4SLinus Torvalds 
15773c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
15783c6b899cSAnna Schumaker 			struct compound_hdr *hdr)
15791da177e4SLinus Torvalds {
15808687b63aSAl Viro 	__be32 *p;
15811da177e4SLinus Torvalds 
1582ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
15839b206149STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
15841da177e4SLinus Torvalds 
158513c65ce9SBenny Halevy 	p = reserve_space(xdr, 12);
1586b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
158734558513SBenny Halevy 	*p = cpu_to_be32(args->count);
15881da177e4SLinus Torvalds }
15891da177e4SLinus Torvalds 
1590cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
15911da177e4SLinus Torvalds {
1592aa9c2669SDavid Quigley 	uint32_t attrs[3] = {
159328331a46STrond Myklebust 		FATTR4_WORD0_RDATTR_ERROR,
159428331a46STrond Myklebust 		FATTR4_WORD1_MOUNTED_ON_FILEID,
159528331a46STrond Myklebust 	};
15966f7a35bdSTrond Myklebust 	uint32_t dircount = readdir->count >> 1;
1597cd93710eSChuck Lever 	__be32 *p, verf[2];
1598d204c5d2STrond Myklebust 	uint32_t attrlen = 0;
1599d204c5d2STrond Myklebust 	unsigned int i;
16001da177e4SLinus Torvalds 
160182f2e547SBryan Schumaker 	if (readdir->plus) {
160282f2e547SBryan Schumaker 		attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
160328331a46STrond Myklebust 			FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
160482f2e547SBryan Schumaker 		attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
160582f2e547SBryan Schumaker 			FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
160682f2e547SBryan Schumaker 			FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
160782f2e547SBryan Schumaker 			FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1608d204c5d2STrond Myklebust 		attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
16096f7a35bdSTrond Myklebust 		dircount >>= 1;
161082f2e547SBryan Schumaker 	}
161128331a46STrond Myklebust 	/* Use mounted_on_fileid only if the server supports it */
161228331a46STrond Myklebust 	if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
161328331a46STrond Myklebust 		attrs[0] |= FATTR4_WORD0_FILEID;
1614d204c5d2STrond Myklebust 	for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1615d204c5d2STrond Myklebust 		attrs[i] &= readdir->bitmask[i];
1616d204c5d2STrond Myklebust 		if (attrs[i] != 0)
1617d204c5d2STrond Myklebust 			attrlen = i+1;
1618d204c5d2STrond Myklebust 	}
16196f7a35bdSTrond Myklebust 
1620475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1621ff2eb681STrond Myklebust 	encode_uint64(xdr, readdir->cookie);
1622cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, &readdir->verifier);
1623d204c5d2STrond Myklebust 	p = reserve_space(xdr, 12 + (attrlen << 2));
16246f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(dircount);
16256f7a35bdSTrond Myklebust 	*p++ = cpu_to_be32(readdir->count);
1626d204c5d2STrond Myklebust 	*p++ = cpu_to_be32(attrlen);
1627d204c5d2STrond Myklebust 	for (i = 0; i < attrlen; i++)
1628d204c5d2STrond Myklebust 		*p++ = cpu_to_be32(attrs[i]);
1629cd93710eSChuck Lever 	memcpy(verf, readdir->verifier.data, sizeof(verf));
1630aa9c2669SDavid Quigley 
1631aa9c2669SDavid Quigley 	dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
163244109241SFred Isaman 			__func__,
1633eadf4598STrond Myklebust 			(unsigned long long)readdir->cookie,
1634cd93710eSChuck Lever 			verf[0], verf[1],
1635eadf4598STrond Myklebust 			attrs[0] & readdir->bitmask[0],
1636aa9c2669SDavid Quigley 			attrs[1] & readdir->bitmask[1],
1637aa9c2669SDavid Quigley 			attrs[2] & readdir->bitmask[2]);
16381da177e4SLinus Torvalds }
16391da177e4SLinus Torvalds 
1640cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
16411da177e4SLinus Torvalds {
1642ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
16431da177e4SLinus Torvalds }
16441da177e4SLinus Torvalds 
1645cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
16461da177e4SLinus Torvalds {
1647ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
16486fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
16491da177e4SLinus Torvalds }
16501da177e4SLinus Torvalds 
1651cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
16521da177e4SLinus Torvalds {
1653ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1654811652bdSBenny Halevy 	encode_string(xdr, oldname->len, oldname->name);
1655811652bdSBenny Halevy 	encode_string(xdr, newname->len, newname->name);
16561da177e4SLinus Torvalds }
16571da177e4SLinus Torvalds 
1658bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1659bb4dae5eSChuck Lever 			 struct compound_hdr *hdr)
16601da177e4SLinus Torvalds {
1661475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1662ff2eb681STrond Myklebust 	encode_uint64(xdr, clid);
16631da177e4SLinus Torvalds }
16641da177e4SLinus Torvalds 
1665cf8cdbe5SAndy Adamson static void
1666d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
166756ae19f3STrond Myklebust {
1668ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
166956ae19f3STrond Myklebust }
167056ae19f3STrond Myklebust 
16719f06c719SChuck Lever static void
1672fcc85819SChristoph Hellwig encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1673fcc85819SChristoph Hellwig 		struct compound_hdr *hdr)
167423ec6965SJ. Bruce Fields {
16758687b63aSAl Viro 	__be32 *p;
167623ec6965SJ. Bruce Fields 
1677ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1678ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &zero_stateid);
167913c65ce9SBenny Halevy 	p = reserve_space(xdr, 2*4);
1680e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
168134558513SBenny Halevy 	*p = cpu_to_be32(FATTR4_WORD0_ACL);
168213c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
168334558513SBenny Halevy 	*p = cpu_to_be32(arg->acl_len);
16848fbcf237SAndreas Gruenbacher 	xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
168523ec6965SJ. Bruce Fields }
168623ec6965SJ. Bruce Fields 
1687cf8cdbe5SAndy Adamson static void
1688d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
16891da177e4SLinus Torvalds {
1690ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
16911da177e4SLinus Torvalds }
16921da177e4SLinus Torvalds 
1693cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
16941da177e4SLinus Torvalds {
1695ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1696ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &arg->stateid);
169728cf22d0STrond Myklebust 	encode_attrs(xdr, arg->iap, arg->label, NULL, server,
169828cf22d0STrond Myklebust 			server->attr_bitmask);
16991da177e4SLinus Torvalds }
17001da177e4SLinus Torvalds 
1701cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
17021da177e4SLinus Torvalds {
17038687b63aSAl Viro 	__be32 *p;
17041da177e4SLinus Torvalds 
170570019514STrond Myklebust 	encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1706cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, setclientid->sc_verifier);
17071da177e4SLinus Torvalds 
17083a6bb738SJeff Layton 	encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
17093a6bb738SJeff Layton 			setclientid->sc_clnt->cl_owner_id);
171013c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
171134558513SBenny Halevy 	*p = cpu_to_be32(setclientid->sc_prog);
17121da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
17131da177e4SLinus Torvalds 	encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
171413c65ce9SBenny Halevy 	p = reserve_space(xdr, 4);
17153a6bb738SJeff Layton 	*p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
17161da177e4SLinus Torvalds }
17171da177e4SLinus Torvalds 
1718bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
17191da177e4SLinus Torvalds {
1720475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1721475d4ba0STrond Myklebust 			decode_setclientid_confirm_maxsz, hdr);
1722ff2eb681STrond Myklebust 	encode_uint64(xdr, arg->clientid);
1723cd93710eSChuck Lever 	encode_nfs4_verifier(xdr, &arg->confirm);
17241da177e4SLinus Torvalds }
17251da177e4SLinus Torvalds 
17263c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
17273c6b899cSAnna Schumaker 			 struct compound_hdr *hdr)
17281da177e4SLinus Torvalds {
17298687b63aSAl Viro 	__be32 *p;
17301da177e4SLinus Torvalds 
1731ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
17329b206149STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
17331da177e4SLinus Torvalds 
173413c65ce9SBenny Halevy 	p = reserve_space(xdr, 16);
1735b95be5a9SBenny Halevy 	p = xdr_encode_hyper(p, args->offset);
1736e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->stable);
173734558513SBenny Halevy 	*p = cpu_to_be32(args->count);
17381da177e4SLinus Torvalds 
17391da177e4SLinus Torvalds 	xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
17401da177e4SLinus Torvalds }
17411da177e4SLinus Torvalds 
1742cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
17431da177e4SLinus Torvalds {
1744ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1745ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, stateid);
17461da177e4SLinus Torvalds }
17479b7b9fccSAndy Adamson 
17485a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
17495a5ea0d4SBryan Schumaker {
1750ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
17516fdfb0bcSTrond Myklebust 	encode_string(xdr, name->len, name->name);
17525a5ea0d4SBryan Schumaker }
17535a5ea0d4SBryan Schumaker 
175499fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
17559b7b9fccSAndy Adamson /* NFSv4.1 operations */
17567c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1757fcc85819SChristoph Hellwig 				   const struct nfs41_bind_conn_to_session_args *args,
17587c44f1aeSWeston Andros Adamson 				   struct compound_hdr *hdr)
17597c44f1aeSWeston Andros Adamson {
17607c44f1aeSWeston Andros Adamson 	__be32 *p;
17617c44f1aeSWeston Andros Adamson 
17627c44f1aeSWeston Andros Adamson 	encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
17637c44f1aeSWeston Andros Adamson 		decode_bind_conn_to_session_maxsz, hdr);
176471a097c6STrond Myklebust 	encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
17657c44f1aeSWeston Andros Adamson 	p = xdr_reserve_space(xdr, 8);
176671a097c6STrond Myklebust 	*p++ = cpu_to_be32(args->dir);
176771a097c6STrond Myklebust 	*p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
17687c44f1aeSWeston Andros Adamson }
17697c44f1aeSWeston Andros Adamson 
1770fcc85819SChristoph Hellwig static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
17712031cd1aSWeston Andros Adamson {
17722031cd1aSWeston Andros Adamson 	unsigned int i;
17732031cd1aSWeston Andros Adamson 	encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
17742031cd1aSWeston Andros Adamson 	for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
17752031cd1aSWeston Andros Adamson 		encode_uint32(xdr, op_map->u.words[i]);
17762031cd1aSWeston Andros Adamson }
17772031cd1aSWeston Andros Adamson 
177899fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr,
1779fcc85819SChristoph Hellwig 			       const struct nfs41_exchange_id_args *args,
178099fe60d0SBenny Halevy 			       struct compound_hdr *hdr)
178199fe60d0SBenny Halevy {
178299fe60d0SBenny Halevy 	__be32 *p;
1783d751f748SJim Rees 	char impl_name[IMPL_NAME_LIMIT];
1784db8ac8baSWeston Andros Adamson 	int len = 0;
178599fe60d0SBenny Halevy 
178670019514STrond Myklebust 	encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1787fd40559cSTrond Myklebust 	encode_nfs4_verifier(xdr, &args->verifier);
178899fe60d0SBenny Halevy 
17893a6bb738SJeff Layton 	encode_string(xdr, strlen(args->client->cl_owner_id),
17903a6bb738SJeff Layton 			args->client->cl_owner_id);
179199fe60d0SBenny Halevy 
17922031cd1aSWeston Andros Adamson 	encode_uint32(xdr, args->flags);
17932031cd1aSWeston Andros Adamson 	encode_uint32(xdr, args->state_protect.how);
17942031cd1aSWeston Andros Adamson 
17952031cd1aSWeston Andros Adamson 	switch (args->state_protect.how) {
17962031cd1aSWeston Andros Adamson 	case SP4_NONE:
17972031cd1aSWeston Andros Adamson 		break;
17982031cd1aSWeston Andros Adamson 	case SP4_MACH_CRED:
17992031cd1aSWeston Andros Adamson 		encode_op_map(xdr, &args->state_protect.enforce);
18002031cd1aSWeston Andros Adamson 		encode_op_map(xdr, &args->state_protect.allow);
18012031cd1aSWeston Andros Adamson 		break;
18022031cd1aSWeston Andros Adamson 	default:
18032031cd1aSWeston Andros Adamson 		WARN_ON_ONCE(1);
18042031cd1aSWeston Andros Adamson 		break;
18052031cd1aSWeston Andros Adamson 	}
1806db8ac8baSWeston Andros Adamson 
1807db8ac8baSWeston Andros Adamson 	if (send_implementation_id &&
1808db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1809db8ac8baSWeston Andros Adamson 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1810d751f748SJim Rees 		<= sizeof(impl_name) + 1)
1811db8ac8baSWeston Andros Adamson 		len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1812db8ac8baSWeston Andros Adamson 			       utsname()->sysname, utsname()->release,
1813db8ac8baSWeston Andros Adamson 			       utsname()->version, utsname()->machine);
1814db8ac8baSWeston Andros Adamson 
1815db8ac8baSWeston Andros Adamson 	if (len > 0) {
18162031cd1aSWeston Andros Adamson 		encode_uint32(xdr, 1);	/* implementation id array length=1 */
1817db8ac8baSWeston Andros Adamson 
1818db8ac8baSWeston Andros Adamson 		encode_string(xdr,
1819db8ac8baSWeston Andros Adamson 			sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1820db8ac8baSWeston Andros Adamson 			CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1821db8ac8baSWeston Andros Adamson 		encode_string(xdr, len, impl_name);
1822db8ac8baSWeston Andros Adamson 		/* just send zeros for nii_date - the date is in nii_name */
1823db8ac8baSWeston Andros Adamson 		p = reserve_space(xdr, 12);
1824db8ac8baSWeston Andros Adamson 		p = xdr_encode_hyper(p, 0);
1825db8ac8baSWeston Andros Adamson 		*p = cpu_to_be32(0);
1826db8ac8baSWeston Andros Adamson 	} else
18272031cd1aSWeston Andros Adamson 		encode_uint32(xdr, 0);	/* implementation id array length=0 */
182899fe60d0SBenny Halevy }
1829fc931582SAndy Adamson 
1830fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr,
1831fcc85819SChristoph Hellwig 				  const struct nfs41_create_session_args *args,
1832fc931582SAndy Adamson 				  struct compound_hdr *hdr)
1833fc931582SAndy Adamson {
1834fc931582SAndy Adamson 	__be32 *p;
1835fc931582SAndy Adamson 	struct nfs_client *clp = args->client;
183689f0ff38STrond Myklebust 	struct rpc_clnt *clnt = clp->cl_rpcclient;
1837f092075dSChuck Lever 	struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
18388e0d46e1SMike Sager 	u32 max_resp_sz_cached;
18398e0d46e1SMike Sager 
18408e0d46e1SMike Sager 	/*
18418e0d46e1SMike Sager 	 * Assumes OPEN is the biggest non-idempotent compound.
18428e0d46e1SMike Sager 	 * 2 is the verifier.
18438e0d46e1SMike Sager 	 */
184435c036efSJ. Bruce Fields 	max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
184535c036efSJ. Bruce Fields 				* XDR_UNIT + RPC_MAX_AUTH_SIZE;
1846fc931582SAndy Adamson 
1847475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
184889f0ff38STrond Myklebust 	p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
184979969dd1STrond Myklebust 	p = xdr_encode_hyper(p, args->clientid);
185079969dd1STrond Myklebust 	*p++ = cpu_to_be32(args->seqid);			/*Sequence id */
1851e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->flags);			/*flags */
1852fc931582SAndy Adamson 
1853fc931582SAndy Adamson 	/* Fore Channel */
1854c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1855e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz);	/* max req size */
1856e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_resp_sz);	/* max resp size */
18578e0d46e1SMike Sager 	*p++ = cpu_to_be32(max_resp_sz_cached);		/* Max resp sz cached */
1858e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_ops);	/* max operations */
1859e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->fc_attrs.max_reqs);	/* max requests */
1860e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1861fc931582SAndy Adamson 
1862fc931582SAndy Adamson 	/* Back Channel */
1863c9c30dd5SBenny Halevy 	*p++ = cpu_to_be32(0);				/* header padding size */
1864e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz);	/* max req size */
1865e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz);	/* max resp size */
1866e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached);	/* Max resp sz cached */
1867e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_ops);	/* max operations */
1868e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->bc_attrs.max_reqs);	/* max requests */
1869e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1870fc931582SAndy Adamson 
1871e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(args->cb_program);		/* cb_program */
1872e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(1);
1873e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(RPC_AUTH_UNIX);			/* auth_sys */
1874fc931582SAndy Adamson 
1875fc931582SAndy Adamson 	/* authsys_parms rfc1831 */
18762f86e091SDeepa Dinamani 	*p++ = cpu_to_be32(ktime_to_ns(nn->boot_time));	/* stamp */
187789f0ff38STrond Myklebust 	p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
1878e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* UID */
1879e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(0);				/* GID */
188034558513SBenny Halevy 	*p = cpu_to_be32(0);				/* No more gids */
1881fc931582SAndy Adamson }
18820f3e66c6SAndy Adamson 
18830f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr,
1884fcc85819SChristoph Hellwig 				   const struct nfs4_session *session,
18850f3e66c6SAndy Adamson 				   struct compound_hdr *hdr)
18860f3e66c6SAndy Adamson {
1887475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1888475d4ba0STrond Myklebust 	encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
18890f3e66c6SAndy Adamson }
189018019753SRicardo Labiaga 
189166245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr,
189266245539STrond Myklebust 				   uint64_t clientid,
189366245539STrond Myklebust 				   struct compound_hdr *hdr)
189466245539STrond Myklebust {
189566245539STrond Myklebust 	encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
189666245539STrond Myklebust 	encode_uint64(xdr, clientid);
189766245539STrond Myklebust }
189866245539STrond Myklebust 
189918019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr,
1900fcc85819SChristoph Hellwig 				    const struct nfs41_reclaim_complete_args *args,
190118019753SRicardo Labiaga 				    struct compound_hdr *hdr)
190218019753SRicardo Labiaga {
1903475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1904475d4ba0STrond Myklebust 	encode_uint32(xdr, args->one_fs);
190518019753SRicardo Labiaga }
190699fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
190799fe60d0SBenny Halevy 
19089b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr,
19099b7b9fccSAndy Adamson 			    const struct nfs4_sequence_args *args,
19109b7b9fccSAndy Adamson 			    struct compound_hdr *hdr)
19119b7b9fccSAndy Adamson {
19129b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
19132b2fa717STrond Myklebust 	struct nfs4_session *session;
1914fc01cea9SAndy Adamson 	struct nfs4_slot_table *tp;
19152b2fa717STrond Myklebust 	struct nfs4_slot *slot = args->sa_slot;
1916fc01cea9SAndy Adamson 	__be32 *p;
19179b7b9fccSAndy Adamson 
19182b2fa717STrond Myklebust 	tp = slot->table;
19192b2fa717STrond Myklebust 	session = tp->session;
19203bd2384aSChuck Lever 	if (!session)
19213bd2384aSChuck Lever 		return;
1922fc01cea9SAndy Adamson 
1923475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1924fc01cea9SAndy Adamson 
1925fc01cea9SAndy Adamson 	/*
1926fc01cea9SAndy Adamson 	 * Sessionid + seqid + slotid + max slotid + cache_this
1927fc01cea9SAndy Adamson 	 */
1928fc01cea9SAndy Adamson 	dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1929fc01cea9SAndy Adamson 		"max_slotid=%d cache_this=%d\n",
1930fc01cea9SAndy Adamson 		__func__,
1931fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[0],
1932fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[1],
1933fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[2],
1934fc01cea9SAndy Adamson 		((u32 *)session->sess_id.data)[3],
19352b2fa717STrond Myklebust 		slot->seq_nr, slot->slot_nr,
1936fc01cea9SAndy Adamson 		tp->highest_used_slotid, args->sa_cache_this);
1937475d4ba0STrond Myklebust 	p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
193893f0cf25SBenny Halevy 	p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1939e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(slot->seq_nr);
19402b2fa717STrond Myklebust 	*p++ = cpu_to_be32(slot->slot_nr);
1941e75bc1c8SBenny Halevy 	*p++ = cpu_to_be32(tp->highest_used_slotid);
194234558513SBenny Halevy 	*p = cpu_to_be32(args->sa_cache_this);
19439b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
19449b7b9fccSAndy Adamson }
19459b7b9fccSAndy Adamson 
1946b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1
1947b1f69b75SAndy Adamson static void
1948b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr,
1949b1f69b75SAndy Adamson 		     const struct nfs4_getdeviceinfo_args *args,
1950b1f69b75SAndy Adamson 		     struct compound_hdr *hdr)
1951b1f69b75SAndy Adamson {
1952b1f69b75SAndy Adamson 	__be32 *p;
1953b1f69b75SAndy Adamson 
1954475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
195584c9dee3SChristoph Hellwig 	p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
1956b1f69b75SAndy Adamson 	p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1957b1f69b75SAndy Adamson 				    NFS4_DEVICEID4_SIZE);
1958b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->pdev->layout_type);
1959f1c097beSAndy Adamson 	*p++ = cpu_to_be32(args->pdev->maxcount);	/* gdia_maxcount */
196084c9dee3SChristoph Hellwig 
196184c9dee3SChristoph Hellwig 	p = reserve_space(xdr, 4 + 4);
196284c9dee3SChristoph Hellwig 	*p++ = cpu_to_be32(1);			/* bitmap length */
19634e590803STrond Myklebust 	*p++ = cpu_to_be32(args->notify_types);
1964b1f69b75SAndy Adamson }
1965b1f69b75SAndy Adamson 
1966b1f69b75SAndy Adamson static void
1967b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr,
1968b1f69b75SAndy Adamson 		      const struct nfs4_layoutget_args *args,
1969b1f69b75SAndy Adamson 		      struct compound_hdr *hdr)
1970b1f69b75SAndy Adamson {
1971b1f69b75SAndy Adamson 	__be32 *p;
1972b1f69b75SAndy Adamson 
1973475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1974475d4ba0STrond Myklebust 	p = reserve_space(xdr, 36);
1975b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(0);     /* Signal layout available */
1976b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->type);
1977b1f69b75SAndy Adamson 	*p++ = cpu_to_be32(args->range.iomode);
1978b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.offset);
1979b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->range.length);
1980b1f69b75SAndy Adamson 	p = xdr_encode_hyper(p, args->minlength);
1981ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
1982475d4ba0STrond Myklebust 	encode_uint32(xdr, args->maxcount);
1983b1f69b75SAndy Adamson 
1984b1f69b75SAndy Adamson 	dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1985b1f69b75SAndy Adamson 		__func__,
1986b1f69b75SAndy Adamson 		args->type,
1987b1f69b75SAndy Adamson 		args->range.iomode,
1988b1f69b75SAndy Adamson 		(unsigned long)args->range.offset,
1989b1f69b75SAndy Adamson 		(unsigned long)args->range.length,
1990b1f69b75SAndy Adamson 		args->maxcount);
1991b1f69b75SAndy Adamson }
1992863a3c6cSAndy Adamson 
1993863a3c6cSAndy Adamson static int
1994863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr,
1995ac7db726SBenny Halevy 		    struct inode *inode,
1996fcc85819SChristoph Hellwig 		    const struct nfs4_layoutcommit_args *args,
1997863a3c6cSAndy Adamson 		    struct compound_hdr *hdr)
1998863a3c6cSAndy Adamson {
1999863a3c6cSAndy Adamson 	__be32 *p;
2000863a3c6cSAndy Adamson 
2001863a3c6cSAndy Adamson 	dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2002863a3c6cSAndy Adamson 		NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2003863a3c6cSAndy Adamson 
2004475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2005475d4ba0STrond Myklebust 	p = reserve_space(xdr, 20);
2006863a3c6cSAndy Adamson 	/* Only whole file layouts */
2007863a3c6cSAndy Adamson 	p = xdr_encode_hyper(p, 0); /* offset */
20083557c6c3SPeng Tao 	p = xdr_encode_hyper(p, args->lastbytewritten + 1);	/* length */
2009ea9d23f5STrond Myklebust 	*p = cpu_to_be32(0); /* reclaim */
2010ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
20112e18d4d8STrond Myklebust 	if (args->lastbytewritten != U64_MAX) {
2012ea9d23f5STrond Myklebust 		p = reserve_space(xdr, 20);
2013863a3c6cSAndy Adamson 		*p++ = cpu_to_be32(1); /* newoffset = TRUE */
2014863a3c6cSAndy Adamson 		p = xdr_encode_hyper(p, args->lastbytewritten);
20152e18d4d8STrond Myklebust 	} else {
20162e18d4d8STrond Myklebust 		p = reserve_space(xdr, 12);
20172e18d4d8STrond Myklebust 		*p++ = cpu_to_be32(0); /* newoffset = FALSE */
20182e18d4d8STrond Myklebust 	}
2019863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2020863a3c6cSAndy Adamson 	*p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2021ac7db726SBenny Halevy 
20225f919c9fSChristoph Hellwig 	encode_uint32(xdr, args->layoutupdate_len);
202373504740STrond Myklebust 	if (args->layoutupdate_pages)
20245f919c9fSChristoph Hellwig 		xdr_write_pages(xdr, args->layoutupdate_pages, 0,
20255f919c9fSChristoph Hellwig 				args->layoutupdate_len);
2026863a3c6cSAndy Adamson 
2027863a3c6cSAndy Adamson 	return 0;
2028863a3c6cSAndy Adamson }
2029cbe82603SBenny Halevy 
2030cbe82603SBenny Halevy static void
2031cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr,
2032cbe82603SBenny Halevy 		    const struct nfs4_layoutreturn_args *args,
2033cbe82603SBenny Halevy 		    struct compound_hdr *hdr)
2034cbe82603SBenny Halevy {
2035cbe82603SBenny Halevy 	__be32 *p;
2036cbe82603SBenny Halevy 
2037475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2038475d4ba0STrond Myklebust 	p = reserve_space(xdr, 16);
2039cbe82603SBenny Halevy 	*p++ = cpu_to_be32(0);		/* reclaim. always 0 for now */
2040cbe82603SBenny Halevy 	*p++ = cpu_to_be32(args->layout_type);
204115eb67c1SPeng Tao 	*p++ = cpu_to_be32(args->range.iomode);
2042cbe82603SBenny Halevy 	*p = cpu_to_be32(RETURN_FILE);
2043ea9d23f5STrond Myklebust 	p = reserve_space(xdr, 16);
204415eb67c1SPeng Tao 	p = xdr_encode_hyper(p, args->range.offset);
204515eb67c1SPeng Tao 	p = xdr_encode_hyper(p, args->range.length);
2046cbe82603SBenny Halevy 	spin_lock(&args->inode->i_lock);
2047ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
2048cbe82603SBenny Halevy 	spin_unlock(&args->inode->i_lock);
20494d796d75STrond Myklebust 	if (args->ld_private->ops && args->ld_private->ops->encode)
20504d796d75STrond Myklebust 		args->ld_private->ops->encode(xdr, args, args->ld_private);
205194e5c571STrond Myklebust 	else
2052475d4ba0STrond Myklebust 		encode_uint32(xdr, 0);
2053cbe82603SBenny Halevy }
2054fca78d6dSBryan Schumaker 
2055fca78d6dSBryan Schumaker static int
2056fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr,
2057fca78d6dSBryan Schumaker 		       const struct nfs41_secinfo_no_name_args *args,
2058fca78d6dSBryan Schumaker 		       struct compound_hdr *hdr)
2059fca78d6dSBryan Schumaker {
2060475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2061475d4ba0STrond Myklebust 	encode_uint32(xdr, args->style);
2062fca78d6dSBryan Schumaker 	return 0;
2063fca78d6dSBryan Schumaker }
20647d974794SBryan Schumaker 
20657d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr,
2066fcc85819SChristoph Hellwig 				const struct nfs41_test_stateid_args *args,
20677d974794SBryan Schumaker 				struct compound_hdr *hdr)
20687d974794SBryan Schumaker {
2069475d4ba0STrond Myklebust 	encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2070475d4ba0STrond Myklebust 	encode_uint32(xdr, 1);
2071ea9d23f5STrond Myklebust 	encode_nfs4_stateid(xdr, args->stateid);
20727d974794SBryan Schumaker }
20739aeda35fSBryan Schumaker 
20749aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr,
2075fcc85819SChristoph Hellwig 				const struct nfs41_free_stateid_args *args,
20769aeda35fSBryan Schumaker 				struct compound_hdr *hdr)
20779aeda35fSBryan Schumaker {
2078ab19b481STrond Myklebust 	encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
20797c1d5faeSTrond Myklebust 	encode_nfs4_stateid(xdr, &args->stateid);
20809aeda35fSBryan Schumaker }
2081cf805165STrond Myklebust #else
2082cf805165STrond Myklebust static inline void
2083cf805165STrond Myklebust encode_layoutreturn(struct xdr_stream *xdr,
2084cf805165STrond Myklebust 		    const struct nfs4_layoutreturn_args *args,
2085cf805165STrond Myklebust 		    struct compound_hdr *hdr)
2086cf805165STrond Myklebust {
2087cf805165STrond Myklebust }
208856f487f8SFred Isaman 
208956f487f8SFred Isaman static void
209056f487f8SFred Isaman encode_layoutget(struct xdr_stream *xdr,
209156f487f8SFred Isaman 		      const struct nfs4_layoutget_args *args,
209256f487f8SFred Isaman 		      struct compound_hdr *hdr)
209356f487f8SFred Isaman {
209456f487f8SFred Isaman }
2095b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
2096b1f69b75SAndy Adamson 
20971da177e4SLinus Torvalds /*
20981da177e4SLinus Torvalds  * END OF "GENERIC" ENCODE ROUTINES.
20991da177e4SLinus Torvalds  */
21001da177e4SLinus Torvalds 
210166cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
210266cc0429SBenny Halevy {
210366cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1)
21043bd2384aSChuck Lever 	struct nfs4_session *session = args->sa_slot->table->session;
21053bd2384aSChuck Lever 	if (session)
21063bd2384aSChuck Lever 		return session->clp->cl_mvops->minor_version;
210766cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
210866cc0429SBenny Halevy 	return 0;
210966cc0429SBenny Halevy }
211066cc0429SBenny Halevy 
21111da177e4SLinus Torvalds /*
21121da177e4SLinus Torvalds  * Encode an ACCESS request
21131da177e4SLinus Torvalds  */
21149f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2115fcc85819SChristoph Hellwig 				const void *data)
21161da177e4SLinus Torvalds {
2117fcc85819SChristoph Hellwig 	const struct nfs4_accessargs *args = data;
21181da177e4SLinus Torvalds 	struct compound_hdr hdr = {
211966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21201da177e4SLinus Torvalds 	};
21211da177e4SLinus Torvalds 
21229f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21239f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21249f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
21259f06c719SChuck Lever 	encode_access(xdr, args->access, &hdr);
21268bcbe7d9STrond Myklebust 	if (args->bitmask)
21279f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2128d017931cSAndy Adamson 	encode_nops(&hdr);
21291da177e4SLinus Torvalds }
21301da177e4SLinus Torvalds 
21311da177e4SLinus Torvalds /*
21321da177e4SLinus Torvalds  * Encode LOOKUP request
21331da177e4SLinus Torvalds  */
21349f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2135fcc85819SChristoph Hellwig 				const void *data)
21361da177e4SLinus Torvalds {
2137fcc85819SChristoph Hellwig 	const struct nfs4_lookup_arg *args = data;
21381da177e4SLinus Torvalds 	struct compound_hdr hdr = {
213966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21401da177e4SLinus Torvalds 	};
21411da177e4SLinus Torvalds 
21429f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21439f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21449f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
21459f06c719SChuck Lever 	encode_lookup(xdr, args->name, &hdr);
21469f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21479f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2148d017931cSAndy Adamson 	encode_nops(&hdr);
21491da177e4SLinus Torvalds }
21501da177e4SLinus Torvalds 
21511da177e4SLinus Torvalds /*
21525b5faaf6SJeff Layton  * Encode LOOKUPP request
21535b5faaf6SJeff Layton  */
21545b5faaf6SJeff Layton static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
21555b5faaf6SJeff Layton 		const void *data)
21565b5faaf6SJeff Layton {
21575b5faaf6SJeff Layton 	const struct nfs4_lookupp_arg *args = data;
21585b5faaf6SJeff Layton 	struct compound_hdr hdr = {
21595b5faaf6SJeff Layton 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21605b5faaf6SJeff Layton 	};
21615b5faaf6SJeff Layton 
21625b5faaf6SJeff Layton 	encode_compound_hdr(xdr, req, &hdr);
21635b5faaf6SJeff Layton 	encode_sequence(xdr, &args->seq_args, &hdr);
21645b5faaf6SJeff Layton 	encode_putfh(xdr, args->fh, &hdr);
21655b5faaf6SJeff Layton 	encode_lookupp(xdr, &hdr);
21665b5faaf6SJeff Layton 	encode_getfh(xdr, &hdr);
21675b5faaf6SJeff Layton 	encode_getfattr(xdr, args->bitmask, &hdr);
21685b5faaf6SJeff Layton 	encode_nops(&hdr);
21695b5faaf6SJeff Layton }
21705b5faaf6SJeff Layton 
21715b5faaf6SJeff Layton /*
21721da177e4SLinus Torvalds  * Encode LOOKUP_ROOT request
21731da177e4SLinus Torvalds  */
21749f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
21759f06c719SChuck Lever 				     struct xdr_stream *xdr,
2176fcc85819SChristoph Hellwig 				     const void *data)
21771da177e4SLinus Torvalds {
2178fcc85819SChristoph Hellwig 	const struct nfs4_lookup_root_arg *args = data;
21791da177e4SLinus Torvalds 	struct compound_hdr hdr = {
218066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
21811da177e4SLinus Torvalds 	};
21821da177e4SLinus Torvalds 
21839f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
21849f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
21859f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
21869f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
21879f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2188d017931cSAndy Adamson 	encode_nops(&hdr);
21891da177e4SLinus Torvalds }
21901da177e4SLinus Torvalds 
21911da177e4SLinus Torvalds /*
21921da177e4SLinus Torvalds  * Encode REMOVE request
21931da177e4SLinus Torvalds  */
21949f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2195fcc85819SChristoph Hellwig 				const void *data)
21961da177e4SLinus Torvalds {
2197fcc85819SChristoph Hellwig 	const struct nfs_removeargs *args = data;
21981da177e4SLinus Torvalds 	struct compound_hdr hdr = {
219966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22001da177e4SLinus Torvalds 	};
22011da177e4SLinus Torvalds 
22029f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22039f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22049f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22059f06c719SChuck Lever 	encode_remove(xdr, &args->name, &hdr);
2206d017931cSAndy Adamson 	encode_nops(&hdr);
22071da177e4SLinus Torvalds }
22081da177e4SLinus Torvalds 
22091da177e4SLinus Torvalds /*
22101da177e4SLinus Torvalds  * Encode RENAME request
22111da177e4SLinus Torvalds  */
22129f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2213fcc85819SChristoph Hellwig 				const void *data)
22141da177e4SLinus Torvalds {
2215fcc85819SChristoph Hellwig 	const struct nfs_renameargs *args = data;
22161da177e4SLinus Torvalds 	struct compound_hdr hdr = {
221766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22181da177e4SLinus Torvalds 	};
22191da177e4SLinus Torvalds 
22209f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22219f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22229f06c719SChuck Lever 	encode_putfh(xdr, args->old_dir, &hdr);
22239f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
22249f06c719SChuck Lever 	encode_putfh(xdr, args->new_dir, &hdr);
22259f06c719SChuck Lever 	encode_rename(xdr, args->old_name, args->new_name, &hdr);
2226d017931cSAndy Adamson 	encode_nops(&hdr);
22271da177e4SLinus Torvalds }
22281da177e4SLinus Torvalds 
22291da177e4SLinus Torvalds /*
22301da177e4SLinus Torvalds  * Encode LINK request
22311da177e4SLinus Torvalds  */
22329f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2233fcc85819SChristoph Hellwig 			      const void *data)
22341da177e4SLinus Torvalds {
2235fcc85819SChristoph Hellwig 	const struct nfs4_link_arg *args = data;
22361da177e4SLinus Torvalds 	struct compound_hdr hdr = {
223766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22381da177e4SLinus Torvalds 	};
22391da177e4SLinus Torvalds 
22409f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22419f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22429f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22439f06c719SChuck Lever 	encode_savefh(xdr, &hdr);
22449f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
22459f06c719SChuck Lever 	encode_link(xdr, args->name, &hdr);
22469f06c719SChuck Lever 	encode_restorefh(xdr, &hdr);
22479f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2248d017931cSAndy Adamson 	encode_nops(&hdr);
22491da177e4SLinus Torvalds }
22501da177e4SLinus Torvalds 
22511da177e4SLinus Torvalds /*
22521da177e4SLinus Torvalds  * Encode CREATE request
22531da177e4SLinus Torvalds  */
22549f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2255fcc85819SChristoph Hellwig 				const void *data)
22561da177e4SLinus Torvalds {
2257fcc85819SChristoph Hellwig 	const struct nfs4_create_arg *args = data;
22581da177e4SLinus Torvalds 	struct compound_hdr hdr = {
225966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22601da177e4SLinus Torvalds 	};
22611da177e4SLinus Torvalds 
22629f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22639f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22649f06c719SChuck Lever 	encode_putfh(xdr, args->dir_fh, &hdr);
22659f06c719SChuck Lever 	encode_create(xdr, args, &hdr);
22669f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
22679f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2268d017931cSAndy Adamson 	encode_nops(&hdr);
22691da177e4SLinus Torvalds }
22701da177e4SLinus Torvalds 
22711da177e4SLinus Torvalds /*
22721da177e4SLinus Torvalds  * Encode SYMLINK request
22731da177e4SLinus Torvalds  */
22749f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2275fcc85819SChristoph Hellwig 				 const void *data)
22761da177e4SLinus Torvalds {
2277fcc85819SChristoph Hellwig 	const struct nfs4_create_arg *args = data;
2278fcc85819SChristoph Hellwig 
22799f06c719SChuck Lever 	nfs4_xdr_enc_create(req, xdr, args);
22801da177e4SLinus Torvalds }
22811da177e4SLinus Torvalds 
22821da177e4SLinus Torvalds /*
22831da177e4SLinus Torvalds  * Encode GETATTR request
22841da177e4SLinus Torvalds  */
22859f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2286fcc85819SChristoph Hellwig 				 const void *data)
22871da177e4SLinus Torvalds {
2288fcc85819SChristoph Hellwig 	const struct nfs4_getattr_arg *args = data;
22891da177e4SLinus Torvalds 	struct compound_hdr hdr = {
229066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
22911da177e4SLinus Torvalds 	};
22921da177e4SLinus Torvalds 
22939f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
22949f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
22959f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
22969f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2297d017931cSAndy Adamson 	encode_nops(&hdr);
22981da177e4SLinus Torvalds }
22991da177e4SLinus Torvalds 
23001da177e4SLinus Torvalds /*
23011da177e4SLinus Torvalds  * Encode a CLOSE request
23021da177e4SLinus Torvalds  */
23039f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2304fcc85819SChristoph Hellwig 			       const void *data)
23051da177e4SLinus Torvalds {
2306fcc85819SChristoph Hellwig 	const struct nfs_closeargs *args = data;
23071da177e4SLinus Torvalds 	struct compound_hdr hdr = {
230866cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23091da177e4SLinus Torvalds 	};
23101da177e4SLinus Torvalds 
23119f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23129f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23139f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
2314cf805165STrond Myklebust 	if (args->lr_args)
2315cf805165STrond Myklebust 		encode_layoutreturn(xdr, args->lr_args, &hdr);
23163ecefc92STrond Myklebust 	if (args->bitmask != NULL)
23179f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2318d8d84983STrond Myklebust 	encode_close(xdr, args, &hdr);
2319d017931cSAndy Adamson 	encode_nops(&hdr);
23201da177e4SLinus Torvalds }
23211da177e4SLinus Torvalds 
23221da177e4SLinus Torvalds /*
23231da177e4SLinus Torvalds  * Encode an OPEN request
23241da177e4SLinus Torvalds  */
23259f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2326fcc85819SChristoph Hellwig 			      const void *data)
23271da177e4SLinus Torvalds {
2328fcc85819SChristoph Hellwig 	const struct nfs_openargs *args = data;
23291da177e4SLinus Torvalds 	struct compound_hdr hdr = {
233066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23311da177e4SLinus Torvalds 	};
23321da177e4SLinus Torvalds 
23339f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23349f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23359f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23369f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
23379f06c719SChuck Lever 	encode_getfh(xdr, &hdr);
2338ae2bb032SWeston Andros Adamson 	if (args->access)
23396168f62cSWeston Andros Adamson 		encode_access(xdr, args->access, &hdr);
23401549210fSTrond Myklebust 	encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
234156f487f8SFred Isaman 	if (args->lg_args) {
234256f487f8SFred Isaman 		encode_layoutget(xdr, args->lg_args, &hdr);
2343cf500bacSChuck Lever 		rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2344cf500bacSChuck Lever 					args->lg_args->layout.pglen,
2345cf500bacSChuck Lever 					hdr.replen);
234656f487f8SFred Isaman 	}
2347d017931cSAndy Adamson 	encode_nops(&hdr);
23481da177e4SLinus Torvalds }
23491da177e4SLinus Torvalds 
23501da177e4SLinus Torvalds /*
23511da177e4SLinus Torvalds  * Encode an OPEN_CONFIRM request
23521da177e4SLinus Torvalds  */
23539f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
23549f06c719SChuck Lever 				      struct xdr_stream *xdr,
2355fcc85819SChristoph Hellwig 				      const void *data)
23561da177e4SLinus Torvalds {
2357fcc85819SChristoph Hellwig 	const struct nfs_open_confirmargs *args = data;
23581da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2359d017931cSAndy Adamson 		.nops   = 0,
23601da177e4SLinus Torvalds 	};
23611da177e4SLinus Torvalds 
23629f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23639f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23649f06c719SChuck Lever 	encode_open_confirm(xdr, args, &hdr);
2365d017931cSAndy Adamson 	encode_nops(&hdr);
23661da177e4SLinus Torvalds }
23671da177e4SLinus Torvalds 
23681da177e4SLinus Torvalds /*
23691da177e4SLinus Torvalds  * Encode an OPEN request with no attributes.
23701da177e4SLinus Torvalds  */
23719f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
23729f06c719SChuck Lever 				     struct xdr_stream *xdr,
2373fcc85819SChristoph Hellwig 				     const void *data)
23741da177e4SLinus Torvalds {
2375fcc85819SChristoph Hellwig 	const struct nfs_openargs *args = data;
23761da177e4SLinus Torvalds 	struct compound_hdr hdr = {
237766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
23781da177e4SLinus Torvalds 	};
23791da177e4SLinus Torvalds 
23809f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
23819f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
23829f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
23839f06c719SChuck Lever 	encode_open(xdr, args, &hdr);
2384ae2bb032SWeston Andros Adamson 	if (args->access)
23856168f62cSWeston Andros Adamson 		encode_access(xdr, args->access, &hdr);
2386e23008ecSAndy Adamson 	encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
238756f487f8SFred Isaman 	if (args->lg_args) {
238856f487f8SFred Isaman 		encode_layoutget(xdr, args->lg_args, &hdr);
2389cf500bacSChuck Lever 		rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2390cf500bacSChuck Lever 					args->lg_args->layout.pglen,
2391cf500bacSChuck Lever 					hdr.replen);
239256f487f8SFred Isaman 	}
2393d017931cSAndy Adamson 	encode_nops(&hdr);
23941da177e4SLinus Torvalds }
23951da177e4SLinus Torvalds 
23961da177e4SLinus Torvalds /*
23971da177e4SLinus Torvalds  * Encode an OPEN_DOWNGRADE request
23981da177e4SLinus Torvalds  */
23999f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
24009f06c719SChuck Lever 					struct xdr_stream *xdr,
2401fcc85819SChristoph Hellwig 					const void *data)
24021da177e4SLinus Torvalds {
2403fcc85819SChristoph Hellwig 	const struct nfs_closeargs *args = data;
24041da177e4SLinus Torvalds 	struct compound_hdr hdr = {
240566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24061da177e4SLinus Torvalds 	};
24071da177e4SLinus Torvalds 
24089f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24099f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24109f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
2411b6808145STrond Myklebust 	if (args->lr_args)
2412b6808145STrond Myklebust 		encode_layoutreturn(xdr, args->lr_args, &hdr);
24139f06c719SChuck Lever 	encode_open_downgrade(xdr, args, &hdr);
2414d017931cSAndy Adamson 	encode_nops(&hdr);
24151da177e4SLinus Torvalds }
24161da177e4SLinus Torvalds 
24171da177e4SLinus Torvalds /*
24181da177e4SLinus Torvalds  * Encode a LOCK request
24191da177e4SLinus Torvalds  */
24209f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2421fcc85819SChristoph Hellwig 			      const void *data)
24221da177e4SLinus Torvalds {
2423fcc85819SChristoph Hellwig 	const struct nfs_lock_args *args = data;
24241da177e4SLinus Torvalds 	struct compound_hdr hdr = {
242566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24261da177e4SLinus Torvalds 	};
24271da177e4SLinus Torvalds 
24289f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24299f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24309f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24319f06c719SChuck Lever 	encode_lock(xdr, args, &hdr);
2432d017931cSAndy Adamson 	encode_nops(&hdr);
24331da177e4SLinus Torvalds }
24341da177e4SLinus Torvalds 
24351da177e4SLinus Torvalds /*
24361da177e4SLinus Torvalds  * Encode a LOCKT request
24371da177e4SLinus Torvalds  */
24389f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2439fcc85819SChristoph Hellwig 			       const void *data)
24401da177e4SLinus Torvalds {
2441fcc85819SChristoph Hellwig 	const struct nfs_lockt_args *args = data;
24421da177e4SLinus Torvalds 	struct compound_hdr hdr = {
244366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24441da177e4SLinus Torvalds 	};
24451da177e4SLinus Torvalds 
24469f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24479f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24489f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24499f06c719SChuck Lever 	encode_lockt(xdr, args, &hdr);
2450d017931cSAndy Adamson 	encode_nops(&hdr);
24511da177e4SLinus Torvalds }
24521da177e4SLinus Torvalds 
24531da177e4SLinus Torvalds /*
24541da177e4SLinus Torvalds  * Encode a LOCKU request
24551da177e4SLinus Torvalds  */
24569f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2457fcc85819SChristoph Hellwig 			       const void *data)
24581da177e4SLinus Torvalds {
2459fcc85819SChristoph Hellwig 	const struct nfs_locku_args *args = data;
24601da177e4SLinus Torvalds 	struct compound_hdr hdr = {
246166cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24621da177e4SLinus Torvalds 	};
24631da177e4SLinus Torvalds 
24649f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24659f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24669f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24679f06c719SChuck Lever 	encode_locku(xdr, args, &hdr);
2468d017931cSAndy Adamson 	encode_nops(&hdr);
24691da177e4SLinus Torvalds }
24701da177e4SLinus Torvalds 
24719f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
24729f06c719SChuck Lever 					   struct xdr_stream *xdr,
2473fcc85819SChristoph Hellwig 					   const void *data)
2474d3c7b7ccSTrond Myklebust {
2475fcc85819SChristoph Hellwig 	const struct nfs_release_lockowner_args *args = data;
2476d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr = {
2477d3c7b7ccSTrond Myklebust 		.minorversion = 0,
2478d3c7b7ccSTrond Myklebust 	};
2479d3c7b7ccSTrond Myklebust 
24809f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24819f06c719SChuck Lever 	encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2482d3c7b7ccSTrond Myklebust 	encode_nops(&hdr);
2483d3c7b7ccSTrond Myklebust }
2484d3c7b7ccSTrond Myklebust 
24851da177e4SLinus Torvalds /*
24861da177e4SLinus Torvalds  * Encode a READLINK request
24871da177e4SLinus Torvalds  */
24889f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2489fcc85819SChristoph Hellwig 				  const void *data)
24901da177e4SLinus Torvalds {
2491fcc85819SChristoph Hellwig 	const struct nfs4_readlink *args = data;
24921da177e4SLinus Torvalds 	struct compound_hdr hdr = {
249366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
24941da177e4SLinus Torvalds 	};
24951da177e4SLinus Torvalds 
24969f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
24979f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
24989f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
24999f06c719SChuck Lever 	encode_readlink(xdr, args, req, &hdr);
2500e3a535e1STrond Myklebust 
2501cf500bacSChuck Lever 	rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2502cf500bacSChuck Lever 				args->pglen, hdr.replen);
2503d017931cSAndy Adamson 	encode_nops(&hdr);
25041da177e4SLinus Torvalds }
25051da177e4SLinus Torvalds 
25061da177e4SLinus Torvalds /*
25071da177e4SLinus Torvalds  * Encode a READDIR request
25081da177e4SLinus Torvalds  */
25099f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2510fcc85819SChristoph Hellwig 				 const void *data)
25111da177e4SLinus Torvalds {
2512fcc85819SChristoph Hellwig 	const struct nfs4_readdir_arg *args = data;
25131da177e4SLinus Torvalds 	struct compound_hdr hdr = {
251466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25151da177e4SLinus Torvalds 	};
25161da177e4SLinus Torvalds 
25179f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25189f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25199f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25209f06c719SChuck Lever 	encode_readdir(xdr, args, req, &hdr);
2521d6ac02dfSTrond Myklebust 
2522cf500bacSChuck Lever 	rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2523cf500bacSChuck Lever 				args->count, hdr.replen);
2524d017931cSAndy Adamson 	encode_nops(&hdr);
25251da177e4SLinus Torvalds }
25261da177e4SLinus Torvalds 
25271da177e4SLinus Torvalds /*
25281da177e4SLinus Torvalds  * Encode a READ request
25291da177e4SLinus Torvalds  */
25309f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2531fcc85819SChristoph Hellwig 			      const void *data)
25321da177e4SLinus Torvalds {
2533fcc85819SChristoph Hellwig 	const struct nfs_pgio_args *args = data;
25341da177e4SLinus Torvalds 	struct compound_hdr hdr = {
253566cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25361da177e4SLinus Torvalds 	};
25371da177e4SLinus Torvalds 
25389f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25399f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25409f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25419f06c719SChuck Lever 	encode_read(xdr, args, &hdr);
25421da177e4SLinus Torvalds 
2543cf500bacSChuck Lever 	rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2544cf500bacSChuck Lever 				args->count, hdr.replen);
25454f22ccc3S\"Talpey, Thomas\ 	req->rq_rcv_buf.flags |= XDRBUF_READ;
2546d017931cSAndy Adamson 	encode_nops(&hdr);
25471da177e4SLinus Torvalds }
25481da177e4SLinus Torvalds 
25491da177e4SLinus Torvalds /*
25501da177e4SLinus Torvalds  * Encode an SETATTR request
25511da177e4SLinus Torvalds  */
25529f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2553fcc85819SChristoph Hellwig 				 const void *data)
25541da177e4SLinus Torvalds {
2555fcc85819SChristoph Hellwig 	const struct nfs_setattrargs *args = data;
25561da177e4SLinus Torvalds 	struct compound_hdr hdr = {
255766cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
25581da177e4SLinus Torvalds 	};
25591da177e4SLinus Torvalds 
25609f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25619f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25629f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25639f06c719SChuck Lever 	encode_setattr(xdr, args, args->server, &hdr);
25649f06c719SChuck Lever 	encode_getfattr(xdr, args->bitmask, &hdr);
2565d017931cSAndy Adamson 	encode_nops(&hdr);
25661da177e4SLinus Torvalds }
25671da177e4SLinus Torvalds 
25681da177e4SLinus Torvalds /*
2569029d105eSJ. Bruce Fields  * Encode a GETACL request
2570029d105eSJ. Bruce Fields  */
25719f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2572fcc85819SChristoph Hellwig 				const void *data)
2573029d105eSJ. Bruce Fields {
2574fcc85819SChristoph Hellwig 	const struct nfs_getaclargs *args = data;
2575029d105eSJ. Bruce Fields 	struct compound_hdr hdr = {
257666cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2577029d105eSJ. Bruce Fields 	};
257837c88763STrond Myklebust 	const __u32 nfs4_acl_bitmap[1] = {
257937c88763STrond Myklebust 		[0] = FATTR4_WORD0_ACL,
258037c88763STrond Myklebust 	};
258128f56694SBenny Halevy 	uint32_t replen;
2582029d105eSJ. Bruce Fields 
25839f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
25849f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
25859f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
25866682c14bSJ. Bruce Fields 	replen = hdr.replen + op_decode_hdr_maxsz;
258737c88763STrond Myklebust 	encode_getattr(xdr, nfs4_acl_bitmap, NULL,
258837c88763STrond Myklebust 			ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
2589cf8cdbe5SAndy Adamson 
2590cf500bacSChuck Lever 	rpc_prepare_reply_pages(req, args->acl_pages, 0,
259129e7ca71SChuck Lever 				args->acl_len, replen + 1);
2592d017931cSAndy Adamson 	encode_nops(&hdr);
2593029d105eSJ. Bruce Fields }
2594029d105eSJ. Bruce Fields 
2595029d105eSJ. Bruce Fields /*
25961da177e4SLinus Torvalds  * Encode a WRITE request
25971da177e4SLinus Torvalds  */
25989f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2599fcc85819SChristoph Hellwig 			       const void *data)
26001da177e4SLinus Torvalds {
2601fcc85819SChristoph Hellwig 	const struct nfs_pgio_args *args = data;
26021da177e4SLinus Torvalds 	struct compound_hdr hdr = {
260366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26041da177e4SLinus Torvalds 	};
26051da177e4SLinus Torvalds 
26069f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26079f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26089f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26099f06c719SChuck Lever 	encode_write(xdr, args, &hdr);
26104f22ccc3S\"Talpey, Thomas\ 	req->rq_snd_buf.flags |= XDRBUF_WRITE;
26117ffd1064SFred Isaman 	if (args->bitmask)
26129f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2613d017931cSAndy Adamson 	encode_nops(&hdr);
26141da177e4SLinus Torvalds }
26151da177e4SLinus Torvalds 
26161da177e4SLinus Torvalds /*
26171da177e4SLinus Torvalds  *  a COMMIT request
26181da177e4SLinus Torvalds  */
26199f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2620fcc85819SChristoph Hellwig 				const void *data)
26211da177e4SLinus Torvalds {
2622fcc85819SChristoph Hellwig 	const struct nfs_commitargs *args = data;
26231da177e4SLinus Torvalds 	struct compound_hdr hdr = {
262466cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26251da177e4SLinus Torvalds 	};
26261da177e4SLinus Torvalds 
26279f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26289f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26299f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26309f06c719SChuck Lever 	encode_commit(xdr, args, &hdr);
2631d017931cSAndy Adamson 	encode_nops(&hdr);
26321da177e4SLinus Torvalds }
26331da177e4SLinus Torvalds 
26341da177e4SLinus Torvalds /*
26351da177e4SLinus Torvalds  * FSINFO request
26361da177e4SLinus Torvalds  */
26379f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2638fcc85819SChristoph Hellwig 				const void *data)
26391da177e4SLinus Torvalds {
2640fcc85819SChristoph Hellwig 	const struct nfs4_fsinfo_arg *args = data;
26411da177e4SLinus Torvalds 	struct compound_hdr hdr = {
264266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26431da177e4SLinus Torvalds 	};
26441da177e4SLinus Torvalds 
26459f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26469f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26479f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
26489f06c719SChuck Lever 	encode_fsinfo(xdr, args->bitmask, &hdr);
2649d017931cSAndy Adamson 	encode_nops(&hdr);
26501da177e4SLinus Torvalds }
26511da177e4SLinus Torvalds 
26521da177e4SLinus Torvalds /*
26531da177e4SLinus Torvalds  * a PATHCONF request
26541da177e4SLinus Torvalds  */
26559f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2656fcc85819SChristoph Hellwig 				  const void *data)
26571da177e4SLinus Torvalds {
2658fcc85819SChristoph Hellwig 	const struct nfs4_pathconf_arg *args = data;
26591da177e4SLinus Torvalds 	struct compound_hdr hdr = {
266066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26611da177e4SLinus Torvalds 	};
26621da177e4SLinus Torvalds 
26639f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26649f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26659f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
266637c88763STrond Myklebust 	encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
266737c88763STrond Myklebust 			ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
2668d017931cSAndy Adamson 	encode_nops(&hdr);
26691da177e4SLinus Torvalds }
26701da177e4SLinus Torvalds 
26711da177e4SLinus Torvalds /*
26721da177e4SLinus Torvalds  * a STATFS request
26731da177e4SLinus Torvalds  */
26749f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2675fcc85819SChristoph Hellwig 				const void *data)
26761da177e4SLinus Torvalds {
2677fcc85819SChristoph Hellwig 	const struct nfs4_statfs_arg *args = data;
26781da177e4SLinus Torvalds 	struct compound_hdr hdr = {
267966cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
26801da177e4SLinus Torvalds 	};
26811da177e4SLinus Torvalds 
26829f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
26839f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
26849f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
268537c88763STrond Myklebust 	encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
268637c88763STrond Myklebust 			ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
2687d017931cSAndy Adamson 	encode_nops(&hdr);
26881da177e4SLinus Torvalds }
26891da177e4SLinus Torvalds 
26901da177e4SLinus Torvalds /*
26911da177e4SLinus Torvalds  * GETATTR_BITMAP request
26921da177e4SLinus Torvalds  */
26939f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
26949f06c719SChuck Lever 				     struct xdr_stream *xdr,
2695fcc85819SChristoph Hellwig 				     const void *data)
26961da177e4SLinus Torvalds {
2697fcc85819SChristoph Hellwig 	const struct nfs4_server_caps_arg *args = data;
26988c61282fSKinglong Mee 	const u32 *bitmask = args->bitmask;
26991da177e4SLinus Torvalds 	struct compound_hdr hdr = {
270066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
27011da177e4SLinus Torvalds 	};
27021da177e4SLinus Torvalds 
27039f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27049f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
27059f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
270637c88763STrond Myklebust 	encode_getattr(xdr, bitmask, NULL, 3, &hdr);
2707d017931cSAndy Adamson 	encode_nops(&hdr);
27081da177e4SLinus Torvalds }
27091da177e4SLinus Torvalds 
27101da177e4SLinus Torvalds /*
27111da177e4SLinus Torvalds  * a RENEW request
27121da177e4SLinus Torvalds  */
27139f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2714fcc85819SChristoph Hellwig 			       const void *data)
2715fcc85819SChristoph Hellwig 
27161da177e4SLinus Torvalds {
2717fcc85819SChristoph Hellwig 	const struct nfs_client *clp = data;
27181da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2719d017931cSAndy Adamson 		.nops	= 0,
27201da177e4SLinus Torvalds 	};
27211da177e4SLinus Torvalds 
27229f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
2723bb4dae5eSChuck Lever 	encode_renew(xdr, clp->cl_clientid, &hdr);
2724d017931cSAndy Adamson 	encode_nops(&hdr);
27251da177e4SLinus Torvalds }
27261da177e4SLinus Torvalds 
27271da177e4SLinus Torvalds /*
27281da177e4SLinus Torvalds  * a SETCLIENTID request
27291da177e4SLinus Torvalds  */
27309f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
27319f06c719SChuck Lever 				     struct xdr_stream *xdr,
2732fcc85819SChristoph Hellwig 				     const void *data)
27331da177e4SLinus Torvalds {
2734fcc85819SChristoph Hellwig 	const struct nfs4_setclientid *sc = data;
27351da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2736d017931cSAndy Adamson 		.nops	= 0,
27371da177e4SLinus Torvalds 	};
27381da177e4SLinus Torvalds 
27399f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27409f06c719SChuck Lever 	encode_setclientid(xdr, sc, &hdr);
2741d017931cSAndy Adamson 	encode_nops(&hdr);
27421da177e4SLinus Torvalds }
27431da177e4SLinus Torvalds 
27441da177e4SLinus Torvalds /*
27451da177e4SLinus Torvalds  * a SETCLIENTID_CONFIRM request
27461da177e4SLinus Torvalds  */
27479f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
27489f06c719SChuck Lever 					     struct xdr_stream *xdr,
2749fcc85819SChristoph Hellwig 					     const void *data)
27501da177e4SLinus Torvalds {
2751fcc85819SChristoph Hellwig 	const struct nfs4_setclientid_res *arg = data;
27521da177e4SLinus Torvalds 	struct compound_hdr hdr = {
2753d017931cSAndy Adamson 		.nops	= 0,
27541da177e4SLinus Torvalds 	};
27551da177e4SLinus Torvalds 
27569f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27579f06c719SChuck Lever 	encode_setclientid_confirm(xdr, arg, &hdr);
2758d017931cSAndy Adamson 	encode_nops(&hdr);
27591da177e4SLinus Torvalds }
27601da177e4SLinus Torvalds 
27611da177e4SLinus Torvalds /*
27621da177e4SLinus Torvalds  * DELEGRETURN request
27631da177e4SLinus Torvalds  */
27649f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
27659f06c719SChuck Lever 				     struct xdr_stream *xdr,
2766fcc85819SChristoph Hellwig 				     const void *data)
27671da177e4SLinus Torvalds {
2768fcc85819SChristoph Hellwig 	const struct nfs4_delegreturnargs *args = data;
27691da177e4SLinus Torvalds 	struct compound_hdr hdr = {
277066cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
27711da177e4SLinus Torvalds 	};
27721da177e4SLinus Torvalds 
27739f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27749f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
27759f06c719SChuck Lever 	encode_putfh(xdr, args->fhandle, &hdr);
2776586f1c39STrond Myklebust 	if (args->lr_args)
2777586f1c39STrond Myklebust 		encode_layoutreturn(xdr, args->lr_args, &hdr);
27788ac2b422STrond Myklebust 	if (args->bitmask)
27799f06c719SChuck Lever 		encode_getfattr(xdr, args->bitmask, &hdr);
2780e144cbccSTrond Myklebust 	encode_delegreturn(xdr, args->stateid, &hdr);
2781d017931cSAndy Adamson 	encode_nops(&hdr);
27821da177e4SLinus Torvalds }
27831da177e4SLinus Torvalds 
27841da177e4SLinus Torvalds /*
2785683b57b4STrond Myklebust  * Encode FS_LOCATIONS request
2786683b57b4STrond Myklebust  */
27879f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
27889f06c719SChuck Lever 				      struct xdr_stream *xdr,
2789fcc85819SChristoph Hellwig 				      const void *data)
2790683b57b4STrond Myklebust {
2791fcc85819SChristoph Hellwig 	const struct nfs4_fs_locations_arg *args = data;
2792683b57b4STrond Myklebust 	struct compound_hdr hdr = {
279366cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2794683b57b4STrond Myklebust 	};
279528f56694SBenny Halevy 	uint32_t replen;
2796683b57b4STrond Myklebust 
27979f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
27989f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
2799b03d735bSChuck Lever 	if (args->migration) {
2800b03d735bSChuck Lever 		encode_putfh(xdr, args->fh, &hdr);
2801b03d735bSChuck Lever 		replen = hdr.replen;
2802b03d735bSChuck Lever 		encode_fs_locations(xdr, args->bitmask, &hdr);
2803b03d735bSChuck Lever 		if (args->renew)
2804b03d735bSChuck Lever 			encode_renew(xdr, args->clientid, &hdr);
2805b03d735bSChuck Lever 	} else {
28069f06c719SChuck Lever 		encode_putfh(xdr, args->dir_fh, &hdr);
28079f06c719SChuck Lever 		encode_lookup(xdr, args->name, &hdr);
2808b03d735bSChuck Lever 		replen = hdr.replen;
28099f06c719SChuck Lever 		encode_fs_locations(xdr, args->bitmask, &hdr);
2810b03d735bSChuck Lever 	}
2811cf8cdbe5SAndy Adamson 
2812cf500bacSChuck Lever 	rpc_prepare_reply_pages(req, (struct page **)&args->page, 0,
281329e7ca71SChuck Lever 				PAGE_SIZE, replen + 1);
2814d017931cSAndy Adamson 	encode_nops(&hdr);
2815683b57b4STrond Myklebust }
2816683b57b4STrond Myklebust 
28175a5ea0d4SBryan Schumaker /*
28185a5ea0d4SBryan Schumaker  * Encode SECINFO request
28195a5ea0d4SBryan Schumaker  */
28205a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
28215a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
2822fcc85819SChristoph Hellwig 				const void *data)
28235a5ea0d4SBryan Schumaker {
2824fcc85819SChristoph Hellwig 	const struct nfs4_secinfo_arg *args = data;
28255a5ea0d4SBryan Schumaker 	struct compound_hdr hdr = {
28265a5ea0d4SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
28275a5ea0d4SBryan Schumaker 	};
28285a5ea0d4SBryan Schumaker 
28295a5ea0d4SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
28305a5ea0d4SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
28315a5ea0d4SBryan Schumaker 	encode_putfh(xdr, args->dir_fh, &hdr);
28325a5ea0d4SBryan Schumaker 	encode_secinfo(xdr, args->name, &hdr);
28335a5ea0d4SBryan Schumaker 	encode_nops(&hdr);
28345a5ea0d4SBryan Schumaker }
28355a5ea0d4SBryan Schumaker 
283644c99933SChuck Lever /*
283744c99933SChuck Lever  * Encode FSID_PRESENT request
283844c99933SChuck Lever  */
283944c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
284044c99933SChuck Lever 				      struct xdr_stream *xdr,
2841fcc85819SChristoph Hellwig 				      const void *data)
284244c99933SChuck Lever {
2843fcc85819SChristoph Hellwig 	const struct nfs4_fsid_present_arg *args = data;
284444c99933SChuck Lever 	struct compound_hdr hdr = {
284544c99933SChuck Lever 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
284644c99933SChuck Lever 	};
284744c99933SChuck Lever 
284844c99933SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
284944c99933SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
285044c99933SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
285144c99933SChuck Lever 	encode_getfh(xdr, &hdr);
285244c99933SChuck Lever 	if (args->renew)
285344c99933SChuck Lever 		encode_renew(xdr, args->clientid, &hdr);
285444c99933SChuck Lever 	encode_nops(&hdr);
285544c99933SChuck Lever }
285644c99933SChuck Lever 
285799fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
285899fe60d0SBenny Halevy /*
28597c44f1aeSWeston Andros Adamson  * BIND_CONN_TO_SESSION request
28607c44f1aeSWeston Andros Adamson  */
28617c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
28627c44f1aeSWeston Andros Adamson 				struct xdr_stream *xdr,
2863fcc85819SChristoph Hellwig 				const void *data)
28647c44f1aeSWeston Andros Adamson {
2865fcc85819SChristoph Hellwig 	const struct nfs41_bind_conn_to_session_args *args = data;
28667c44f1aeSWeston Andros Adamson 	struct compound_hdr hdr = {
286771a097c6STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
28687c44f1aeSWeston Andros Adamson 	};
28697c44f1aeSWeston Andros Adamson 
28707c44f1aeSWeston Andros Adamson 	encode_compound_hdr(xdr, req, &hdr);
287171a097c6STrond Myklebust 	encode_bind_conn_to_session(xdr, args, &hdr);
28727c44f1aeSWeston Andros Adamson 	encode_nops(&hdr);
28737c44f1aeSWeston Andros Adamson }
28747c44f1aeSWeston Andros Adamson 
28757c44f1aeSWeston Andros Adamson /*
287699fe60d0SBenny Halevy  * EXCHANGE_ID request
287799fe60d0SBenny Halevy  */
28789f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
28799f06c719SChuck Lever 				     struct xdr_stream *xdr,
2880fcc85819SChristoph Hellwig 				     const void *data)
288199fe60d0SBenny Halevy {
2882fcc85819SChristoph Hellwig 	const struct nfs41_exchange_id_args *args = data;
288399fe60d0SBenny Halevy 	struct compound_hdr hdr = {
2884a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
288599fe60d0SBenny Halevy 	};
288699fe60d0SBenny Halevy 
28879f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
28889f06c719SChuck Lever 	encode_exchange_id(xdr, args, &hdr);
288999fe60d0SBenny Halevy 	encode_nops(&hdr);
289099fe60d0SBenny Halevy }
28912050f0ccSAndy Adamson 
28922050f0ccSAndy Adamson /*
2893fc931582SAndy Adamson  * a CREATE_SESSION request
2894fc931582SAndy Adamson  */
28959f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
28969f06c719SChuck Lever 					struct xdr_stream *xdr,
2897fcc85819SChristoph Hellwig 					const void *data)
2898fc931582SAndy Adamson {
2899fcc85819SChristoph Hellwig 	const struct nfs41_create_session_args *args = data;
2900fc931582SAndy Adamson 	struct compound_hdr hdr = {
2901a4432345STrond Myklebust 		.minorversion = args->client->cl_mvops->minor_version,
2902fc931582SAndy Adamson 	};
2903fc931582SAndy Adamson 
29049f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29059f06c719SChuck Lever 	encode_create_session(xdr, args, &hdr);
2906fc931582SAndy Adamson 	encode_nops(&hdr);
2907fc931582SAndy Adamson }
2908fc931582SAndy Adamson 
2909fc931582SAndy Adamson /*
29100f3e66c6SAndy Adamson  * a DESTROY_SESSION request
29110f3e66c6SAndy Adamson  */
29129f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
29139f06c719SChuck Lever 					 struct xdr_stream *xdr,
2914fcc85819SChristoph Hellwig 					 const void *data)
29150f3e66c6SAndy Adamson {
2916fcc85819SChristoph Hellwig 	const struct nfs4_session *session = data;
29170f3e66c6SAndy Adamson 	struct compound_hdr hdr = {
2918a4432345STrond Myklebust 		.minorversion = session->clp->cl_mvops->minor_version,
29190f3e66c6SAndy Adamson 	};
29200f3e66c6SAndy Adamson 
29219f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29229f06c719SChuck Lever 	encode_destroy_session(xdr, session, &hdr);
29230f3e66c6SAndy Adamson 	encode_nops(&hdr);
29240f3e66c6SAndy Adamson }
29250f3e66c6SAndy Adamson 
29260f3e66c6SAndy Adamson /*
292766245539STrond Myklebust  * a DESTROY_CLIENTID request
292866245539STrond Myklebust  */
292966245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
293066245539STrond Myklebust 					 struct xdr_stream *xdr,
2931fcc85819SChristoph Hellwig 					 const void *data)
293266245539STrond Myklebust {
2933fcc85819SChristoph Hellwig 	const struct nfs_client *clp = data;
293466245539STrond Myklebust 	struct compound_hdr hdr = {
293566245539STrond Myklebust 		.minorversion = clp->cl_mvops->minor_version,
293666245539STrond Myklebust 	};
293766245539STrond Myklebust 
293866245539STrond Myklebust 	encode_compound_hdr(xdr, req, &hdr);
293966245539STrond Myklebust 	encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
294066245539STrond Myklebust 	encode_nops(&hdr);
294166245539STrond Myklebust }
294266245539STrond Myklebust 
294366245539STrond Myklebust /*
2944fc01cea9SAndy Adamson  * a SEQUENCE request
2945fc01cea9SAndy Adamson  */
29469f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2947fcc85819SChristoph Hellwig 				  const void *data)
2948fc01cea9SAndy Adamson {
2949fcc85819SChristoph Hellwig 	const struct nfs4_sequence_args *args = data;
2950fc01cea9SAndy Adamson 	struct compound_hdr hdr = {
2951fc01cea9SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(args),
2952fc01cea9SAndy Adamson 	};
2953fc01cea9SAndy Adamson 
29549f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29559f06c719SChuck Lever 	encode_sequence(xdr, args, &hdr);
2956fc01cea9SAndy Adamson 	encode_nops(&hdr);
2957fc01cea9SAndy Adamson }
2958fc01cea9SAndy Adamson 
29590efb01b2SDonald Buczek #endif
29600efb01b2SDonald Buczek 
2961fc01cea9SAndy Adamson /*
29622050f0ccSAndy Adamson  * a GET_LEASE_TIME request
29632050f0ccSAndy Adamson  */
29649f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
29659f06c719SChuck Lever 					struct xdr_stream *xdr,
2966fcc85819SChristoph Hellwig 					const void *data)
29672050f0ccSAndy Adamson {
2968fcc85819SChristoph Hellwig 	const struct nfs4_get_lease_time_args *args = data;
29692050f0ccSAndy Adamson 	struct compound_hdr hdr = {
29702050f0ccSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
29712050f0ccSAndy Adamson 	};
2972dae100c2SFred Isaman 	const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
29732050f0ccSAndy Adamson 
29749f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29759f06c719SChuck Lever 	encode_sequence(xdr, &args->la_seq_args, &hdr);
29769f06c719SChuck Lever 	encode_putrootfh(xdr, &hdr);
29779f06c719SChuck Lever 	encode_fsinfo(xdr, lease_bitmap, &hdr);
29782050f0ccSAndy Adamson 	encode_nops(&hdr);
29792050f0ccSAndy Adamson }
298018019753SRicardo Labiaga 
29810efb01b2SDonald Buczek #ifdef CONFIG_NFS_V4_1
29820efb01b2SDonald Buczek 
298318019753SRicardo Labiaga /*
298418019753SRicardo Labiaga  * a RECLAIM_COMPLETE request
298518019753SRicardo Labiaga  */
29869f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
29879f06c719SChuck Lever 					  struct xdr_stream *xdr,
2988fcc85819SChristoph Hellwig 					  const void *data)
298918019753SRicardo Labiaga {
2990fcc85819SChristoph Hellwig 	const struct nfs41_reclaim_complete_args *args = data;
299118019753SRicardo Labiaga 	struct compound_hdr hdr = {
299218019753SRicardo Labiaga 		.minorversion = nfs4_xdr_minorversion(&args->seq_args)
299318019753SRicardo Labiaga 	};
299418019753SRicardo Labiaga 
29959f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
29969f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
29979f06c719SChuck Lever 	encode_reclaim_complete(xdr, args, &hdr);
299818019753SRicardo Labiaga 	encode_nops(&hdr);
299918019753SRicardo Labiaga }
300018019753SRicardo Labiaga 
3001b1f69b75SAndy Adamson /*
3002b1f69b75SAndy Adamson  * Encode GETDEVICEINFO request
3003b1f69b75SAndy Adamson  */
30049f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
30059f06c719SChuck Lever 				       struct xdr_stream *xdr,
3006fcc85819SChristoph Hellwig 				       const void *data)
3007b1f69b75SAndy Adamson {
3008fcc85819SChristoph Hellwig 	const struct nfs4_getdeviceinfo_args *args = data;
3009b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
3010b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3011b1f69b75SAndy Adamson 	};
3012b1f69b75SAndy Adamson 
30139f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
30149f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
30159f06c719SChuck Lever 	encode_getdeviceinfo(xdr, args, &hdr);
3016b1f69b75SAndy Adamson 
3017b1f69b75SAndy Adamson 	/* set up reply kvec. Subtract notification bitmap max size (2)
3018b1f69b75SAndy Adamson 	 * so that notification bitmap is put in xdr_buf tail */
3019cf500bacSChuck Lever 	rpc_prepare_reply_pages(req, args->pdev->pages, args->pdev->pgbase,
3020cf500bacSChuck Lever 				args->pdev->pglen, hdr.replen - 2);
3021b1f69b75SAndy Adamson 	encode_nops(&hdr);
3022b1f69b75SAndy Adamson }
3023b1f69b75SAndy Adamson 
3024b1f69b75SAndy Adamson /*
3025b1f69b75SAndy Adamson  *  Encode LAYOUTGET request
3026b1f69b75SAndy Adamson  */
30279f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
30289f06c719SChuck Lever 				   struct xdr_stream *xdr,
3029fcc85819SChristoph Hellwig 				   const void *data)
3030b1f69b75SAndy Adamson {
3031fcc85819SChristoph Hellwig 	const struct nfs4_layoutget_args *args = data;
3032b1f69b75SAndy Adamson 	struct compound_hdr hdr = {
3033b1f69b75SAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3034b1f69b75SAndy Adamson 	};
3035b1f69b75SAndy Adamson 
30369f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
30379f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
30389f06c719SChuck Lever 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
30399f06c719SChuck Lever 	encode_layoutget(xdr, args, &hdr);
304035124a09SWeston Andros Adamson 
3041cf500bacSChuck Lever 	rpc_prepare_reply_pages(req, args->layout.pages, 0,
3042cf500bacSChuck Lever 				args->layout.pglen, hdr.replen);
3043b1f69b75SAndy Adamson 	encode_nops(&hdr);
3044b1f69b75SAndy Adamson }
3045863a3c6cSAndy Adamson 
3046863a3c6cSAndy Adamson /*
3047863a3c6cSAndy Adamson  *  Encode LAYOUTCOMMIT request
3048863a3c6cSAndy Adamson  */
3049cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3050863a3c6cSAndy Adamson 				      struct xdr_stream *xdr,
3051fcc85819SChristoph Hellwig 				      const void *priv)
3052863a3c6cSAndy Adamson {
3053fcc85819SChristoph Hellwig 	const struct nfs4_layoutcommit_args *args = priv;
3054ac7db726SBenny Halevy 	struct nfs4_layoutcommit_data *data =
3055ac7db726SBenny Halevy 		container_of(args, struct nfs4_layoutcommit_data, args);
3056863a3c6cSAndy Adamson 	struct compound_hdr hdr = {
3057863a3c6cSAndy Adamson 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3058863a3c6cSAndy Adamson 	};
3059863a3c6cSAndy Adamson 
3060863a3c6cSAndy Adamson 	encode_compound_hdr(xdr, req, &hdr);
3061863a3c6cSAndy Adamson 	encode_sequence(xdr, &args->seq_args, &hdr);
3062863a3c6cSAndy Adamson 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3063ac7db726SBenny Halevy 	encode_layoutcommit(xdr, data->args.inode, args, &hdr);
3064863a3c6cSAndy Adamson 	encode_getfattr(xdr, args->bitmask, &hdr);
3065863a3c6cSAndy Adamson 	encode_nops(&hdr);
3066cbe82603SBenny Halevy }
3067cbe82603SBenny Halevy 
3068cbe82603SBenny Halevy /*
3069cbe82603SBenny Halevy  * Encode LAYOUTRETURN request
3070cbe82603SBenny Halevy  */
3071cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3072cbe82603SBenny Halevy 				      struct xdr_stream *xdr,
3073fcc85819SChristoph Hellwig 				      const void *data)
3074cbe82603SBenny Halevy {
3075fcc85819SChristoph Hellwig 	const struct nfs4_layoutreturn_args *args = data;
3076cbe82603SBenny Halevy 	struct compound_hdr hdr = {
3077cbe82603SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3078cbe82603SBenny Halevy 	};
3079cbe82603SBenny Halevy 
3080cbe82603SBenny Halevy 	encode_compound_hdr(xdr, req, &hdr);
3081cbe82603SBenny Halevy 	encode_sequence(xdr, &args->seq_args, &hdr);
3082cbe82603SBenny Halevy 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3083cbe82603SBenny Halevy 	encode_layoutreturn(xdr, args, &hdr);
3084cbe82603SBenny Halevy 	encode_nops(&hdr);
3085863a3c6cSAndy Adamson }
3086fca78d6dSBryan Schumaker 
3087fca78d6dSBryan Schumaker /*
3088fca78d6dSBryan Schumaker  * Encode SECINFO_NO_NAME request
3089fca78d6dSBryan Schumaker  */
3090fcc85819SChristoph Hellwig static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3091fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
3092fcc85819SChristoph Hellwig 					const void *data)
3093fca78d6dSBryan Schumaker {
3094fcc85819SChristoph Hellwig 	const struct nfs41_secinfo_no_name_args *args = data;
3095fca78d6dSBryan Schumaker 	struct compound_hdr hdr = {
3096fca78d6dSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3097fca78d6dSBryan Schumaker 	};
3098fca78d6dSBryan Schumaker 
3099fca78d6dSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
3100fca78d6dSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
3101fca78d6dSBryan Schumaker 	encode_putrootfh(xdr, &hdr);
3102fca78d6dSBryan Schumaker 	encode_secinfo_no_name(xdr, args, &hdr);
3103fca78d6dSBryan Schumaker 	encode_nops(&hdr);
3104fca78d6dSBryan Schumaker }
31057d974794SBryan Schumaker 
31067d974794SBryan Schumaker /*
31077d974794SBryan Schumaker  *  Encode TEST_STATEID request
31087d974794SBryan Schumaker  */
31097d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
31107d974794SBryan Schumaker 				      struct xdr_stream *xdr,
3111fcc85819SChristoph Hellwig 				      const void *data)
31127d974794SBryan Schumaker {
3113fcc85819SChristoph Hellwig 	const struct nfs41_test_stateid_args *args = data;
31147d974794SBryan Schumaker 	struct compound_hdr hdr = {
31157d974794SBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
31167d974794SBryan Schumaker 	};
31177d974794SBryan Schumaker 
31187d974794SBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
31197d974794SBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
31207d974794SBryan Schumaker 	encode_test_stateid(xdr, args, &hdr);
31217d974794SBryan Schumaker 	encode_nops(&hdr);
31227d974794SBryan Schumaker }
31239aeda35fSBryan Schumaker 
31249aeda35fSBryan Schumaker /*
31259aeda35fSBryan Schumaker  *  Encode FREE_STATEID request
31269aeda35fSBryan Schumaker  */
31279aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
31289aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
3129fcc85819SChristoph Hellwig 				     const void *data)
31309aeda35fSBryan Schumaker {
3131fcc85819SChristoph Hellwig 	const struct nfs41_free_stateid_args *args = data;
31329aeda35fSBryan Schumaker 	struct compound_hdr hdr = {
31339aeda35fSBryan Schumaker 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
31349aeda35fSBryan Schumaker 	};
31359aeda35fSBryan Schumaker 
31369aeda35fSBryan Schumaker 	encode_compound_hdr(xdr, req, &hdr);
31379aeda35fSBryan Schumaker 	encode_sequence(xdr, &args->seq_args, &hdr);
31389aeda35fSBryan Schumaker 	encode_free_stateid(xdr, args, &hdr);
31399aeda35fSBryan Schumaker 	encode_nops(&hdr);
31409aeda35fSBryan Schumaker }
314199fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
314299fe60d0SBenny Halevy 
3143683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
31441da177e4SLinus Torvalds {
31456da59ce2STrond Myklebust 	ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
31466da59ce2STrond Myklebust 			NFS4_OPAQUE_LIMIT);
3147eb72f484SChuck Lever 	if (unlikely(ret < 0))
3148c0eae66eSBenny Halevy 		return -EIO;
31496da59ce2STrond Myklebust 	*len = ret;
31506da59ce2STrond Myklebust 	return 0;
31516da59ce2STrond Myklebust }
31521da177e4SLinus Torvalds 
31531da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
31541da177e4SLinus Torvalds {
31558687b63aSAl Viro 	__be32 *p;
31561da177e4SLinus Torvalds 
3157c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3158c0eae66eSBenny Halevy 	if (unlikely(!p))
3159eb72f484SChuck Lever 		return -EIO;
31606f723f77SBenny Halevy 	hdr->status = be32_to_cpup(p++);
3161cccddf4fSBenny Halevy 	hdr->taglen = be32_to_cpup(p);
31621da177e4SLinus Torvalds 
3163c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, hdr->taglen + 4);
3164c0eae66eSBenny Halevy 	if (unlikely(!p))
3165eb72f484SChuck Lever 		return -EIO;
31661da177e4SLinus Torvalds 	hdr->tag = (char *)p;
31671da177e4SLinus Torvalds 	p += XDR_QUADLEN(hdr->taglen);
3168cccddf4fSBenny Halevy 	hdr->nops = be32_to_cpup(p);
3169aadf6152SBenny Halevy 	if (unlikely(hdr->nops < 1))
3170aadf6152SBenny Halevy 		return nfs4_stat_to_errno(hdr->status);
31711da177e4SLinus Torvalds 	return 0;
31721da177e4SLinus Torvalds }
31731da177e4SLinus Torvalds 
3174c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3175c7848f69STrond Myklebust 		int *nfs_retval)
31761da177e4SLinus Torvalds {
31778687b63aSAl Viro 	__be32 *p;
31781da177e4SLinus Torvalds 	uint32_t opnum;
31791da177e4SLinus Torvalds 	int32_t nfserr;
31801da177e4SLinus Torvalds 
3181c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
3182c0eae66eSBenny Halevy 	if (unlikely(!p))
3183c0eae66eSBenny Halevy 		goto out_overflow;
31846f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
3185c7848f69STrond Myklebust 	if (unlikely(opnum != expected))
3186c7848f69STrond Myklebust 		goto out_bad_operation;
3187f23f6584SChuck Lever 	if (unlikely(*p != cpu_to_be32(NFS_OK)))
3188f23f6584SChuck Lever 		goto out_status;
3189c7848f69STrond Myklebust 	*nfs_retval = 0;
3190f23f6584SChuck Lever 	return true;
3191f23f6584SChuck Lever out_status:
3192f23f6584SChuck Lever 	nfserr = be32_to_cpup(p);
319362a92ba9SChuck Lever 	trace_nfs4_xdr_status(xdr, opnum, nfserr);
3194c7848f69STrond Myklebust 	*nfs_retval = nfs4_stat_to_errno(nfserr);
3195c7848f69STrond Myklebust 	return true;
3196c7848f69STrond Myklebust out_bad_operation:
3197fe82a183SChuck Lever 	dprintk("nfs: Server returned operation"
31981da177e4SLinus Torvalds 		" %d but we issued a request for %d\n",
31991da177e4SLinus Torvalds 			opnum, expected);
3200c7848f69STrond Myklebust 	*nfs_retval = -EREMOTEIO;
3201c7848f69STrond Myklebust 	return false;
3202c0eae66eSBenny Halevy out_overflow:
3203c7848f69STrond Myklebust 	*nfs_retval = -EIO;
3204c7848f69STrond Myklebust 	return false;
3205c7848f69STrond Myklebust }
3206c7848f69STrond Myklebust 
3207c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3208c7848f69STrond Myklebust {
3209c7848f69STrond Myklebust 	int retval;
3210c7848f69STrond Myklebust 
3211c7848f69STrond Myklebust 	__decode_op_hdr(xdr, expected, &retval);
3212c7848f69STrond Myklebust 	return retval;
32131da177e4SLinus Torvalds }
32141da177e4SLinus Torvalds 
32151da177e4SLinus Torvalds /* Dummy routine */
32161bbe60ffSTrond Myklebust static int decode_ace(struct xdr_stream *xdr, void *ace)
32171da177e4SLinus Torvalds {
32188687b63aSAl Viro 	__be32 *p;
3219683b57b4STrond Myklebust 	unsigned int strlen;
32201da177e4SLinus Torvalds 	char *str;
32211da177e4SLinus Torvalds 
3222c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
3223eb72f484SChuck Lever 	if (unlikely(!p))
3224c0eae66eSBenny Halevy 		return -EIO;
3225eb72f484SChuck Lever 	return decode_opaque_inline(xdr, &strlen, &str);
32261da177e4SLinus Torvalds }
32271da177e4SLinus Torvalds 
322837c88763STrond Myklebust static ssize_t
322937c88763STrond Myklebust decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
32301da177e4SLinus Torvalds {
323137c88763STrond Myklebust 	ssize_t ret;
32321da177e4SLinus Torvalds 
323337c88763STrond Myklebust 	ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
323437c88763STrond Myklebust 	if (likely(ret >= 0))
323537c88763STrond Myklebust 		return ret;
3236eb72f484SChuck Lever 	if (ret != -EMSGSIZE)
3237c0eae66eSBenny Halevy 		return -EIO;
3238eb72f484SChuck Lever 	return sz;
32391da177e4SLinus Torvalds }
32401da177e4SLinus Torvalds 
324137c88763STrond Myklebust static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
324237c88763STrond Myklebust {
324337c88763STrond Myklebust 	ssize_t ret;
324437c88763STrond Myklebust 	ret = decode_bitmap4(xdr, bitmap, 3);
324537c88763STrond Myklebust 	return ret < 0 ? ret : 0;
324637c88763STrond Myklebust }
324737c88763STrond Myklebust 
3248256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
32491da177e4SLinus Torvalds {
32508687b63aSAl Viro 	__be32 *p;
32511da177e4SLinus Torvalds 
3252c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3253c0eae66eSBenny Halevy 	if (unlikely(!p))
3254eb72f484SChuck Lever 		return -EIO;
3255cccddf4fSBenny Halevy 	*attrlen = be32_to_cpup(p);
3256256e48bbSTrond Myklebust 	*savep = xdr_stream_pos(xdr);
32571da177e4SLinus Torvalds 	return 0;
32581da177e4SLinus Torvalds }
32591da177e4SLinus Torvalds 
32601da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
32611da177e4SLinus Torvalds {
32621da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
32633388bff5SRoman Borisov 		int ret;
32643388bff5SRoman Borisov 		ret = decode_attr_bitmap(xdr, bitmask);
32653388bff5SRoman Borisov 		if (unlikely(ret < 0))
32663388bff5SRoman Borisov 			return ret;
32671da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
32681da177e4SLinus Torvalds 	} else
3269dae100c2SFred Isaman 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
3270dae100c2SFred Isaman 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3271dae100c2SFred Isaman 		bitmask[0], bitmask[1], bitmask[2]);
32721da177e4SLinus Torvalds 	return 0;
32731da177e4SLinus Torvalds }
32741da177e4SLinus Torvalds 
32751da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
32761da177e4SLinus Torvalds {
32778687b63aSAl Viro 	__be32 *p;
3278409924e4STrond Myklebust 	int ret = 0;
32791da177e4SLinus Torvalds 
32801da177e4SLinus Torvalds 	*type = 0;
32811da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
32821da177e4SLinus Torvalds 		return -EIO;
32831da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3284c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3285c0eae66eSBenny Halevy 		if (unlikely(!p))
3286eb72f484SChuck Lever 			return -EIO;
3287cccddf4fSBenny Halevy 		*type = be32_to_cpup(p);
32881da177e4SLinus Torvalds 		if (*type < NF4REG || *type > NF4NAMEDATTR) {
32893110ff80SHarvey Harrison 			dprintk("%s: bad type %d\n", __func__, *type);
32901da177e4SLinus Torvalds 			return -EIO;
32911da177e4SLinus Torvalds 		}
32921da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_TYPE;
3293409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_TYPE;
32941da177e4SLinus Torvalds 	}
3295bca79478STrond Myklebust 	dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3296409924e4STrond Myklebust 	return ret;
32971da177e4SLinus Torvalds }
32981da177e4SLinus Torvalds 
3299264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3300264e6351SChuck Lever 				      uint32_t *bitmap, uint32_t *type)
3301264e6351SChuck Lever {
3302264e6351SChuck Lever 	__be32 *p;
3303264e6351SChuck Lever 
3304264e6351SChuck Lever 	*type = 0;
3305264e6351SChuck Lever 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3306264e6351SChuck Lever 		return -EIO;
3307264e6351SChuck Lever 	if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3308264e6351SChuck Lever 		p = xdr_inline_decode(xdr, 4);
3309264e6351SChuck Lever 		if (unlikely(!p))
3310eb72f484SChuck Lever 			return -EIO;
3311264e6351SChuck Lever 		*type = be32_to_cpup(p);
3312264e6351SChuck Lever 		bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3313264e6351SChuck Lever 	}
3314264e6351SChuck Lever 	dprintk("%s: expire type=0x%x\n", __func__, *type);
3315264e6351SChuck Lever 	return 0;
3316264e6351SChuck Lever }
3317264e6351SChuck Lever 
33181da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
33191da177e4SLinus Torvalds {
33208687b63aSAl Viro 	__be32 *p;
3321409924e4STrond Myklebust 	int ret = 0;
33221da177e4SLinus Torvalds 
33231da177e4SLinus Torvalds 	*change = 0;
33241da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
33251da177e4SLinus Torvalds 		return -EIO;
33261da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3327c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3328c0eae66eSBenny Halevy 		if (unlikely(!p))
3329eb72f484SChuck Lever 			return -EIO;
3330cccddf4fSBenny Halevy 		xdr_decode_hyper(p, change);
33311da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3332409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_CHANGE;
33331da177e4SLinus Torvalds 	}
33343110ff80SHarvey Harrison 	dprintk("%s: change attribute=%Lu\n", __func__,
33351da177e4SLinus Torvalds 			(unsigned long long)*change);
3336409924e4STrond Myklebust 	return ret;
33371da177e4SLinus Torvalds }
33381da177e4SLinus Torvalds 
33391da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
33401da177e4SLinus Torvalds {
33418687b63aSAl Viro 	__be32 *p;
3342409924e4STrond Myklebust 	int ret = 0;
33431da177e4SLinus Torvalds 
33441da177e4SLinus Torvalds 	*size = 0;
33451da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
33461da177e4SLinus Torvalds 		return -EIO;
33471da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3348c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3349c0eae66eSBenny Halevy 		if (unlikely(!p))
3350eb72f484SChuck Lever 			return -EIO;
3351cccddf4fSBenny Halevy 		xdr_decode_hyper(p, size);
33521da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SIZE;
3353409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SIZE;
33541da177e4SLinus Torvalds 	}
33553110ff80SHarvey Harrison 	dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3356409924e4STrond Myklebust 	return ret;
33571da177e4SLinus Torvalds }
33581da177e4SLinus Torvalds 
33591da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33601da177e4SLinus Torvalds {
33618687b63aSAl Viro 	__be32 *p;
33621da177e4SLinus Torvalds 
33631da177e4SLinus Torvalds 	*res = 0;
33641da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
33651da177e4SLinus Torvalds 		return -EIO;
33661da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3367c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3368c0eae66eSBenny Halevy 		if (unlikely(!p))
3369eb72f484SChuck Lever 			return -EIO;
3370cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33711da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
33721da177e4SLinus Torvalds 	}
33733110ff80SHarvey Harrison 	dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
33741da177e4SLinus Torvalds 	return 0;
33751da177e4SLinus Torvalds }
33761da177e4SLinus Torvalds 
33771da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33781da177e4SLinus Torvalds {
33798687b63aSAl Viro 	__be32 *p;
33801da177e4SLinus Torvalds 
33811da177e4SLinus Torvalds 	*res = 0;
33821da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
33831da177e4SLinus Torvalds 		return -EIO;
33841da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3385c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3386c0eae66eSBenny Halevy 		if (unlikely(!p))
3387eb72f484SChuck Lever 			return -EIO;
3388cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
33891da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
33901da177e4SLinus Torvalds 	}
33913110ff80SHarvey Harrison 	dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
33921da177e4SLinus Torvalds 	return 0;
33931da177e4SLinus Torvalds }
33941da177e4SLinus Torvalds 
33958b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
33961da177e4SLinus Torvalds {
33978687b63aSAl Viro 	__be32 *p;
3398409924e4STrond Myklebust 	int ret = 0;
33991da177e4SLinus Torvalds 
34001da177e4SLinus Torvalds 	fsid->major = 0;
34011da177e4SLinus Torvalds 	fsid->minor = 0;
34021da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
34031da177e4SLinus Torvalds 		return -EIO;
34041da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3405c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 16);
3406c0eae66eSBenny Halevy 		if (unlikely(!p))
3407eb72f484SChuck Lever 			return -EIO;
34083ceb4dbbSBenny Halevy 		p = xdr_decode_hyper(p, &fsid->major);
3409cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &fsid->minor);
34101da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FSID;
3411409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FSID;
34121da177e4SLinus Torvalds 	}
34133110ff80SHarvey Harrison 	dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
34141da177e4SLinus Torvalds 			(unsigned long long)fsid->major,
34151da177e4SLinus Torvalds 			(unsigned long long)fsid->minor);
3416409924e4STrond Myklebust 	return ret;
34171da177e4SLinus Torvalds }
34181da177e4SLinus Torvalds 
34191da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
34201da177e4SLinus Torvalds {
34218687b63aSAl Viro 	__be32 *p;
34221da177e4SLinus Torvalds 
34231da177e4SLinus Torvalds 	*res = 60;
34241da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
34251da177e4SLinus Torvalds 		return -EIO;
34261da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3427c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3428c0eae66eSBenny Halevy 		if (unlikely(!p))
3429eb72f484SChuck Lever 			return -EIO;
3430cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
34311da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
34321da177e4SLinus Torvalds 	}
34332eaf426dSDonald Buczek 	dprintk("%s: lease time=%u\n", __func__, (unsigned int)*res);
34341da177e4SLinus Torvalds 	return 0;
34351da177e4SLinus Torvalds }
34361da177e4SLinus Torvalds 
3437ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3438ae42c70aSBryan Schumaker {
3439ae42c70aSBryan Schumaker 	__be32 *p;
3440ae42c70aSBryan Schumaker 
3441ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3442ae42c70aSBryan Schumaker 		return -EIO;
3443ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3444ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3445ae42c70aSBryan Schumaker 		if (unlikely(!p))
3446eb72f484SChuck Lever 			return -EIO;
3447ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3448ee7b75fcSTrond Myklebust 		*res = -be32_to_cpup(p);
3449ae42c70aSBryan Schumaker 	}
3450ae42c70aSBryan Schumaker 	return 0;
3451ae42c70aSBryan Schumaker }
3452ae42c70aSBryan Schumaker 
34538c61282fSKinglong Mee static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
34548c61282fSKinglong Mee 				 uint32_t *bitmap, uint32_t *bitmask)
34558c61282fSKinglong Mee {
34568c61282fSKinglong Mee 	if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
34578c61282fSKinglong Mee 		int ret;
34588c61282fSKinglong Mee 		ret = decode_attr_bitmap(xdr, bitmask);
34598c61282fSKinglong Mee 		if (unlikely(ret < 0))
34608c61282fSKinglong Mee 			return ret;
34618c61282fSKinglong Mee 		bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
34628c61282fSKinglong Mee 	} else
34638c61282fSKinglong Mee 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
34648c61282fSKinglong Mee 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
34658c61282fSKinglong Mee 		bitmask[0], bitmask[1], bitmask[2]);
34668c61282fSKinglong Mee 	return 0;
34678c61282fSKinglong Mee }
34688c61282fSKinglong Mee 
3469ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3470ae42c70aSBryan Schumaker {
3471ae42c70aSBryan Schumaker 	__be32 *p;
347286bbd742SFrank Sorenson 	u32 len;
3473ae42c70aSBryan Schumaker 
34747ad07353STrond Myklebust 	if (fh != NULL)
3475ae42c70aSBryan Schumaker 		memset(fh, 0, sizeof(*fh));
3476ae42c70aSBryan Schumaker 
3477ae42c70aSBryan Schumaker 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3478ae42c70aSBryan Schumaker 		return -EIO;
3479ae42c70aSBryan Schumaker 	if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3480ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
3481ae42c70aSBryan Schumaker 		if (unlikely(!p))
3482eb72f484SChuck Lever 			return -EIO;
3483ae42c70aSBryan Schumaker 		len = be32_to_cpup(p);
3484ae42c70aSBryan Schumaker 		if (len > NFS4_FHSIZE)
3485ae42c70aSBryan Schumaker 			return -EIO;
3486ae42c70aSBryan Schumaker 		p = xdr_inline_decode(xdr, len);
3487ae42c70aSBryan Schumaker 		if (unlikely(!p))
3488eb72f484SChuck Lever 			return -EIO;
34897ad07353STrond Myklebust 		if (fh != NULL) {
3490ae42c70aSBryan Schumaker 			memcpy(fh->data, p, len);
34917ad07353STrond Myklebust 			fh->size = len;
34927ad07353STrond Myklebust 		}
3493ae42c70aSBryan Schumaker 		bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3494ae42c70aSBryan Schumaker 	}
3495ae42c70aSBryan Schumaker 	return 0;
3496ae42c70aSBryan Schumaker }
3497ae42c70aSBryan Schumaker 
34981da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
34991da177e4SLinus Torvalds {
35008687b63aSAl Viro 	__be32 *p;
35011da177e4SLinus Torvalds 
3502a1800acaSMalahal Naineni 	*res = 0;
35031da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
35041da177e4SLinus Torvalds 		return -EIO;
35051da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3506c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3507c0eae66eSBenny Halevy 		if (unlikely(!p))
3508eb72f484SChuck Lever 			return -EIO;
3509cccddf4fSBenny Halevy 		*res = be32_to_cpup(p);
35101da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
35111da177e4SLinus Torvalds 	}
35123110ff80SHarvey Harrison 	dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
35131da177e4SLinus Torvalds 	return 0;
35141da177e4SLinus Torvalds }
35151da177e4SLinus Torvalds 
35161da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
35171da177e4SLinus Torvalds {
35188687b63aSAl Viro 	__be32 *p;
3519409924e4STrond Myklebust 	int ret = 0;
35201da177e4SLinus Torvalds 
35211da177e4SLinus Torvalds 	*fileid = 0;
35221da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
35231da177e4SLinus Torvalds 		return -EIO;
35241da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3525c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3526c0eae66eSBenny Halevy 		if (unlikely(!p))
3527eb72f484SChuck Lever 			return -EIO;
3528cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
35291da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILEID;
3530409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_FILEID;
35311da177e4SLinus Torvalds 	}
35323110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3533409924e4STrond Myklebust 	return ret;
35341da177e4SLinus Torvalds }
35351da177e4SLinus Torvalds 
353699baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
353799baf625SManoj Naik {
35388687b63aSAl Viro 	__be32 *p;
3539409924e4STrond Myklebust 	int ret = 0;
354099baf625SManoj Naik 
354199baf625SManoj Naik 	*fileid = 0;
354299baf625SManoj Naik 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
354399baf625SManoj Naik 		return -EIO;
354499baf625SManoj Naik 	if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3545c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3546c0eae66eSBenny Halevy 		if (unlikely(!p))
3547eb72f484SChuck Lever 			return -EIO;
3548cccddf4fSBenny Halevy 		xdr_decode_hyper(p, fileid);
354999baf625SManoj Naik 		bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
355028331a46STrond Myklebust 		ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
355199baf625SManoj Naik 	}
35523110ff80SHarvey Harrison 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3553409924e4STrond Myklebust 	return ret;
355499baf625SManoj Naik }
355599baf625SManoj Naik 
35561da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35571da177e4SLinus Torvalds {
35588687b63aSAl Viro 	__be32 *p;
35591da177e4SLinus Torvalds 	int status = 0;
35601da177e4SLinus Torvalds 
35611da177e4SLinus Torvalds 	*res = 0;
35621da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
35631da177e4SLinus Torvalds 		return -EIO;
35641da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3565c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3566c0eae66eSBenny Halevy 		if (unlikely(!p))
3567eb72f484SChuck Lever 			return -EIO;
3568cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35691da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
35701da177e4SLinus Torvalds 	}
35713110ff80SHarvey Harrison 	dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
35721da177e4SLinus Torvalds 	return status;
35731da177e4SLinus Torvalds }
35741da177e4SLinus Torvalds 
35751da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35761da177e4SLinus Torvalds {
35778687b63aSAl Viro 	__be32 *p;
35781da177e4SLinus Torvalds 	int status = 0;
35791da177e4SLinus Torvalds 
35801da177e4SLinus Torvalds 	*res = 0;
35811da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
35821da177e4SLinus Torvalds 		return -EIO;
35831da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3584c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3585c0eae66eSBenny Halevy 		if (unlikely(!p))
3586eb72f484SChuck Lever 			return -EIO;
3587cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
35881da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
35891da177e4SLinus Torvalds 	}
35903110ff80SHarvey Harrison 	dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
35911da177e4SLinus Torvalds 	return status;
35921da177e4SLinus Torvalds }
35931da177e4SLinus Torvalds 
35941da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
35951da177e4SLinus Torvalds {
35968687b63aSAl Viro 	__be32 *p;
35971da177e4SLinus Torvalds 	int status = 0;
35981da177e4SLinus Torvalds 
35991da177e4SLinus Torvalds 	*res = 0;
36001da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
36011da177e4SLinus Torvalds 		return -EIO;
36021da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3603c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3604c0eae66eSBenny Halevy 		if (unlikely(!p))
3605eb72f484SChuck Lever 			return -EIO;
3606cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
36071da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
36081da177e4SLinus Torvalds 	}
36093110ff80SHarvey Harrison 	dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
36101da177e4SLinus Torvalds 	return status;
36111da177e4SLinus Torvalds }
36121da177e4SLinus Torvalds 
36137aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
36147aaa0b3bSManoj Naik {
3615464ad6b1SChuck Lever 	u32 n;
36168687b63aSAl Viro 	__be32 *p;
36177aaa0b3bSManoj Naik 	int status = 0;
36187aaa0b3bSManoj Naik 
3619c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3620c0eae66eSBenny Halevy 	if (unlikely(!p))
3621eb72f484SChuck Lever 		return -EIO;
3622cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
362333a43f28SAndy Adamson 	if (n == 0)
362433a43f28SAndy Adamson 		goto root_path;
362502a2976cSChuck Lever 	dprintk("pathname4: ");
3626809b426cSTrond Myklebust 	if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3627809b426cSTrond Myklebust 		dprintk("cannot parse %d components in path\n", n);
3628809b426cSTrond Myklebust 		goto out_eio;
3629809b426cSTrond Myklebust 	}
3630809b426cSTrond Myklebust 	for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
36317aaa0b3bSManoj Naik 		struct nfs4_string *component = &path->components[path->ncomponents];
36327aaa0b3bSManoj Naik 		status = decode_opaque_inline(xdr, &component->len, &component->data);
36337aaa0b3bSManoj Naik 		if (unlikely(status != 0))
36347aaa0b3bSManoj Naik 			goto out_eio;
363595a13f7bSTrond Myklebust 		ifdebug (XDR)
363602a2976cSChuck Lever 			pr_cont("%s%.*s ",
363702a2976cSChuck Lever 				(path->ncomponents != n ? "/ " : ""),
363802a2976cSChuck Lever 				component->len, component->data);
36397aaa0b3bSManoj Naik 	}
36407aaa0b3bSManoj Naik out:
36417aaa0b3bSManoj Naik 	return status;
364233a43f28SAndy Adamson root_path:
364333a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */
364433a43f28SAndy Adamson 	path->ncomponents = 1;
364533a43f28SAndy Adamson 	path->components[0].len=0;
364633a43f28SAndy Adamson 	path->components[0].data=NULL;
364702a2976cSChuck Lever 	dprintk("pathname4: /\n");
364833a43f28SAndy Adamson 	goto out;
36497aaa0b3bSManoj Naik out_eio:
36507aaa0b3bSManoj Naik 	dprintk(" status %d", status);
36517aaa0b3bSManoj Naik 	status = -EIO;
36527aaa0b3bSManoj Naik 	goto out;
36537aaa0b3bSManoj Naik }
36547aaa0b3bSManoj Naik 
36557aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3656683b57b4STrond Myklebust {
3657683b57b4STrond Myklebust 	int n;
36588687b63aSAl Viro 	__be32 *p;
3659683b57b4STrond Myklebust 	int status = -EIO;
3660683b57b4STrond Myklebust 
3661683b57b4STrond Myklebust 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3662683b57b4STrond Myklebust 		goto out;
3663683b57b4STrond Myklebust 	status = 0;
3664683b57b4STrond Myklebust 	if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3665683b57b4STrond Myklebust 		goto out;
3666f54423a1SKinglong Mee 	bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
36678b7e3f49STrond Myklebust 	status = -EIO;
36688b7e3f49STrond Myklebust 	/* Ignore borken servers that return unrequested attrs */
36698b7e3f49STrond Myklebust 	if (unlikely(res == NULL))
36708b7e3f49STrond Myklebust 		goto out;
367102a2976cSChuck Lever 	dprintk("%s: fsroot:\n", __func__);
36727aaa0b3bSManoj Naik 	status = decode_pathname(xdr, &res->fs_path);
3673683b57b4STrond Myklebust 	if (unlikely(status != 0))
3674683b57b4STrond Myklebust 		goto out;
3675c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
3676c0eae66eSBenny Halevy 	if (unlikely(!p))
3677eb72f484SChuck Lever 		goto out_eio;
3678cccddf4fSBenny Halevy 	n = be32_to_cpup(p);
3679683b57b4STrond Myklebust 	if (n <= 0)
3680683b57b4STrond Myklebust 		goto out_eio;
3681809b426cSTrond Myklebust 	for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3682464ad6b1SChuck Lever 		u32 m;
3683809b426cSTrond Myklebust 		struct nfs4_fs_location *loc;
3684683b57b4STrond Myklebust 
3685809b426cSTrond Myklebust 		if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3686809b426cSTrond Myklebust 			break;
3687809b426cSTrond Myklebust 		loc = &res->locations[res->nlocations];
3688c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3689c0eae66eSBenny Halevy 		if (unlikely(!p))
3690eb72f484SChuck Lever 			goto out_eio;
3691cccddf4fSBenny Halevy 		m = be32_to_cpup(p);
36927aaa0b3bSManoj Naik 
369302a2976cSChuck Lever 		dprintk("%s: servers:\n", __func__);
3694809b426cSTrond Myklebust 		for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3695809b426cSTrond Myklebust 			struct nfs4_string *server;
3696809b426cSTrond Myklebust 
3697809b426cSTrond Myklebust 			if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3698464ad6b1SChuck Lever 				unsigned int i;
3699464ad6b1SChuck Lever 				dprintk("%s: using first %u of %u servers "
3700464ad6b1SChuck Lever 					"returned for location %u\n",
37013110ff80SHarvey Harrison 						__func__,
3702464ad6b1SChuck Lever 						NFS4_FS_LOCATION_MAXSERVERS,
3703464ad6b1SChuck Lever 						m, res->nlocations);
37047aaa0b3bSManoj Naik 				for (i = loc->nservers; i < m; i++) {
37052e42c3e2STrond Myklebust 					unsigned int len;
37067aaa0b3bSManoj Naik 					char *data;
37077aaa0b3bSManoj Naik 					status = decode_opaque_inline(xdr, &len, &data);
3708683b57b4STrond Myklebust 					if (unlikely(status != 0))
3709683b57b4STrond Myklebust 						goto out_eio;
37107aaa0b3bSManoj Naik 				}
3711809b426cSTrond Myklebust 				break;
37127aaa0b3bSManoj Naik 			}
3713809b426cSTrond Myklebust 			server = &loc->servers[loc->nservers];
3714809b426cSTrond Myklebust 			status = decode_opaque_inline(xdr, &server->len, &server->data);
3715809b426cSTrond Myklebust 			if (unlikely(status != 0))
3716809b426cSTrond Myklebust 				goto out_eio;
3717809b426cSTrond Myklebust 			dprintk("%s ", server->data);
37187aaa0b3bSManoj Naik 		}
37197aaa0b3bSManoj Naik 		status = decode_pathname(xdr, &loc->rootpath);
37207aaa0b3bSManoj Naik 		if (unlikely(status != 0))
37217aaa0b3bSManoj Naik 			goto out_eio;
3722683b57b4STrond Myklebust 	}
3723409924e4STrond Myklebust 	if (res->nlocations != 0)
372481934ddbSChuck Lever 		status = NFS_ATTR_FATTR_V4_LOCATIONS;
3725683b57b4STrond Myklebust out:
37263110ff80SHarvey Harrison 	dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3727683b57b4STrond Myklebust 	return status;
3728683b57b4STrond Myklebust out_eio:
3729683b57b4STrond Myklebust 	status = -EIO;
3730683b57b4STrond Myklebust 	goto out;
3731683b57b4STrond Myklebust }
3732683b57b4STrond Myklebust 
37331da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
37341da177e4SLinus Torvalds {
37358687b63aSAl Viro 	__be32 *p;
37361da177e4SLinus Torvalds 	int status = 0;
37371da177e4SLinus Torvalds 
37381da177e4SLinus Torvalds 	*res = 0;
37391da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
37401da177e4SLinus Torvalds 		return -EIO;
37411da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3742c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3743c0eae66eSBenny Halevy 		if (unlikely(!p))
3744eb72f484SChuck Lever 			return -EIO;
3745cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
37461da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
37471da177e4SLinus Torvalds 	}
37483110ff80SHarvey Harrison 	dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
37491da177e4SLinus Torvalds 	return status;
37501da177e4SLinus Torvalds }
37511da177e4SLinus Torvalds 
37521da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
37531da177e4SLinus Torvalds {
37548687b63aSAl Viro 	__be32 *p;
37551da177e4SLinus Torvalds 	int status = 0;
37561da177e4SLinus Torvalds 
37571da177e4SLinus Torvalds 	*maxlink = 1;
37581da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
37591da177e4SLinus Torvalds 		return -EIO;
37601da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3761c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3762c0eae66eSBenny Halevy 		if (unlikely(!p))
3763eb72f484SChuck Lever 			return -EIO;
3764cccddf4fSBenny Halevy 		*maxlink = be32_to_cpup(p);
37651da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
37661da177e4SLinus Torvalds 	}
37673110ff80SHarvey Harrison 	dprintk("%s: maxlink=%u\n", __func__, *maxlink);
37681da177e4SLinus Torvalds 	return status;
37691da177e4SLinus Torvalds }
37701da177e4SLinus Torvalds 
37711da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
37721da177e4SLinus Torvalds {
37738687b63aSAl Viro 	__be32 *p;
37741da177e4SLinus Torvalds 	int status = 0;
37751da177e4SLinus Torvalds 
37761da177e4SLinus Torvalds 	*maxname = 1024;
37771da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
37781da177e4SLinus Torvalds 		return -EIO;
37791da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3780c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3781c0eae66eSBenny Halevy 		if (unlikely(!p))
3782eb72f484SChuck Lever 			return -EIO;
3783cccddf4fSBenny Halevy 		*maxname = be32_to_cpup(p);
37841da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
37851da177e4SLinus Torvalds 	}
37863110ff80SHarvey Harrison 	dprintk("%s: maxname=%u\n", __func__, *maxname);
37871da177e4SLinus Torvalds 	return status;
37881da177e4SLinus Torvalds }
37891da177e4SLinus Torvalds 
37901da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
37911da177e4SLinus Torvalds {
37928687b63aSAl Viro 	__be32 *p;
37931da177e4SLinus Torvalds 	int status = 0;
37941da177e4SLinus Torvalds 
37951da177e4SLinus Torvalds 	*res = 1024;
37961da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
37971da177e4SLinus Torvalds 		return -EIO;
37981da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
37991da177e4SLinus Torvalds 		uint64_t maxread;
3800c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3801c0eae66eSBenny Halevy 		if (unlikely(!p))
3802eb72f484SChuck Lever 			return -EIO;
3803cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxread);
38041da177e4SLinus Torvalds 		if (maxread > 0x7FFFFFFF)
38051da177e4SLinus Torvalds 			maxread = 0x7FFFFFFF;
38061da177e4SLinus Torvalds 		*res = (uint32_t)maxread;
38071da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
38081da177e4SLinus Torvalds 	}
38093110ff80SHarvey Harrison 	dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
38101da177e4SLinus Torvalds 	return status;
38111da177e4SLinus Torvalds }
38121da177e4SLinus Torvalds 
38131da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
38141da177e4SLinus Torvalds {
38158687b63aSAl Viro 	__be32 *p;
38161da177e4SLinus Torvalds 	int status = 0;
38171da177e4SLinus Torvalds 
38181da177e4SLinus Torvalds 	*res = 1024;
38191da177e4SLinus Torvalds 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
38201da177e4SLinus Torvalds 		return -EIO;
38211da177e4SLinus Torvalds 	if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
38221da177e4SLinus Torvalds 		uint64_t maxwrite;
3823c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3824c0eae66eSBenny Halevy 		if (unlikely(!p))
3825eb72f484SChuck Lever 			return -EIO;
3826cccddf4fSBenny Halevy 		xdr_decode_hyper(p, &maxwrite);
38271da177e4SLinus Torvalds 		if (maxwrite > 0x7FFFFFFF)
38281da177e4SLinus Torvalds 			maxwrite = 0x7FFFFFFF;
38291da177e4SLinus Torvalds 		*res = (uint32_t)maxwrite;
38301da177e4SLinus Torvalds 		bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
38311da177e4SLinus Torvalds 	}
38323110ff80SHarvey Harrison 	dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
38331da177e4SLinus Torvalds 	return status;
38341da177e4SLinus Torvalds }
38351da177e4SLinus Torvalds 
3836bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
38371da177e4SLinus Torvalds {
3838bca79478STrond Myklebust 	uint32_t tmp;
38398687b63aSAl Viro 	__be32 *p;
3840409924e4STrond Myklebust 	int ret = 0;
38411da177e4SLinus Torvalds 
38421da177e4SLinus Torvalds 	*mode = 0;
38431da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
38441da177e4SLinus Torvalds 		return -EIO;
38451da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3846c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3847c0eae66eSBenny Halevy 		if (unlikely(!p))
3848eb72f484SChuck Lever 			return -EIO;
3849cccddf4fSBenny Halevy 		tmp = be32_to_cpup(p);
3850bca79478STrond Myklebust 		*mode = tmp & ~S_IFMT;
38511da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_MODE;
3852409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_MODE;
38531da177e4SLinus Torvalds 	}
38543110ff80SHarvey Harrison 	dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3855409924e4STrond Myklebust 	return ret;
38561da177e4SLinus Torvalds }
38571da177e4SLinus Torvalds 
38581da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
38591da177e4SLinus Torvalds {
38608687b63aSAl Viro 	__be32 *p;
3861409924e4STrond Myklebust 	int ret = 0;
38621da177e4SLinus Torvalds 
38631da177e4SLinus Torvalds 	*nlink = 1;
38641da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
38651da177e4SLinus Torvalds 		return -EIO;
38661da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3867c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
3868c0eae66eSBenny Halevy 		if (unlikely(!p))
3869eb72f484SChuck Lever 			return -EIO;
3870cccddf4fSBenny Halevy 		*nlink = be32_to_cpup(p);
38711da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3872409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_NLINK;
38731da177e4SLinus Torvalds 	}
38743110ff80SHarvey Harrison 	dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3875409924e4STrond Myklebust 	return ret;
38761da177e4SLinus Torvalds }
38771da177e4SLinus Torvalds 
3878686a816aSTrond Myklebust static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3879686a816aSTrond Myklebust 		struct nfs4_string *name, gfp_t gfp_flags)
3880686a816aSTrond Myklebust {
3881686a816aSTrond Myklebust 	ssize_t ret;
3882686a816aSTrond Myklebust 
3883686a816aSTrond Myklebust 	ret = xdr_stream_decode_string_dup(xdr, &name->data,
3884686a816aSTrond Myklebust 			XDR_MAX_NETOBJ, gfp_flags);
3885686a816aSTrond Myklebust 	name->len = 0;
3886686a816aSTrond Myklebust 	if (ret > 0)
3887686a816aSTrond Myklebust 		name->len = ret;
3888686a816aSTrond Myklebust 	return ret;
3889686a816aSTrond Myklebust }
3890686a816aSTrond Myklebust 
389180e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3892e5782076SEric W. Biederman 		const struct nfs_server *server, kuid_t *uid,
38936926afd1STrond Myklebust 		struct nfs4_string *owner_name)
38941da177e4SLinus Torvalds {
3895686a816aSTrond Myklebust 	ssize_t len;
3896686a816aSTrond Myklebust 	char *p;
38971da177e4SLinus Torvalds 
3898e5782076SEric W. Biederman 	*uid = make_kuid(&init_user_ns, -2);
38991da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
39001da177e4SLinus Torvalds 		return -EIO;
3901686a816aSTrond Myklebust 	if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3902686a816aSTrond Myklebust 		return 0;
39031da177e4SLinus Torvalds 	bitmap[1] &= ~FATTR4_WORD1_OWNER;
3904686a816aSTrond Myklebust 
3905686a816aSTrond Myklebust 	if (owner_name != NULL) {
3906e8d8aa46STrond Myklebust 		len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
3907686a816aSTrond Myklebust 		if (len <= 0)
3908686a816aSTrond Myklebust 			goto out;
3909686a816aSTrond Myklebust 		dprintk("%s: name=%s\n", __func__, owner_name->data);
3910686a816aSTrond Myklebust 		return NFS_ATTR_FATTR_OWNER_NAME;
3911686a816aSTrond Myklebust 	} else {
3912686a816aSTrond Myklebust 		len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3913686a816aSTrond Myklebust 				XDR_MAX_NETOBJ);
3914686a816aSTrond Myklebust 		if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3915686a816aSTrond Myklebust 			goto out;
3916e5782076SEric W. Biederman 		dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3917686a816aSTrond Myklebust 		return NFS_ATTR_FATTR_OWNER;
3918686a816aSTrond Myklebust 	}
3919686a816aSTrond Myklebust out:
3920eb72f484SChuck Lever 	if (len == -EBADMSG)
3921c0eae66eSBenny Halevy 		return -EIO;
3922eb72f484SChuck Lever 	return 0;
39231da177e4SLinus Torvalds }
39241da177e4SLinus Torvalds 
392580e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3926e5782076SEric W. Biederman 		const struct nfs_server *server, kgid_t *gid,
39276926afd1STrond Myklebust 		struct nfs4_string *group_name)
39281da177e4SLinus Torvalds {
3929686a816aSTrond Myklebust 	ssize_t len;
3930686a816aSTrond Myklebust 	char *p;
39311da177e4SLinus Torvalds 
3932e5782076SEric W. Biederman 	*gid = make_kgid(&init_user_ns, -2);
39331da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
39341da177e4SLinus Torvalds 		return -EIO;
3935686a816aSTrond Myklebust 	if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
3936686a816aSTrond Myklebust 		return 0;
39371da177e4SLinus Torvalds 	bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3938686a816aSTrond Myklebust 
3939686a816aSTrond Myklebust 	if (group_name != NULL) {
3940e8d8aa46STrond Myklebust 		len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
3941686a816aSTrond Myklebust 		if (len <= 0)
3942686a816aSTrond Myklebust 			goto out;
3943686a816aSTrond Myklebust 		dprintk("%s: name=%s\n", __func__, group_name->data);
39446f1f6220SKinglong Mee 		return NFS_ATTR_FATTR_GROUP_NAME;
3945686a816aSTrond Myklebust 	} else {
3946686a816aSTrond Myklebust 		len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3947686a816aSTrond Myklebust 				XDR_MAX_NETOBJ);
3948686a816aSTrond Myklebust 		if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
3949686a816aSTrond Myklebust 			goto out;
3950e5782076SEric W. Biederman 		dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3951686a816aSTrond Myklebust 		return NFS_ATTR_FATTR_GROUP;
3952686a816aSTrond Myklebust 	}
3953686a816aSTrond Myklebust out:
3954eb72f484SChuck Lever 	if (len == -EBADMSG)
3955c0eae66eSBenny Halevy 		return -EIO;
3956eb72f484SChuck Lever 	return 0;
39571da177e4SLinus Torvalds }
39581da177e4SLinus Torvalds 
39591da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
39601da177e4SLinus Torvalds {
39618687b63aSAl Viro 	uint32_t major = 0, minor = 0;
39628687b63aSAl Viro 	__be32 *p;
3963409924e4STrond Myklebust 	int ret = 0;
39641da177e4SLinus Torvalds 
39651da177e4SLinus Torvalds 	*rdev = MKDEV(0,0);
39661da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
39671da177e4SLinus Torvalds 		return -EIO;
39681da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
39691da177e4SLinus Torvalds 		dev_t tmp;
39701da177e4SLinus Torvalds 
3971c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3972c0eae66eSBenny Halevy 		if (unlikely(!p))
3973eb72f484SChuck Lever 			return -EIO;
39746f723f77SBenny Halevy 		major = be32_to_cpup(p++);
3975cccddf4fSBenny Halevy 		minor = be32_to_cpup(p);
39761da177e4SLinus Torvalds 		tmp = MKDEV(major, minor);
39771da177e4SLinus Torvalds 		if (MAJOR(tmp) == major && MINOR(tmp) == minor)
39781da177e4SLinus Torvalds 			*rdev = tmp;
39791da177e4SLinus Torvalds 		bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3980409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_RDEV;
39811da177e4SLinus Torvalds 	}
39823110ff80SHarvey Harrison 	dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3983409924e4STrond Myklebust 	return ret;
39841da177e4SLinus Torvalds }
39851da177e4SLinus Torvalds 
39861da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
39871da177e4SLinus Torvalds {
39888687b63aSAl Viro 	__be32 *p;
39891da177e4SLinus Torvalds 	int status = 0;
39901da177e4SLinus Torvalds 
39911da177e4SLinus Torvalds 	*res = 0;
39921da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
39931da177e4SLinus Torvalds 		return -EIO;
39941da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3995c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
3996c0eae66eSBenny Halevy 		if (unlikely(!p))
3997eb72f484SChuck Lever 			return -EIO;
3998cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
39991da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
40001da177e4SLinus Torvalds 	}
40013110ff80SHarvey Harrison 	dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
40021da177e4SLinus Torvalds 	return status;
40031da177e4SLinus Torvalds }
40041da177e4SLinus Torvalds 
40051da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40061da177e4SLinus Torvalds {
40078687b63aSAl Viro 	__be32 *p;
40081da177e4SLinus Torvalds 	int status = 0;
40091da177e4SLinus Torvalds 
40101da177e4SLinus Torvalds 	*res = 0;
40111da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
40121da177e4SLinus Torvalds 		return -EIO;
40131da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
4014c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4015c0eae66eSBenny Halevy 		if (unlikely(!p))
4016eb72f484SChuck Lever 			return -EIO;
4017cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40181da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
40191da177e4SLinus Torvalds 	}
40203110ff80SHarvey Harrison 	dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
40211da177e4SLinus Torvalds 	return status;
40221da177e4SLinus Torvalds }
40231da177e4SLinus Torvalds 
40241da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40251da177e4SLinus Torvalds {
40268687b63aSAl Viro 	__be32 *p;
40271da177e4SLinus Torvalds 	int status = 0;
40281da177e4SLinus Torvalds 
40291da177e4SLinus Torvalds 	*res = 0;
40301da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
40311da177e4SLinus Torvalds 		return -EIO;
40321da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4033c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4034c0eae66eSBenny Halevy 		if (unlikely(!p))
4035eb72f484SChuck Lever 			return -EIO;
4036cccddf4fSBenny Halevy 		xdr_decode_hyper(p, res);
40371da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
40381da177e4SLinus Torvalds 	}
40393110ff80SHarvey Harrison 	dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
40401da177e4SLinus Torvalds 	return status;
40411da177e4SLinus Torvalds }
40421da177e4SLinus Torvalds 
40431da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
40441da177e4SLinus Torvalds {
40458687b63aSAl Viro 	__be32 *p;
4046409924e4STrond Myklebust 	int ret = 0;
40471da177e4SLinus Torvalds 
40481da177e4SLinus Torvalds 	*used = 0;
40491da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
40501da177e4SLinus Torvalds 		return -EIO;
40511da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4052c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8);
4053c0eae66eSBenny Halevy 		if (unlikely(!p))
4054eb72f484SChuck Lever 			return -EIO;
4055cccddf4fSBenny Halevy 		xdr_decode_hyper(p, used);
40561da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4057409924e4STrond Myklebust 		ret = NFS_ATTR_FATTR_SPACE_USED;
40581da177e4SLinus Torvalds 	}
40593110ff80SHarvey Harrison 	dprintk("%s: space used=%Lu\n", __func__,
40601da177e4SLinus Torvalds 			(unsigned long long)*used);
4061409924e4STrond Myklebust 	return ret;
40621da177e4SLinus Torvalds }
40631da177e4SLinus Torvalds 
406436b3743fSTrond Myklebust static __be32 *
4065e86d5a02STrond Myklebust xdr_decode_nfstime4(__be32 *p, struct timespec64 *t)
406636b3743fSTrond Myklebust {
406736b3743fSTrond Myklebust 	__u64 sec;
406836b3743fSTrond Myklebust 
406936b3743fSTrond Myklebust 	p = xdr_decode_hyper(p, &sec);
4070e86d5a02STrond Myklebust 	t-> tv_sec = sec;
407136b3743fSTrond Myklebust 	t->tv_nsec = be32_to_cpup(p++);
407236b3743fSTrond Myklebust 	return p;
407336b3743fSTrond Myklebust }
407436b3743fSTrond Myklebust 
4075e86d5a02STrond Myklebust static int decode_attr_time(struct xdr_stream *xdr, struct timespec64 *time)
40761da177e4SLinus Torvalds {
40778687b63aSAl Viro 	__be32 *p;
40781da177e4SLinus Torvalds 
407936b3743fSTrond Myklebust 	p = xdr_inline_decode(xdr, nfstime4_maxsz << 2);
4080c0eae66eSBenny Halevy 	if (unlikely(!p))
4081eb72f484SChuck Lever 		return -EIO;
408236b3743fSTrond Myklebust 	xdr_decode_nfstime4(p, time);
40831da177e4SLinus Torvalds 	return 0;
40841da177e4SLinus Torvalds }
40851da177e4SLinus Torvalds 
4086e86d5a02STrond Myklebust static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
40871da177e4SLinus Torvalds {
40881da177e4SLinus Torvalds 	int status = 0;
40891da177e4SLinus Torvalds 
40901da177e4SLinus Torvalds 	time->tv_sec = 0;
40911da177e4SLinus Torvalds 	time->tv_nsec = 0;
40921da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
40931da177e4SLinus Torvalds 		return -EIO;
40941da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
40951da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4096409924e4STrond Myklebust 		if (status == 0)
4097409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_ATIME;
40981da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
40991da177e4SLinus Torvalds 	}
4100ae08483cSArnd Bergmann 	dprintk("%s: atime=%lld\n", __func__, time->tv_sec);
41011da177e4SLinus Torvalds 	return status;
41021da177e4SLinus Torvalds }
41031da177e4SLinus Torvalds 
4104e86d5a02STrond Myklebust static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
41051da177e4SLinus Torvalds {
41061da177e4SLinus Torvalds 	int status = 0;
41071da177e4SLinus Torvalds 
41081da177e4SLinus Torvalds 	time->tv_sec = 0;
41091da177e4SLinus Torvalds 	time->tv_nsec = 0;
41101da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
41111da177e4SLinus Torvalds 		return -EIO;
41121da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
41131da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4114409924e4STrond Myklebust 		if (status == 0)
4115409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_CTIME;
41161da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
41171da177e4SLinus Torvalds 	}
4118ae08483cSArnd Bergmann 	dprintk("%s: ctime=%lld\n", __func__, time->tv_sec);
41191da177e4SLinus Torvalds 	return status;
41201da177e4SLinus Torvalds }
41211da177e4SLinus Torvalds 
412255b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4123e86d5a02STrond Myklebust 				  struct timespec64 *time)
412455b6e774SRicardo Labiaga {
412555b6e774SRicardo Labiaga 	int status = 0;
412655b6e774SRicardo Labiaga 
412755b6e774SRicardo Labiaga 	time->tv_sec = 0;
412855b6e774SRicardo Labiaga 	time->tv_nsec = 0;
412955b6e774SRicardo Labiaga 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
413055b6e774SRicardo Labiaga 		return -EIO;
413155b6e774SRicardo Labiaga 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
413255b6e774SRicardo Labiaga 		status = decode_attr_time(xdr, time);
413355b6e774SRicardo Labiaga 		bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
413455b6e774SRicardo Labiaga 	}
4135ae08483cSArnd Bergmann 	dprintk("%s: time_delta=%lld %ld\n", __func__, time->tv_sec,
4136ae08483cSArnd Bergmann 		time->tv_nsec);
413755b6e774SRicardo Labiaga 	return status;
413855b6e774SRicardo Labiaga }
413955b6e774SRicardo Labiaga 
4140aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4141aa9c2669SDavid Quigley 					struct nfs4_label *label)
4142aa9c2669SDavid Quigley {
4143aa9c2669SDavid Quigley 	uint32_t pi = 0;
4144aa9c2669SDavid Quigley 	uint32_t lfs = 0;
4145aa9c2669SDavid Quigley 	__u32 len;
4146aa9c2669SDavid Quigley 	__be32 *p;
4147aa9c2669SDavid Quigley 	int status = 0;
4148aa9c2669SDavid Quigley 
4149aa9c2669SDavid Quigley 	if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4150aa9c2669SDavid Quigley 		return -EIO;
4151aa9c2669SDavid Quigley 	if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4152aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4153aa9c2669SDavid Quigley 		if (unlikely(!p))
4154eb72f484SChuck Lever 			return -EIO;
4155aa9c2669SDavid Quigley 		lfs = be32_to_cpup(p++);
4156aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4157aa9c2669SDavid Quigley 		if (unlikely(!p))
4158eb72f484SChuck Lever 			return -EIO;
4159aa9c2669SDavid Quigley 		pi = be32_to_cpup(p++);
4160aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, 4);
4161aa9c2669SDavid Quigley 		if (unlikely(!p))
4162eb72f484SChuck Lever 			return -EIO;
4163aa9c2669SDavid Quigley 		len = be32_to_cpup(p++);
4164aa9c2669SDavid Quigley 		p = xdr_inline_decode(xdr, len);
4165aa9c2669SDavid Quigley 		if (unlikely(!p))
4166eb72f484SChuck Lever 			return -EIO;
4167aa9c2669SDavid Quigley 		if (len < NFS4_MAXLABELLEN) {
4168aa9c2669SDavid Quigley 			if (label) {
4169aa9c2669SDavid Quigley 				memcpy(label->label, p, len);
4170aa9c2669SDavid Quigley 				label->len = len;
4171aa9c2669SDavid Quigley 				label->pi = pi;
4172aa9c2669SDavid Quigley 				label->lfs = lfs;
4173aa9c2669SDavid Quigley 				status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4174aa9c2669SDavid Quigley 			}
4175aa9c2669SDavid Quigley 			bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4176aa9c2669SDavid Quigley 		} else
4177aa9c2669SDavid Quigley 			printk(KERN_WARNING "%s: label too long (%u)!\n",
4178aa9c2669SDavid Quigley 					__func__, len);
4179aa9c2669SDavid Quigley 	}
4180aa9c2669SDavid Quigley 	if (label && label->label)
4181aa9c2669SDavid Quigley 		dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4182aa9c2669SDavid Quigley 			(char *)label->label, label->len, label->pi, label->lfs);
4183aa9c2669SDavid Quigley 	return status;
4184aa9c2669SDavid Quigley }
4185aa9c2669SDavid Quigley 
4186e86d5a02STrond Myklebust static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
41871da177e4SLinus Torvalds {
41881da177e4SLinus Torvalds 	int status = 0;
41891da177e4SLinus Torvalds 
41901da177e4SLinus Torvalds 	time->tv_sec = 0;
41911da177e4SLinus Torvalds 	time->tv_nsec = 0;
41921da177e4SLinus Torvalds 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
41931da177e4SLinus Torvalds 		return -EIO;
41941da177e4SLinus Torvalds 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
41951da177e4SLinus Torvalds 		status = decode_attr_time(xdr, time);
4196409924e4STrond Myklebust 		if (status == 0)
4197409924e4STrond Myklebust 			status = NFS_ATTR_FATTR_MTIME;
41981da177e4SLinus Torvalds 		bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
41991da177e4SLinus Torvalds 	}
4200ae08483cSArnd Bergmann 	dprintk("%s: mtime=%lld\n", __func__, time->tv_sec);
42011da177e4SLinus Torvalds 	return status;
42021da177e4SLinus Torvalds }
42031da177e4SLinus Torvalds 
4204256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
42051da177e4SLinus Torvalds {
42061da177e4SLinus Torvalds 	unsigned int attrwords = XDR_QUADLEN(attrlen);
4207256e48bbSTrond Myklebust 	unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
42081da177e4SLinus Torvalds 
42091da177e4SLinus Torvalds 	if (unlikely(attrwords != nwords)) {
4210fe82a183SChuck Lever 		dprintk("%s: server returned incorrect attribute length: "
4211fe82a183SChuck Lever 			"%u %c %u\n",
42123110ff80SHarvey Harrison 				__func__,
42131da177e4SLinus Torvalds 				attrwords << 2,
42141da177e4SLinus Torvalds 				(attrwords < nwords) ? '<' : '>',
42151da177e4SLinus Torvalds 				nwords << 2);
42161da177e4SLinus Torvalds 		return -EIO;
42171da177e4SLinus Torvalds 	}
42181da177e4SLinus Torvalds 	return 0;
42191da177e4SLinus Torvalds }
42201da177e4SLinus Torvalds 
42211da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
42221da177e4SLinus Torvalds {
42238687b63aSAl Viro 	__be32 *p;
42241da177e4SLinus Torvalds 
4225c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
4226c0eae66eSBenny Halevy 	if (unlikely(!p))
4227eb72f484SChuck Lever 		return -EIO;
42286f723f77SBenny Halevy 	cinfo->atomic = be32_to_cpup(p++);
42293ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &cinfo->before);
4230cccddf4fSBenny Halevy 	xdr_decode_hyper(p, &cinfo->after);
42311da177e4SLinus Torvalds 	return 0;
42321da177e4SLinus Torvalds }
42331da177e4SLinus Torvalds 
42346168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
42351da177e4SLinus Torvalds {
42368687b63aSAl Viro 	__be32 *p;
42371da177e4SLinus Torvalds 	uint32_t supp, acc;
42381da177e4SLinus Torvalds 	int status;
42391da177e4SLinus Torvalds 
42401da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_ACCESS);
42411da177e4SLinus Torvalds 	if (status)
42421da177e4SLinus Torvalds 		return status;
4243c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
4244c0eae66eSBenny Halevy 	if (unlikely(!p))
4245eb72f484SChuck Lever 		return -EIO;
42466f723f77SBenny Halevy 	supp = be32_to_cpup(p++);
4247cccddf4fSBenny Halevy 	acc = be32_to_cpup(p);
42486168f62cSWeston Andros Adamson 	*supported = supp;
42496168f62cSWeston Andros Adamson 	*access = acc;
42501da177e4SLinus Torvalds 	return 0;
42511da177e4SLinus Torvalds }
42521da177e4SLinus Torvalds 
425307d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
42541da177e4SLinus Torvalds {
4255ab6e9aafSTrond Myklebust 	ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4256eb72f484SChuck Lever 	if (unlikely(ret < 0))
425707d30434SBenny Halevy 		return -EIO;
4258ab6e9aafSTrond Myklebust 	return 0;
4259ab6e9aafSTrond Myklebust }
426007d30434SBenny Halevy 
426107d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
426207d30434SBenny Halevy {
42632d2f24adSTrond Myklebust 	return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
42641da177e4SLinus Torvalds }
42651da177e4SLinus Torvalds 
426693b717fdSTrond Myklebust static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
426793b717fdSTrond Myklebust {
426893b717fdSTrond Myklebust 	stateid->type = NFS4_OPEN_STATEID_TYPE;
426993b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
427093b717fdSTrond Myklebust }
427193b717fdSTrond Myklebust 
427293b717fdSTrond Myklebust static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
427393b717fdSTrond Myklebust {
427493b717fdSTrond Myklebust 	stateid->type = NFS4_LOCK_STATEID_TYPE;
427593b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
427693b717fdSTrond Myklebust }
427793b717fdSTrond Myklebust 
427893b717fdSTrond Myklebust static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
427993b717fdSTrond Myklebust {
428093b717fdSTrond Myklebust 	stateid->type = NFS4_DELEGATION_STATEID_TYPE;
428193b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
428293b717fdSTrond Myklebust }
428393b717fdSTrond Myklebust 
4284fcd8843cSTrond Myklebust static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4285fcd8843cSTrond Myklebust {
4286fcd8843cSTrond Myklebust 	nfs4_stateid dummy;
4287fcd8843cSTrond Myklebust 
4288fcd8843cSTrond Myklebust 	nfs4_stateid_copy(stateid, &invalid_stateid);
4289fcd8843cSTrond Myklebust 	return decode_stateid(xdr, &dummy);
4290fcd8843cSTrond Myklebust }
4291fcd8843cSTrond Myklebust 
42921da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
42931da177e4SLinus Torvalds {
42941da177e4SLinus Torvalds 	int status;
42951da177e4SLinus Torvalds 
42961da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CLOSE);
4297c1d51931STrond Myklebust 	if (status != -EIO)
4298c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
429907d30434SBenny Halevy 	if (!status)
4300fcd8843cSTrond Myklebust 		status = decode_invalid_stateid(xdr, &res->stateid);
43011da177e4SLinus Torvalds 	return status;
43021da177e4SLinus Torvalds }
43031da177e4SLinus Torvalds 
4304db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4305db942bbdSBenny Halevy {
4306cd93710eSChuck Lever 	return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
43071da177e4SLinus Torvalds }
43081da177e4SLinus Torvalds 
43092f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
43102f2c63bcSTrond Myklebust {
43112f2c63bcSTrond Myklebust 	return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
43122f2c63bcSTrond Myklebust }
43132f2c63bcSTrond Myklebust 
43140b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
43151da177e4SLinus Torvalds {
43161da177e4SLinus Torvalds 	int status;
43171da177e4SLinus Torvalds 
43181da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_COMMIT);
4319db942bbdSBenny Halevy 	if (!status)
43202f2c63bcSTrond Myklebust 		status = decode_write_verifier(xdr, &res->verf->verifier);
43211da177e4SLinus Torvalds 	return status;
43221da177e4SLinus Torvalds }
43231da177e4SLinus Torvalds 
43241da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
43251da177e4SLinus Torvalds {
43268687b63aSAl Viro 	__be32 *p;
43271da177e4SLinus Torvalds 	uint32_t bmlen;
43281da177e4SLinus Torvalds 	int status;
43291da177e4SLinus Torvalds 
43301da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_CREATE);
43311da177e4SLinus Torvalds 	if (status)
43321da177e4SLinus Torvalds 		return status;
43331da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, cinfo)))
43341da177e4SLinus Torvalds 		return status;
4335c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4336c0eae66eSBenny Halevy 	if (unlikely(!p))
4337eb72f484SChuck Lever 		return -EIO;
4338cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
4339c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
4340c0eae66eSBenny Halevy 	if (likely(p))
43411da177e4SLinus Torvalds 		return 0;
4342c0eae66eSBenny Halevy 	return -EIO;
43431da177e4SLinus Torvalds }
43441da177e4SLinus Torvalds 
43451da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
43461da177e4SLinus Torvalds {
4347256e48bbSTrond Myklebust 	unsigned int savep;
4348dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
43491da177e4SLinus Torvalds 	int status;
43501da177e4SLinus Torvalds 
43511da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
43521da177e4SLinus Torvalds 		goto xdr_error;
43531da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
43541da177e4SLinus Torvalds 		goto xdr_error;
43551da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
43561da177e4SLinus Torvalds 		goto xdr_error;
43571da177e4SLinus Torvalds 	if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
43581da177e4SLinus Torvalds 		goto xdr_error;
4359264e6351SChuck Lever 	if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4360264e6351SChuck Lever 						 &res->fh_expire_type)) != 0)
4361264e6351SChuck Lever 		goto xdr_error;
43621da177e4SLinus Torvalds 	if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
43631da177e4SLinus Torvalds 		goto xdr_error;
43641da177e4SLinus Torvalds 	if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
43651da177e4SLinus Torvalds 		goto xdr_error;
43661da177e4SLinus Torvalds 	if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
43671da177e4SLinus Torvalds 		goto xdr_error;
43688c61282fSKinglong Mee 	if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
43698c61282fSKinglong Mee 				res->exclcreat_bitmask)) != 0)
43708c61282fSKinglong Mee 		goto xdr_error;
43711da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
43721da177e4SLinus Torvalds xdr_error:
43733110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
43741da177e4SLinus Torvalds 	return status;
43751da177e4SLinus Torvalds }
43761da177e4SLinus Torvalds 
43771da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
43781da177e4SLinus Torvalds {
4379256e48bbSTrond Myklebust 	unsigned int savep;
4380dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
43811da177e4SLinus Torvalds 	int status;
43821da177e4SLinus Torvalds 
43831da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
43841da177e4SLinus Torvalds 		goto xdr_error;
43851da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
43861da177e4SLinus Torvalds 		goto xdr_error;
43871da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
43881da177e4SLinus Torvalds 		goto xdr_error;
43891da177e4SLinus Torvalds 
43901da177e4SLinus Torvalds 	if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
43911da177e4SLinus Torvalds 		goto xdr_error;
43921da177e4SLinus Torvalds 	if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
43931da177e4SLinus Torvalds 		goto xdr_error;
43941da177e4SLinus Torvalds 	if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
43951da177e4SLinus Torvalds 		goto xdr_error;
43961ca843a2SAndreas Gruenbacher 
43971ca843a2SAndreas Gruenbacher 	status = -EIO;
43981ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[0]))
43991ca843a2SAndreas Gruenbacher 		goto xdr_error;
44001ca843a2SAndreas Gruenbacher 
44011da177e4SLinus Torvalds 	if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
44021da177e4SLinus Torvalds 		goto xdr_error;
44031da177e4SLinus Torvalds 	if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
44041da177e4SLinus Torvalds 		goto xdr_error;
44051da177e4SLinus Torvalds 	if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
44061da177e4SLinus Torvalds 		goto xdr_error;
44071da177e4SLinus Torvalds 
44081da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
44091da177e4SLinus Torvalds xdr_error:
44103110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
44111da177e4SLinus Torvalds 	return status;
44121da177e4SLinus Torvalds }
44131da177e4SLinus Torvalds 
44141da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
44151da177e4SLinus Torvalds {
4416256e48bbSTrond Myklebust 	unsigned int savep;
4417dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3] = {0};
44181da177e4SLinus Torvalds 	int status;
44191da177e4SLinus Torvalds 
44201da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
44211da177e4SLinus Torvalds 		goto xdr_error;
44221da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
44231da177e4SLinus Torvalds 		goto xdr_error;
44241da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
44251da177e4SLinus Torvalds 		goto xdr_error;
44261da177e4SLinus Torvalds 
44271da177e4SLinus Torvalds 	if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
44281da177e4SLinus Torvalds 		goto xdr_error;
44291da177e4SLinus Torvalds 	if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
44301da177e4SLinus Torvalds 		goto xdr_error;
44311da177e4SLinus Torvalds 
44321da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
44331da177e4SLinus Torvalds xdr_error:
44343110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
44351da177e4SLinus Torvalds 	return status;
44361da177e4SLinus Torvalds }
44371da177e4SLinus Torvalds 
443888034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr,
443988034c3dSAndy Adamson 				  uint32_t *bitmap,
444088034c3dSAndy Adamson 				  uint64_t *res,
444188034c3dSAndy Adamson 				  uint32_t hint_bit)
444288034c3dSAndy Adamson {
444388034c3dSAndy Adamson 	__be32 *p;
444488034c3dSAndy Adamson 
444588034c3dSAndy Adamson 	*res = 0;
444688034c3dSAndy Adamson 	if (likely(bitmap[0] & hint_bit)) {
444788034c3dSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
444888034c3dSAndy Adamson 		if (unlikely(!p))
4449eb72f484SChuck Lever 			return -EIO;
445088034c3dSAndy Adamson 		xdr_decode_hyper(p, res);
445188034c3dSAndy Adamson 	}
445288034c3dSAndy Adamson 	return 0;
445388034c3dSAndy Adamson }
445488034c3dSAndy Adamson 
445588034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr,
445688034c3dSAndy Adamson 					struct nfs4_threshold *res)
445788034c3dSAndy Adamson {
4458256e48bbSTrond Myklebust 	__be32 *p;
4459256e48bbSTrond Myklebust 	unsigned int savep;
446088034c3dSAndy Adamson 	uint32_t bitmap[3] = {0,}, attrlen;
446188034c3dSAndy Adamson 	int status;
446288034c3dSAndy Adamson 
446388034c3dSAndy Adamson 	/* layout type */
446488034c3dSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
4465eb72f484SChuck Lever 	if (unlikely(!p))
446688034c3dSAndy Adamson 		return -EIO;
446788034c3dSAndy Adamson 	res->l_type = be32_to_cpup(p);
446888034c3dSAndy Adamson 
446988034c3dSAndy Adamson 	/* thi_hintset bitmap */
447088034c3dSAndy Adamson 	status = decode_attr_bitmap(xdr, bitmap);
447188034c3dSAndy Adamson 	if (status < 0)
447288034c3dSAndy Adamson 		goto xdr_error;
447388034c3dSAndy Adamson 
447488034c3dSAndy Adamson 	/* thi_hintlist length */
447588034c3dSAndy Adamson 	status = decode_attr_length(xdr, &attrlen, &savep);
447688034c3dSAndy Adamson 	if (status < 0)
447788034c3dSAndy Adamson 		goto xdr_error;
447888034c3dSAndy Adamson 	/* thi_hintlist */
447988034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
448088034c3dSAndy Adamson 	if (status < 0)
448188034c3dSAndy Adamson 		goto xdr_error;
448288034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
448388034c3dSAndy Adamson 	if (status < 0)
448488034c3dSAndy Adamson 		goto xdr_error;
448588034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
448688034c3dSAndy Adamson 				       THRESHOLD_RD_IO);
448788034c3dSAndy Adamson 	if (status < 0)
448888034c3dSAndy Adamson 		goto xdr_error;
448988034c3dSAndy Adamson 	status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
449088034c3dSAndy Adamson 				       THRESHOLD_WR_IO);
449188034c3dSAndy Adamson 	if (status < 0)
449288034c3dSAndy Adamson 		goto xdr_error;
449388034c3dSAndy Adamson 
449488034c3dSAndy Adamson 	status = verify_attr_len(xdr, savep, attrlen);
449588034c3dSAndy Adamson 	res->bm = bitmap[0];
449688034c3dSAndy Adamson 
449788034c3dSAndy Adamson 	dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
449888034c3dSAndy Adamson 		 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
449988034c3dSAndy Adamson 		res->wr_io_sz);
450088034c3dSAndy Adamson xdr_error:
450188034c3dSAndy Adamson 	dprintk("%s ret=%d!\n", __func__, status);
450288034c3dSAndy Adamson 	return status;
450388034c3dSAndy Adamson }
450488034c3dSAndy Adamson 
450588034c3dSAndy Adamson /*
450688034c3dSAndy Adamson  * Thresholds on pNFS direct I/O vrs MDS I/O
450788034c3dSAndy Adamson  */
450888034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
450988034c3dSAndy Adamson 				    uint32_t *bitmap,
451088034c3dSAndy Adamson 				    struct nfs4_threshold *res)
451188034c3dSAndy Adamson {
451288034c3dSAndy Adamson 	__be32 *p;
451388034c3dSAndy Adamson 	int status = 0;
451488034c3dSAndy Adamson 	uint32_t num;
451588034c3dSAndy Adamson 
451688034c3dSAndy Adamson 	if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
451788034c3dSAndy Adamson 		return -EIO;
4518029c5347STrond Myklebust 	if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
45191549210fSTrond Myklebust 		/* Did the server return an unrequested attribute? */
45201549210fSTrond Myklebust 		if (unlikely(res == NULL))
45211549210fSTrond Myklebust 			return -EREMOTEIO;
452288034c3dSAndy Adamson 		p = xdr_inline_decode(xdr, 4);
452388034c3dSAndy Adamson 		if (unlikely(!p))
4524eb72f484SChuck Lever 			return -EIO;
452588034c3dSAndy Adamson 		num = be32_to_cpup(p);
452688034c3dSAndy Adamson 		if (num == 0)
452788034c3dSAndy Adamson 			return 0;
452888034c3dSAndy Adamson 		if (num > 1)
452988034c3dSAndy Adamson 			printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
453088034c3dSAndy Adamson 				"drivers per filesystem not supported\n",
453188034c3dSAndy Adamson 				__func__);
453288034c3dSAndy Adamson 
453388034c3dSAndy Adamson 		status = decode_first_threshold_item4(xdr, res);
4534029c5347STrond Myklebust 		bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
453588034c3dSAndy Adamson 	}
453688034c3dSAndy Adamson 	return status;
453788034c3dSAndy Adamson }
453888034c3dSAndy Adamson 
4539ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4540ae42c70aSBryan Schumaker 		struct nfs_fattr *fattr, struct nfs_fh *fh,
4541aa9c2669SDavid Quigley 		struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
45426926afd1STrond Myklebust 		const struct nfs_server *server)
45431da177e4SLinus Torvalds {
4544bca79478STrond Myklebust 	int status;
4545bca79478STrond Myklebust 	umode_t fmode = 0;
4546ae42c70aSBryan Schumaker 	uint32_t type;
4547ee7b75fcSTrond Myklebust 	int32_t err;
45481da177e4SLinus Torvalds 
4549f26c7a78STrond Myklebust 	status = decode_attr_type(xdr, bitmap, &type);
4550f26c7a78STrond Myklebust 	if (status < 0)
45511da177e4SLinus Torvalds 		goto xdr_error;
4552409924e4STrond Myklebust 	fattr->mode = 0;
4553409924e4STrond Myklebust 	if (status != 0) {
4554409924e4STrond Myklebust 		fattr->mode |= nfs_type2fmt[type];
4555409924e4STrond Myklebust 		fattr->valid |= status;
4556409924e4STrond Myklebust 	}
45571da177e4SLinus Torvalds 
4558f26c7a78STrond Myklebust 	status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4559f26c7a78STrond Myklebust 	if (status < 0)
45601da177e4SLinus Torvalds 		goto xdr_error;
4561409924e4STrond Myklebust 	fattr->valid |= status;
4562f26c7a78STrond Myklebust 
4563f26c7a78STrond Myklebust 	status = decode_attr_size(xdr, bitmap, &fattr->size);
4564f26c7a78STrond Myklebust 	if (status < 0)
45651da177e4SLinus Torvalds 		goto xdr_error;
4566409924e4STrond Myklebust 	fattr->valid |= status;
4567f26c7a78STrond Myklebust 
4568f26c7a78STrond Myklebust 	status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4569f26c7a78STrond Myklebust 	if (status < 0)
45701da177e4SLinus Torvalds 		goto xdr_error;
4571409924e4STrond Myklebust 	fattr->valid |= status;
4572f26c7a78STrond Myklebust 
4573ee7b75fcSTrond Myklebust 	err = 0;
4574ee7b75fcSTrond Myklebust 	status = decode_attr_error(xdr, bitmap, &err);
4575ae42c70aSBryan Schumaker 	if (status < 0)
4576ae42c70aSBryan Schumaker 		goto xdr_error;
4577ae42c70aSBryan Schumaker 
4578ae42c70aSBryan Schumaker 	status = decode_attr_filehandle(xdr, bitmap, fh);
4579ae42c70aSBryan Schumaker 	if (status < 0)
4580ae42c70aSBryan Schumaker 		goto xdr_error;
4581ae42c70aSBryan Schumaker 
4582f26c7a78STrond Myklebust 	status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4583f26c7a78STrond Myklebust 	if (status < 0)
45841da177e4SLinus Torvalds 		goto xdr_error;
4585409924e4STrond Myklebust 	fattr->valid |= status;
4586f26c7a78STrond Myklebust 
45878b7e3f49STrond Myklebust 	status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4588f26c7a78STrond Myklebust 	if (status < 0)
4589683b57b4STrond Myklebust 		goto xdr_error;
4590409924e4STrond Myklebust 	fattr->valid |= status;
4591f26c7a78STrond Myklebust 
45921ca843a2SAndreas Gruenbacher 	status = -EIO;
45931ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[0]))
45941ca843a2SAndreas Gruenbacher 		goto xdr_error;
45951ca843a2SAndreas Gruenbacher 
4596f26c7a78STrond Myklebust 	status = decode_attr_mode(xdr, bitmap, &fmode);
4597f26c7a78STrond Myklebust 	if (status < 0)
45981da177e4SLinus Torvalds 		goto xdr_error;
4599409924e4STrond Myklebust 	if (status != 0) {
46001da177e4SLinus Torvalds 		fattr->mode |= fmode;
4601409924e4STrond Myklebust 		fattr->valid |= status;
4602409924e4STrond Myklebust 	}
4603f26c7a78STrond Myklebust 
4604f26c7a78STrond Myklebust 	status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4605f26c7a78STrond Myklebust 	if (status < 0)
46061da177e4SLinus Torvalds 		goto xdr_error;
4607409924e4STrond Myklebust 	fattr->valid |= status;
4608f26c7a78STrond Myklebust 
46096926afd1STrond Myklebust 	status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4610f26c7a78STrond Myklebust 	if (status < 0)
46111da177e4SLinus Torvalds 		goto xdr_error;
4612409924e4STrond Myklebust 	fattr->valid |= status;
4613f26c7a78STrond Myklebust 
46146926afd1STrond Myklebust 	status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4615f26c7a78STrond Myklebust 	if (status < 0)
46161da177e4SLinus Torvalds 		goto xdr_error;
4617409924e4STrond Myklebust 	fattr->valid |= status;
4618f26c7a78STrond Myklebust 
4619f26c7a78STrond Myklebust 	status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4620f26c7a78STrond Myklebust 	if (status < 0)
46211da177e4SLinus Torvalds 		goto xdr_error;
4622409924e4STrond Myklebust 	fattr->valid |= status;
4623f26c7a78STrond Myklebust 
4624f26c7a78STrond Myklebust 	status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4625f26c7a78STrond Myklebust 	if (status < 0)
46261da177e4SLinus Torvalds 		goto xdr_error;
4627409924e4STrond Myklebust 	fattr->valid |= status;
4628f26c7a78STrond Myklebust 
4629f26c7a78STrond Myklebust 	status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4630f26c7a78STrond Myklebust 	if (status < 0)
46311da177e4SLinus Torvalds 		goto xdr_error;
4632409924e4STrond Myklebust 	fattr->valid |= status;
4633f26c7a78STrond Myklebust 
4634f26c7a78STrond Myklebust 	status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4635f26c7a78STrond Myklebust 	if (status < 0)
46361da177e4SLinus Torvalds 		goto xdr_error;
4637409924e4STrond Myklebust 	fattr->valid |= status;
4638f26c7a78STrond Myklebust 
4639f26c7a78STrond Myklebust 	status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4640f26c7a78STrond Myklebust 	if (status < 0)
46411da177e4SLinus Torvalds 		goto xdr_error;
4642409924e4STrond Myklebust 	fattr->valid |= status;
4643f26c7a78STrond Myklebust 
464428331a46STrond Myklebust 	status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4645f26c7a78STrond Myklebust 	if (status < 0)
464699baf625SManoj Naik 		goto xdr_error;
4647409924e4STrond Myklebust 	fattr->valid |= status;
4648f26c7a78STrond Myklebust 
46491ca843a2SAndreas Gruenbacher 	status = -EIO;
46501ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[1]))
46511ca843a2SAndreas Gruenbacher 		goto xdr_error;
46521ca843a2SAndreas Gruenbacher 
465388034c3dSAndy Adamson 	status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
465488034c3dSAndy Adamson 	if (status < 0)
465588034c3dSAndy Adamson 		goto xdr_error;
465688034c3dSAndy Adamson 
4657aa9c2669SDavid Quigley 	if (label) {
4658aa9c2669SDavid Quigley 		status = decode_attr_security_label(xdr, bitmap, label);
4659aa9c2669SDavid Quigley 		if (status < 0)
4660aa9c2669SDavid Quigley 			goto xdr_error;
4661aa9c2669SDavid Quigley 		fattr->valid |= status;
4662aa9c2669SDavid Quigley 	}
4663aa9c2669SDavid Quigley 
4664ae42c70aSBryan Schumaker xdr_error:
4665ae42c70aSBryan Schumaker 	dprintk("%s: xdr returned %d\n", __func__, -status);
4666ae42c70aSBryan Schumaker 	return status;
4667ae42c70aSBryan Schumaker }
4668ae42c70aSBryan Schumaker 
4669ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
46708b7e3f49STrond Myklebust 		struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4671aa9c2669SDavid Quigley 		struct nfs4_label *label, const struct nfs_server *server)
4672ae42c70aSBryan Schumaker {
4673256e48bbSTrond Myklebust 	unsigned int savep;
4674ae42c70aSBryan Schumaker 	uint32_t attrlen,
4675dae100c2SFred Isaman 		 bitmap[3] = {0};
4676ae42c70aSBryan Schumaker 	int status;
4677ae42c70aSBryan Schumaker 
4678ae42c70aSBryan Schumaker 	status = decode_op_hdr(xdr, OP_GETATTR);
4679ae42c70aSBryan Schumaker 	if (status < 0)
4680ae42c70aSBryan Schumaker 		goto xdr_error;
4681ae42c70aSBryan Schumaker 
4682ae42c70aSBryan Schumaker 	status = decode_attr_bitmap(xdr, bitmap);
4683ae42c70aSBryan Schumaker 	if (status < 0)
4684ae42c70aSBryan Schumaker 		goto xdr_error;
4685ae42c70aSBryan Schumaker 
4686ae42c70aSBryan Schumaker 	status = decode_attr_length(xdr, &attrlen, &savep);
4687ae42c70aSBryan Schumaker 	if (status < 0)
4688ae42c70aSBryan Schumaker 		goto xdr_error;
4689ae42c70aSBryan Schumaker 
4690aa9c2669SDavid Quigley 	status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4691aa9c2669SDavid Quigley 					label, server);
4692ae42c70aSBryan Schumaker 	if (status < 0)
4693ae42c70aSBryan Schumaker 		goto xdr_error;
4694ae42c70aSBryan Schumaker 
4695f26c7a78STrond Myklebust 	status = verify_attr_len(xdr, savep, attrlen);
46961da177e4SLinus Torvalds xdr_error:
46973110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d\n", __func__, -status);
46981da177e4SLinus Torvalds 	return status;
46991da177e4SLinus Torvalds }
47001da177e4SLinus Torvalds 
4701aa9c2669SDavid Quigley static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4702aa9c2669SDavid Quigley 		struct nfs4_label *label, const struct nfs_server *server)
4703aa9c2669SDavid Quigley {
4704aa9c2669SDavid Quigley 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4705aa9c2669SDavid Quigley }
4706aa9c2669SDavid Quigley 
4707ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
47086926afd1STrond Myklebust 		const struct nfs_server *server)
4709ae42c70aSBryan Schumaker {
4710aa9c2669SDavid Quigley 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
4711ae42c70aSBryan Schumaker }
47121da177e4SLinus Torvalds 
4713504913fbSAndy Adamson /*
47143132e49eSJeff Layton  * Decode potentially multiple layout types.
4715504913fbSAndy Adamson  */
47163132e49eSJeff Layton static int decode_pnfs_layout_types(struct xdr_stream *xdr,
4717ca440c38SJeff Layton 				    struct nfs_fsinfo *fsinfo)
4718504913fbSAndy Adamson {
4719b8a8a0ddSTrond Myklebust 	__be32 *p;
4720ca440c38SJeff Layton 	uint32_t i;
4721504913fbSAndy Adamson 
4722504913fbSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
4723504913fbSAndy Adamson 	if (unlikely(!p))
4724eb72f484SChuck Lever 		return -EIO;
4725ca440c38SJeff Layton 	fsinfo->nlayouttypes = be32_to_cpup(p);
4726504913fbSAndy Adamson 
4727504913fbSAndy Adamson 	/* pNFS is not supported by the underlying file system */
4728ca440c38SJeff Layton 	if (fsinfo->nlayouttypes == 0)
4729504913fbSAndy Adamson 		return 0;
4730504913fbSAndy Adamson 
4731504913fbSAndy Adamson 	/* Decode and set first layout type, move xdr->p past unused types */
4732ca440c38SJeff Layton 	p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
4733504913fbSAndy Adamson 	if (unlikely(!p))
4734eb72f484SChuck Lever 		return -EIO;
4735ca440c38SJeff Layton 
4736ca440c38SJeff Layton 	/* If we get too many, then just cap it at the max */
4737ca440c38SJeff Layton 	if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4738ca440c38SJeff Layton 		printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4739ca440c38SJeff Layton 			__func__, fsinfo->nlayouttypes);
4740ca440c38SJeff Layton 		fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4741ca440c38SJeff Layton 	}
4742ca440c38SJeff Layton 
4743ca440c38SJeff Layton 	for(i = 0; i < fsinfo->nlayouttypes; ++i)
4744ca440c38SJeff Layton 		fsinfo->layouttype[i] = be32_to_cpup(p++);
4745504913fbSAndy Adamson 	return 0;
4746504913fbSAndy Adamson }
4747504913fbSAndy Adamson 
4748504913fbSAndy Adamson /*
4749504913fbSAndy Adamson  * The type of file system exported.
4750504913fbSAndy Adamson  * Note we must ensure that layouttype is set in any non-error case.
4751504913fbSAndy Adamson  */
4752504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4753ca440c38SJeff Layton 				struct nfs_fsinfo *fsinfo)
4754504913fbSAndy Adamson {
4755504913fbSAndy Adamson 	int status = 0;
4756504913fbSAndy Adamson 
4757504913fbSAndy Adamson 	dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4758504913fbSAndy Adamson 	if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4759504913fbSAndy Adamson 		return -EIO;
4760504913fbSAndy Adamson 	if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4761ca440c38SJeff Layton 		status = decode_pnfs_layout_types(xdr, fsinfo);
4762504913fbSAndy Adamson 		bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
47633132e49eSJeff Layton 	}
4764504913fbSAndy Adamson 	return status;
4765504913fbSAndy Adamson }
4766504913fbSAndy Adamson 
4767dae100c2SFred Isaman /*
4768dae100c2SFred Isaman  * The prefered block size for layout directed io
4769dae100c2SFred Isaman  */
4770dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4771dae100c2SFred Isaman 				      uint32_t *res)
4772dae100c2SFred Isaman {
4773dae100c2SFred Isaman 	__be32 *p;
4774dae100c2SFred Isaman 
4775dae100c2SFred Isaman 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4776dae100c2SFred Isaman 	*res = 0;
4777dae100c2SFred Isaman 	if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4778dae100c2SFred Isaman 		p = xdr_inline_decode(xdr, 4);
4779eb72f484SChuck Lever 		if (unlikely(!p))
4780dae100c2SFred Isaman 			return -EIO;
4781dae100c2SFred Isaman 		*res = be32_to_cpup(p);
4782dae100c2SFred Isaman 		bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4783dae100c2SFred Isaman 	}
4784dae100c2SFred Isaman 	return 0;
4785dae100c2SFred Isaman }
4786dae100c2SFred Isaman 
47872a92ee92SPeng Tao /*
47882a92ee92SPeng Tao  * The granularity of a CLONE operation.
47892a92ee92SPeng Tao  */
47902a92ee92SPeng Tao static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
47912a92ee92SPeng Tao 				     uint32_t *res)
47922a92ee92SPeng Tao {
47932a92ee92SPeng Tao 	__be32 *p;
47942a92ee92SPeng Tao 
47952a92ee92SPeng Tao 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
47962a92ee92SPeng Tao 	*res = 0;
47972a92ee92SPeng Tao 	if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
47982a92ee92SPeng Tao 		p = xdr_inline_decode(xdr, 4);
4799eb72f484SChuck Lever 		if (unlikely(!p))
48002a92ee92SPeng Tao 			return -EIO;
48012a92ee92SPeng Tao 		*res = be32_to_cpup(p);
48022a92ee92SPeng Tao 		bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
48032a92ee92SPeng Tao 	}
48042a92ee92SPeng Tao 	return 0;
48052a92ee92SPeng Tao }
48062a92ee92SPeng Tao 
48071da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
48081da177e4SLinus Torvalds {
4809256e48bbSTrond Myklebust 	unsigned int savep;
4810dae100c2SFred Isaman 	uint32_t attrlen, bitmap[3];
48111da177e4SLinus Torvalds 	int status;
48121da177e4SLinus Torvalds 
48131da177e4SLinus Torvalds 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
48141da177e4SLinus Torvalds 		goto xdr_error;
48151da177e4SLinus Torvalds 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
48161da177e4SLinus Torvalds 		goto xdr_error;
48171da177e4SLinus Torvalds 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
48181da177e4SLinus Torvalds 		goto xdr_error;
48191da177e4SLinus Torvalds 
48201da177e4SLinus Torvalds 	fsinfo->rtmult = fsinfo->wtmult = 512;	/* ??? */
48211da177e4SLinus Torvalds 
48221da177e4SLinus Torvalds 	if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
48231da177e4SLinus Torvalds 		goto xdr_error;
48241da177e4SLinus Torvalds 	if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
48251da177e4SLinus Torvalds 		goto xdr_error;
48261da177e4SLinus Torvalds 	if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
48271da177e4SLinus Torvalds 		goto xdr_error;
48281da177e4SLinus Torvalds 	fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
48291da177e4SLinus Torvalds 	if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
48301da177e4SLinus Torvalds 		goto xdr_error;
48311da177e4SLinus Torvalds 	fsinfo->wtpref = fsinfo->wtmax;
48321ca843a2SAndreas Gruenbacher 
48331ca843a2SAndreas Gruenbacher 	status = -EIO;
48341ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[0]))
48351ca843a2SAndreas Gruenbacher 		goto xdr_error;
48361ca843a2SAndreas Gruenbacher 
483755b6e774SRicardo Labiaga 	status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
483855b6e774SRicardo Labiaga 	if (status != 0)
483955b6e774SRicardo Labiaga 		goto xdr_error;
4840ca440c38SJeff Layton 	status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
4841504913fbSAndy Adamson 	if (status != 0)
4842504913fbSAndy Adamson 		goto xdr_error;
48431ca843a2SAndreas Gruenbacher 
48441ca843a2SAndreas Gruenbacher 	status = -EIO;
48451ca843a2SAndreas Gruenbacher 	if (unlikely(bitmap[1]))
48461ca843a2SAndreas Gruenbacher 		goto xdr_error;
48471ca843a2SAndreas Gruenbacher 
4848dae100c2SFred Isaman 	status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4849dae100c2SFred Isaman 	if (status)
4850dae100c2SFred Isaman 		goto xdr_error;
48512a92ee92SPeng Tao 	status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
48522a92ee92SPeng Tao 	if (status)
48532a92ee92SPeng Tao 		goto xdr_error;
48541da177e4SLinus Torvalds 
48551da177e4SLinus Torvalds 	status = verify_attr_len(xdr, savep, attrlen);
48561da177e4SLinus Torvalds xdr_error:
48573110ff80SHarvey Harrison 	dprintk("%s: xdr returned %d!\n", __func__, -status);
48581da177e4SLinus Torvalds 	return status;
48591da177e4SLinus Torvalds }
48601da177e4SLinus Torvalds 
48611da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
48621da177e4SLinus Torvalds {
48638687b63aSAl Viro 	__be32 *p;
48641da177e4SLinus Torvalds 	uint32_t len;
48651da177e4SLinus Torvalds 	int status;
48661da177e4SLinus Torvalds 
48679936781dSTrond Myklebust 	/* Zero handle first to allow comparisons */
48689936781dSTrond Myklebust 	memset(fh, 0, sizeof(*fh));
48699936781dSTrond Myklebust 
48701da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_GETFH);
48711da177e4SLinus Torvalds 	if (status)
48721da177e4SLinus Torvalds 		return status;
48731da177e4SLinus Torvalds 
4874c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
4875c0eae66eSBenny Halevy 	if (unlikely(!p))
4876eb72f484SChuck Lever 		return -EIO;
4877cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
48781da177e4SLinus Torvalds 	if (len > NFS4_FHSIZE)
48791da177e4SLinus Torvalds 		return -EIO;
48801da177e4SLinus Torvalds 	fh->size = len;
4881c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, len);
4882c0eae66eSBenny Halevy 	if (unlikely(!p))
4883eb72f484SChuck Lever 		return -EIO;
488499398d06SBenny Halevy 	memcpy(fh->data, p, len);
48851da177e4SLinus Torvalds 	return 0;
48861da177e4SLinus Torvalds }
48871da177e4SLinus Torvalds 
48881da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
48891da177e4SLinus Torvalds {
48901da177e4SLinus Torvalds 	int status;
48911da177e4SLinus Torvalds 
48921da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LINK);
48931da177e4SLinus Torvalds 	if (status)
48941da177e4SLinus Torvalds 		return status;
48951da177e4SLinus Torvalds 	return decode_change_info(xdr, cinfo);
48961da177e4SLinus Torvalds }
48971da177e4SLinus Torvalds 
48981da177e4SLinus Torvalds /*
48991da177e4SLinus Torvalds  * We create the owner, so we know a proper owner.id length is 4.
49001da177e4SLinus Torvalds  */
4901911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
49021da177e4SLinus Torvalds {
4903911d1aafSTrond Myklebust 	uint64_t offset, length, clientid;
49048687b63aSAl Viro 	__be32 *p;
4905911d1aafSTrond Myklebust 	uint32_t namelen, type;
49061da177e4SLinus Torvalds 
4907babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4908c0eae66eSBenny Halevy 	if (unlikely(!p))
4909eb72f484SChuck Lever 		return -EIO;
4910babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
49113ceb4dbbSBenny Halevy 	p = xdr_decode_hyper(p, &length);
4912babddc72SBryan Schumaker 	type = be32_to_cpup(p++); /* 4 byte read */
4913babddc72SBryan Schumaker 	if (fl != NULL) { /* manipulate file lock */
4914911d1aafSTrond Myklebust 		fl->fl_start = (loff_t)offset;
4915911d1aafSTrond Myklebust 		fl->fl_end = fl->fl_start + (loff_t)length - 1;
4916911d1aafSTrond Myklebust 		if (length == ~(uint64_t)0)
4917911d1aafSTrond Myklebust 			fl->fl_end = OFFSET_MAX;
4918911d1aafSTrond Myklebust 		fl->fl_type = F_WRLCK;
4919911d1aafSTrond Myklebust 		if (type & 1)
4920911d1aafSTrond Myklebust 			fl->fl_type = F_RDLCK;
4921911d1aafSTrond Myklebust 		fl->fl_pid = 0;
4922911d1aafSTrond Myklebust 	}
4923babddc72SBryan Schumaker 	p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4924babddc72SBryan Schumaker 	namelen = be32_to_cpup(p); /* read 4 bytes */  /* have read all 32 bytes now */
4925babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, namelen); /* variable size field */
4926eb72f484SChuck Lever 	if (likely(!p))
4927c0eae66eSBenny Halevy 		return -EIO;
4928eb72f484SChuck Lever 	return -NFS4ERR_DENIED;
49291da177e4SLinus Torvalds }
49301da177e4SLinus Torvalds 
4931911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
49321da177e4SLinus Torvalds {
49331da177e4SLinus Torvalds 	int status;
49341da177e4SLinus Torvalds 
49351da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCK);
4936c1d51931STrond Myklebust 	if (status == -EIO)
4937c1d51931STrond Myklebust 		goto out;
49381da177e4SLinus Torvalds 	if (status == 0) {
493993b717fdSTrond Myklebust 		status = decode_lock_stateid(xdr, &res->stateid);
494007d30434SBenny Halevy 		if (unlikely(status))
494107d30434SBenny Halevy 			goto out;
49421da177e4SLinus Torvalds 	} else if (status == -NFS4ERR_DENIED)
4943c1d51931STrond Myklebust 		status = decode_lock_denied(xdr, NULL);
4944c1d51931STrond Myklebust 	if (res->open_seqid != NULL)
4945c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->open_seqid);
4946c1d51931STrond Myklebust 	nfs_increment_lock_seqid(status, res->lock_seqid);
4947c1d51931STrond Myklebust out:
49481da177e4SLinus Torvalds 	return status;
49491da177e4SLinus Torvalds }
49501da177e4SLinus Torvalds 
4951911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
49521da177e4SLinus Torvalds {
49531da177e4SLinus Torvalds 	int status;
49541da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKT);
49551da177e4SLinus Torvalds 	if (status == -NFS4ERR_DENIED)
4956911d1aafSTrond Myklebust 		return decode_lock_denied(xdr, res->denied);
49571da177e4SLinus Torvalds 	return status;
49581da177e4SLinus Torvalds }
49591da177e4SLinus Torvalds 
4960911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
49611da177e4SLinus Torvalds {
49621da177e4SLinus Torvalds 	int status;
49631da177e4SLinus Torvalds 
49641da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_LOCKU);
4965c1d51931STrond Myklebust 	if (status != -EIO)
4966c1d51931STrond Myklebust 		nfs_increment_lock_seqid(status, res->seqid);
496707d30434SBenny Halevy 	if (status == 0)
496893b717fdSTrond Myklebust 		status = decode_lock_stateid(xdr, &res->stateid);
49691da177e4SLinus Torvalds 	return status;
49701da177e4SLinus Torvalds }
49711da177e4SLinus Torvalds 
4972d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr)
4973d3c7b7ccSTrond Myklebust {
4974d3c7b7ccSTrond Myklebust 	return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4975d3c7b7ccSTrond Myklebust }
4976d3c7b7ccSTrond Myklebust 
49771da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr)
49781da177e4SLinus Torvalds {
49791da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_LOOKUP);
49801da177e4SLinus Torvalds }
49811da177e4SLinus Torvalds 
49825b5faaf6SJeff Layton static int decode_lookupp(struct xdr_stream *xdr)
49835b5faaf6SJeff Layton {
49845b5faaf6SJeff Layton 	return decode_op_hdr(xdr, OP_LOOKUPP);
49855b5faaf6SJeff Layton }
49865b5faaf6SJeff Layton 
49871da177e4SLinus Torvalds /* This is too sick! */
49887d160a6cSTrond Myklebust static int decode_space_limit(struct xdr_stream *xdr,
49897d160a6cSTrond Myklebust 		unsigned long *pagemod_limit)
49901da177e4SLinus Torvalds {
49918687b63aSAl Viro 	__be32 *p;
49921da177e4SLinus Torvalds 	uint32_t limit_type, nblocks, blocksize;
49937d160a6cSTrond Myklebust 	u64 maxsize = 0;
49941da177e4SLinus Torvalds 
4995c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
4996c0eae66eSBenny Halevy 	if (unlikely(!p))
4997eb72f484SChuck Lever 		return -EIO;
49986f723f77SBenny Halevy 	limit_type = be32_to_cpup(p++);
49991da177e4SLinus Torvalds 	switch (limit_type) {
50007d160a6cSTrond Myklebust 	case NFS4_LIMIT_SIZE:
50017d160a6cSTrond Myklebust 		xdr_decode_hyper(p, &maxsize);
50021da177e4SLinus Torvalds 		break;
50037d160a6cSTrond Myklebust 	case NFS4_LIMIT_BLOCKS:
50046f723f77SBenny Halevy 		nblocks = be32_to_cpup(p++);
5005cccddf4fSBenny Halevy 		blocksize = be32_to_cpup(p);
50067d160a6cSTrond Myklebust 		maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
50071da177e4SLinus Torvalds 	}
500809cbfeafSKirill A. Shutemov 	maxsize >>= PAGE_SHIFT;
50097d160a6cSTrond Myklebust 	*pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
50101da177e4SLinus Torvalds 	return 0;
50111da177e4SLinus Torvalds }
50121da177e4SLinus Torvalds 
50136ae37339STrond Myklebust static int decode_rw_delegation(struct xdr_stream *xdr,
50146ae37339STrond Myklebust 		uint32_t delegation_type,
50156ae37339STrond Myklebust 		struct nfs_openres *res)
50161da177e4SLinus Torvalds {
50178687b63aSAl Viro 	__be32 *p;
501807d30434SBenny Halevy 	int status;
50191da177e4SLinus Torvalds 
502093b717fdSTrond Myklebust 	status = decode_delegation_stateid(xdr, &res->delegation);
502107d30434SBenny Halevy 	if (unlikely(status))
502207d30434SBenny Halevy 		return status;
5023c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5024c0eae66eSBenny Halevy 	if (unlikely(!p))
5025eb72f484SChuck Lever 		return -EIO;
5026cccddf4fSBenny Halevy 	res->do_recall = be32_to_cpup(p);
502705d564feSAndy Adamson 
50281da177e4SLinus Torvalds 	switch (delegation_type) {
50291da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_READ:
50301da177e4SLinus Torvalds 		res->delegation_type = FMODE_READ;
50311da177e4SLinus Torvalds 		break;
50321da177e4SLinus Torvalds 	case NFS4_OPEN_DELEGATE_WRITE:
50331da177e4SLinus Torvalds 		res->delegation_type = FMODE_WRITE|FMODE_READ;
50347d160a6cSTrond Myklebust 		if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
50351da177e4SLinus Torvalds 				return -EIO;
50361da177e4SLinus Torvalds 	}
50371bbe60ffSTrond Myklebust 	return decode_ace(xdr, NULL);
50381da177e4SLinus Torvalds }
50391da177e4SLinus Torvalds 
50406ae37339STrond Myklebust static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
50416ae37339STrond Myklebust {
50426ae37339STrond Myklebust 	__be32 *p;
50436ae37339STrond Myklebust 	uint32_t why_no_delegation;
50446ae37339STrond Myklebust 
50456ae37339STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
50466ae37339STrond Myklebust 	if (unlikely(!p))
5047eb72f484SChuck Lever 		return -EIO;
50486ae37339STrond Myklebust 	why_no_delegation = be32_to_cpup(p);
50496ae37339STrond Myklebust 	switch (why_no_delegation) {
50506ae37339STrond Myklebust 		case WND4_CONTENTION:
50516ae37339STrond Myklebust 		case WND4_RESOURCE:
50526ae37339STrond Myklebust 			xdr_inline_decode(xdr, 4);
50536ae37339STrond Myklebust 			/* Ignore for now */
50546ae37339STrond Myklebust 	}
50556ae37339STrond Myklebust 	return 0;
50566ae37339STrond Myklebust }
50576ae37339STrond Myklebust 
50586ae37339STrond Myklebust static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
50596ae37339STrond Myklebust {
50606ae37339STrond Myklebust 	__be32 *p;
50616ae37339STrond Myklebust 	uint32_t delegation_type;
50626ae37339STrond Myklebust 
50636ae37339STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
50646ae37339STrond Myklebust 	if (unlikely(!p))
5065eb72f484SChuck Lever 		return -EIO;
50666ae37339STrond Myklebust 	delegation_type = be32_to_cpup(p);
50676ae37339STrond Myklebust 	res->delegation_type = 0;
50686ae37339STrond Myklebust 	switch (delegation_type) {
50696ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_NONE:
50706ae37339STrond Myklebust 		return 0;
50716ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_READ:
50726ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_WRITE:
50736ae37339STrond Myklebust 		return decode_rw_delegation(xdr, delegation_type, res);
50746ae37339STrond Myklebust 	case NFS4_OPEN_DELEGATE_NONE_EXT:
50756ae37339STrond Myklebust 		return decode_no_delegation(xdr, res);
50766ae37339STrond Myklebust 	}
50776ae37339STrond Myklebust 	return -EIO;
50786ae37339STrond Myklebust }
50796ae37339STrond Myklebust 
50801da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
50811da177e4SLinus Torvalds {
50828687b63aSAl Viro 	__be32 *p;
5083aa53ed54SJeff Layton 	uint32_t savewords, bmlen, i;
50841da177e4SLinus Torvalds 	int status;
50851da177e4SLinus Torvalds 
5086c7848f69STrond Myklebust 	if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5087c7848f69STrond Myklebust 		return status;
5088c1d51931STrond Myklebust 	nfs_increment_open_seqid(status, res->seqid);
5089c7848f69STrond Myklebust 	if (status)
5090c7848f69STrond Myklebust 		return status;
509193b717fdSTrond Myklebust 	status = decode_open_stateid(xdr, &res->stateid);
509207d30434SBenny Halevy 	if (unlikely(status))
50931da177e4SLinus Torvalds 		return status;
50941da177e4SLinus Torvalds 
50951da177e4SLinus Torvalds 	decode_change_info(xdr, &res->cinfo);
50961da177e4SLinus Torvalds 
5097c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5098c0eae66eSBenny Halevy 	if (unlikely(!p))
5099eb72f484SChuck Lever 		return -EIO;
51006f723f77SBenny Halevy 	res->rflags = be32_to_cpup(p++);
5101cccddf4fSBenny Halevy 	bmlen = be32_to_cpup(p);
51021da177e4SLinus Torvalds 	if (bmlen > 10)
51031da177e4SLinus Torvalds 		goto xdr_error;
51041da177e4SLinus Torvalds 
5105c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, bmlen << 2);
5106c0eae66eSBenny Halevy 	if (unlikely(!p))
5107eb72f484SChuck Lever 		return -EIO;
5108aa53ed54SJeff Layton 	savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5109aa53ed54SJeff Layton 	for (i = 0; i < savewords; ++i)
51106f723f77SBenny Halevy 		res->attrset[i] = be32_to_cpup(p++);
5111aa53ed54SJeff Layton 	for (; i < NFS4_BITMAP_SIZE; i++)
5112aa53ed54SJeff Layton 		res->attrset[i] = 0;
5113aa53ed54SJeff Layton 
51141da177e4SLinus Torvalds 	return decode_delegation(xdr, res);
51151da177e4SLinus Torvalds xdr_error:
51163110ff80SHarvey Harrison 	dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
51171da177e4SLinus Torvalds 	return -EIO;
51181da177e4SLinus Torvalds }
51191da177e4SLinus Torvalds 
51201da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
51211da177e4SLinus Torvalds {
51221da177e4SLinus Torvalds 	int status;
51231da177e4SLinus Torvalds 
51241da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5125c1d51931STrond Myklebust 	if (status != -EIO)
5126c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
512707d30434SBenny Halevy 	if (!status)
512893b717fdSTrond Myklebust 		status = decode_open_stateid(xdr, &res->stateid);
51291da177e4SLinus Torvalds 	return status;
51301da177e4SLinus Torvalds }
51311da177e4SLinus Torvalds 
51321da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
51331da177e4SLinus Torvalds {
51341da177e4SLinus Torvalds 	int status;
51351da177e4SLinus Torvalds 
51361da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5137c1d51931STrond Myklebust 	if (status != -EIO)
5138c1d51931STrond Myklebust 		nfs_increment_open_seqid(status, res->seqid);
513907d30434SBenny Halevy 	if (!status)
514093b717fdSTrond Myklebust 		status = decode_open_stateid(xdr, &res->stateid);
51411da177e4SLinus Torvalds 	return status;
51421da177e4SLinus Torvalds }
51431da177e4SLinus Torvalds 
51441da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr)
51451da177e4SLinus Torvalds {
51461da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTFH);
51471da177e4SLinus Torvalds }
51481da177e4SLinus Torvalds 
51491da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr)
51501da177e4SLinus Torvalds {
51511da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_PUTROOTFH);
51521da177e4SLinus Torvalds }
51531da177e4SLinus Torvalds 
51549137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
51559137bdf3SAnna Schumaker 		       struct nfs_pgio_res *res)
51561da177e4SLinus Torvalds {
51578687b63aSAl Viro 	__be32 *p;
515864bd577eSTrond Myklebust 	uint32_t count, eof, recvd;
51591da177e4SLinus Torvalds 	int status;
51601da177e4SLinus Torvalds 
51611da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READ);
51621da177e4SLinus Torvalds 	if (status)
51631da177e4SLinus Torvalds 		return status;
5164c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5165c0eae66eSBenny Halevy 	if (unlikely(!p))
5166eb72f484SChuck Lever 		return -EIO;
51676f723f77SBenny Halevy 	eof = be32_to_cpup(p++);
5168cccddf4fSBenny Halevy 	count = be32_to_cpup(p);
516964bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, count);
51701da177e4SLinus Torvalds 	if (count > recvd) {
5171fe82a183SChuck Lever 		dprintk("NFS: server cheating in read reply: "
51721da177e4SLinus Torvalds 				"count %u > recvd %u\n", count, recvd);
51731da177e4SLinus Torvalds 		count = recvd;
51741da177e4SLinus Torvalds 		eof = 0;
51751da177e4SLinus Torvalds 	}
51761da177e4SLinus Torvalds 	res->eof = eof;
51771da177e4SLinus Torvalds 	res->count = count;
51781da177e4SLinus Torvalds 	return 0;
51791da177e4SLinus Torvalds }
51801da177e4SLinus Torvalds 
51811da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
51821da177e4SLinus Torvalds {
5183bcecff77SChuck Lever 	int		status;
5184cd93710eSChuck Lever 	__be32		verf[2];
51851da177e4SLinus Torvalds 
51861da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READDIR);
5187db942bbdSBenny Halevy 	if (!status)
5188db942bbdSBenny Halevy 		status = decode_verifier(xdr, readdir->verifier.data);
5189db942bbdSBenny Halevy 	if (unlikely(status))
51901da177e4SLinus Torvalds 		return status;
5191cd93710eSChuck Lever 	memcpy(verf, readdir->verifier.data, sizeof(verf));
519244109241SFred Isaman 	dprintk("%s: verifier = %08x:%08x\n",
5193cd93710eSChuck Lever 			__func__, verf[0], verf[1]);
519464bd577eSTrond Myklebust 	return xdr_read_pages(xdr, xdr->buf->page_len);
51951da177e4SLinus Torvalds }
51961da177e4SLinus Torvalds 
51971da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
51981da177e4SLinus Torvalds {
51991da177e4SLinus Torvalds 	struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5200bcecff77SChuck Lever 	u32 len, recvd;
52018687b63aSAl Viro 	__be32 *p;
52021da177e4SLinus Torvalds 	int status;
52031da177e4SLinus Torvalds 
52041da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_READLINK);
52051da177e4SLinus Torvalds 	if (status)
52061da177e4SLinus Torvalds 		return status;
52071da177e4SLinus Torvalds 
52081da177e4SLinus Torvalds 	/* Convert length of symlink */
5209c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5210c0eae66eSBenny Halevy 	if (unlikely(!p))
5211eb72f484SChuck Lever 		return -EIO;
5212cccddf4fSBenny Halevy 	len = be32_to_cpup(p);
52131da177e4SLinus Torvalds 	if (len >= rcvbuf->page_len || len <= 0) {
5214fe82a183SChuck Lever 		dprintk("nfs: server returned giant symlink!\n");
52151da177e4SLinus Torvalds 		return -ENAMETOOLONG;
52161da177e4SLinus Torvalds 	}
521764bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, len);
52181da177e4SLinus Torvalds 	if (recvd < len) {
5219fe82a183SChuck Lever 		dprintk("NFS: server cheating in readlink reply: "
52201da177e4SLinus Torvalds 				"count %u > recvd %u\n", len, recvd);
52211da177e4SLinus Torvalds 		return -EIO;
52221da177e4SLinus Torvalds 	}
52231da177e4SLinus Torvalds 	/*
52241da177e4SLinus Torvalds 	 * The XDR encode routine has set things up so that
52251da177e4SLinus Torvalds 	 * the link text will be copied directly into the
52261da177e4SLinus Torvalds 	 * buffer.  We just have to do overflow-checking,
52271da177e4SLinus Torvalds 	 * and and null-terminate the text (the VFS expects
52281da177e4SLinus Torvalds 	 * null-termination).
52291da177e4SLinus Torvalds 	 */
5230b4687da7SChuck Lever 	xdr_terminate_string(rcvbuf, len);
52311da177e4SLinus Torvalds 	return 0;
52321da177e4SLinus Torvalds }
52331da177e4SLinus Torvalds 
52341da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
52351da177e4SLinus Torvalds {
52361da177e4SLinus Torvalds 	int status;
52371da177e4SLinus Torvalds 
52381da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_REMOVE);
52391da177e4SLinus Torvalds 	if (status)
52401da177e4SLinus Torvalds 		goto out;
52411da177e4SLinus Torvalds 	status = decode_change_info(xdr, cinfo);
52421da177e4SLinus Torvalds out:
52431da177e4SLinus Torvalds 	return status;
52441da177e4SLinus Torvalds }
52451da177e4SLinus Torvalds 
52461da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
52471da177e4SLinus Torvalds 	      struct nfs4_change_info *new_cinfo)
52481da177e4SLinus Torvalds {
52491da177e4SLinus Torvalds 	int status;
52501da177e4SLinus Torvalds 
52511da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_RENAME);
52521da177e4SLinus Torvalds 	if (status)
52531da177e4SLinus Torvalds 		goto out;
52541da177e4SLinus Torvalds 	if ((status = decode_change_info(xdr, old_cinfo)))
52551da177e4SLinus Torvalds 		goto out;
52561da177e4SLinus Torvalds 	status = decode_change_info(xdr, new_cinfo);
52571da177e4SLinus Torvalds out:
52581da177e4SLinus Torvalds 	return status;
52591da177e4SLinus Torvalds }
52601da177e4SLinus Torvalds 
52611da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr)
52621da177e4SLinus Torvalds {
52631da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_RENEW);
52641da177e4SLinus Torvalds }
52651da177e4SLinus Torvalds 
526656ae19f3STrond Myklebust static int
526756ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr)
526856ae19f3STrond Myklebust {
526956ae19f3STrond Myklebust 	return decode_op_hdr(xdr, OP_RESTOREFH);
527056ae19f3STrond Myklebust }
527156ae19f3STrond Myklebust 
5272029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5273bf118a34SAndy Adamson 			 struct nfs_getaclres *res)
5274029d105eSJ. Bruce Fields {
5275256e48bbSTrond Myklebust 	unsigned int savep;
5276029d105eSJ. Bruce Fields 	uint32_t attrlen,
5277dae100c2SFred Isaman 		 bitmap[3] = {0};
5278029d105eSJ. Bruce Fields 	int status;
5279cff298c7STrond Myklebust 	unsigned int pg_offset;
5280029d105eSJ. Bruce Fields 
5281bf118a34SAndy Adamson 	res->acl_len = 0;
5282029d105eSJ. Bruce Fields 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5283029d105eSJ. Bruce Fields 		goto out;
52845a006899SSachin Prabhu 
5285519d3959STrond Myklebust 	xdr_enter_page(xdr, xdr->buf->page_len);
5286519d3959STrond Myklebust 
5287cff298c7STrond Myklebust 	/* Calculate the offset of the page data */
5288cff298c7STrond Myklebust 	pg_offset = xdr->buf->head[0].iov_len;
52895a006899SSachin Prabhu 
5290029d105eSJ. Bruce Fields 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5291029d105eSJ. Bruce Fields 		goto out;
5292029d105eSJ. Bruce Fields 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5293029d105eSJ. Bruce Fields 		goto out;
5294029d105eSJ. Bruce Fields 
5295029d105eSJ. Bruce Fields 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5296029d105eSJ. Bruce Fields 		return -EIO;
5297029d105eSJ. Bruce Fields 	if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5298029d105eSJ. Bruce Fields 
5299bf118a34SAndy Adamson 		/* The bitmap (xdr len + bitmaps) and the attr xdr len words
5300bf118a34SAndy Adamson 		 * are stored with the acl data to handle the problem of
5301bf118a34SAndy Adamson 		 * variable length bitmaps.*/
5302cff298c7STrond Myklebust 		res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
5303519d3959STrond Myklebust 		res->acl_len = attrlen;
53041f1ea6c2STrond Myklebust 
53051f1ea6c2STrond Myklebust 		/* Check for receive buffer overflow */
53061f1ea6c2STrond Myklebust 		if (res->acl_len > (xdr->nwords << 2) ||
53071f1ea6c2STrond Myklebust 		    res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
53081f1ea6c2STrond Myklebust 			res->acl_flags |= NFS4_ACL_TRUNC;
5309519d3959STrond Myklebust 			dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
5310cff298c7STrond Myklebust 					attrlen, xdr->nwords << 2);
5311029d105eSJ. Bruce Fields 		}
53128c233cf9SJ. Bruce Fields 	} else
53138c233cf9SJ. Bruce Fields 		status = -EOPNOTSUPP;
5314029d105eSJ. Bruce Fields 
5315029d105eSJ. Bruce Fields out:
5316029d105eSJ. Bruce Fields 	return status;
5317029d105eSJ. Bruce Fields }
5318029d105eSJ. Bruce Fields 
53191da177e4SLinus Torvalds static int
53201da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr)
53211da177e4SLinus Torvalds {
53221da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SAVEFH);
53231da177e4SLinus Torvalds }
53241da177e4SLinus Torvalds 
53259e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr)
53261da177e4SLinus Torvalds {
53271da177e4SLinus Torvalds 	int status;
53281da177e4SLinus Torvalds 
53291da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_SETATTR);
53301da177e4SLinus Torvalds 	if (status)
53311da177e4SLinus Torvalds 		return status;
533237c88763STrond Myklebust 	if (decode_bitmap4(xdr, NULL, 0) >= 0)
53331da177e4SLinus Torvalds 		return 0;
5334c0eae66eSBenny Halevy 	return -EIO;
53351da177e4SLinus Torvalds }
53361da177e4SLinus Torvalds 
5337bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
53381da177e4SLinus Torvalds {
53398687b63aSAl Viro 	__be32 *p;
53401da177e4SLinus Torvalds 	uint32_t opnum;
53411da177e4SLinus Torvalds 	int32_t nfserr;
53421da177e4SLinus Torvalds 
5343c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5344c0eae66eSBenny Halevy 	if (unlikely(!p))
5345eb72f484SChuck Lever 		return -EIO;
53466f723f77SBenny Halevy 	opnum = be32_to_cpup(p++);
53471da177e4SLinus Torvalds 	if (opnum != OP_SETCLIENTID) {
5348fe82a183SChuck Lever 		dprintk("nfs: decode_setclientid: Server returned operation"
53491da177e4SLinus Torvalds 			" %d\n", opnum);
53501da177e4SLinus Torvalds 		return -EIO;
53511da177e4SLinus Torvalds 	}
5352cccddf4fSBenny Halevy 	nfserr = be32_to_cpup(p);
53531da177e4SLinus Torvalds 	if (nfserr == NFS_OK) {
5354c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5355c0eae66eSBenny Halevy 		if (unlikely(!p))
5356eb72f484SChuck Lever 			return -EIO;
5357bb8b27e5STrond Myklebust 		p = xdr_decode_hyper(p, &res->clientid);
5358bb8b27e5STrond Myklebust 		memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
53591da177e4SLinus Torvalds 	} else if (nfserr == NFSERR_CLID_INUSE) {
53601da177e4SLinus Torvalds 		uint32_t len;
53611da177e4SLinus Torvalds 
53621da177e4SLinus Torvalds 		/* skip netid string */
5363c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5364c0eae66eSBenny Halevy 		if (unlikely(!p))
5365eb72f484SChuck Lever 			return -EIO;
5366cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5367c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5368c0eae66eSBenny Halevy 		if (unlikely(!p))
5369eb72f484SChuck Lever 			return -EIO;
53701da177e4SLinus Torvalds 
53711da177e4SLinus Torvalds 		/* skip uaddr string */
5372c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4);
5373c0eae66eSBenny Halevy 		if (unlikely(!p))
5374eb72f484SChuck Lever 			return -EIO;
5375cccddf4fSBenny Halevy 		len = be32_to_cpup(p);
5376c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, len);
5377c0eae66eSBenny Halevy 		if (unlikely(!p))
5378eb72f484SChuck Lever 			return -EIO;
53791da177e4SLinus Torvalds 		return -NFSERR_CLID_INUSE;
53801da177e4SLinus Torvalds 	} else
5381856dff3dSBenny Halevy 		return nfs4_stat_to_errno(nfserr);
53821da177e4SLinus Torvalds 
53831da177e4SLinus Torvalds 	return 0;
53841da177e4SLinus Torvalds }
53851da177e4SLinus Torvalds 
53861da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr)
53871da177e4SLinus Torvalds {
53881da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
53891da177e4SLinus Torvalds }
53901da177e4SLinus Torvalds 
53919137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
53921da177e4SLinus Torvalds {
53938687b63aSAl Viro 	__be32 *p;
53941da177e4SLinus Torvalds 	int status;
53951da177e4SLinus Torvalds 
53961da177e4SLinus Torvalds 	status = decode_op_hdr(xdr, OP_WRITE);
53971da177e4SLinus Torvalds 	if (status)
53981da177e4SLinus Torvalds 		return status;
53991da177e4SLinus Torvalds 
54002f2c63bcSTrond Myklebust 	p = xdr_inline_decode(xdr, 8);
5401c0eae66eSBenny Halevy 	if (unlikely(!p))
5402eb72f484SChuck Lever 		return -EIO;
54036f723f77SBenny Halevy 	res->count = be32_to_cpup(p++);
54046f723f77SBenny Halevy 	res->verf->committed = be32_to_cpup(p++);
54052f2c63bcSTrond Myklebust 	return decode_write_verifier(xdr, &res->verf->verifier);
54061da177e4SLinus Torvalds }
54071da177e4SLinus Torvalds 
54081da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr)
54091da177e4SLinus Torvalds {
54101da177e4SLinus Torvalds 	return decode_op_hdr(xdr, OP_DELEGRETURN);
54111da177e4SLinus Torvalds }
54121da177e4SLinus Torvalds 
5413fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr,
5414fb15b26fSChuck Lever 			      struct nfs4_secinfo4 *flavor)
54155a5ea0d4SBryan Schumaker {
5416fb15b26fSChuck Lever 	u32 oid_len;
54175a5ea0d4SBryan Schumaker 	__be32 *p;
54185a5ea0d4SBryan Schumaker 
54195a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
54205a5ea0d4SBryan Schumaker 	if (unlikely(!p))
5421eb72f484SChuck Lever 		return -EIO;
5422fb15b26fSChuck Lever 	oid_len = be32_to_cpup(p);
5423fb15b26fSChuck Lever 	if (oid_len > GSS_OID_MAX_LEN)
5424eb72f484SChuck Lever 		return -EINVAL;
54255a5ea0d4SBryan Schumaker 
5426fb15b26fSChuck Lever 	p = xdr_inline_decode(xdr, oid_len);
54275a5ea0d4SBryan Schumaker 	if (unlikely(!p))
5428eb72f484SChuck Lever 		return -EIO;
5429fb15b26fSChuck Lever 	memcpy(flavor->flavor_info.oid.data, p, oid_len);
5430fb15b26fSChuck Lever 	flavor->flavor_info.oid.len = oid_len;
54315a5ea0d4SBryan Schumaker 
54325a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 8);
54335a5ea0d4SBryan Schumaker 	if (unlikely(!p))
5434eb72f484SChuck Lever 		return -EIO;
5435fb15b26fSChuck Lever 	flavor->flavor_info.qop = be32_to_cpup(p++);
5436fb15b26fSChuck Lever 	flavor->flavor_info.service = be32_to_cpup(p);
54375a5ea0d4SBryan Schumaker 
54385a5ea0d4SBryan Schumaker 	return 0;
54395a5ea0d4SBryan Schumaker }
54405a5ea0d4SBryan Schumaker 
544131e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
54425a5ea0d4SBryan Schumaker {
5443fb15b26fSChuck Lever 	struct nfs4_secinfo4 *sec_flavor;
5444fb15b26fSChuck Lever 	unsigned int i, num_flavors;
54455a5ea0d4SBryan Schumaker 	int status;
54465a5ea0d4SBryan Schumaker 	__be32 *p;
54475a5ea0d4SBryan Schumaker 
54485a5ea0d4SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
54495a5ea0d4SBryan Schumaker 	if (unlikely(!p))
5450eb72f484SChuck Lever 		return -EIO;
54515a5ea0d4SBryan Schumaker 
5452c3dfc280SBryan Schumaker 	res->flavors->num_flavors = 0;
5453c3dfc280SBryan Schumaker 	num_flavors = be32_to_cpup(p);
5454c3dfc280SBryan Schumaker 
5455c3dfc280SBryan Schumaker 	for (i = 0; i < num_flavors; i++) {
54565a5ea0d4SBryan Schumaker 		sec_flavor = &res->flavors->flavors[i];
5457c3dfc280SBryan Schumaker 		if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
54585a5ea0d4SBryan Schumaker 			break;
54595a5ea0d4SBryan Schumaker 
54605a5ea0d4SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
54615a5ea0d4SBryan Schumaker 		if (unlikely(!p))
5462eb72f484SChuck Lever 			return -EIO;
54635a5ea0d4SBryan Schumaker 		sec_flavor->flavor = be32_to_cpup(p);
54645a5ea0d4SBryan Schumaker 
54655a5ea0d4SBryan Schumaker 		if (sec_flavor->flavor == RPC_AUTH_GSS) {
5466613e901eSBryan Schumaker 			status = decode_secinfo_gss(xdr, sec_flavor);
5467613e901eSBryan Schumaker 			if (status)
5468613e901eSBryan Schumaker 				goto out;
54695a5ea0d4SBryan Schumaker 		}
5470c3dfc280SBryan Schumaker 		res->flavors->num_flavors++;
54715a5ea0d4SBryan Schumaker 	}
54725a5ea0d4SBryan Schumaker 
547331e4dda4SBryan Schumaker 	status = 0;
5474613e901eSBryan Schumaker out:
5475613e901eSBryan Schumaker 	return status;
54765a5ea0d4SBryan Schumaker }
54775a5ea0d4SBryan Schumaker 
547831e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
547931e4dda4SBryan Schumaker {
548031e4dda4SBryan Schumaker 	int status = decode_op_hdr(xdr, OP_SECINFO);
548131e4dda4SBryan Schumaker 	if (status)
548231e4dda4SBryan Schumaker 		return status;
548331e4dda4SBryan Schumaker 	return decode_secinfo_common(xdr, res);
548431e4dda4SBryan Schumaker }
548531e4dda4SBryan Schumaker 
548699fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
548731e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
548831e4dda4SBryan Schumaker {
548931e4dda4SBryan Schumaker 	int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
549031e4dda4SBryan Schumaker 	if (status)
549131e4dda4SBryan Schumaker 		return status;
549231e4dda4SBryan Schumaker 	return decode_secinfo_common(xdr, res);
549331e4dda4SBryan Schumaker }
549431e4dda4SBryan Schumaker 
54952031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
54962031cd1aSWeston Andros Adamson {
54972031cd1aSWeston Andros Adamson 	__be32 *p;
54982031cd1aSWeston Andros Adamson 	uint32_t bitmap_words;
54992031cd1aSWeston Andros Adamson 	unsigned int i;
55002031cd1aSWeston Andros Adamson 
55012031cd1aSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4);
55024edabfd7SPan Bian 	if (!p)
55034edabfd7SPan Bian 		return -EIO;
55042031cd1aSWeston Andros Adamson 	bitmap_words = be32_to_cpup(p++);
55052031cd1aSWeston Andros Adamson 	if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
55062031cd1aSWeston Andros Adamson 		return -EIO;
55072031cd1aSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4 * bitmap_words);
55082031cd1aSWeston Andros Adamson 	for (i = 0; i < bitmap_words; i++)
55092031cd1aSWeston Andros Adamson 		op_map->u.words[i] = be32_to_cpup(p++);
55102031cd1aSWeston Andros Adamson 
55112031cd1aSWeston Andros Adamson 	return 0;
55122031cd1aSWeston Andros Adamson }
55132031cd1aSWeston Andros Adamson 
551499fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr,
551599fe60d0SBenny Halevy 			      struct nfs41_exchange_id_res *res)
551699fe60d0SBenny Halevy {
551799fe60d0SBenny Halevy 	__be32 *p;
551899fe60d0SBenny Halevy 	uint32_t dummy;
55192460ba57SBenny Halevy 	char *dummy_str;
552099fe60d0SBenny Halevy 	int status;
55217d2ed9acSWeston Andros Adamson 	uint32_t impl_id_count;
552299fe60d0SBenny Halevy 
552399fe60d0SBenny Halevy 	status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
552499fe60d0SBenny Halevy 	if (status)
552599fe60d0SBenny Halevy 		return status;
552699fe60d0SBenny Halevy 
5527c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5528c0eae66eSBenny Halevy 	if (unlikely(!p))
5529eb72f484SChuck Lever 		return -EIO;
553032b01310STrond Myklebust 	xdr_decode_hyper(p, &res->clientid);
5531c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 12);
5532c0eae66eSBenny Halevy 	if (unlikely(!p))
5533eb72f484SChuck Lever 		return -EIO;
553432b01310STrond Myklebust 	res->seqid = be32_to_cpup(p++);
553532b01310STrond Myklebust 	res->flags = be32_to_cpup(p++);
553699fe60d0SBenny Halevy 
55372031cd1aSWeston Andros Adamson 	res->state_protect.how = be32_to_cpup(p);
55382031cd1aSWeston Andros Adamson 	switch (res->state_protect.how) {
55392031cd1aSWeston Andros Adamson 	case SP4_NONE:
55402031cd1aSWeston Andros Adamson 		break;
55412031cd1aSWeston Andros Adamson 	case SP4_MACH_CRED:
55422031cd1aSWeston Andros Adamson 		status = decode_op_map(xdr, &res->state_protect.enforce);
55432031cd1aSWeston Andros Adamson 		if (status)
55442031cd1aSWeston Andros Adamson 			return status;
55452031cd1aSWeston Andros Adamson 		status = decode_op_map(xdr, &res->state_protect.allow);
55462031cd1aSWeston Andros Adamson 		if (status)
55472031cd1aSWeston Andros Adamson 			return status;
55482031cd1aSWeston Andros Adamson 		break;
55492031cd1aSWeston Andros Adamson 	default:
55502031cd1aSWeston Andros Adamson 		WARN_ON_ONCE(1);
555199fe60d0SBenny Halevy 		return -EIO;
55522031cd1aSWeston Andros Adamson 	}
555399fe60d0SBenny Halevy 
5554acdeb69dSChuck Lever 	/* server_owner4.so_minor_id */
5555c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5556c0eae66eSBenny Halevy 	if (unlikely(!p))
5557eb72f484SChuck Lever 		return -EIO;
5558acdeb69dSChuck Lever 	p = xdr_decode_hyper(p, &res->server_owner->minor_id);
555999fe60d0SBenny Halevy 
5560acdeb69dSChuck Lever 	/* server_owner4.so_major_id */
55612460ba57SBenny Halevy 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
55622460ba57SBenny Halevy 	if (unlikely(status))
55632460ba57SBenny Halevy 		return status;
5564acdeb69dSChuck Lever 	memcpy(res->server_owner->major_id, dummy_str, dummy);
5565acdeb69dSChuck Lever 	res->server_owner->major_id_sz = dummy;
556678fe0f41SWeston Andros Adamson 
5567acdeb69dSChuck Lever 	/* server_scope4 */
5568acdeb69dSChuck Lever 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5569acdeb69dSChuck Lever 	if (unlikely(status))
5570acdeb69dSChuck Lever 		return status;
557178fe0f41SWeston Andros Adamson 	memcpy(res->server_scope->server_scope, dummy_str, dummy);
557278fe0f41SWeston Andros Adamson 	res->server_scope->server_scope_sz = dummy;
557378fe0f41SWeston Andros Adamson 
55747d2ed9acSWeston Andros Adamson 	/* Implementation Id */
55757d2ed9acSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 4);
55767d2ed9acSWeston Andros Adamson 	if (unlikely(!p))
5577eb72f484SChuck Lever 		return -EIO;
55787d2ed9acSWeston Andros Adamson 	impl_id_count = be32_to_cpup(p++);
55797d2ed9acSWeston Andros Adamson 
55807d2ed9acSWeston Andros Adamson 	if (impl_id_count) {
55817d2ed9acSWeston Andros Adamson 		/* nii_domain */
55822460ba57SBenny Halevy 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
55832460ba57SBenny Halevy 		if (unlikely(status))
55842460ba57SBenny Halevy 			return status;
55857d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->domain, dummy_str, dummy);
558699fe60d0SBenny Halevy 
55877d2ed9acSWeston Andros Adamson 		/* nii_name */
55887d2ed9acSWeston Andros Adamson 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
55897d2ed9acSWeston Andros Adamson 		if (unlikely(status))
55907d2ed9acSWeston Andros Adamson 			return status;
55917d2ed9acSWeston Andros Adamson 		memcpy(res->impl_id->name, dummy_str, dummy);
55927d2ed9acSWeston Andros Adamson 
55937d2ed9acSWeston Andros Adamson 		/* nii_date */
55947d2ed9acSWeston Andros Adamson 		p = xdr_inline_decode(xdr, 12);
55957d2ed9acSWeston Andros Adamson 		if (unlikely(!p))
5596eb72f484SChuck Lever 			return -EIO;
55977d2ed9acSWeston Andros Adamson 		p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
55987d2ed9acSWeston Andros Adamson 		res->impl_id->date.nseconds = be32_to_cpup(p);
55997d2ed9acSWeston Andros Adamson 
56007d2ed9acSWeston Andros Adamson 		/* if there's more than one entry, ignore the rest */
56017d2ed9acSWeston Andros Adamson 	}
560299fe60d0SBenny Halevy 	return 0;
560399fe60d0SBenny Halevy }
5604fc931582SAndy Adamson 
5605fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr,
5606fc931582SAndy Adamson 			     struct nfs4_channel_attrs *attrs)
5607fc931582SAndy Adamson {
5608fc931582SAndy Adamson 	__be32 *p;
5609c9c30dd5SBenny Halevy 	u32 nr_attrs, val;
5610fc931582SAndy Adamson 
5611c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 28);
5612c0eae66eSBenny Halevy 	if (unlikely(!p))
5613eb72f484SChuck Lever 		return -EIO;
5614c9c30dd5SBenny Halevy 	val = be32_to_cpup(p++);	/* headerpadsz */
5615c9c30dd5SBenny Halevy 	if (val)
5616c9c30dd5SBenny Halevy 		return -EINVAL;		/* no support for header padding yet */
56176f723f77SBenny Halevy 	attrs->max_rqst_sz = be32_to_cpup(p++);
56186f723f77SBenny Halevy 	attrs->max_resp_sz = be32_to_cpup(p++);
56196f723f77SBenny Halevy 	attrs->max_resp_sz_cached = be32_to_cpup(p++);
56206f723f77SBenny Halevy 	attrs->max_ops = be32_to_cpup(p++);
56216f723f77SBenny Halevy 	attrs->max_reqs = be32_to_cpup(p++);
5622cccddf4fSBenny Halevy 	nr_attrs = be32_to_cpup(p);
5623fc931582SAndy Adamson 	if (unlikely(nr_attrs > 1)) {
5624a030889aSWeston Andros Adamson 		printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5625a030889aSWeston Andros Adamson 			"count %u\n", __func__, nr_attrs);
5626fc931582SAndy Adamson 		return -EINVAL;
5627fc931582SAndy Adamson 	}
5628c0eae66eSBenny Halevy 	if (nr_attrs == 1) {
5629c0eae66eSBenny Halevy 		p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5630c0eae66eSBenny Halevy 		if (unlikely(!p))
5631eb72f484SChuck Lever 			return -EIO;
5632c0eae66eSBenny Halevy 	}
5633fc931582SAndy Adamson 	return 0;
5634fc931582SAndy Adamson }
5635fc931582SAndy Adamson 
5636e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5637e78291e4SBenny Halevy {
5638e78291e4SBenny Halevy 	return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5639fc931582SAndy Adamson }
5640fc931582SAndy Adamson 
56417c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr,
56427c44f1aeSWeston Andros Adamson 				struct nfs41_bind_conn_to_session_res *res)
56437c44f1aeSWeston Andros Adamson {
56447c44f1aeSWeston Andros Adamson 	__be32 *p;
56457c44f1aeSWeston Andros Adamson 	int status;
56467c44f1aeSWeston Andros Adamson 
56477c44f1aeSWeston Andros Adamson 	status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
56487c44f1aeSWeston Andros Adamson 	if (!status)
564971a097c6STrond Myklebust 		status = decode_sessionid(xdr, &res->sessionid);
56507c44f1aeSWeston Andros Adamson 	if (unlikely(status))
56517c44f1aeSWeston Andros Adamson 		return status;
56527c44f1aeSWeston Andros Adamson 
56537c44f1aeSWeston Andros Adamson 	/* dir flags, rdma mode bool */
56547c44f1aeSWeston Andros Adamson 	p = xdr_inline_decode(xdr, 8);
56557c44f1aeSWeston Andros Adamson 	if (unlikely(!p))
5656eb72f484SChuck Lever 		return -EIO;
56577c44f1aeSWeston Andros Adamson 
56587c44f1aeSWeston Andros Adamson 	res->dir = be32_to_cpup(p++);
56597c44f1aeSWeston Andros Adamson 	if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
56607c44f1aeSWeston Andros Adamson 		return -EIO;
56617c44f1aeSWeston Andros Adamson 	if (be32_to_cpup(p) == 0)
56627c44f1aeSWeston Andros Adamson 		res->use_conn_in_rdma_mode = false;
56637c44f1aeSWeston Andros Adamson 	else
56647c44f1aeSWeston Andros Adamson 		res->use_conn_in_rdma_mode = true;
56657c44f1aeSWeston Andros Adamson 
56667c44f1aeSWeston Andros Adamson 	return 0;
56677c44f1aeSWeston Andros Adamson }
56687c44f1aeSWeston Andros Adamson 
5669fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr,
5670fc931582SAndy Adamson 				 struct nfs41_create_session_res *res)
5671fc931582SAndy Adamson {
5672fc931582SAndy Adamson 	__be32 *p;
5673fc931582SAndy Adamson 	int status;
5674fc931582SAndy Adamson 
5675fc931582SAndy Adamson 	status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5676e78291e4SBenny Halevy 	if (!status)
567779969dd1STrond Myklebust 		status = decode_sessionid(xdr, &res->sessionid);
5678e78291e4SBenny Halevy 	if (unlikely(status))
5679fc931582SAndy Adamson 		return status;
5680fc931582SAndy Adamson 
5681fc931582SAndy Adamson 	/* seqid, flags */
5682c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 8);
5683c0eae66eSBenny Halevy 	if (unlikely(!p))
5684eb72f484SChuck Lever 		return -EIO;
568579969dd1STrond Myklebust 	res->seqid = be32_to_cpup(p++);
568679969dd1STrond Myklebust 	res->flags = be32_to_cpup(p);
5687fc931582SAndy Adamson 
5688fc931582SAndy Adamson 	/* Channel attributes */
568979969dd1STrond Myklebust 	status = decode_chan_attrs(xdr, &res->fc_attrs);
5690fc931582SAndy Adamson 	if (!status)
569179969dd1STrond Myklebust 		status = decode_chan_attrs(xdr, &res->bc_attrs);
5692fc931582SAndy Adamson 	return status;
5693fc931582SAndy Adamson }
56940f3e66c6SAndy Adamson 
56950f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
56960f3e66c6SAndy Adamson {
56970f3e66c6SAndy Adamson 	return decode_op_hdr(xdr, OP_DESTROY_SESSION);
56980f3e66c6SAndy Adamson }
569918019753SRicardo Labiaga 
570066245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
570166245539STrond Myklebust {
570266245539STrond Myklebust 	return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
570366245539STrond Myklebust }
570466245539STrond Myklebust 
570518019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
570618019753SRicardo Labiaga {
570718019753SRicardo Labiaga 	return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
570818019753SRicardo Labiaga }
570999fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
571099fe60d0SBenny Halevy 
57119b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr,
57129b7b9fccSAndy Adamson 			   struct nfs4_sequence_res *res,
57139b7b9fccSAndy Adamson 			   struct rpc_rqst *rqstp)
57149b7b9fccSAndy Adamson {
57159b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
5716e3725ec0STrond Myklebust 	struct nfs4_session *session;
5717fc01cea9SAndy Adamson 	struct nfs4_sessionid id;
5718fc01cea9SAndy Adamson 	u32 dummy;
5719fc01cea9SAndy Adamson 	int status;
5720fc01cea9SAndy Adamson 	__be32 *p;
5721fc01cea9SAndy Adamson 
5722e3725ec0STrond Myklebust 	if (res->sr_slot == NULL)
57239b7b9fccSAndy Adamson 		return 0;
57243bd2384aSChuck Lever 	if (!res->sr_slot->table->session)
57253bd2384aSChuck Lever 		return 0;
57269b7b9fccSAndy Adamson 
5727fc01cea9SAndy Adamson 	status = decode_op_hdr(xdr, OP_SEQUENCE);
5728e78291e4SBenny Halevy 	if (!status)
5729e78291e4SBenny Halevy 		status = decode_sessionid(xdr, &id);
5730e78291e4SBenny Halevy 	if (unlikely(status))
5731fc01cea9SAndy Adamson 		goto out_err;
57329b7b9fccSAndy Adamson 
5733fc01cea9SAndy Adamson 	/*
5734fc01cea9SAndy Adamson 	 * If the server returns different values for sessionID, slotID or
5735fc01cea9SAndy Adamson 	 * sequence number, the server is looney tunes.
5736fc01cea9SAndy Adamson 	 */
5737fdcb4577STrond Myklebust 	status = -EREMOTEIO;
5738e3725ec0STrond Myklebust 	session = res->sr_slot->table->session;
5739fc01cea9SAndy Adamson 
5740e3725ec0STrond Myklebust 	if (memcmp(id.data, session->sess_id.data,
5741fc01cea9SAndy Adamson 		   NFS4_MAX_SESSIONID_LEN)) {
5742fc01cea9SAndy Adamson 		dprintk("%s Invalid session id\n", __func__);
5743fc01cea9SAndy Adamson 		goto out_err;
5744fc01cea9SAndy Adamson 	}
5745e78291e4SBenny Halevy 
5746c0eae66eSBenny Halevy 	p = xdr_inline_decode(xdr, 20);
5747c0eae66eSBenny Halevy 	if (unlikely(!p))
5748c0eae66eSBenny Halevy 		goto out_overflow;
5749e78291e4SBenny Halevy 
5750fc01cea9SAndy Adamson 	/* seqid */
57516f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5752dfb4f309SBenny Halevy 	if (dummy != res->sr_slot->seq_nr) {
5753fc01cea9SAndy Adamson 		dprintk("%s Invalid sequence number\n", __func__);
5754fc01cea9SAndy Adamson 		goto out_err;
5755fc01cea9SAndy Adamson 	}
5756fc01cea9SAndy Adamson 	/* slot id */
57576f723f77SBenny Halevy 	dummy = be32_to_cpup(p++);
5758df2fabffSTrond Myklebust 	if (dummy != res->sr_slot->slot_nr) {
5759fc01cea9SAndy Adamson 		dprintk("%s Invalid slot id\n", __func__);
5760fc01cea9SAndy Adamson 		goto out_err;
5761fc01cea9SAndy Adamson 	}
5762da0507b7STrond Myklebust 	/* highest slot id */
5763da0507b7STrond Myklebust 	res->sr_highest_slotid = be32_to_cpup(p++);
5764464ee9f9STrond Myklebust 	/* target highest slot id */
5765464ee9f9STrond Myklebust 	res->sr_target_highest_slotid = be32_to_cpup(p++);
57660629e370SAlexandros Batsakis 	/* result flags */
57670629e370SAlexandros Batsakis 	res->sr_status_flags = be32_to_cpup(p);
5768fc01cea9SAndy Adamson 	status = 0;
5769fc01cea9SAndy Adamson out_err:
5770fc01cea9SAndy Adamson 	res->sr_status = status;
5771fc01cea9SAndy Adamson 	return status;
5772c0eae66eSBenny Halevy out_overflow:
5773c0eae66eSBenny Halevy 	status = -EIO;
5774c0eae66eSBenny Halevy 	goto out_err;
5775fc01cea9SAndy Adamson #else  /* CONFIG_NFS_V4_1 */
57769b7b9fccSAndy Adamson 	return 0;
5777fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
57789b7b9fccSAndy Adamson }
57799b7b9fccSAndy Adamson 
5780b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1)
578193b717fdSTrond Myklebust static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
578293b717fdSTrond Myklebust {
578393b717fdSTrond Myklebust 	stateid->type = NFS4_LAYOUT_STATEID_TYPE;
578493b717fdSTrond Myklebust 	return decode_stateid(xdr, stateid);
578593b717fdSTrond Myklebust }
578693b717fdSTrond Myklebust 
5787b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr,
57884e590803STrond Myklebust 				struct nfs4_getdeviceinfo_res *res)
5789b1f69b75SAndy Adamson {
57904e590803STrond Myklebust 	struct pnfs_device *pdev = res->pdev;
5791b1f69b75SAndy Adamson 	__be32 *p;
5792b1f69b75SAndy Adamson 	uint32_t len, type;
5793b1f69b75SAndy Adamson 	int status;
5794b1f69b75SAndy Adamson 
5795b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5796b1f69b75SAndy Adamson 	if (status) {
5797b1f69b75SAndy Adamson 		if (status == -ETOOSMALL) {
5798b1f69b75SAndy Adamson 			p = xdr_inline_decode(xdr, 4);
5799b1f69b75SAndy Adamson 			if (unlikely(!p))
5800eb72f484SChuck Lever 				return -EIO;
5801b1f69b75SAndy Adamson 			pdev->mincount = be32_to_cpup(p);
5802b1f69b75SAndy Adamson 			dprintk("%s: Min count too small. mincnt = %u\n",
5803b1f69b75SAndy Adamson 				__func__, pdev->mincount);
5804b1f69b75SAndy Adamson 		}
5805b1f69b75SAndy Adamson 		return status;
5806b1f69b75SAndy Adamson 	}
5807b1f69b75SAndy Adamson 
5808b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 8);
5809b1f69b75SAndy Adamson 	if (unlikely(!p))
5810eb72f484SChuck Lever 		return -EIO;
5811b1f69b75SAndy Adamson 	type = be32_to_cpup(p++);
5812b1f69b75SAndy Adamson 	if (type != pdev->layout_type) {
5813b1f69b75SAndy Adamson 		dprintk("%s: layout mismatch req: %u pdev: %u\n",
5814b1f69b75SAndy Adamson 			__func__, pdev->layout_type, type);
5815b1f69b75SAndy Adamson 		return -EINVAL;
5816b1f69b75SAndy Adamson 	}
5817b1f69b75SAndy Adamson 	/*
5818b1f69b75SAndy Adamson 	 * Get the length of the opaque device_addr4. xdr_read_pages places
5819b1f69b75SAndy Adamson 	 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5820b1f69b75SAndy Adamson 	 * and places the remaining xdr data in xdr_buf->tail
5821b1f69b75SAndy Adamson 	 */
5822b1f69b75SAndy Adamson 	pdev->mincount = be32_to_cpup(p);
582313fe4ba1STrond Myklebust 	if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5824eb72f484SChuck Lever 		return -EIO;
5825b1f69b75SAndy Adamson 
5826b1f69b75SAndy Adamson 	/* Parse notification bitmap, verifying that it is zero. */
5827b1f69b75SAndy Adamson 	p = xdr_inline_decode(xdr, 4);
5828b1f69b75SAndy Adamson 	if (unlikely(!p))
5829eb72f484SChuck Lever 		return -EIO;
5830b1f69b75SAndy Adamson 	len = be32_to_cpup(p);
5831b1f69b75SAndy Adamson 	if (len) {
5832ead00597SChuck Lever 		uint32_t i;
5833b1f69b75SAndy Adamson 
5834b1f69b75SAndy Adamson 		p = xdr_inline_decode(xdr, 4 * len);
5835b1f69b75SAndy Adamson 		if (unlikely(!p))
5836eb72f484SChuck Lever 			return -EIO;
583784c9dee3SChristoph Hellwig 
58384e590803STrond Myklebust 		res->notification = be32_to_cpup(p++);
583984c9dee3SChristoph Hellwig 		for (i = 1; i < len; i++) {
584084c9dee3SChristoph Hellwig 			if (be32_to_cpup(p++)) {
584184c9dee3SChristoph Hellwig 				dprintk("%s: unsupported notification\n",
5842b1f69b75SAndy Adamson 					__func__);
5843b1f69b75SAndy Adamson 				return -EIO;
5844b1f69b75SAndy Adamson 			}
5845b1f69b75SAndy Adamson 		}
5846b1f69b75SAndy Adamson 	}
5847b1f69b75SAndy Adamson 	return 0;
5848b1f69b75SAndy Adamson }
5849b1f69b75SAndy Adamson 
5850b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5851b1f69b75SAndy Adamson 			    struct nfs4_layoutget_res *res)
5852b1f69b75SAndy Adamson {
5853b1f69b75SAndy Adamson 	__be32 *p;
5854b1f69b75SAndy Adamson 	int status;
5855b1f69b75SAndy Adamson 	u32 layout_count;
585664bd577eSTrond Myklebust 	u32 recvd;
5857b1f69b75SAndy Adamson 
5858b1f69b75SAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTGET);
5859b1f69b75SAndy Adamson 	if (status)
5860808ba32aSFred Isaman 		goto out;
5861ea9d23f5STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
5862b1f69b75SAndy Adamson 	if (unlikely(!p))
5863b1f69b75SAndy Adamson 		goto out_overflow;
5864ea9d23f5STrond Myklebust 	res->return_on_close = be32_to_cpup(p);
586593b717fdSTrond Myklebust 	decode_layout_stateid(xdr, &res->stateid);
5866ea9d23f5STrond Myklebust 	p = xdr_inline_decode(xdr, 4);
5867ea9d23f5STrond Myklebust 	if (unlikely(!p))
5868ea9d23f5STrond Myklebust 		goto out_overflow;
5869b1f69b75SAndy Adamson 	layout_count = be32_to_cpup(p);
5870b1f69b75SAndy Adamson 	if (!layout_count) {
5871b1f69b75SAndy Adamson 		dprintk("%s: server responded with empty layout array\n",
5872b1f69b75SAndy Adamson 			__func__);
5873808ba32aSFred Isaman 		status = -EINVAL;
5874808ba32aSFred Isaman 		goto out;
5875b1f69b75SAndy Adamson 	}
5876b1f69b75SAndy Adamson 
587735124a09SWeston Andros Adamson 	p = xdr_inline_decode(xdr, 28);
5878b1f69b75SAndy Adamson 	if (unlikely(!p))
5879b1f69b75SAndy Adamson 		goto out_overflow;
5880b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.offset);
5881b1f69b75SAndy Adamson 	p = xdr_decode_hyper(p, &res->range.length);
5882b1f69b75SAndy Adamson 	res->range.iomode = be32_to_cpup(p++);
5883b1f69b75SAndy Adamson 	res->type = be32_to_cpup(p++);
588435124a09SWeston Andros Adamson 	res->layoutp->len = be32_to_cpup(p);
5885b1f69b75SAndy Adamson 
5886b1f69b75SAndy Adamson 	dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5887b1f69b75SAndy Adamson 		__func__,
5888b1f69b75SAndy Adamson 		(unsigned long)res->range.offset,
5889b1f69b75SAndy Adamson 		(unsigned long)res->range.length,
5890b1f69b75SAndy Adamson 		res->range.iomode,
5891b1f69b75SAndy Adamson 		res->type,
589235124a09SWeston Andros Adamson 		res->layoutp->len);
5893b1f69b75SAndy Adamson 
589464bd577eSTrond Myklebust 	recvd = xdr_read_pages(xdr, res->layoutp->len);
589535124a09SWeston Andros Adamson 	if (res->layoutp->len > recvd) {
589635124a09SWeston Andros Adamson 		dprintk("NFS: server cheating in layoutget reply: "
589735124a09SWeston Andros Adamson 				"layout len %u > recvd %u\n",
589835124a09SWeston Andros Adamson 				res->layoutp->len, recvd);
5899808ba32aSFred Isaman 		status = -EINVAL;
5900808ba32aSFred Isaman 		goto out;
590135124a09SWeston Andros Adamson 	}
590235124a09SWeston Andros Adamson 
5903b1f69b75SAndy Adamson 	if (layout_count > 1) {
5904b1f69b75SAndy Adamson 		/* We only handle a length one array at the moment.  Any
5905b1f69b75SAndy Adamson 		 * further entries are just ignored.  Note that this means
5906b1f69b75SAndy Adamson 		 * the client may see a response that is less than the
5907b1f69b75SAndy Adamson 		 * minimum it requested.
5908b1f69b75SAndy Adamson 		 */
5909b1f69b75SAndy Adamson 		dprintk("%s: server responded with %d layouts, dropping tail\n",
5910b1f69b75SAndy Adamson 			__func__, layout_count);
5911b1f69b75SAndy Adamson 	}
5912b1f69b75SAndy Adamson 
5913808ba32aSFred Isaman out:
5914808ba32aSFred Isaman 	res->status = status;
5915808ba32aSFred Isaman 	return status;
5916b1f69b75SAndy Adamson out_overflow:
5917808ba32aSFred Isaman 	status = -EIO;
5918808ba32aSFred Isaman 	goto out;
5919b1f69b75SAndy Adamson }
5920863a3c6cSAndy Adamson 
5921cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr,
5922cbe82603SBenny Halevy 			       struct nfs4_layoutreturn_res *res)
5923cbe82603SBenny Halevy {
5924cbe82603SBenny Halevy 	__be32 *p;
5925cbe82603SBenny Halevy 	int status;
5926cbe82603SBenny Halevy 
5927cbe82603SBenny Halevy 	status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5928cbe82603SBenny Halevy 	if (status)
5929cbe82603SBenny Halevy 		return status;
5930cbe82603SBenny Halevy 	p = xdr_inline_decode(xdr, 4);
5931cbe82603SBenny Halevy 	if (unlikely(!p))
5932eb72f484SChuck Lever 		return -EIO;
5933cbe82603SBenny Halevy 	res->lrs_present = be32_to_cpup(p);
5934cbe82603SBenny Halevy 	if (res->lrs_present)
593593b717fdSTrond Myklebust 		status = decode_layout_stateid(xdr, &res->stateid);
5936fcd8843cSTrond Myklebust 	else
5937fcd8843cSTrond Myklebust 		nfs4_stateid_copy(&res->stateid, &invalid_stateid);
5938cbe82603SBenny Halevy 	return status;
5939cbe82603SBenny Halevy }
5940cbe82603SBenny Halevy 
5941863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr,
5942863a3c6cSAndy Adamson 			       struct rpc_rqst *req,
5943863a3c6cSAndy Adamson 			       struct nfs4_layoutcommit_res *res)
5944863a3c6cSAndy Adamson {
5945863a3c6cSAndy Adamson 	__be32 *p;
5946863a3c6cSAndy Adamson 	__u32 sizechanged;
5947863a3c6cSAndy Adamson 	int status;
5948863a3c6cSAndy Adamson 
5949863a3c6cSAndy Adamson 	status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5950db29c089SAndy Adamson 	res->status = status;
5951863a3c6cSAndy Adamson 	if (status)
5952863a3c6cSAndy Adamson 		return status;
5953863a3c6cSAndy Adamson 
5954863a3c6cSAndy Adamson 	p = xdr_inline_decode(xdr, 4);
5955863a3c6cSAndy Adamson 	if (unlikely(!p))
5956eb72f484SChuck Lever 		return -EIO;
5957863a3c6cSAndy Adamson 	sizechanged = be32_to_cpup(p);
5958863a3c6cSAndy Adamson 
5959863a3c6cSAndy Adamson 	if (sizechanged) {
5960863a3c6cSAndy Adamson 		/* throw away new size */
5961863a3c6cSAndy Adamson 		p = xdr_inline_decode(xdr, 8);
5962863a3c6cSAndy Adamson 		if (unlikely(!p))
5963eb72f484SChuck Lever 			return -EIO;
5964863a3c6cSAndy Adamson 	}
5965863a3c6cSAndy Adamson 	return 0;
5966863a3c6cSAndy Adamson }
59677d974794SBryan Schumaker 
59687d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr,
59697d974794SBryan Schumaker 			       struct nfs41_test_stateid_res *res)
59707d974794SBryan Schumaker {
59717d974794SBryan Schumaker 	__be32 *p;
59727d974794SBryan Schumaker 	int status;
59737d974794SBryan Schumaker 	int num_res;
59747d974794SBryan Schumaker 
59757d974794SBryan Schumaker 	status = decode_op_hdr(xdr, OP_TEST_STATEID);
59767d974794SBryan Schumaker 	if (status)
59777d974794SBryan Schumaker 		return status;
59787d974794SBryan Schumaker 
59797d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
59807d974794SBryan Schumaker 	if (unlikely(!p))
5981eb72f484SChuck Lever 		return -EIO;
59827d974794SBryan Schumaker 	num_res = be32_to_cpup(p++);
59837d974794SBryan Schumaker 	if (num_res != 1)
5984eb72f484SChuck Lever 		return -EIO;
59857d974794SBryan Schumaker 
59867d974794SBryan Schumaker 	p = xdr_inline_decode(xdr, 4);
59877d974794SBryan Schumaker 	if (unlikely(!p))
5988eb72f484SChuck Lever 		return -EIO;
59897d974794SBryan Schumaker 	res->status = be32_to_cpup(p++);
59901cab0652SBryan Schumaker 
59911cab0652SBryan Schumaker 	return status;
59927d974794SBryan Schumaker }
59939aeda35fSBryan Schumaker 
59949aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr,
59959aeda35fSBryan Schumaker 			       struct nfs41_free_stateid_res *res)
59969aeda35fSBryan Schumaker {
59979f79fb48SAndy Adamson 	res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
59989aeda35fSBryan Schumaker 	return res->status;
59999aeda35fSBryan Schumaker }
6000cf805165STrond Myklebust #else
6001cf805165STrond Myklebust static inline
6002cf805165STrond Myklebust int decode_layoutreturn(struct xdr_stream *xdr,
6003cf805165STrond Myklebust 			       struct nfs4_layoutreturn_res *res)
6004cf805165STrond Myklebust {
6005cf805165STrond Myklebust 	return 0;
6006cf805165STrond Myklebust }
600756f487f8SFred Isaman 
600856f487f8SFred Isaman static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
600956f487f8SFred Isaman 			    struct nfs4_layoutget_res *res)
601056f487f8SFred Isaman {
601156f487f8SFred Isaman 	return 0;
601256f487f8SFred Isaman }
601356f487f8SFred Isaman 
6014b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
6015b1f69b75SAndy Adamson 
60161da177e4SLinus Torvalds /*
601749c2559eSBenny Halevy  * END OF "GENERIC" DECODE ROUTINES.
601849c2559eSBenny Halevy  */
601949c2559eSBenny Halevy 
602049c2559eSBenny Halevy /*
60211da177e4SLinus Torvalds  * Decode OPEN_DOWNGRADE response
60221da177e4SLinus Torvalds  */
6023bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6024bf269551SChuck Lever 				       struct xdr_stream *xdr,
6025fc016483SChristoph Hellwig 				       void *data)
60261da177e4SLinus Torvalds {
6027fc016483SChristoph Hellwig 	struct nfs_closeres *res = data;
60281da177e4SLinus Torvalds 	struct compound_hdr hdr;
60291da177e4SLinus Torvalds 	int status;
60301da177e4SLinus Torvalds 
6031bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
60321da177e4SLinus Torvalds 	if (status)
60331da177e4SLinus Torvalds 		goto out;
6034bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
60359b7b9fccSAndy Adamson 	if (status)
60369b7b9fccSAndy Adamson 		goto out;
6037bf269551SChuck Lever 	status = decode_putfh(xdr);
60381da177e4SLinus Torvalds 	if (status)
60391da177e4SLinus Torvalds 		goto out;
6040b6808145STrond Myklebust 	if (res->lr_res) {
6041b6808145STrond Myklebust 		status = decode_layoutreturn(xdr, res->lr_res);
6042b6808145STrond Myklebust 		res->lr_ret = status;
6043b6808145STrond Myklebust 		if (status)
6044b6808145STrond Myklebust 			goto out;
6045b6808145STrond Myklebust 	}
6046bf269551SChuck Lever 	status = decode_open_downgrade(xdr, res);
60471da177e4SLinus Torvalds out:
60481da177e4SLinus Torvalds 	return status;
60491da177e4SLinus Torvalds }
60501da177e4SLinus Torvalds 
60511da177e4SLinus Torvalds /*
60521da177e4SLinus Torvalds  * Decode ACCESS response
60531da177e4SLinus Torvalds  */
6054bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6055fc016483SChristoph Hellwig 			       void *data)
60561da177e4SLinus Torvalds {
6057fc016483SChristoph Hellwig 	struct nfs4_accessres *res = data;
60581da177e4SLinus Torvalds 	struct compound_hdr hdr;
60591da177e4SLinus Torvalds 	int status;
60601da177e4SLinus Torvalds 
6061bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
60629b7b9fccSAndy Adamson 	if (status)
60639b7b9fccSAndy Adamson 		goto out;
6064bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
60659b7b9fccSAndy Adamson 	if (status)
60661da177e4SLinus Torvalds 		goto out;
6067bf269551SChuck Lever 	status = decode_putfh(xdr);
606876b32999STrond Myklebust 	if (status != 0)
606976b32999STrond Myklebust 		goto out;
60706168f62cSWeston Andros Adamson 	status = decode_access(xdr, &res->supported, &res->access);
607176b32999STrond Myklebust 	if (status != 0)
607276b32999STrond Myklebust 		goto out;
60738bcbe7d9STrond Myklebust 	if (res->fattr)
60746926afd1STrond Myklebust 		decode_getfattr(xdr, res->fattr, res->server);
60751da177e4SLinus Torvalds out:
60761da177e4SLinus Torvalds 	return status;
60771da177e4SLinus Torvalds }
60781da177e4SLinus Torvalds 
60791da177e4SLinus Torvalds /*
60801da177e4SLinus Torvalds  * Decode LOOKUP response
60811da177e4SLinus Torvalds  */
6082bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6083fc016483SChristoph Hellwig 			       void *data)
60841da177e4SLinus Torvalds {
6085fc016483SChristoph Hellwig 	struct nfs4_lookup_res *res = data;
60861da177e4SLinus Torvalds 	struct compound_hdr hdr;
60871da177e4SLinus Torvalds 	int status;
60881da177e4SLinus Torvalds 
6089bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
60909b7b9fccSAndy Adamson 	if (status)
60919b7b9fccSAndy Adamson 		goto out;
6092bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
60939b7b9fccSAndy Adamson 	if (status)
60941da177e4SLinus Torvalds 		goto out;
6095bf269551SChuck Lever 	status = decode_putfh(xdr);
6096bf269551SChuck Lever 	if (status)
60971da177e4SLinus Torvalds 		goto out;
6098bf269551SChuck Lever 	status = decode_lookup(xdr);
6099bf269551SChuck Lever 	if (status)
61001da177e4SLinus Torvalds 		goto out;
6101bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6102bf269551SChuck Lever 	if (status)
61031da177e4SLinus Torvalds 		goto out;
6104aa9c2669SDavid Quigley 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
61051da177e4SLinus Torvalds out:
61061da177e4SLinus Torvalds 	return status;
61071da177e4SLinus Torvalds }
61081da177e4SLinus Torvalds 
61091da177e4SLinus Torvalds /*
61105b5faaf6SJeff Layton  * Decode LOOKUPP response
61115b5faaf6SJeff Layton  */
61125b5faaf6SJeff Layton static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
61135b5faaf6SJeff Layton 		void *data)
61145b5faaf6SJeff Layton {
61155b5faaf6SJeff Layton 	struct nfs4_lookupp_res *res = data;
61165b5faaf6SJeff Layton 	struct compound_hdr hdr;
61175b5faaf6SJeff Layton 	int status;
61185b5faaf6SJeff Layton 
61195b5faaf6SJeff Layton 	status = decode_compound_hdr(xdr, &hdr);
61205b5faaf6SJeff Layton 	if (status)
61215b5faaf6SJeff Layton 		goto out;
61225b5faaf6SJeff Layton 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61235b5faaf6SJeff Layton 	if (status)
61245b5faaf6SJeff Layton 		goto out;
61255b5faaf6SJeff Layton 	status = decode_putfh(xdr);
61265b5faaf6SJeff Layton 	if (status)
61275b5faaf6SJeff Layton 		goto out;
61285b5faaf6SJeff Layton 	status = decode_lookupp(xdr);
61295b5faaf6SJeff Layton 	if (status)
61305b5faaf6SJeff Layton 		goto out;
61315b5faaf6SJeff Layton 	status = decode_getfh(xdr, res->fh);
61325b5faaf6SJeff Layton 	if (status)
61335b5faaf6SJeff Layton 		goto out;
61345b5faaf6SJeff Layton 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
61355b5faaf6SJeff Layton out:
61365b5faaf6SJeff Layton 	return status;
61375b5faaf6SJeff Layton }
61385b5faaf6SJeff Layton 
61395b5faaf6SJeff Layton /*
61401da177e4SLinus Torvalds  * Decode LOOKUP_ROOT response
61411da177e4SLinus Torvalds  */
6142bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6143bf269551SChuck Lever 				    struct xdr_stream *xdr,
6144fc016483SChristoph Hellwig 				    void *data)
61451da177e4SLinus Torvalds {
6146fc016483SChristoph Hellwig 	struct nfs4_lookup_res *res = data;
61471da177e4SLinus Torvalds 	struct compound_hdr hdr;
61481da177e4SLinus Torvalds 	int status;
61491da177e4SLinus Torvalds 
6150bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61519b7b9fccSAndy Adamson 	if (status)
61529b7b9fccSAndy Adamson 		goto out;
6153bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61549b7b9fccSAndy Adamson 	if (status)
61551da177e4SLinus Torvalds 		goto out;
6156bf269551SChuck Lever 	status = decode_putrootfh(xdr);
6157bf269551SChuck Lever 	if (status)
61581da177e4SLinus Torvalds 		goto out;
6159bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6160bf269551SChuck Lever 	if (status == 0)
6161aa9c2669SDavid Quigley 		status = decode_getfattr_label(xdr, res->fattr,
6162aa9c2669SDavid Quigley 						res->label, res->server);
61631da177e4SLinus Torvalds out:
61641da177e4SLinus Torvalds 	return status;
61651da177e4SLinus Torvalds }
61661da177e4SLinus Torvalds 
61671da177e4SLinus Torvalds /*
61681da177e4SLinus Torvalds  * Decode REMOVE response
61691da177e4SLinus Torvalds  */
6170bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6171fc016483SChristoph Hellwig 			       void *data)
61721da177e4SLinus Torvalds {
6173fc016483SChristoph Hellwig 	struct nfs_removeres *res = data;
61741da177e4SLinus Torvalds 	struct compound_hdr hdr;
61751da177e4SLinus Torvalds 	int status;
61761da177e4SLinus Torvalds 
6177bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
61789b7b9fccSAndy Adamson 	if (status)
61799b7b9fccSAndy Adamson 		goto out;
6180bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
61819b7b9fccSAndy Adamson 	if (status)
61821da177e4SLinus Torvalds 		goto out;
6183bf269551SChuck Lever 	status = decode_putfh(xdr);
6184bf269551SChuck Lever 	if (status)
618516e42959STrond Myklebust 		goto out;
6186bf269551SChuck Lever 	status = decode_remove(xdr, &res->cinfo);
61871da177e4SLinus Torvalds out:
61881da177e4SLinus Torvalds 	return status;
61891da177e4SLinus Torvalds }
61901da177e4SLinus Torvalds 
61911da177e4SLinus Torvalds /*
61921da177e4SLinus Torvalds  * Decode RENAME response
61931da177e4SLinus Torvalds  */
6194bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6195fc016483SChristoph Hellwig 			       void *data)
61961da177e4SLinus Torvalds {
6197fc016483SChristoph Hellwig 	struct nfs_renameres *res = data;
61981da177e4SLinus Torvalds 	struct compound_hdr hdr;
61991da177e4SLinus Torvalds 	int status;
62001da177e4SLinus Torvalds 
6201bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62029b7b9fccSAndy Adamson 	if (status)
62039b7b9fccSAndy Adamson 		goto out;
6204bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62059b7b9fccSAndy Adamson 	if (status)
62061da177e4SLinus Torvalds 		goto out;
6207bf269551SChuck Lever 	status = decode_putfh(xdr);
6208bf269551SChuck Lever 	if (status)
62091da177e4SLinus Torvalds 		goto out;
6210bf269551SChuck Lever 	status = decode_savefh(xdr);
6211bf269551SChuck Lever 	if (status)
62121da177e4SLinus Torvalds 		goto out;
6213bf269551SChuck Lever 	status = decode_putfh(xdr);
6214bf269551SChuck Lever 	if (status)
62151da177e4SLinus Torvalds 		goto out;
6216bf269551SChuck Lever 	status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
62171da177e4SLinus Torvalds out:
62181da177e4SLinus Torvalds 	return status;
62191da177e4SLinus Torvalds }
62201da177e4SLinus Torvalds 
62211da177e4SLinus Torvalds /*
62221da177e4SLinus Torvalds  * Decode LINK response
62231da177e4SLinus Torvalds  */
6224bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6225fc016483SChristoph Hellwig 			     void *data)
62261da177e4SLinus Torvalds {
6227fc016483SChristoph Hellwig 	struct nfs4_link_res *res = data;
62281da177e4SLinus Torvalds 	struct compound_hdr hdr;
62291da177e4SLinus Torvalds 	int status;
62301da177e4SLinus Torvalds 
6231bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62329b7b9fccSAndy Adamson 	if (status)
62339b7b9fccSAndy Adamson 		goto out;
6234bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62359b7b9fccSAndy Adamson 	if (status)
62361da177e4SLinus Torvalds 		goto out;
6237bf269551SChuck Lever 	status = decode_putfh(xdr);
6238bf269551SChuck Lever 	if (status)
62391da177e4SLinus Torvalds 		goto out;
6240bf269551SChuck Lever 	status = decode_savefh(xdr);
6241bf269551SChuck Lever 	if (status)
62421da177e4SLinus Torvalds 		goto out;
6243bf269551SChuck Lever 	status = decode_putfh(xdr);
6244bf269551SChuck Lever 	if (status)
62451da177e4SLinus Torvalds 		goto out;
6246bf269551SChuck Lever 	status = decode_link(xdr, &res->cinfo);
6247bf269551SChuck Lever 	if (status)
624891ba2eeeSTrond Myklebust 		goto out;
624991ba2eeeSTrond Myklebust 	/*
625091ba2eeeSTrond Myklebust 	 * Note order: OP_LINK leaves the directory as the current
625191ba2eeeSTrond Myklebust 	 *             filehandle.
625291ba2eeeSTrond Myklebust 	 */
6253bf269551SChuck Lever 	status = decode_restorefh(xdr);
6254bf269551SChuck Lever 	if (status)
625591ba2eeeSTrond Myklebust 		goto out;
6256aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
62571da177e4SLinus Torvalds out:
62581da177e4SLinus Torvalds 	return status;
62591da177e4SLinus Torvalds }
62601da177e4SLinus Torvalds 
62611da177e4SLinus Torvalds /*
62621da177e4SLinus Torvalds  * Decode CREATE response
62631da177e4SLinus Torvalds  */
6264bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6265fc016483SChristoph Hellwig 			       void *data)
62661da177e4SLinus Torvalds {
6267fc016483SChristoph Hellwig 	struct nfs4_create_res *res = data;
62681da177e4SLinus Torvalds 	struct compound_hdr hdr;
62691da177e4SLinus Torvalds 	int status;
62701da177e4SLinus Torvalds 
6271bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
62729b7b9fccSAndy Adamson 	if (status)
62739b7b9fccSAndy Adamson 		goto out;
6274bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
62759b7b9fccSAndy Adamson 	if (status)
62761da177e4SLinus Torvalds 		goto out;
6277bf269551SChuck Lever 	status = decode_putfh(xdr);
6278bf269551SChuck Lever 	if (status)
62791da177e4SLinus Torvalds 		goto out;
6280bf269551SChuck Lever 	status = decode_create(xdr, &res->dir_cinfo);
6281bf269551SChuck Lever 	if (status)
62821da177e4SLinus Torvalds 		goto out;
6283bf269551SChuck Lever 	status = decode_getfh(xdr, res->fh);
6284bf269551SChuck Lever 	if (status)
62851da177e4SLinus Torvalds 		goto out;
6286aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
62871da177e4SLinus Torvalds out:
62881da177e4SLinus Torvalds 	return status;
62891da177e4SLinus Torvalds }
62901da177e4SLinus Torvalds 
62911da177e4SLinus Torvalds /*
62921da177e4SLinus Torvalds  * Decode SYMLINK response
62931da177e4SLinus Torvalds  */
6294bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6295fc016483SChristoph Hellwig 				void *res)
62961da177e4SLinus Torvalds {
6297bf269551SChuck Lever 	return nfs4_xdr_dec_create(rqstp, xdr, res);
62981da177e4SLinus Torvalds }
62991da177e4SLinus Torvalds 
63001da177e4SLinus Torvalds /*
63011da177e4SLinus Torvalds  * Decode GETATTR response
63021da177e4SLinus Torvalds  */
6303bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6304fc016483SChristoph Hellwig 				void *data)
63051da177e4SLinus Torvalds {
6306fc016483SChristoph Hellwig 	struct nfs4_getattr_res *res = data;
63071da177e4SLinus Torvalds 	struct compound_hdr hdr;
63081da177e4SLinus Torvalds 	int status;
63091da177e4SLinus Torvalds 
6310bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
63111da177e4SLinus Torvalds 	if (status)
63121da177e4SLinus Torvalds 		goto out;
6313bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63149b7b9fccSAndy Adamson 	if (status)
63159b7b9fccSAndy Adamson 		goto out;
6316bf269551SChuck Lever 	status = decode_putfh(xdr);
63171da177e4SLinus Torvalds 	if (status)
63181da177e4SLinus Torvalds 		goto out;
6319aa9c2669SDavid Quigley 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
63201da177e4SLinus Torvalds out:
63211da177e4SLinus Torvalds 	return status;
63221da177e4SLinus Torvalds }
63231da177e4SLinus Torvalds 
632423ec6965SJ. Bruce Fields /*
632523ec6965SJ. Bruce Fields  * Encode an SETACL request
632623ec6965SJ. Bruce Fields  */
63279f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6328fcc85819SChristoph Hellwig 				const void *data)
632923ec6965SJ. Bruce Fields {
6330fcc85819SChristoph Hellwig 	const struct nfs_setaclargs *args = data;
633123ec6965SJ. Bruce Fields 	struct compound_hdr hdr = {
633266cc0429SBenny Halevy 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
633323ec6965SJ. Bruce Fields 	};
633423ec6965SJ. Bruce Fields 
63359f06c719SChuck Lever 	encode_compound_hdr(xdr, req, &hdr);
63369f06c719SChuck Lever 	encode_sequence(xdr, &args->seq_args, &hdr);
63379f06c719SChuck Lever 	encode_putfh(xdr, args->fh, &hdr);
63389f06c719SChuck Lever 	encode_setacl(xdr, args, &hdr);
6339d017931cSAndy Adamson 	encode_nops(&hdr);
634023ec6965SJ. Bruce Fields }
634105d564feSAndy Adamson 
634223ec6965SJ. Bruce Fields /*
634323ec6965SJ. Bruce Fields  * Decode SETACL response
634423ec6965SJ. Bruce Fields  */
634523ec6965SJ. Bruce Fields static int
6346bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6347fc016483SChristoph Hellwig 		    void *data)
634823ec6965SJ. Bruce Fields {
6349fc016483SChristoph Hellwig 	struct nfs_setaclres *res = data;
635023ec6965SJ. Bruce Fields 	struct compound_hdr hdr;
635123ec6965SJ. Bruce Fields 	int status;
635223ec6965SJ. Bruce Fields 
6353bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
635423ec6965SJ. Bruce Fields 	if (status)
635523ec6965SJ. Bruce Fields 		goto out;
6356bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63579b7b9fccSAndy Adamson 	if (status)
63589b7b9fccSAndy Adamson 		goto out;
6359bf269551SChuck Lever 	status = decode_putfh(xdr);
636023ec6965SJ. Bruce Fields 	if (status)
636123ec6965SJ. Bruce Fields 		goto out;
6362bf269551SChuck Lever 	status = decode_setattr(xdr);
636323ec6965SJ. Bruce Fields out:
636423ec6965SJ. Bruce Fields 	return status;
636523ec6965SJ. Bruce Fields }
63661da177e4SLinus Torvalds 
63671da177e4SLinus Torvalds /*
6368029d105eSJ. Bruce Fields  * Decode GETACL response
6369029d105eSJ. Bruce Fields  */
6370029d105eSJ. Bruce Fields static int
6371bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6372fc016483SChristoph Hellwig 		    void *data)
6373029d105eSJ. Bruce Fields {
6374fc016483SChristoph Hellwig 	struct nfs_getaclres *res = data;
6375029d105eSJ. Bruce Fields 	struct compound_hdr hdr;
6376029d105eSJ. Bruce Fields 	int status;
6377029d105eSJ. Bruce Fields 
6378331818f1STrond Myklebust 	if (res->acl_scratch != NULL) {
6379331818f1STrond Myklebust 		void *p = page_address(res->acl_scratch);
6380331818f1STrond Myklebust 		xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6381331818f1STrond Myklebust 	}
6382bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6383029d105eSJ. Bruce Fields 	if (status)
6384029d105eSJ. Bruce Fields 		goto out;
6385bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
63869b7b9fccSAndy Adamson 	if (status)
63879b7b9fccSAndy Adamson 		goto out;
6388bf269551SChuck Lever 	status = decode_putfh(xdr);
6389029d105eSJ. Bruce Fields 	if (status)
6390029d105eSJ. Bruce Fields 		goto out;
6391bf118a34SAndy Adamson 	status = decode_getacl(xdr, rqstp, res);
6392029d105eSJ. Bruce Fields 
6393029d105eSJ. Bruce Fields out:
6394029d105eSJ. Bruce Fields 	return status;
6395029d105eSJ. Bruce Fields }
6396029d105eSJ. Bruce Fields 
6397029d105eSJ. Bruce Fields /*
63981da177e4SLinus Torvalds  * Decode CLOSE response
63991da177e4SLinus Torvalds  */
6400bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6401fc016483SChristoph Hellwig 			      void *data)
64021da177e4SLinus Torvalds {
6403fc016483SChristoph Hellwig 	struct nfs_closeres *res = data;
64041da177e4SLinus Torvalds 	struct compound_hdr hdr;
64051da177e4SLinus Torvalds 	int status;
64061da177e4SLinus Torvalds 
6407bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64081da177e4SLinus Torvalds 	if (status)
64091da177e4SLinus Torvalds 		goto out;
6410bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64119b7b9fccSAndy Adamson 	if (status)
64129b7b9fccSAndy Adamson 		goto out;
6413bf269551SChuck Lever 	status = decode_putfh(xdr);
64141da177e4SLinus Torvalds 	if (status)
64151da177e4SLinus Torvalds 		goto out;
6416cf805165STrond Myklebust 	if (res->lr_res) {
6417cf805165STrond Myklebust 		status = decode_layoutreturn(xdr, res->lr_res);
6418cf805165STrond Myklebust 		res->lr_ret = status;
6419cf805165STrond Myklebust 		if (status)
6420cf805165STrond Myklebust 			goto out;
6421cf805165STrond Myklebust 	}
6422d8d84983STrond Myklebust 	if (res->fattr != NULL) {
6423d8d84983STrond Myklebust 		status = decode_getfattr(xdr, res->fattr, res->server);
6424516a6af6STrond Myklebust 		if (status != 0)
6425516a6af6STrond Myklebust 			goto out;
6426d8d84983STrond Myklebust 	}
6427d8d84983STrond Myklebust 	status = decode_close(xdr, res);
64281da177e4SLinus Torvalds out:
64291da177e4SLinus Torvalds 	return status;
64301da177e4SLinus Torvalds }
64311da177e4SLinus Torvalds 
64321da177e4SLinus Torvalds /*
64331da177e4SLinus Torvalds  * Decode OPEN response
64341da177e4SLinus Torvalds  */
6435bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6436fc016483SChristoph Hellwig 			     void *data)
64371da177e4SLinus Torvalds {
6438fc016483SChristoph Hellwig 	struct nfs_openres *res = data;
64391da177e4SLinus Torvalds 	struct compound_hdr hdr;
64401da177e4SLinus Torvalds 	int status;
64411da177e4SLinus Torvalds 
6442bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64431da177e4SLinus Torvalds 	if (status)
64441da177e4SLinus Torvalds 		goto out;
6445bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
64469b7b9fccSAndy Adamson 	if (status)
64479b7b9fccSAndy Adamson 		goto out;
6448bf269551SChuck Lever 	status = decode_putfh(xdr);
64491da177e4SLinus Torvalds 	if (status)
64501da177e4SLinus Torvalds 		goto out;
6451bf269551SChuck Lever 	status = decode_open(xdr, res);
64521da177e4SLinus Torvalds 	if (status)
64531da177e4SLinus Torvalds 		goto out;
645401913b49SWeston Andros Adamson 	status = decode_getfh(xdr, &res->fh);
645501913b49SWeston Andros Adamson 	if (status)
64561da177e4SLinus Torvalds 		goto out;
6457ae2bb032SWeston Andros Adamson 	if (res->access_request)
64586168f62cSWeston Andros Adamson 		decode_access(xdr, &res->access_supported, &res->access_result);
6459aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
646056f487f8SFred Isaman 	if (res->lg_res)
646156f487f8SFred Isaman 		decode_layoutget(xdr, rqstp, res->lg_res);
64621da177e4SLinus Torvalds out:
64631da177e4SLinus Torvalds 	return status;
64641da177e4SLinus Torvalds }
64651da177e4SLinus Torvalds 
64661da177e4SLinus Torvalds /*
64671da177e4SLinus Torvalds  * Decode OPEN_CONFIRM response
64681da177e4SLinus Torvalds  */
6469bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6470bf269551SChuck Lever 				     struct xdr_stream *xdr,
6471fc016483SChristoph Hellwig 				     void *data)
64721da177e4SLinus Torvalds {
6473fc016483SChristoph Hellwig 	struct nfs_open_confirmres *res = data;
64741da177e4SLinus Torvalds 	struct compound_hdr hdr;
64751da177e4SLinus Torvalds 	int status;
64761da177e4SLinus Torvalds 
6477bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
64781da177e4SLinus Torvalds 	if (status)
64791da177e4SLinus Torvalds 		goto out;
6480bf269551SChuck Lever 	status = decode_putfh(xdr);
64811da177e4SLinus Torvalds 	if (status)
64821da177e4SLinus Torvalds 		goto out;
6483bf269551SChuck Lever 	status = decode_open_confirm(xdr, res);
64841da177e4SLinus Torvalds out:
64851da177e4SLinus Torvalds 	return status;
64861da177e4SLinus Torvalds }
64871da177e4SLinus Torvalds 
64881da177e4SLinus Torvalds /*
64891da177e4SLinus Torvalds  * Decode OPEN response
64901da177e4SLinus Torvalds  */
6491bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6492bf269551SChuck Lever 				    struct xdr_stream *xdr,
6493fc016483SChristoph Hellwig 				    void *data)
64941da177e4SLinus Torvalds {
6495fc016483SChristoph Hellwig 	struct nfs_openres *res = data;
64961da177e4SLinus Torvalds 	struct compound_hdr hdr;
64971da177e4SLinus Torvalds 	int status;
64981da177e4SLinus Torvalds 
6499bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65001da177e4SLinus Torvalds 	if (status)
65011da177e4SLinus Torvalds 		goto out;
6502bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65039b7b9fccSAndy Adamson 	if (status)
65049b7b9fccSAndy Adamson 		goto out;
6505bf269551SChuck Lever 	status = decode_putfh(xdr);
65061da177e4SLinus Torvalds 	if (status)
65071da177e4SLinus Torvalds 		goto out;
6508bf269551SChuck Lever 	status = decode_open(xdr, res);
6509864472e9STrond Myklebust 	if (status)
6510864472e9STrond Myklebust 		goto out;
6511ae2bb032SWeston Andros Adamson 	if (res->access_request)
65126168f62cSWeston Andros Adamson 		decode_access(xdr, &res->access_supported, &res->access_result);
65136926afd1STrond Myklebust 	decode_getfattr(xdr, res->f_attr, res->server);
651456f487f8SFred Isaman 	if (res->lg_res)
651556f487f8SFred Isaman 		decode_layoutget(xdr, rqstp, res->lg_res);
65161da177e4SLinus Torvalds out:
65171da177e4SLinus Torvalds 	return status;
65181da177e4SLinus Torvalds }
65191da177e4SLinus Torvalds 
65201da177e4SLinus Torvalds /*
65211da177e4SLinus Torvalds  * Decode SETATTR response
65221da177e4SLinus Torvalds  */
6523bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6524bf269551SChuck Lever 				struct xdr_stream *xdr,
6525fc016483SChristoph Hellwig 				void *data)
65261da177e4SLinus Torvalds {
6527fc016483SChristoph Hellwig 	struct nfs_setattrres *res = data;
65281da177e4SLinus Torvalds 	struct compound_hdr hdr;
65291da177e4SLinus Torvalds 	int status;
65301da177e4SLinus Torvalds 
6531bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65321da177e4SLinus Torvalds 	if (status)
65331da177e4SLinus Torvalds 		goto out;
6534bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65359b7b9fccSAndy Adamson 	if (status)
65369b7b9fccSAndy Adamson 		goto out;
6537bf269551SChuck Lever 	status = decode_putfh(xdr);
65381da177e4SLinus Torvalds 	if (status)
65391da177e4SLinus Torvalds 		goto out;
6540bf269551SChuck Lever 	status = decode_setattr(xdr);
65411da177e4SLinus Torvalds 	if (status)
65421da177e4SLinus Torvalds 		goto out;
6543aa9c2669SDavid Quigley 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
65441da177e4SLinus Torvalds out:
65451da177e4SLinus Torvalds 	return status;
65461da177e4SLinus Torvalds }
65471da177e4SLinus Torvalds 
65481da177e4SLinus Torvalds /*
65491da177e4SLinus Torvalds  * Decode LOCK response
65501da177e4SLinus Torvalds  */
6551bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6552fc016483SChristoph Hellwig 			     void *data)
65531da177e4SLinus Torvalds {
6554fc016483SChristoph Hellwig 	struct nfs_lock_res *res = data;
65551da177e4SLinus Torvalds 	struct compound_hdr hdr;
65561da177e4SLinus Torvalds 	int status;
65571da177e4SLinus Torvalds 
6558bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65591da177e4SLinus Torvalds 	if (status)
65601da177e4SLinus Torvalds 		goto out;
6561bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65629b7b9fccSAndy Adamson 	if (status)
65639b7b9fccSAndy Adamson 		goto out;
6564bf269551SChuck Lever 	status = decode_putfh(xdr);
65651da177e4SLinus Torvalds 	if (status)
65661da177e4SLinus Torvalds 		goto out;
6567bf269551SChuck Lever 	status = decode_lock(xdr, res);
65681da177e4SLinus Torvalds out:
65691da177e4SLinus Torvalds 	return status;
65701da177e4SLinus Torvalds }
65711da177e4SLinus Torvalds 
65721da177e4SLinus Torvalds /*
65731da177e4SLinus Torvalds  * Decode LOCKT response
65741da177e4SLinus Torvalds  */
6575bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6576fc016483SChristoph Hellwig 			      void *data)
65771da177e4SLinus Torvalds {
6578fc016483SChristoph Hellwig 	struct nfs_lockt_res *res = data;
65791da177e4SLinus Torvalds 	struct compound_hdr hdr;
65801da177e4SLinus Torvalds 	int status;
65811da177e4SLinus Torvalds 
6582bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
65831da177e4SLinus Torvalds 	if (status)
65841da177e4SLinus Torvalds 		goto out;
6585bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
65869b7b9fccSAndy Adamson 	if (status)
65879b7b9fccSAndy Adamson 		goto out;
6588bf269551SChuck Lever 	status = decode_putfh(xdr);
65891da177e4SLinus Torvalds 	if (status)
65901da177e4SLinus Torvalds 		goto out;
6591bf269551SChuck Lever 	status = decode_lockt(xdr, res);
65921da177e4SLinus Torvalds out:
65931da177e4SLinus Torvalds 	return status;
65941da177e4SLinus Torvalds }
65951da177e4SLinus Torvalds 
65961da177e4SLinus Torvalds /*
65971da177e4SLinus Torvalds  * Decode LOCKU response
65981da177e4SLinus Torvalds  */
6599bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6600fc016483SChristoph Hellwig 			      void *data)
66011da177e4SLinus Torvalds {
6602fc016483SChristoph Hellwig 	struct nfs_locku_res *res = data;
66031da177e4SLinus Torvalds 	struct compound_hdr hdr;
66041da177e4SLinus Torvalds 	int status;
66051da177e4SLinus Torvalds 
6606bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66071da177e4SLinus Torvalds 	if (status)
66081da177e4SLinus Torvalds 		goto out;
6609bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66109b7b9fccSAndy Adamson 	if (status)
66119b7b9fccSAndy Adamson 		goto out;
6612bf269551SChuck Lever 	status = decode_putfh(xdr);
66131da177e4SLinus Torvalds 	if (status)
66141da177e4SLinus Torvalds 		goto out;
6615bf269551SChuck Lever 	status = decode_locku(xdr, res);
66161da177e4SLinus Torvalds out:
66171da177e4SLinus Torvalds 	return status;
66181da177e4SLinus Torvalds }
66191da177e4SLinus Torvalds 
6620bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6621bf269551SChuck Lever 					  struct xdr_stream *xdr, void *dummy)
6622d3c7b7ccSTrond Myklebust {
6623d3c7b7ccSTrond Myklebust 	struct compound_hdr hdr;
6624d3c7b7ccSTrond Myklebust 	int status;
6625d3c7b7ccSTrond Myklebust 
6626bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6627d3c7b7ccSTrond Myklebust 	if (!status)
6628bf269551SChuck Lever 		status = decode_release_lockowner(xdr);
6629d3c7b7ccSTrond Myklebust 	return status;
6630d3c7b7ccSTrond Myklebust }
6631d3c7b7ccSTrond Myklebust 
66321da177e4SLinus Torvalds /*
66331da177e4SLinus Torvalds  * Decode READLINK response
66341da177e4SLinus Torvalds  */
6635bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6636bf269551SChuck Lever 				 struct xdr_stream *xdr,
6637fc016483SChristoph Hellwig 				 void *data)
66381da177e4SLinus Torvalds {
6639fc016483SChristoph Hellwig 	struct nfs4_readlink_res *res = data;
66401da177e4SLinus Torvalds 	struct compound_hdr hdr;
66411da177e4SLinus Torvalds 	int status;
66421da177e4SLinus Torvalds 
6643bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66441da177e4SLinus Torvalds 	if (status)
66451da177e4SLinus Torvalds 		goto out;
6646bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66479b7b9fccSAndy Adamson 	if (status)
66489b7b9fccSAndy Adamson 		goto out;
6649bf269551SChuck Lever 	status = decode_putfh(xdr);
66501da177e4SLinus Torvalds 	if (status)
66511da177e4SLinus Torvalds 		goto out;
6652bf269551SChuck Lever 	status = decode_readlink(xdr, rqstp);
66531da177e4SLinus Torvalds out:
66541da177e4SLinus Torvalds 	return status;
66551da177e4SLinus Torvalds }
66561da177e4SLinus Torvalds 
66571da177e4SLinus Torvalds /*
66581da177e4SLinus Torvalds  * Decode READDIR response
66591da177e4SLinus Torvalds  */
6660bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6661fc016483SChristoph Hellwig 				void *data)
66621da177e4SLinus Torvalds {
6663fc016483SChristoph Hellwig 	struct nfs4_readdir_res *res = data;
66641da177e4SLinus Torvalds 	struct compound_hdr hdr;
66651da177e4SLinus Torvalds 	int status;
66661da177e4SLinus Torvalds 
6667bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
66681da177e4SLinus Torvalds 	if (status)
66691da177e4SLinus Torvalds 		goto out;
6670bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66719b7b9fccSAndy Adamson 	if (status)
66729b7b9fccSAndy Adamson 		goto out;
6673bf269551SChuck Lever 	status = decode_putfh(xdr);
66741da177e4SLinus Torvalds 	if (status)
66751da177e4SLinus Torvalds 		goto out;
6676bf269551SChuck Lever 	status = decode_readdir(xdr, rqstp, res);
66771da177e4SLinus Torvalds out:
66781da177e4SLinus Torvalds 	return status;
66791da177e4SLinus Torvalds }
66801da177e4SLinus Torvalds 
66811da177e4SLinus Torvalds /*
66821da177e4SLinus Torvalds  * Decode Read response
66831da177e4SLinus Torvalds  */
6684bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6685fc016483SChristoph Hellwig 			     void *data)
66861da177e4SLinus Torvalds {
6687fc016483SChristoph Hellwig 	struct nfs_pgio_res *res = data;
66881da177e4SLinus Torvalds 	struct compound_hdr hdr;
66891da177e4SLinus Torvalds 	int status;
66901da177e4SLinus Torvalds 
6691bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6692aabff4ddSPeng Tao 	res->op_status = hdr.status;
66931da177e4SLinus Torvalds 	if (status)
66941da177e4SLinus Torvalds 		goto out;
6695bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
66969b7b9fccSAndy Adamson 	if (status)
66979b7b9fccSAndy Adamson 		goto out;
6698bf269551SChuck Lever 	status = decode_putfh(xdr);
66991da177e4SLinus Torvalds 	if (status)
67001da177e4SLinus Torvalds 		goto out;
6701bf269551SChuck Lever 	status = decode_read(xdr, rqstp, res);
67021da177e4SLinus Torvalds 	if (!status)
67031da177e4SLinus Torvalds 		status = res->count;
67041da177e4SLinus Torvalds out:
67051da177e4SLinus Torvalds 	return status;
67061da177e4SLinus Torvalds }
67071da177e4SLinus Torvalds 
67081da177e4SLinus Torvalds /*
67091da177e4SLinus Torvalds  * Decode WRITE response
67101da177e4SLinus Torvalds  */
6711bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6712fc016483SChristoph Hellwig 			      void *data)
67131da177e4SLinus Torvalds {
6714fc016483SChristoph Hellwig 	struct nfs_pgio_res *res = data;
67151da177e4SLinus Torvalds 	struct compound_hdr hdr;
67161da177e4SLinus Torvalds 	int status;
67171da177e4SLinus Torvalds 
6718bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6719aabff4ddSPeng Tao 	res->op_status = hdr.status;
67201da177e4SLinus Torvalds 	if (status)
67211da177e4SLinus Torvalds 		goto out;
6722bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67239b7b9fccSAndy Adamson 	if (status)
67249b7b9fccSAndy Adamson 		goto out;
6725bf269551SChuck Lever 	status = decode_putfh(xdr);
67261da177e4SLinus Torvalds 	if (status)
67271da177e4SLinus Torvalds 		goto out;
6728bf269551SChuck Lever 	status = decode_write(xdr, res);
67294f9838c7STrond Myklebust 	if (status)
67304f9838c7STrond Myklebust 		goto out;
67317ffd1064SFred Isaman 	if (res->fattr)
67326926afd1STrond Myklebust 		decode_getfattr(xdr, res->fattr, res->server);
67331da177e4SLinus Torvalds 	if (!status)
67341da177e4SLinus Torvalds 		status = res->count;
67351da177e4SLinus Torvalds out:
67361da177e4SLinus Torvalds 	return status;
67371da177e4SLinus Torvalds }
67381da177e4SLinus Torvalds 
67391da177e4SLinus Torvalds /*
67401da177e4SLinus Torvalds  * Decode COMMIT response
67411da177e4SLinus Torvalds  */
6742bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6743fc016483SChristoph Hellwig 			       void *data)
67441da177e4SLinus Torvalds {
6745fc016483SChristoph Hellwig 	struct nfs_commitres *res = data;
67461da177e4SLinus Torvalds 	struct compound_hdr hdr;
67471da177e4SLinus Torvalds 	int status;
67481da177e4SLinus Torvalds 
6749bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
6750aabff4ddSPeng Tao 	res->op_status = hdr.status;
67511da177e4SLinus Torvalds 	if (status)
67521da177e4SLinus Torvalds 		goto out;
6753bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
67549b7b9fccSAndy Adamson 	if (status)
67559b7b9fccSAndy Adamson 		goto out;
6756bf269551SChuck Lever 	status = decode_putfh(xdr);
67571da177e4SLinus Torvalds 	if (status)
67581da177e4SLinus Torvalds 		goto out;
6759bf269551SChuck Lever 	status = decode_commit(xdr, res);
67601da177e4SLinus Torvalds out:
67611da177e4SLinus Torvalds 	return status;
67621da177e4SLinus Torvalds }
67631da177e4SLinus Torvalds 
67641da177e4SLinus Torvalds /*
67658b173218SRicardo Labiaga  * Decode FSINFO response
67661da177e4SLinus Torvalds  */
6767bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6768fc016483SChristoph Hellwig 			       void *data)
67691da177e4SLinus Torvalds {
6770fc016483SChristoph Hellwig 	struct nfs4_fsinfo_res *res = data;
67711da177e4SLinus Torvalds 	struct compound_hdr hdr;
67721da177e4SLinus Torvalds 	int status;
67731da177e4SLinus Torvalds 
6774bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67751da177e4SLinus Torvalds 	if (!status)
6776bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
67779b7b9fccSAndy Adamson 	if (!status)
6778bf269551SChuck Lever 		status = decode_putfh(xdr);
67791da177e4SLinus Torvalds 	if (!status)
6780bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->fsinfo);
67811da177e4SLinus Torvalds 	return status;
67821da177e4SLinus Torvalds }
67831da177e4SLinus Torvalds 
67841da177e4SLinus Torvalds /*
67858b173218SRicardo Labiaga  * Decode PATHCONF response
67861da177e4SLinus Torvalds  */
6787bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6788fc016483SChristoph Hellwig 				 void *data)
67891da177e4SLinus Torvalds {
6790fc016483SChristoph Hellwig 	struct nfs4_pathconf_res *res = data;
67911da177e4SLinus Torvalds 	struct compound_hdr hdr;
67921da177e4SLinus Torvalds 	int status;
67931da177e4SLinus Torvalds 
6794bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
67951da177e4SLinus Torvalds 	if (!status)
6796bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
67979b7b9fccSAndy Adamson 	if (!status)
6798bf269551SChuck Lever 		status = decode_putfh(xdr);
67991da177e4SLinus Torvalds 	if (!status)
6800bf269551SChuck Lever 		status = decode_pathconf(xdr, res->pathconf);
68011da177e4SLinus Torvalds 	return status;
68021da177e4SLinus Torvalds }
68031da177e4SLinus Torvalds 
68041da177e4SLinus Torvalds /*
68058b173218SRicardo Labiaga  * Decode STATFS response
68061da177e4SLinus Torvalds  */
6807bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6808fc016483SChristoph Hellwig 			       void *data)
68091da177e4SLinus Torvalds {
6810fc016483SChristoph Hellwig 	struct nfs4_statfs_res *res = data;
68111da177e4SLinus Torvalds 	struct compound_hdr hdr;
68121da177e4SLinus Torvalds 	int status;
68131da177e4SLinus Torvalds 
6814bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68151da177e4SLinus Torvalds 	if (!status)
6816bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, req);
68179b7b9fccSAndy Adamson 	if (!status)
6818bf269551SChuck Lever 		status = decode_putfh(xdr);
68191da177e4SLinus Torvalds 	if (!status)
6820bf269551SChuck Lever 		status = decode_statfs(xdr, res->fsstat);
68211da177e4SLinus Torvalds 	return status;
68221da177e4SLinus Torvalds }
68231da177e4SLinus Torvalds 
68241da177e4SLinus Torvalds /*
68258b173218SRicardo Labiaga  * Decode GETATTR_BITMAP response
68261da177e4SLinus Torvalds  */
6827bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6828bf269551SChuck Lever 				    struct xdr_stream *xdr,
6829fc016483SChristoph Hellwig 				    void *data)
68301da177e4SLinus Torvalds {
6831fc016483SChristoph Hellwig 	struct nfs4_server_caps_res *res = data;
68321da177e4SLinus Torvalds 	struct compound_hdr hdr;
68331da177e4SLinus Torvalds 	int status;
68341da177e4SLinus Torvalds 
6835bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68369b7b9fccSAndy Adamson 	if (status)
68379b7b9fccSAndy Adamson 		goto out;
6838bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
68399b7b9fccSAndy Adamson 	if (status)
68401da177e4SLinus Torvalds 		goto out;
6841bf269551SChuck Lever 	status = decode_putfh(xdr);
6842bf269551SChuck Lever 	if (status)
68431da177e4SLinus Torvalds 		goto out;
6844bf269551SChuck Lever 	status = decode_server_caps(xdr, res);
68451da177e4SLinus Torvalds out:
68461da177e4SLinus Torvalds 	return status;
68471da177e4SLinus Torvalds }
68481da177e4SLinus Torvalds 
68491da177e4SLinus Torvalds /*
68501da177e4SLinus Torvalds  * Decode RENEW response
68511da177e4SLinus Torvalds  */
6852bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6853bf269551SChuck Lever 			      void *__unused)
68541da177e4SLinus Torvalds {
68551da177e4SLinus Torvalds 	struct compound_hdr hdr;
68561da177e4SLinus Torvalds 	int status;
68571da177e4SLinus Torvalds 
6858bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68591da177e4SLinus Torvalds 	if (!status)
6860bf269551SChuck Lever 		status = decode_renew(xdr);
68611da177e4SLinus Torvalds 	return status;
68621da177e4SLinus Torvalds }
68631da177e4SLinus Torvalds 
68641da177e4SLinus Torvalds /*
68658b173218SRicardo Labiaga  * Decode SETCLIENTID response
68661da177e4SLinus Torvalds  */
6867bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6868bf269551SChuck Lever 				    struct xdr_stream *xdr,
6869fc016483SChristoph Hellwig 				    void *data)
68701da177e4SLinus Torvalds {
6871fc016483SChristoph Hellwig 	struct nfs4_setclientid_res *res = data;
68721da177e4SLinus Torvalds 	struct compound_hdr hdr;
68731da177e4SLinus Torvalds 	int status;
68741da177e4SLinus Torvalds 
6875bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68761da177e4SLinus Torvalds 	if (!status)
6877bf269551SChuck Lever 		status = decode_setclientid(xdr, res);
68781da177e4SLinus Torvalds 	return status;
68791da177e4SLinus Torvalds }
68801da177e4SLinus Torvalds 
68811da177e4SLinus Torvalds /*
68828b173218SRicardo Labiaga  * Decode SETCLIENTID_CONFIRM response
68831da177e4SLinus Torvalds  */
6884bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6885fc016483SChristoph Hellwig 					    struct xdr_stream *xdr,
6886fc016483SChristoph Hellwig 					    void *data)
68871da177e4SLinus Torvalds {
68881da177e4SLinus Torvalds 	struct compound_hdr hdr;
68891da177e4SLinus Torvalds 	int status;
68901da177e4SLinus Torvalds 
6891bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
68921da177e4SLinus Torvalds 	if (!status)
6893bf269551SChuck Lever 		status = decode_setclientid_confirm(xdr);
68941da177e4SLinus Torvalds 	return status;
68951da177e4SLinus Torvalds }
68961da177e4SLinus Torvalds 
68971da177e4SLinus Torvalds /*
68988b173218SRicardo Labiaga  * Decode DELEGRETURN response
68991da177e4SLinus Torvalds  */
6900bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6901bf269551SChuck Lever 				    struct xdr_stream *xdr,
6902fc016483SChristoph Hellwig 				    void *data)
69031da177e4SLinus Torvalds {
6904fc016483SChristoph Hellwig 	struct nfs4_delegreturnres *res = data;
69051da177e4SLinus Torvalds 	struct compound_hdr hdr;
69061da177e4SLinus Torvalds 	int status;
69071da177e4SLinus Torvalds 
6908bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
69099b7b9fccSAndy Adamson 	if (status)
69109b7b9fccSAndy Adamson 		goto out;
6911bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
69129b7b9fccSAndy Adamson 	if (status)
6913fa178f29STrond Myklebust 		goto out;
6914bf269551SChuck Lever 	status = decode_putfh(xdr);
6915fa178f29STrond Myklebust 	if (status != 0)
6916fa178f29STrond Myklebust 		goto out;
6917586f1c39STrond Myklebust 	if (res->lr_res) {
6918586f1c39STrond Myklebust 		status = decode_layoutreturn(xdr, res->lr_res);
6919586f1c39STrond Myklebust 		res->lr_ret = status;
6920586f1c39STrond Myklebust 		if (status)
6921586f1c39STrond Myklebust 			goto out;
6922586f1c39STrond Myklebust 	}
69238ac2b422STrond Myklebust 	if (res->fattr) {
6924e144cbccSTrond Myklebust 		status = decode_getfattr(xdr, res->fattr, res->server);
6925556ae3bbSJeff Layton 		if (status != 0)
6926556ae3bbSJeff Layton 			goto out;
69278ac2b422STrond Myklebust 	}
6928e144cbccSTrond Myklebust 	status = decode_delegreturn(xdr);
6929fa178f29STrond Myklebust out:
69301da177e4SLinus Torvalds 	return status;
69311da177e4SLinus Torvalds }
69321da177e4SLinus Torvalds 
6933683b57b4STrond Myklebust /*
69348b173218SRicardo Labiaga  * Decode FS_LOCATIONS response
6935683b57b4STrond Myklebust  */
6936bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6937bf269551SChuck Lever 				     struct xdr_stream *xdr,
6938fc016483SChristoph Hellwig 				     void *data)
6939683b57b4STrond Myklebust {
6940fc016483SChristoph Hellwig 	struct nfs4_fs_locations_res *res = data;
6941683b57b4STrond Myklebust 	struct compound_hdr hdr;
6942683b57b4STrond Myklebust 	int status;
6943683b57b4STrond Myklebust 
6944bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
69459b7b9fccSAndy Adamson 	if (status)
69469b7b9fccSAndy Adamson 		goto out;
6947bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, req);
69489b7b9fccSAndy Adamson 	if (status)
6949683b57b4STrond Myklebust 		goto out;
6950bf269551SChuck Lever 	status = decode_putfh(xdr);
6951bf269551SChuck Lever 	if (status)
6952683b57b4STrond Myklebust 		goto out;
6953b03d735bSChuck Lever 	if (res->migration) {
6954b03d735bSChuck Lever 		xdr_enter_page(xdr, PAGE_SIZE);
6955b03d735bSChuck Lever 		status = decode_getfattr_generic(xdr,
6956b03d735bSChuck Lever 					&res->fs_locations->fattr,
6957b03d735bSChuck Lever 					 NULL, res->fs_locations,
6958b03d735bSChuck Lever 					 NULL, res->fs_locations->server);
6959b03d735bSChuck Lever 		if (status)
6960b03d735bSChuck Lever 			goto out;
6961b03d735bSChuck Lever 		if (res->renew)
6962b03d735bSChuck Lever 			status = decode_renew(xdr);
6963b03d735bSChuck Lever 	} else {
6964bf269551SChuck Lever 		status = decode_lookup(xdr);
6965bf269551SChuck Lever 		if (status)
6966683b57b4STrond Myklebust 			goto out;
6967bf269551SChuck Lever 		xdr_enter_page(xdr, PAGE_SIZE);
6968b03d735bSChuck Lever 		status = decode_getfattr_generic(xdr,
6969b03d735bSChuck Lever 					&res->fs_locations->fattr,
69708b7e3f49STrond Myklebust 					 NULL, res->fs_locations,
6971aa9c2669SDavid Quigley 					 NULL, res->fs_locations->server);
6972b03d735bSChuck Lever 	}
6973683b57b4STrond Myklebust out:
6974683b57b4STrond Myklebust 	return status;
6975683b57b4STrond Myklebust }
6976683b57b4STrond Myklebust 
69775a5ea0d4SBryan Schumaker /*
69785a5ea0d4SBryan Schumaker  * Decode SECINFO response
69795a5ea0d4SBryan Schumaker  */
69805a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
69815a5ea0d4SBryan Schumaker 				struct xdr_stream *xdr,
6982fc016483SChristoph Hellwig 				void *data)
69835a5ea0d4SBryan Schumaker {
6984fc016483SChristoph Hellwig 	struct nfs4_secinfo_res *res = data;
69855a5ea0d4SBryan Schumaker 	struct compound_hdr hdr;
69865a5ea0d4SBryan Schumaker 	int status;
69875a5ea0d4SBryan Schumaker 
69885a5ea0d4SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
69895a5ea0d4SBryan Schumaker 	if (status)
69905a5ea0d4SBryan Schumaker 		goto out;
69915a5ea0d4SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
69925a5ea0d4SBryan Schumaker 	if (status)
69935a5ea0d4SBryan Schumaker 		goto out;
69945a5ea0d4SBryan Schumaker 	status = decode_putfh(xdr);
69955a5ea0d4SBryan Schumaker 	if (status)
69965a5ea0d4SBryan Schumaker 		goto out;
69975a5ea0d4SBryan Schumaker 	status = decode_secinfo(xdr, res);
69985a5ea0d4SBryan Schumaker out:
69995a5ea0d4SBryan Schumaker 	return status;
70005a5ea0d4SBryan Schumaker }
70015a5ea0d4SBryan Schumaker 
700244c99933SChuck Lever /*
700344c99933SChuck Lever  * Decode FSID_PRESENT response
700444c99933SChuck Lever  */
700544c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
700644c99933SChuck Lever 				     struct xdr_stream *xdr,
7007fc016483SChristoph Hellwig 				     void *data)
700844c99933SChuck Lever {
7009fc016483SChristoph Hellwig 	struct nfs4_fsid_present_res *res = data;
701044c99933SChuck Lever 	struct compound_hdr hdr;
701144c99933SChuck Lever 	int status;
701244c99933SChuck Lever 
701344c99933SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
701444c99933SChuck Lever 	if (status)
701544c99933SChuck Lever 		goto out;
701644c99933SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
701744c99933SChuck Lever 	if (status)
701844c99933SChuck Lever 		goto out;
701944c99933SChuck Lever 	status = decode_putfh(xdr);
702044c99933SChuck Lever 	if (status)
702144c99933SChuck Lever 		goto out;
702244c99933SChuck Lever 	status = decode_getfh(xdr, res->fh);
702344c99933SChuck Lever 	if (status)
702444c99933SChuck Lever 		goto out;
702544c99933SChuck Lever 	if (res->renew)
702644c99933SChuck Lever 		status = decode_renew(xdr);
702744c99933SChuck Lever out:
702844c99933SChuck Lever 	return status;
702944c99933SChuck Lever }
703044c99933SChuck Lever 
703199fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
703299fe60d0SBenny Halevy /*
70337c44f1aeSWeston Andros Adamson  * Decode BIND_CONN_TO_SESSION response
70347c44f1aeSWeston Andros Adamson  */
70357c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
70367c44f1aeSWeston Andros Adamson 					struct xdr_stream *xdr,
70377c44f1aeSWeston Andros Adamson 					void *res)
70387c44f1aeSWeston Andros Adamson {
70397c44f1aeSWeston Andros Adamson 	struct compound_hdr hdr;
70407c44f1aeSWeston Andros Adamson 	int status;
70417c44f1aeSWeston Andros Adamson 
70427c44f1aeSWeston Andros Adamson 	status = decode_compound_hdr(xdr, &hdr);
70437c44f1aeSWeston Andros Adamson 	if (!status)
70447c44f1aeSWeston Andros Adamson 		status = decode_bind_conn_to_session(xdr, res);
70457c44f1aeSWeston Andros Adamson 	return status;
70467c44f1aeSWeston Andros Adamson }
70477c44f1aeSWeston Andros Adamson 
70487c44f1aeSWeston Andros Adamson /*
70498b173218SRicardo Labiaga  * Decode EXCHANGE_ID response
705099fe60d0SBenny Halevy  */
7051bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7052bf269551SChuck Lever 				    struct xdr_stream *xdr,
705399fe60d0SBenny Halevy 				    void *res)
705499fe60d0SBenny Halevy {
705599fe60d0SBenny Halevy 	struct compound_hdr hdr;
705699fe60d0SBenny Halevy 	int status;
705799fe60d0SBenny Halevy 
7058bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
705999fe60d0SBenny Halevy 	if (!status)
7060bf269551SChuck Lever 		status = decode_exchange_id(xdr, res);
706199fe60d0SBenny Halevy 	return status;
706299fe60d0SBenny Halevy }
70632050f0ccSAndy Adamson 
70642050f0ccSAndy Adamson /*
70658b173218SRicardo Labiaga  * Decode CREATE_SESSION response
7066fc931582SAndy Adamson  */
7067bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7068bf269551SChuck Lever 				       struct xdr_stream *xdr,
7069fc016483SChristoph Hellwig 				       void *res)
7070fc931582SAndy Adamson {
7071fc931582SAndy Adamson 	struct compound_hdr hdr;
7072fc931582SAndy Adamson 	int status;
7073fc931582SAndy Adamson 
7074bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7075fc931582SAndy Adamson 	if (!status)
7076bf269551SChuck Lever 		status = decode_create_session(xdr, res);
7077fc931582SAndy Adamson 	return status;
7078fc931582SAndy Adamson }
7079fc931582SAndy Adamson 
7080fc931582SAndy Adamson /*
70818b173218SRicardo Labiaga  * Decode DESTROY_SESSION response
70820f3e66c6SAndy Adamson  */
7083bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7084bf269551SChuck Lever 					struct xdr_stream *xdr,
7085bf269551SChuck Lever 					void *res)
70860f3e66c6SAndy Adamson {
70870f3e66c6SAndy Adamson 	struct compound_hdr hdr;
70880f3e66c6SAndy Adamson 	int status;
70890f3e66c6SAndy Adamson 
7090bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
70910f3e66c6SAndy Adamson 	if (!status)
7092bf269551SChuck Lever 		status = decode_destroy_session(xdr, res);
70930f3e66c6SAndy Adamson 	return status;
70940f3e66c6SAndy Adamson }
70950f3e66c6SAndy Adamson 
70960f3e66c6SAndy Adamson /*
709766245539STrond Myklebust  * Decode DESTROY_CLIENTID response
709866245539STrond Myklebust  */
709966245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
710066245539STrond Myklebust 					struct xdr_stream *xdr,
710166245539STrond Myklebust 					void *res)
710266245539STrond Myklebust {
710366245539STrond Myklebust 	struct compound_hdr hdr;
710466245539STrond Myklebust 	int status;
710566245539STrond Myklebust 
710666245539STrond Myklebust 	status = decode_compound_hdr(xdr, &hdr);
710766245539STrond Myklebust 	if (!status)
710866245539STrond Myklebust 		status = decode_destroy_clientid(xdr, res);
710966245539STrond Myklebust 	return status;
711066245539STrond Myklebust }
711166245539STrond Myklebust 
711266245539STrond Myklebust /*
71138b173218SRicardo Labiaga  * Decode SEQUENCE response
7114fc01cea9SAndy Adamson  */
7115bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7116bf269551SChuck Lever 				 struct xdr_stream *xdr,
7117fc016483SChristoph Hellwig 				 void *res)
7118fc01cea9SAndy Adamson {
7119fc01cea9SAndy Adamson 	struct compound_hdr hdr;
7120fc01cea9SAndy Adamson 	int status;
7121fc01cea9SAndy Adamson 
7122bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7123fc01cea9SAndy Adamson 	if (!status)
7124bf269551SChuck Lever 		status = decode_sequence(xdr, res, rqstp);
7125fc01cea9SAndy Adamson 	return status;
7126fc01cea9SAndy Adamson }
7127fc01cea9SAndy Adamson 
71280efb01b2SDonald Buczek #endif
71290efb01b2SDonald Buczek 
7130fc01cea9SAndy Adamson /*
71318b173218SRicardo Labiaga  * Decode GET_LEASE_TIME response
71322050f0ccSAndy Adamson  */
7133bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7134bf269551SChuck Lever 				       struct xdr_stream *xdr,
7135fc016483SChristoph Hellwig 				       void *data)
71362050f0ccSAndy Adamson {
7137fc016483SChristoph Hellwig 	struct nfs4_get_lease_time_res *res = data;
71382050f0ccSAndy Adamson 	struct compound_hdr hdr;
71392050f0ccSAndy Adamson 	int status;
71402050f0ccSAndy Adamson 
7141bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
71422050f0ccSAndy Adamson 	if (!status)
7143bf269551SChuck Lever 		status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
71442050f0ccSAndy Adamson 	if (!status)
7145bf269551SChuck Lever 		status = decode_putrootfh(xdr);
71462050f0ccSAndy Adamson 	if (!status)
7147bf269551SChuck Lever 		status = decode_fsinfo(xdr, res->lr_fsinfo);
71482050f0ccSAndy Adamson 	return status;
71492050f0ccSAndy Adamson }
715018019753SRicardo Labiaga 
71510efb01b2SDonald Buczek #ifdef CONFIG_NFS_V4_1
71520efb01b2SDonald Buczek 
715318019753SRicardo Labiaga /*
715418019753SRicardo Labiaga  * Decode RECLAIM_COMPLETE response
715518019753SRicardo Labiaga  */
7156bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7157bf269551SChuck Lever 					 struct xdr_stream *xdr,
7158fc016483SChristoph Hellwig 					 void *data)
715918019753SRicardo Labiaga {
7160fc016483SChristoph Hellwig 	struct nfs41_reclaim_complete_res *res = data;
716118019753SRicardo Labiaga 	struct compound_hdr hdr;
716218019753SRicardo Labiaga 	int status;
716318019753SRicardo Labiaga 
7164bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
716518019753SRicardo Labiaga 	if (!status)
7166bf269551SChuck Lever 		status = decode_sequence(xdr, &res->seq_res, rqstp);
716718019753SRicardo Labiaga 	if (!status)
71688ee2b78aSHimangi Saraogi 		status = decode_reclaim_complete(xdr, NULL);
716918019753SRicardo Labiaga 	return status;
717018019753SRicardo Labiaga }
7171b1f69b75SAndy Adamson 
7172b1f69b75SAndy Adamson /*
7173b1f69b75SAndy Adamson  * Decode GETDEVINFO response
7174b1f69b75SAndy Adamson  */
7175bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7176bf269551SChuck Lever 				      struct xdr_stream *xdr,
7177fc016483SChristoph Hellwig 				      void *data)
7178b1f69b75SAndy Adamson {
7179fc016483SChristoph Hellwig 	struct nfs4_getdeviceinfo_res *res = data;
7180b1f69b75SAndy Adamson 	struct compound_hdr hdr;
7181b1f69b75SAndy Adamson 	int status;
7182b1f69b75SAndy Adamson 
7183bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7184b1f69b75SAndy Adamson 	if (status != 0)
7185b1f69b75SAndy Adamson 		goto out;
7186bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7187b1f69b75SAndy Adamson 	if (status != 0)
7188b1f69b75SAndy Adamson 		goto out;
71894e590803STrond Myklebust 	status = decode_getdeviceinfo(xdr, res);
7190b1f69b75SAndy Adamson out:
7191b1f69b75SAndy Adamson 	return status;
7192b1f69b75SAndy Adamson }
7193b1f69b75SAndy Adamson 
7194b1f69b75SAndy Adamson /*
7195b1f69b75SAndy Adamson  * Decode LAYOUTGET response
7196b1f69b75SAndy Adamson  */
7197bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7198bf269551SChuck Lever 				  struct xdr_stream *xdr,
7199fc016483SChristoph Hellwig 				  void *data)
7200b1f69b75SAndy Adamson {
7201fc016483SChristoph Hellwig 	struct nfs4_layoutget_res *res = data;
7202b1f69b75SAndy Adamson 	struct compound_hdr hdr;
7203b1f69b75SAndy Adamson 	int status;
7204b1f69b75SAndy Adamson 
7205bf269551SChuck Lever 	status = decode_compound_hdr(xdr, &hdr);
7206b1f69b75SAndy Adamson 	if (status)
7207b1f69b75SAndy Adamson 		goto out;
7208bf269551SChuck Lever 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7209b1f69b75SAndy Adamson 	if (status)
7210b1f69b75SAndy Adamson 		goto out;
7211bf269551SChuck Lever 	status = decode_putfh(xdr);
7212b1f69b75SAndy Adamson 	if (status)
7213b1f69b75SAndy Adamson 		goto out;
7214bf269551SChuck Lever 	status = decode_layoutget(xdr, rqstp, res);
7215b1f69b75SAndy Adamson out:
7216b1f69b75SAndy Adamson 	return status;
7217b1f69b75SAndy Adamson }
7218863a3c6cSAndy Adamson 
7219863a3c6cSAndy Adamson /*
7220cbe82603SBenny Halevy  * Decode LAYOUTRETURN response
7221cbe82603SBenny Halevy  */
7222cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7223cbe82603SBenny Halevy 				     struct xdr_stream *xdr,
7224fc016483SChristoph Hellwig 				     void *data)
7225cbe82603SBenny Halevy {
7226fc016483SChristoph Hellwig 	struct nfs4_layoutreturn_res *res = data;
7227cbe82603SBenny Halevy 	struct compound_hdr hdr;
7228cbe82603SBenny Halevy 	int status;
7229cbe82603SBenny Halevy 
7230cbe82603SBenny Halevy 	status = decode_compound_hdr(xdr, &hdr);
7231cbe82603SBenny Halevy 	if (status)
7232cbe82603SBenny Halevy 		goto out;
7233cbe82603SBenny Halevy 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7234cbe82603SBenny Halevy 	if (status)
7235cbe82603SBenny Halevy 		goto out;
7236cbe82603SBenny Halevy 	status = decode_putfh(xdr);
7237cbe82603SBenny Halevy 	if (status)
7238cbe82603SBenny Halevy 		goto out;
7239cbe82603SBenny Halevy 	status = decode_layoutreturn(xdr, res);
7240cbe82603SBenny Halevy out:
7241cbe82603SBenny Halevy 	return status;
7242cbe82603SBenny Halevy }
7243cbe82603SBenny Halevy 
7244cbe82603SBenny Halevy /*
7245863a3c6cSAndy Adamson  * Decode LAYOUTCOMMIT response
7246863a3c6cSAndy Adamson  */
7247863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7248863a3c6cSAndy Adamson 				     struct xdr_stream *xdr,
7249fc016483SChristoph Hellwig 				     void *data)
7250863a3c6cSAndy Adamson {
7251fc016483SChristoph Hellwig 	struct nfs4_layoutcommit_res *res = data;
7252863a3c6cSAndy Adamson 	struct compound_hdr hdr;
7253863a3c6cSAndy Adamson 	int status;
7254863a3c6cSAndy Adamson 
7255863a3c6cSAndy Adamson 	status = decode_compound_hdr(xdr, &hdr);
7256863a3c6cSAndy Adamson 	if (status)
7257863a3c6cSAndy Adamson 		goto out;
7258863a3c6cSAndy Adamson 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7259863a3c6cSAndy Adamson 	if (status)
7260863a3c6cSAndy Adamson 		goto out;
7261863a3c6cSAndy Adamson 	status = decode_putfh(xdr);
7262863a3c6cSAndy Adamson 	if (status)
7263863a3c6cSAndy Adamson 		goto out;
7264863a3c6cSAndy Adamson 	status = decode_layoutcommit(xdr, rqstp, res);
7265863a3c6cSAndy Adamson 	if (status)
7266863a3c6cSAndy Adamson 		goto out;
72676926afd1STrond Myklebust 	decode_getfattr(xdr, res->fattr, res->server);
7268863a3c6cSAndy Adamson out:
7269863a3c6cSAndy Adamson 	return status;
7270863a3c6cSAndy Adamson }
7271fca78d6dSBryan Schumaker 
7272fca78d6dSBryan Schumaker /*
7273fca78d6dSBryan Schumaker  * Decode SECINFO_NO_NAME response
7274fca78d6dSBryan Schumaker  */
7275fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7276fca78d6dSBryan Schumaker 					struct xdr_stream *xdr,
7277fc016483SChristoph Hellwig 					void *data)
7278fca78d6dSBryan Schumaker {
7279fc016483SChristoph Hellwig 	struct nfs4_secinfo_res *res = data;
7280fca78d6dSBryan Schumaker 	struct compound_hdr hdr;
7281fca78d6dSBryan Schumaker 	int status;
7282fca78d6dSBryan Schumaker 
7283fca78d6dSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
7284fca78d6dSBryan Schumaker 	if (status)
7285fca78d6dSBryan Schumaker 		goto out;
7286fca78d6dSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7287fca78d6dSBryan Schumaker 	if (status)
7288fca78d6dSBryan Schumaker 		goto out;
7289fca78d6dSBryan Schumaker 	status = decode_putrootfh(xdr);
7290fca78d6dSBryan Schumaker 	if (status)
7291fca78d6dSBryan Schumaker 		goto out;
729231e4dda4SBryan Schumaker 	status = decode_secinfo_no_name(xdr, res);
7293fca78d6dSBryan Schumaker out:
7294fca78d6dSBryan Schumaker 	return status;
7295fca78d6dSBryan Schumaker }
72967d974794SBryan Schumaker 
72977d974794SBryan Schumaker /*
72987d974794SBryan Schumaker  * Decode TEST_STATEID response
72997d974794SBryan Schumaker  */
73007d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
73017d974794SBryan Schumaker 				     struct xdr_stream *xdr,
7302fc016483SChristoph Hellwig 				     void *data)
73037d974794SBryan Schumaker {
7304fc016483SChristoph Hellwig 	struct nfs41_test_stateid_res *res = data;
73057d974794SBryan Schumaker 	struct compound_hdr hdr;
73067d974794SBryan Schumaker 	int status;
73077d974794SBryan Schumaker 
73087d974794SBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
73097d974794SBryan Schumaker 	if (status)
73107d974794SBryan Schumaker 		goto out;
73117d974794SBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
73127d974794SBryan Schumaker 	if (status)
73137d974794SBryan Schumaker 		goto out;
73147d974794SBryan Schumaker 	status = decode_test_stateid(xdr, res);
73157d974794SBryan Schumaker out:
73167d974794SBryan Schumaker 	return status;
73177d974794SBryan Schumaker }
73189aeda35fSBryan Schumaker 
73199aeda35fSBryan Schumaker /*
73209aeda35fSBryan Schumaker  * Decode FREE_STATEID response
73219aeda35fSBryan Schumaker  */
73229aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
73239aeda35fSBryan Schumaker 				     struct xdr_stream *xdr,
7324fc016483SChristoph Hellwig 				     void *data)
73259aeda35fSBryan Schumaker {
7326fc016483SChristoph Hellwig 	struct nfs41_free_stateid_res *res = data;
73279aeda35fSBryan Schumaker 	struct compound_hdr hdr;
73289aeda35fSBryan Schumaker 	int status;
73299aeda35fSBryan Schumaker 
73309aeda35fSBryan Schumaker 	status = decode_compound_hdr(xdr, &hdr);
73319aeda35fSBryan Schumaker 	if (status)
73329aeda35fSBryan Schumaker 		goto out;
73339aeda35fSBryan Schumaker 	status = decode_sequence(xdr, &res->seq_res, rqstp);
73349aeda35fSBryan Schumaker 	if (status)
73359aeda35fSBryan Schumaker 		goto out;
73369aeda35fSBryan Schumaker 	status = decode_free_stateid(xdr, res);
73379aeda35fSBryan Schumaker out:
73389aeda35fSBryan Schumaker 	return status;
73399aeda35fSBryan Schumaker }
734099fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
734199fe60d0SBenny Halevy 
7342573c4e1eSChuck Lever /**
7343573c4e1eSChuck Lever  * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7344573c4e1eSChuck Lever  *                      the local page cache.
7345573c4e1eSChuck Lever  * @xdr: XDR stream where entry resides
7346573c4e1eSChuck Lever  * @entry: buffer to fill in with entry data
7347573c4e1eSChuck Lever  * @plus: boolean indicating whether this should be a readdirplus entry
7348573c4e1eSChuck Lever  *
7349573c4e1eSChuck Lever  * Returns zero if successful, otherwise a negative errno value is
7350573c4e1eSChuck Lever  * returned.
7351573c4e1eSChuck Lever  *
7352573c4e1eSChuck Lever  * This function is not invoked during READDIR reply decoding, but
7353573c4e1eSChuck Lever  * rather whenever an application invokes the getdents(2) system call
7354573c4e1eSChuck Lever  * on a directory already in our cache.
7355573c4e1eSChuck Lever  */
7356573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7357a7a3b1e9SBenjamin Coddington 		       bool plus)
73581da177e4SLinus Torvalds {
7359256e48bbSTrond Myklebust 	unsigned int savep;
7360dae100c2SFred Isaman 	uint32_t bitmap[3] = {0};
73611da177e4SLinus Torvalds 	uint32_t len;
736298de9ce6SFrank Sorenson 	uint64_t new_cookie;
7363babddc72SBryan Schumaker 	__be32 *p = xdr_inline_decode(xdr, 4);
7364babddc72SBryan Schumaker 	if (unlikely(!p))
7365eb72f484SChuck Lever 		return -EAGAIN;
7366c08e76d0SChuck Lever 	if (*p == xdr_zero) {
7367babddc72SBryan Schumaker 		p = xdr_inline_decode(xdr, 4);
7368babddc72SBryan Schumaker 		if (unlikely(!p))
7369eb72f484SChuck Lever 			return -EAGAIN;
7370c08e76d0SChuck Lever 		if (*p == xdr_zero)
7371573c4e1eSChuck Lever 			return -EAGAIN;
73721da177e4SLinus Torvalds 		entry->eof = 1;
7373573c4e1eSChuck Lever 		return -EBADCOOKIE;
73741da177e4SLinus Torvalds 	}
73751da177e4SLinus Torvalds 
7376babddc72SBryan Schumaker 	p = xdr_inline_decode(xdr, 12);
7377babddc72SBryan Schumaker 	if (unlikely(!p))
7378eb72f484SChuck Lever 		return -EAGAIN;
737998de9ce6SFrank Sorenson 	p = xdr_decode_hyper(p, &new_cookie);
7380c08e76d0SChuck Lever 	entry->len = be32_to_cpup(p);
7381babddc72SBryan Schumaker 
73829af8c222STrond Myklebust 	p = xdr_inline_decode(xdr, entry->len);
7383babddc72SBryan Schumaker 	if (unlikely(!p))
7384eb72f484SChuck Lever 		return -EAGAIN;
73851da177e4SLinus Torvalds 	entry->name = (const char *) p;
73861da177e4SLinus Torvalds 
73871da177e4SLinus Torvalds 	/*
73881da177e4SLinus Torvalds 	 * In case the server doesn't return an inode number,
73891da177e4SLinus Torvalds 	 * we fake one here.  (We don't use inode number 0,
73901da177e4SLinus Torvalds 	 * since glibc seems to choke on it...)
73911da177e4SLinus Torvalds 	 */
73921da177e4SLinus Torvalds 	entry->ino = 1;
73934f082222STrond Myklebust 	entry->fattr->valid = 0;
73941da177e4SLinus Torvalds 
73959af8c222STrond Myklebust 	if (decode_attr_bitmap(xdr, bitmap) < 0)
7396eb72f484SChuck Lever 		return -EAGAIN;
73979af8c222STrond Myklebust 
7398256e48bbSTrond Myklebust 	if (decode_attr_length(xdr, &len, &savep) < 0)
7399eb72f484SChuck Lever 		return -EAGAIN;
74009af8c222STrond Myklebust 
7401573c4e1eSChuck Lever 	if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7402aa9c2669SDavid Quigley 			NULL, entry->label, entry->server) < 0)
7403eb72f484SChuck Lever 		return -EAGAIN;
740428331a46STrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
740528331a46STrond Myklebust 		entry->ino = entry->fattr->mounted_on_fileid;
740628331a46STrond Myklebust 	else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
740782f2e547SBryan Schumaker 		entry->ino = entry->fattr->fileid;
74089af8c222STrond Myklebust 
74090b26a0bfSTrond Myklebust 	entry->d_type = DT_UNKNOWN;
74100b26a0bfSTrond Myklebust 	if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
74110b26a0bfSTrond Myklebust 		entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
74120b26a0bfSTrond Myklebust 
741398de9ce6SFrank Sorenson 	entry->prev_cookie = entry->cookie;
741498de9ce6SFrank Sorenson 	entry->cookie = new_cookie;
741598de9ce6SFrank Sorenson 
7416573c4e1eSChuck Lever 	return 0;
74171da177e4SLinus Torvalds }
74181da177e4SLinus Torvalds 
74191da177e4SLinus Torvalds /*
74201da177e4SLinus Torvalds  * We need to translate between nfs status return values and
74211da177e4SLinus Torvalds  * the local errno values which may not be the same.
74221da177e4SLinus Torvalds  */
74231da177e4SLinus Torvalds static struct {
74241da177e4SLinus Torvalds 	int stat;
74251da177e4SLinus Torvalds 	int errno;
74261da177e4SLinus Torvalds } nfs_errtbl[] = {
74271da177e4SLinus Torvalds 	{ NFS4_OK,		0		},
7428856dff3dSBenny Halevy 	{ NFS4ERR_PERM,		-EPERM		},
7429856dff3dSBenny Halevy 	{ NFS4ERR_NOENT,	-ENOENT		},
7430856dff3dSBenny Halevy 	{ NFS4ERR_IO,		-errno_NFSERR_IO},
7431856dff3dSBenny Halevy 	{ NFS4ERR_NXIO,		-ENXIO		},
7432856dff3dSBenny Halevy 	{ NFS4ERR_ACCESS,	-EACCES		},
7433856dff3dSBenny Halevy 	{ NFS4ERR_EXIST,	-EEXIST		},
7434856dff3dSBenny Halevy 	{ NFS4ERR_XDEV,		-EXDEV		},
7435856dff3dSBenny Halevy 	{ NFS4ERR_NOTDIR,	-ENOTDIR	},
7436856dff3dSBenny Halevy 	{ NFS4ERR_ISDIR,	-EISDIR		},
7437856dff3dSBenny Halevy 	{ NFS4ERR_INVAL,	-EINVAL		},
7438856dff3dSBenny Halevy 	{ NFS4ERR_FBIG,		-EFBIG		},
7439856dff3dSBenny Halevy 	{ NFS4ERR_NOSPC,	-ENOSPC		},
7440856dff3dSBenny Halevy 	{ NFS4ERR_ROFS,		-EROFS		},
7441856dff3dSBenny Halevy 	{ NFS4ERR_MLINK,	-EMLINK		},
7442856dff3dSBenny Halevy 	{ NFS4ERR_NAMETOOLONG,	-ENAMETOOLONG	},
7443856dff3dSBenny Halevy 	{ NFS4ERR_NOTEMPTY,	-ENOTEMPTY	},
7444856dff3dSBenny Halevy 	{ NFS4ERR_DQUOT,	-EDQUOT		},
7445856dff3dSBenny Halevy 	{ NFS4ERR_STALE,	-ESTALE		},
7446856dff3dSBenny Halevy 	{ NFS4ERR_BADHANDLE,	-EBADHANDLE	},
7447856dff3dSBenny Halevy 	{ NFS4ERR_BAD_COOKIE,	-EBADCOOKIE	},
7448856dff3dSBenny Halevy 	{ NFS4ERR_NOTSUPP,	-ENOTSUPP	},
7449856dff3dSBenny Halevy 	{ NFS4ERR_TOOSMALL,	-ETOOSMALL	},
7450fdcb4577STrond Myklebust 	{ NFS4ERR_SERVERFAULT,	-EREMOTEIO	},
7451856dff3dSBenny Halevy 	{ NFS4ERR_BADTYPE,	-EBADTYPE	},
7452856dff3dSBenny Halevy 	{ NFS4ERR_LOCKED,	-EAGAIN		},
7453856dff3dSBenny Halevy 	{ NFS4ERR_SYMLINK,	-ELOOP		},
7454856dff3dSBenny Halevy 	{ NFS4ERR_OP_ILLEGAL,	-EOPNOTSUPP	},
7455856dff3dSBenny Halevy 	{ NFS4ERR_DEADLOCK,	-EDEADLK	},
7456856dff3dSBenny Halevy 	{ -1,			-EIO		}
74571da177e4SLinus Torvalds };
74581da177e4SLinus Torvalds 
74591da177e4SLinus Torvalds /*
74601da177e4SLinus Torvalds  * Convert an NFS error code to a local one.
74611da177e4SLinus Torvalds  * This one is used jointly by NFSv2 and NFSv3.
74621da177e4SLinus Torvalds  */
74631da177e4SLinus Torvalds static int
74640a8ea437SDavid Howells nfs4_stat_to_errno(int stat)
74651da177e4SLinus Torvalds {
74661da177e4SLinus Torvalds 	int i;
74671da177e4SLinus Torvalds 	for (i = 0; nfs_errtbl[i].stat != -1; i++) {
74681da177e4SLinus Torvalds 		if (nfs_errtbl[i].stat == stat)
74691da177e4SLinus Torvalds 			return nfs_errtbl[i].errno;
74701da177e4SLinus Torvalds 	}
74711da177e4SLinus Torvalds 	if (stat <= 10000 || stat > 10100) {
74721da177e4SLinus Torvalds 		/* The server is looney tunes. */
7473fdcb4577STrond Myklebust 		return -EREMOTEIO;
74741da177e4SLinus Torvalds 	}
74751da177e4SLinus Torvalds 	/* If we cannot translate the error, the recovery routines should
74761da177e4SLinus Torvalds 	 * handle it.
74771da177e4SLinus Torvalds 	 * Note: remaining NFSv4 error codes have values > 10000, so should
74781da177e4SLinus Torvalds 	 * not conflict with native Linux error codes.
74791da177e4SLinus Torvalds 	 */
7480856dff3dSBenny Halevy 	return -stat;
74811da177e4SLinus Torvalds }
74821da177e4SLinus Torvalds 
74831c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2
74841c6dcbe5SAnna Schumaker #include "nfs42xdr.c"
74851c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */
74861c6dcbe5SAnna Schumaker 
74871da177e4SLinus Torvalds #define PROC(proc, argtype, restype)				\
74881da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = {					\
74891da177e4SLinus Torvalds 	.p_proc   = NFSPROC4_COMPOUND,				\
7490fcc85819SChristoph Hellwig 	.p_encode = nfs4_xdr_##argtype,				\
7491fc016483SChristoph Hellwig 	.p_decode = nfs4_xdr_##restype,				\
74922bea90d4SChuck Lever 	.p_arglen = NFS4_##argtype##_sz,			\
74932bea90d4SChuck Lever 	.p_replen = NFS4_##restype##_sz,			\
7494cc0175c1SChuck Lever 	.p_statidx = NFSPROC4_CLNT_##proc,			\
7495cc0175c1SChuck Lever 	.p_name   = #proc,					\
74961da177e4SLinus Torvalds }
74971da177e4SLinus Torvalds 
74987c61f0d3SAnna Schumaker #define STUB(proc)		\
74997c61f0d3SAnna Schumaker [NFSPROC4_CLNT_##proc] = {	\
75007c61f0d3SAnna Schumaker 	.p_name = #proc,	\
75017c61f0d3SAnna Schumaker }
75027c61f0d3SAnna Schumaker 
75038634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_1)
75048634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype)				\
75058634ef5eSTrond Myklebust 	PROC(proc, argtype, restype)
75068634ef5eSTrond Myklebust #else
75078634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype)				\
75088634ef5eSTrond Myklebust 	STUB(proc)
75098634ef5eSTrond Myklebust #endif
75108634ef5eSTrond Myklebust 
75118634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_2)
75128634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype)				\
75138634ef5eSTrond Myklebust 	PROC(proc, argtype, restype)
75148634ef5eSTrond Myklebust #else
75158634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype)				\
75168634ef5eSTrond Myklebust 	STUB(proc)
75178634ef5eSTrond Myklebust #endif
75188634ef5eSTrond Myklebust 
7519511e936bSChristoph Hellwig const struct rpc_procinfo nfs4_procedures[] = {
75201da177e4SLinus Torvalds 	PROC(READ,		enc_read,		dec_read),
75211da177e4SLinus Torvalds 	PROC(WRITE,		enc_write,		dec_write),
75221da177e4SLinus Torvalds 	PROC(COMMIT,		enc_commit,		dec_commit),
75231da177e4SLinus Torvalds 	PROC(OPEN,		enc_open,		dec_open),
75241da177e4SLinus Torvalds 	PROC(OPEN_CONFIRM,	enc_open_confirm,	dec_open_confirm),
75251da177e4SLinus Torvalds 	PROC(OPEN_NOATTR,	enc_open_noattr,	dec_open_noattr),
75261da177e4SLinus Torvalds 	PROC(OPEN_DOWNGRADE,	enc_open_downgrade,	dec_open_downgrade),
75271da177e4SLinus Torvalds 	PROC(CLOSE,		enc_close,		dec_close),
75281da177e4SLinus Torvalds 	PROC(SETATTR,		enc_setattr,		dec_setattr),
75291da177e4SLinus Torvalds 	PROC(FSINFO,		enc_fsinfo,		dec_fsinfo),
75301da177e4SLinus Torvalds 	PROC(RENEW,		enc_renew,		dec_renew),
75311da177e4SLinus Torvalds 	PROC(SETCLIENTID,	enc_setclientid,	dec_setclientid),
75321da177e4SLinus Torvalds 	PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
75331da177e4SLinus Torvalds 	PROC(LOCK,		enc_lock,		dec_lock),
75341da177e4SLinus Torvalds 	PROC(LOCKT,		enc_lockt,		dec_lockt),
75351da177e4SLinus Torvalds 	PROC(LOCKU,		enc_locku,		dec_locku),
75361da177e4SLinus Torvalds 	PROC(ACCESS,		enc_access,		dec_access),
75371da177e4SLinus Torvalds 	PROC(GETATTR,		enc_getattr,		dec_getattr),
75381da177e4SLinus Torvalds 	PROC(LOOKUP,		enc_lookup,		dec_lookup),
75391da177e4SLinus Torvalds 	PROC(LOOKUP_ROOT,	enc_lookup_root,	dec_lookup_root),
75401da177e4SLinus Torvalds 	PROC(REMOVE,		enc_remove,		dec_remove),
75411da177e4SLinus Torvalds 	PROC(RENAME,		enc_rename,		dec_rename),
75421da177e4SLinus Torvalds 	PROC(LINK,		enc_link,		dec_link),
75431da177e4SLinus Torvalds 	PROC(SYMLINK,		enc_symlink,		dec_symlink),
75441da177e4SLinus Torvalds 	PROC(CREATE,		enc_create,		dec_create),
75451da177e4SLinus Torvalds 	PROC(PATHCONF,		enc_pathconf,		dec_pathconf),
75461da177e4SLinus Torvalds 	PROC(STATFS,		enc_statfs,		dec_statfs),
75471da177e4SLinus Torvalds 	PROC(READLINK,		enc_readlink,		dec_readlink),
75481da177e4SLinus Torvalds 	PROC(READDIR,		enc_readdir,		dec_readdir),
75491da177e4SLinus Torvalds 	PROC(SERVER_CAPS,	enc_server_caps,	dec_server_caps),
75501da177e4SLinus Torvalds 	PROC(DELEGRETURN,	enc_delegreturn,	dec_delegreturn),
7551029d105eSJ. Bruce Fields 	PROC(GETACL,		enc_getacl,		dec_getacl),
755223ec6965SJ. Bruce Fields 	PROC(SETACL,		enc_setacl,		dec_setacl),
7553683b57b4STrond Myklebust 	PROC(FS_LOCATIONS,	enc_fs_locations,	dec_fs_locations),
7554d3c7b7ccSTrond Myklebust 	PROC(RELEASE_LOCKOWNER,	enc_release_lockowner,	dec_release_lockowner),
75555a5ea0d4SBryan Schumaker 	PROC(SECINFO,		enc_secinfo,		dec_secinfo),
755644c99933SChuck Lever 	PROC(FSID_PRESENT,	enc_fsid_present,	dec_fsid_present),
75578634ef5eSTrond Myklebust 	PROC41(EXCHANGE_ID,	enc_exchange_id,	dec_exchange_id),
75588634ef5eSTrond Myklebust 	PROC41(CREATE_SESSION,	enc_create_session,	dec_create_session),
75598634ef5eSTrond Myklebust 	PROC41(DESTROY_SESSION,	enc_destroy_session,	dec_destroy_session),
75608634ef5eSTrond Myklebust 	PROC41(SEQUENCE,	enc_sequence,		dec_sequence),
75610efb01b2SDonald Buczek 	PROC(GET_LEASE_TIME,	enc_get_lease_time,	dec_get_lease_time),
75628634ef5eSTrond Myklebust 	PROC41(RECLAIM_COMPLETE,enc_reclaim_complete,	dec_reclaim_complete),
75638634ef5eSTrond Myklebust 	PROC41(GETDEVICEINFO,	enc_getdeviceinfo,	dec_getdeviceinfo),
75648634ef5eSTrond Myklebust 	PROC41(LAYOUTGET,	enc_layoutget,		dec_layoutget),
75658634ef5eSTrond Myklebust 	PROC41(LAYOUTCOMMIT,	enc_layoutcommit,	dec_layoutcommit),
75668634ef5eSTrond Myklebust 	PROC41(LAYOUTRETURN,	enc_layoutreturn,	dec_layoutreturn),
75678634ef5eSTrond Myklebust 	PROC41(SECINFO_NO_NAME,	enc_secinfo_no_name,	dec_secinfo_no_name),
75688634ef5eSTrond Myklebust 	PROC41(TEST_STATEID,	enc_test_stateid,	dec_test_stateid),
75698634ef5eSTrond Myklebust 	PROC41(FREE_STATEID,	enc_free_stateid,	dec_free_stateid),
75707c61f0d3SAnna Schumaker 	STUB(GETDEVICELIST),
75718634ef5eSTrond Myklebust 	PROC41(BIND_CONN_TO_SESSION,
7572ad24ecfbSTrond Myklebust 			enc_bind_conn_to_session, dec_bind_conn_to_session),
75738634ef5eSTrond Myklebust 	PROC41(DESTROY_CLIENTID,enc_destroy_clientid,	dec_destroy_clientid),
75748634ef5eSTrond Myklebust 	PROC42(SEEK,		enc_seek,		dec_seek),
75758634ef5eSTrond Myklebust 	PROC42(ALLOCATE,	enc_allocate,		dec_allocate),
75768634ef5eSTrond Myklebust 	PROC42(DEALLOCATE,	enc_deallocate,		dec_deallocate),
75778634ef5eSTrond Myklebust 	PROC42(LAYOUTSTATS,	enc_layoutstats,	dec_layoutstats),
75788634ef5eSTrond Myklebust 	PROC42(CLONE,		enc_clone,		dec_clone),
75798634ef5eSTrond Myklebust 	PROC42(COPY,		enc_copy,		dec_copy),
7580cb95deeaSOlga Kornievskaia 	PROC42(OFFLOAD_CANCEL,	enc_offload_cancel,	dec_offload_cancel),
75810491567bSOlga Kornievskaia 	PROC42(COPY_NOTIFY,	enc_copy_notify,	dec_copy_notify),
75828634ef5eSTrond Myklebust 	PROC(LOOKUPP,		enc_lookupp,		dec_lookupp),
75833eb86093STrond Myklebust 	PROC42(LAYOUTERROR,	enc_layouterror,	dec_layouterror),
75841da177e4SLinus Torvalds };
75851da177e4SLinus Torvalds 
7586c551858aSChristoph Hellwig static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
7587a613fa16STrond Myklebust const struct rpc_version nfs_version4 = {
75881da177e4SLinus Torvalds 	.number			= 4,
7589e8c96f8cSTobias Klauser 	.nrprocs		= ARRAY_SIZE(nfs4_procedures),
7590c551858aSChristoph Hellwig 	.procs			= nfs4_procedures,
7591c551858aSChristoph Hellwig 	.counts			= nfs_version4_counts,
75921da177e4SLinus Torvalds };
75931da177e4SLinus Torvalds 
75941da177e4SLinus Torvalds /*
75951da177e4SLinus Torvalds  * Local variables:
75961da177e4SLinus Torvalds  *  c-basic-offset: 8
75971da177e4SLinus Torvalds  * End:
75981da177e4SLinus Torvalds  */
7599