xref: /openbmc/linux/fs/nfs/nfs4xdr.c (revision b737eecd)
1 /*
2  *  fs/nfs/nfs4xdr.c
3  *
4  *  Client-side XDR for NFSv4.
5  *
6  *  Copyright (c) 2002 The Regents of the University of Michigan.
7  *  All rights reserved.
8  *
9  *  Kendrick Smith <kmsmith@umich.edu>
10  *  Andy Adamson   <andros@umich.edu>
11  *
12  *  Redistribution and use in source and binary forms, with or without
13  *  modification, are permitted provided that the following conditions
14  *  are met:
15  *
16  *  1. Redistributions of source code must retain the above copyright
17  *     notice, this list of conditions and the following disclaimer.
18  *  2. Redistributions in binary form must reproduce the above copyright
19  *     notice, this list of conditions and the following disclaimer in the
20  *     documentation and/or other materials provided with the distribution.
21  *  3. Neither the name of the University nor the names of its
22  *     contributors may be used to endorse or promote products derived
23  *     from this software without specific prior written permission.
24  *
25  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28  *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32  *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #include <linux/param.h>
39 #include <linux/time.h>
40 #include <linux/mm.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
43 #include <linux/in.h>
44 #include <linux/pagemap.h>
45 #include <linux/proc_fs.h>
46 #include <linux/kdev_t.h>
47 #include <linux/module.h>
48 #include <linux/utsname.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/sunrpc/msg_prot.h>
51 #include <linux/sunrpc/gss_api.h>
52 #include <linux/nfs.h>
53 #include <linux/nfs4.h>
54 #include <linux/nfs_fs.h>
55 
56 #include "nfs4_fs.h"
57 #include "nfs4trace.h"
58 #include "internal.h"
59 #include "nfs4idmap.h"
60 #include "nfs4session.h"
61 #include "pnfs.h"
62 #include "netns.h"
63 
64 #define NFSDBG_FACILITY		NFSDBG_XDR
65 
66 /* Mapping from NFS error code to "errno" error code. */
67 #define errno_NFSERR_IO		EIO
68 
69 struct compound_hdr;
70 static int nfs4_stat_to_errno(int);
71 static void encode_layoutget(struct xdr_stream *xdr,
72 			     const struct nfs4_layoutget_args *args,
73 			     struct compound_hdr *hdr);
74 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
75 			     struct nfs4_layoutget_res *res);
76 
77 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
78 #ifdef DEBUG
79 #define NFS4_MAXTAGLEN		20
80 #else
81 #define NFS4_MAXTAGLEN		0
82 #endif
83 
84 /* lock,open owner id:
85  * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT  >> 2)
86  */
87 #define pagepad_maxsz		(1)
88 #define open_owner_id_maxsz	(1 + 2 + 1 + 1 + 2)
89 #define lock_owner_id_maxsz	(1 + 1 + 4)
90 #define decode_lockowner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
91 #define compound_encode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
92 #define compound_decode_hdr_maxsz	(3 + (NFS4_MAXTAGLEN >> 2))
93 #define op_encode_hdr_maxsz	(1)
94 #define op_decode_hdr_maxsz	(2)
95 #define encode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
96 #define decode_stateid_maxsz	(XDR_QUADLEN(NFS4_STATEID_SIZE))
97 #define encode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
98 #define decode_verifier_maxsz	(XDR_QUADLEN(NFS4_VERIFIER_SIZE))
99 #define encode_putfh_maxsz	(op_encode_hdr_maxsz + 1 + \
100 				(NFS4_FHSIZE >> 2))
101 #define decode_putfh_maxsz	(op_decode_hdr_maxsz)
102 #define encode_putrootfh_maxsz	(op_encode_hdr_maxsz)
103 #define decode_putrootfh_maxsz	(op_decode_hdr_maxsz)
104 #define encode_getfh_maxsz      (op_encode_hdr_maxsz)
105 #define decode_getfh_maxsz      (op_decode_hdr_maxsz + 1 + \
106 				((3+NFS4_FHSIZE) >> 2))
107 #define nfs4_fattr_bitmap_maxsz 4
108 #define encode_getattr_maxsz    (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
109 #define nfstime4_maxsz		(3)
110 #define nfs4_name_maxsz		(1 + ((3 + NFS4_MAXNAMLEN) >> 2))
111 #define nfs4_path_maxsz		(1 + ((3 + NFS4_MAXPATHLEN) >> 2))
112 #define nfs4_owner_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
113 #define nfs4_group_maxsz	(1 + XDR_QUADLEN(IDMAP_NAMESZ))
114 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
115 /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
116 #define	nfs4_label_maxsz	(4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
117 #else
118 #define	nfs4_label_maxsz	0
119 #endif
120 /* We support only one layout type per file system */
121 #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
122 /* This is based on getfattr, which uses the most attributes: */
123 #define nfs4_fattr_value_maxsz	(1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
124 				3*nfstime4_maxsz + \
125 				nfs4_owner_maxsz + \
126 				nfs4_group_maxsz + nfs4_label_maxsz + \
127 				 decode_mdsthreshold_maxsz))
128 #define nfs4_fattr_maxsz	(nfs4_fattr_bitmap_maxsz + \
129 				nfs4_fattr_value_maxsz)
130 #define decode_getattr_maxsz    (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
131 #define encode_attrs_maxsz	(nfs4_fattr_bitmap_maxsz + \
132 				 1 + 2 + 1 + \
133 				nfs4_owner_maxsz + \
134 				nfs4_group_maxsz + \
135 				nfs4_label_maxsz + \
136 				1 + nfstime4_maxsz + \
137 				1 + nfstime4_maxsz)
138 #define encode_savefh_maxsz     (op_encode_hdr_maxsz)
139 #define decode_savefh_maxsz     (op_decode_hdr_maxsz)
140 #define encode_restorefh_maxsz  (op_encode_hdr_maxsz)
141 #define decode_restorefh_maxsz  (op_decode_hdr_maxsz)
142 #define encode_fsinfo_maxsz	(encode_getattr_maxsz)
143 /* The 5 accounts for the PNFS attributes, and assumes that at most three
144  * layout types will be returned.
145  */
146 #define decode_fsinfo_maxsz	(op_decode_hdr_maxsz + \
147 				 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
148 #define encode_renew_maxsz	(op_encode_hdr_maxsz + 3)
149 #define decode_renew_maxsz	(op_decode_hdr_maxsz)
150 #define encode_setclientid_maxsz \
151 				(op_encode_hdr_maxsz + \
152 				XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
153 				/* client name */ \
154 				1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
155 				1 /* sc_prog */ + \
156 				1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
157 				1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
158 				1) /* sc_cb_ident */
159 #define decode_setclientid_maxsz \
160 				(op_decode_hdr_maxsz + \
161 				2 /* clientid */ + \
162 				XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
163 				1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
164 				1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
165 #define encode_setclientid_confirm_maxsz \
166 				(op_encode_hdr_maxsz + \
167 				3 + (NFS4_VERIFIER_SIZE >> 2))
168 #define decode_setclientid_confirm_maxsz \
169 				(op_decode_hdr_maxsz)
170 #define encode_lookup_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
171 #define decode_lookup_maxsz	(op_decode_hdr_maxsz)
172 #define encode_lookupp_maxsz	(op_encode_hdr_maxsz)
173 #define decode_lookupp_maxsz	(op_decode_hdr_maxsz)
174 #define encode_share_access_maxsz \
175 				(2)
176 #define encode_createmode_maxsz	(1 + encode_attrs_maxsz + encode_verifier_maxsz)
177 #define encode_opentype_maxsz	(1 + encode_createmode_maxsz)
178 #define encode_claim_null_maxsz	(1 + nfs4_name_maxsz)
179 #define encode_open_maxsz	(op_encode_hdr_maxsz + \
180 				2 + encode_share_access_maxsz + 2 + \
181 				open_owner_id_maxsz + \
182 				encode_opentype_maxsz + \
183 				encode_claim_null_maxsz)
184 #define decode_space_limit_maxsz	(3)
185 #define decode_ace_maxsz	(3 + nfs4_owner_maxsz)
186 #define decode_delegation_maxsz	(1 + decode_stateid_maxsz + 1 + \
187 				decode_space_limit_maxsz + \
188 				decode_ace_maxsz)
189 #define decode_change_info_maxsz	(5)
190 #define decode_open_maxsz	(op_decode_hdr_maxsz + \
191 				decode_stateid_maxsz + \
192 				decode_change_info_maxsz + 1 + \
193 				nfs4_fattr_bitmap_maxsz + \
194 				decode_delegation_maxsz)
195 #define encode_open_confirm_maxsz \
196 				(op_encode_hdr_maxsz + \
197 				 encode_stateid_maxsz + 1)
198 #define decode_open_confirm_maxsz \
199 				(op_decode_hdr_maxsz + \
200 				 decode_stateid_maxsz)
201 #define encode_open_downgrade_maxsz \
202 				(op_encode_hdr_maxsz + \
203 				 encode_stateid_maxsz + 1 + \
204 				 encode_share_access_maxsz)
205 #define decode_open_downgrade_maxsz \
206 				(op_decode_hdr_maxsz + \
207 				 decode_stateid_maxsz)
208 #define encode_close_maxsz	(op_encode_hdr_maxsz + \
209 				 1 + encode_stateid_maxsz)
210 #define decode_close_maxsz	(op_decode_hdr_maxsz + \
211 				 decode_stateid_maxsz)
212 #define encode_setattr_maxsz	(op_encode_hdr_maxsz + \
213 				 encode_stateid_maxsz + \
214 				 encode_attrs_maxsz)
215 #define decode_setattr_maxsz	(op_decode_hdr_maxsz + \
216 				 nfs4_fattr_bitmap_maxsz)
217 #define encode_read_maxsz	(op_encode_hdr_maxsz + \
218 				 encode_stateid_maxsz + 3)
219 #define decode_read_maxsz	(op_decode_hdr_maxsz + 2 + pagepad_maxsz)
220 #define encode_readdir_maxsz	(op_encode_hdr_maxsz + \
221 				 2 + encode_verifier_maxsz + 5 + \
222 				nfs4_label_maxsz)
223 #define decode_readdir_maxsz	(op_decode_hdr_maxsz + \
224 				 decode_verifier_maxsz + pagepad_maxsz)
225 #define encode_readlink_maxsz	(op_encode_hdr_maxsz)
226 #define decode_readlink_maxsz	(op_decode_hdr_maxsz + 1 + pagepad_maxsz)
227 #define encode_write_maxsz	(op_encode_hdr_maxsz + \
228 				 encode_stateid_maxsz + 4)
229 #define decode_write_maxsz	(op_decode_hdr_maxsz + \
230 				 2 + decode_verifier_maxsz)
231 #define encode_commit_maxsz	(op_encode_hdr_maxsz + 3)
232 #define decode_commit_maxsz	(op_decode_hdr_maxsz + \
233 				 decode_verifier_maxsz)
234 #define encode_remove_maxsz	(op_encode_hdr_maxsz + \
235 				nfs4_name_maxsz)
236 #define decode_remove_maxsz	(op_decode_hdr_maxsz + \
237 				 decode_change_info_maxsz)
238 #define encode_rename_maxsz	(op_encode_hdr_maxsz + \
239 				2 * nfs4_name_maxsz)
240 #define decode_rename_maxsz	(op_decode_hdr_maxsz + \
241 				 decode_change_info_maxsz + \
242 				 decode_change_info_maxsz)
243 #define encode_link_maxsz	(op_encode_hdr_maxsz + \
244 				nfs4_name_maxsz)
245 #define decode_link_maxsz	(op_decode_hdr_maxsz + decode_change_info_maxsz)
246 #define encode_lockowner_maxsz	(7)
247 #define encode_lock_maxsz	(op_encode_hdr_maxsz + \
248 				 7 + \
249 				 1 + encode_stateid_maxsz + 1 + \
250 				 encode_lockowner_maxsz)
251 #define decode_lock_denied_maxsz \
252 				(8 + decode_lockowner_maxsz)
253 #define decode_lock_maxsz	(op_decode_hdr_maxsz + \
254 				 decode_lock_denied_maxsz)
255 #define encode_lockt_maxsz	(op_encode_hdr_maxsz + 5 + \
256 				encode_lockowner_maxsz)
257 #define decode_lockt_maxsz	(op_decode_hdr_maxsz + \
258 				 decode_lock_denied_maxsz)
259 #define encode_locku_maxsz	(op_encode_hdr_maxsz + 3 + \
260 				 encode_stateid_maxsz + \
261 				 4)
262 #define decode_locku_maxsz	(op_decode_hdr_maxsz + \
263 				 decode_stateid_maxsz)
264 #define encode_release_lockowner_maxsz \
265 				(op_encode_hdr_maxsz + \
266 				 encode_lockowner_maxsz)
267 #define decode_release_lockowner_maxsz \
268 				(op_decode_hdr_maxsz)
269 #define encode_access_maxsz	(op_encode_hdr_maxsz + 1)
270 #define decode_access_maxsz	(op_decode_hdr_maxsz + 2)
271 #define encode_symlink_maxsz	(op_encode_hdr_maxsz + \
272 				1 + nfs4_name_maxsz + \
273 				1 + \
274 				nfs4_fattr_maxsz)
275 #define decode_symlink_maxsz	(op_decode_hdr_maxsz + 8)
276 #define encode_create_maxsz	(op_encode_hdr_maxsz + \
277 				1 + 2 + nfs4_name_maxsz + \
278 				encode_attrs_maxsz)
279 #define decode_create_maxsz	(op_decode_hdr_maxsz + \
280 				decode_change_info_maxsz + \
281 				nfs4_fattr_bitmap_maxsz)
282 #define encode_statfs_maxsz	(encode_getattr_maxsz)
283 #define decode_statfs_maxsz	(decode_getattr_maxsz)
284 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
285 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
286 #define encode_getacl_maxsz	(encode_getattr_maxsz)
287 #define decode_getacl_maxsz	(op_decode_hdr_maxsz + \
288 				 nfs4_fattr_bitmap_maxsz + 1 + pagepad_maxsz)
289 #define encode_setacl_maxsz	(op_encode_hdr_maxsz + \
290 				 encode_stateid_maxsz + 3)
291 #define decode_setacl_maxsz	(decode_setattr_maxsz)
292 #define encode_fs_locations_maxsz \
293 				(encode_getattr_maxsz)
294 #define decode_fs_locations_maxsz \
295 				(pagepad_maxsz)
296 #define encode_secinfo_maxsz	(op_encode_hdr_maxsz + nfs4_name_maxsz)
297 #define decode_secinfo_maxsz	(op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
298 
299 #if defined(CONFIG_NFS_V4_1)
300 #define NFS4_MAX_MACHINE_NAME_LEN (64)
301 #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
302 			 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
303 
304 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
305 				encode_verifier_maxsz + \
306 				1 /* co_ownerid.len */ + \
307 				/* eia_clientowner */ \
308 				1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
309 				1 /* flags */ + \
310 				1 /* spa_how */ + \
311 				/* max is SP4_MACH_CRED (for now) */ + \
312 				1 + NFS4_OP_MAP_NUM_WORDS + \
313 				1 + NFS4_OP_MAP_NUM_WORDS + \
314 				1 /* implementation id array of size 1 */ + \
315 				1 /* nii_domain */ + \
316 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
317 				1 /* nii_name */ + \
318 				XDR_QUADLEN(IMPL_NAME_LIMIT) + \
319 				3 /* nii_date */)
320 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
321 				2 /* eir_clientid */ + \
322 				1 /* eir_sequenceid */ + \
323 				1 /* eir_flags */ + \
324 				1 /* spr_how */ + \
325 				  /* max is SP4_MACH_CRED (for now) */ + \
326 				1 + NFS4_OP_MAP_NUM_WORDS + \
327 				1 + NFS4_OP_MAP_NUM_WORDS + \
328 				2 /* eir_server_owner.so_minor_id */ + \
329 				/* eir_server_owner.so_major_id<> */ \
330 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
331 				/* eir_server_scope<> */ \
332 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
333 				1 /* eir_server_impl_id array length */ + \
334 				1 /* nii_domain */ + \
335 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
336 				1 /* nii_name */ + \
337 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
338 				3 /* nii_date */)
339 #define encode_channel_attrs_maxsz  (6 + 1 /* ca_rdma_ird.len (0) */)
340 #define decode_channel_attrs_maxsz  (6 + \
341 				     1 /* ca_rdma_ird.len */ + \
342 				     1 /* ca_rdma_ird */)
343 #define encode_create_session_maxsz  (op_encode_hdr_maxsz + \
344 				     2 /* csa_clientid */ + \
345 				     1 /* csa_sequence */ + \
346 				     1 /* csa_flags */ + \
347 				     encode_channel_attrs_maxsz + \
348 				     encode_channel_attrs_maxsz + \
349 				     1 /* csa_cb_program */ + \
350 				     1 /* csa_sec_parms.len (1) */ + \
351 				     1 /* cb_secflavor (AUTH_SYS) */ + \
352 				     1 /* stamp */ + \
353 				     1 /* machinename.len */ + \
354 				     XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
355 				     1 /* uid */ + \
356 				     1 /* gid */ + \
357 				     1 /* gids.len (0) */)
358 #define decode_create_session_maxsz  (op_decode_hdr_maxsz +	\
359 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
360 				     1 /* csr_sequence */ + \
361 				     1 /* csr_flags */ + \
362 				     decode_channel_attrs_maxsz + \
363 				     decode_channel_attrs_maxsz)
364 #define encode_bind_conn_to_session_maxsz  (op_encode_hdr_maxsz + \
365 				     /* bctsa_sessid */ \
366 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
367 				     1 /* bctsa_dir */ + \
368 				     1 /* bctsa_use_conn_in_rdma_mode */)
369 #define decode_bind_conn_to_session_maxsz  (op_decode_hdr_maxsz +	\
370 				     /* bctsr_sessid */ \
371 				     XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
372 				     1 /* bctsr_dir */ + \
373 				     1 /* bctsr_use_conn_in_rdma_mode */)
374 #define encode_destroy_session_maxsz    (op_encode_hdr_maxsz + 4)
375 #define decode_destroy_session_maxsz    (op_decode_hdr_maxsz)
376 #define encode_destroy_clientid_maxsz   (op_encode_hdr_maxsz + 2)
377 #define decode_destroy_clientid_maxsz   (op_decode_hdr_maxsz)
378 #define encode_sequence_maxsz	(op_encode_hdr_maxsz + \
379 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
380 #define decode_sequence_maxsz	(op_decode_hdr_maxsz + \
381 				XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
382 #define encode_reclaim_complete_maxsz	(op_encode_hdr_maxsz + 4)
383 #define decode_reclaim_complete_maxsz	(op_decode_hdr_maxsz + 4)
384 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
385 				XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
386 				1 /* layout type */ + \
387 				1 /* maxcount */ + \
388 				1 /* bitmap size */ + \
389 				1 /* notification bitmap length */ + \
390 				1 /* notification bitmap, word 0 */)
391 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
392 				1 /* layout type */ + \
393 				1 /* opaque devaddr4 length */ + \
394 				  /* devaddr4 payload is read into page */ \
395 				1 /* notification bitmap length */ + \
396 				1 /* notification bitmap, word 0 */ + \
397 				pagepad_maxsz /* possible XDR padding */)
398 #define encode_layoutget_maxsz	(op_encode_hdr_maxsz + 10 + \
399 				encode_stateid_maxsz)
400 #define decode_layoutget_maxsz	(op_decode_hdr_maxsz + 8 + \
401 				decode_stateid_maxsz + \
402 				XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + \
403 				pagepad_maxsz)
404 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz +          \
405 				2 /* offset */ + \
406 				2 /* length */ + \
407 				1 /* reclaim */ + \
408 				encode_stateid_maxsz + \
409 				1 /* new offset (true) */ + \
410 				2 /* last byte written */ + \
411 				1 /* nt_timechanged (false) */ + \
412 				1 /* layoutupdate4 layout type */ + \
413 				1 /* layoutupdate4 opaqueue len */)
414 				  /* the actual content of layoutupdate4 should
415 				     be allocated by drivers and spliced in
416 				     using xdr_write_pages */
417 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
418 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
419 				encode_stateid_maxsz + \
420 				1 + \
421 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
422 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
423 				1 + decode_stateid_maxsz)
424 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
425 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
426 #define encode_test_stateid_maxsz	(op_encode_hdr_maxsz + 2 + \
427 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
428 #define decode_test_stateid_maxsz	(op_decode_hdr_maxsz + 2 + 1)
429 #define encode_free_stateid_maxsz	(op_encode_hdr_maxsz + 1 + \
430 					 XDR_QUADLEN(NFS4_STATEID_SIZE))
431 #define decode_free_stateid_maxsz	(op_decode_hdr_maxsz)
432 #else /* CONFIG_NFS_V4_1 */
433 #define encode_sequence_maxsz	0
434 #define decode_sequence_maxsz	0
435 #define encode_layoutreturn_maxsz 0
436 #define decode_layoutreturn_maxsz 0
437 #define encode_layoutget_maxsz	0
438 #define decode_layoutget_maxsz	0
439 #endif /* CONFIG_NFS_V4_1 */
440 
441 #define NFS4_enc_compound_sz	(1024)  /* XXX: large enough? */
442 #define NFS4_dec_compound_sz	(1024)  /* XXX: large enough? */
443 #define NFS4_enc_read_sz	(compound_encode_hdr_maxsz + \
444 				encode_sequence_maxsz + \
445 				encode_putfh_maxsz + \
446 				encode_read_maxsz)
447 #define NFS4_dec_read_sz	(compound_decode_hdr_maxsz + \
448 				decode_sequence_maxsz + \
449 				decode_putfh_maxsz + \
450 				decode_read_maxsz)
451 #define NFS4_enc_readlink_sz	(compound_encode_hdr_maxsz + \
452 				encode_sequence_maxsz + \
453 				encode_putfh_maxsz + \
454 				encode_readlink_maxsz)
455 #define NFS4_dec_readlink_sz	(compound_decode_hdr_maxsz + \
456 				decode_sequence_maxsz + \
457 				decode_putfh_maxsz + \
458 				decode_readlink_maxsz)
459 #define NFS4_enc_readdir_sz	(compound_encode_hdr_maxsz + \
460 				encode_sequence_maxsz + \
461 				encode_putfh_maxsz + \
462 				encode_readdir_maxsz)
463 #define NFS4_dec_readdir_sz	(compound_decode_hdr_maxsz + \
464 				decode_sequence_maxsz + \
465 				decode_putfh_maxsz + \
466 				decode_readdir_maxsz)
467 #define NFS4_enc_write_sz	(compound_encode_hdr_maxsz + \
468 				encode_sequence_maxsz + \
469 				encode_putfh_maxsz + \
470 				encode_write_maxsz + \
471 				encode_getattr_maxsz)
472 #define NFS4_dec_write_sz	(compound_decode_hdr_maxsz + \
473 				decode_sequence_maxsz + \
474 				decode_putfh_maxsz + \
475 				decode_write_maxsz + \
476 				decode_getattr_maxsz)
477 #define NFS4_enc_commit_sz	(compound_encode_hdr_maxsz + \
478 				encode_sequence_maxsz + \
479 				encode_putfh_maxsz + \
480 				encode_commit_maxsz)
481 #define NFS4_dec_commit_sz	(compound_decode_hdr_maxsz + \
482 				decode_sequence_maxsz + \
483 				decode_putfh_maxsz + \
484 				decode_commit_maxsz)
485 #define NFS4_enc_open_sz        (compound_encode_hdr_maxsz + \
486 				encode_sequence_maxsz + \
487 				encode_putfh_maxsz + \
488 				encode_open_maxsz + \
489 				encode_access_maxsz + \
490 				encode_getfh_maxsz + \
491 				encode_getattr_maxsz + \
492 				encode_layoutget_maxsz)
493 #define NFS4_dec_open_sz        (compound_decode_hdr_maxsz + \
494 				decode_sequence_maxsz + \
495 				decode_putfh_maxsz + \
496 				decode_open_maxsz + \
497 				decode_access_maxsz + \
498 				decode_getfh_maxsz + \
499 				decode_getattr_maxsz + \
500 				decode_layoutget_maxsz)
501 #define NFS4_enc_open_confirm_sz \
502 				(compound_encode_hdr_maxsz + \
503 				 encode_putfh_maxsz + \
504 				 encode_open_confirm_maxsz)
505 #define NFS4_dec_open_confirm_sz \
506 				(compound_decode_hdr_maxsz + \
507 				 decode_putfh_maxsz + \
508 				 decode_open_confirm_maxsz)
509 #define NFS4_enc_open_noattr_sz	(compound_encode_hdr_maxsz + \
510 					encode_sequence_maxsz + \
511 					encode_putfh_maxsz + \
512 					encode_open_maxsz + \
513 					encode_access_maxsz + \
514 					encode_getattr_maxsz + \
515 					encode_layoutget_maxsz)
516 #define NFS4_dec_open_noattr_sz	(compound_decode_hdr_maxsz + \
517 					decode_sequence_maxsz + \
518 					decode_putfh_maxsz + \
519 					decode_open_maxsz + \
520 					decode_access_maxsz + \
521 					decode_getattr_maxsz + \
522 					decode_layoutget_maxsz)
523 #define NFS4_enc_open_downgrade_sz \
524 				(compound_encode_hdr_maxsz + \
525 				 encode_sequence_maxsz + \
526 				 encode_putfh_maxsz + \
527 				 encode_layoutreturn_maxsz + \
528 				 encode_open_downgrade_maxsz)
529 #define NFS4_dec_open_downgrade_sz \
530 				(compound_decode_hdr_maxsz + \
531 				 decode_sequence_maxsz + \
532 				 decode_putfh_maxsz + \
533 				 decode_layoutreturn_maxsz + \
534 				 decode_open_downgrade_maxsz)
535 #define NFS4_enc_close_sz	(compound_encode_hdr_maxsz + \
536 				 encode_sequence_maxsz + \
537 				 encode_putfh_maxsz + \
538 				 encode_layoutreturn_maxsz + \
539 				 encode_close_maxsz + \
540 				 encode_getattr_maxsz)
541 #define NFS4_dec_close_sz	(compound_decode_hdr_maxsz + \
542 				 decode_sequence_maxsz + \
543 				 decode_putfh_maxsz + \
544 				 decode_layoutreturn_maxsz + \
545 				 decode_close_maxsz + \
546 				 decode_getattr_maxsz)
547 #define NFS4_enc_setattr_sz	(compound_encode_hdr_maxsz + \
548 				 encode_sequence_maxsz + \
549 				 encode_putfh_maxsz + \
550 				 encode_setattr_maxsz + \
551 				 encode_getattr_maxsz)
552 #define NFS4_dec_setattr_sz	(compound_decode_hdr_maxsz + \
553 				 decode_sequence_maxsz + \
554 				 decode_putfh_maxsz + \
555 				 decode_setattr_maxsz + \
556 				 decode_getattr_maxsz)
557 #define NFS4_enc_fsinfo_sz	(compound_encode_hdr_maxsz + \
558 				encode_sequence_maxsz + \
559 				encode_putfh_maxsz + \
560 				encode_fsinfo_maxsz)
561 #define NFS4_dec_fsinfo_sz	(compound_decode_hdr_maxsz + \
562 				decode_sequence_maxsz + \
563 				decode_putfh_maxsz + \
564 				decode_fsinfo_maxsz)
565 #define NFS4_enc_renew_sz	(compound_encode_hdr_maxsz + \
566 				encode_renew_maxsz)
567 #define NFS4_dec_renew_sz	(compound_decode_hdr_maxsz + \
568 				decode_renew_maxsz)
569 #define NFS4_enc_setclientid_sz	(compound_encode_hdr_maxsz + \
570 				encode_setclientid_maxsz)
571 #define NFS4_dec_setclientid_sz	(compound_decode_hdr_maxsz + \
572 				decode_setclientid_maxsz)
573 #define NFS4_enc_setclientid_confirm_sz \
574 				(compound_encode_hdr_maxsz + \
575 				encode_setclientid_confirm_maxsz)
576 #define NFS4_dec_setclientid_confirm_sz \
577 				(compound_decode_hdr_maxsz + \
578 				decode_setclientid_confirm_maxsz)
579 #define NFS4_enc_lock_sz        (compound_encode_hdr_maxsz + \
580 				encode_sequence_maxsz + \
581 				encode_putfh_maxsz + \
582 				encode_lock_maxsz)
583 #define NFS4_dec_lock_sz        (compound_decode_hdr_maxsz + \
584 				decode_sequence_maxsz + \
585 				decode_putfh_maxsz + \
586 				decode_lock_maxsz)
587 #define NFS4_enc_lockt_sz       (compound_encode_hdr_maxsz + \
588 				encode_sequence_maxsz + \
589 				encode_putfh_maxsz + \
590 				encode_lockt_maxsz)
591 #define NFS4_dec_lockt_sz       (compound_decode_hdr_maxsz + \
592 				 decode_sequence_maxsz + \
593 				 decode_putfh_maxsz + \
594 				 decode_lockt_maxsz)
595 #define NFS4_enc_locku_sz       (compound_encode_hdr_maxsz + \
596 				encode_sequence_maxsz + \
597 				encode_putfh_maxsz + \
598 				encode_locku_maxsz)
599 #define NFS4_dec_locku_sz       (compound_decode_hdr_maxsz + \
600 				decode_sequence_maxsz + \
601 				decode_putfh_maxsz + \
602 				decode_locku_maxsz)
603 #define NFS4_enc_release_lockowner_sz \
604 				(compound_encode_hdr_maxsz + \
605 				 encode_lockowner_maxsz)
606 #define NFS4_dec_release_lockowner_sz \
607 				(compound_decode_hdr_maxsz + \
608 				 decode_lockowner_maxsz)
609 #define NFS4_enc_access_sz	(compound_encode_hdr_maxsz + \
610 				encode_sequence_maxsz + \
611 				encode_putfh_maxsz + \
612 				encode_access_maxsz + \
613 				encode_getattr_maxsz)
614 #define NFS4_dec_access_sz	(compound_decode_hdr_maxsz + \
615 				decode_sequence_maxsz + \
616 				decode_putfh_maxsz + \
617 				decode_access_maxsz + \
618 				decode_getattr_maxsz)
619 #define NFS4_enc_getattr_sz	(compound_encode_hdr_maxsz + \
620 				encode_sequence_maxsz + \
621 				encode_putfh_maxsz + \
622 				encode_getattr_maxsz + \
623 				encode_renew_maxsz)
624 #define NFS4_dec_getattr_sz	(compound_decode_hdr_maxsz + \
625 				decode_sequence_maxsz + \
626 				decode_putfh_maxsz + \
627 				decode_getattr_maxsz + \
628 				decode_renew_maxsz)
629 #define NFS4_enc_lookup_sz	(compound_encode_hdr_maxsz + \
630 				encode_sequence_maxsz + \
631 				encode_putfh_maxsz + \
632 				encode_lookup_maxsz + \
633 				encode_getattr_maxsz + \
634 				encode_getfh_maxsz)
635 #define NFS4_dec_lookup_sz	(compound_decode_hdr_maxsz + \
636 				decode_sequence_maxsz + \
637 				decode_putfh_maxsz + \
638 				decode_lookup_maxsz + \
639 				decode_getattr_maxsz + \
640 				decode_getfh_maxsz)
641 #define NFS4_enc_lookupp_sz	(compound_encode_hdr_maxsz + \
642 				encode_sequence_maxsz + \
643 				encode_putfh_maxsz + \
644 				encode_lookupp_maxsz + \
645 				encode_getattr_maxsz + \
646 				encode_getfh_maxsz)
647 #define NFS4_dec_lookupp_sz	(compound_decode_hdr_maxsz + \
648 				decode_sequence_maxsz + \
649 				decode_putfh_maxsz + \
650 				decode_lookupp_maxsz + \
651 				decode_getattr_maxsz + \
652 				decode_getfh_maxsz)
653 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
654 				encode_sequence_maxsz + \
655 				encode_putrootfh_maxsz + \
656 				encode_getattr_maxsz + \
657 				encode_getfh_maxsz)
658 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
659 				decode_sequence_maxsz + \
660 				decode_putrootfh_maxsz + \
661 				decode_getattr_maxsz + \
662 				decode_getfh_maxsz)
663 #define NFS4_enc_remove_sz	(compound_encode_hdr_maxsz + \
664 				encode_sequence_maxsz + \
665 				encode_putfh_maxsz + \
666 				encode_remove_maxsz)
667 #define NFS4_dec_remove_sz	(compound_decode_hdr_maxsz + \
668 				decode_sequence_maxsz + \
669 				decode_putfh_maxsz + \
670 				decode_remove_maxsz)
671 #define NFS4_enc_rename_sz	(compound_encode_hdr_maxsz + \
672 				encode_sequence_maxsz + \
673 				encode_putfh_maxsz + \
674 				encode_savefh_maxsz + \
675 				encode_putfh_maxsz + \
676 				encode_rename_maxsz)
677 #define NFS4_dec_rename_sz	(compound_decode_hdr_maxsz + \
678 				decode_sequence_maxsz + \
679 				decode_putfh_maxsz + \
680 				decode_savefh_maxsz + \
681 				decode_putfh_maxsz + \
682 				decode_rename_maxsz)
683 #define NFS4_enc_link_sz	(compound_encode_hdr_maxsz + \
684 				encode_sequence_maxsz + \
685 				encode_putfh_maxsz + \
686 				encode_savefh_maxsz + \
687 				encode_putfh_maxsz + \
688 				encode_link_maxsz + \
689 				encode_restorefh_maxsz + \
690 				encode_getattr_maxsz)
691 #define NFS4_dec_link_sz	(compound_decode_hdr_maxsz + \
692 				decode_sequence_maxsz + \
693 				decode_putfh_maxsz + \
694 				decode_savefh_maxsz + \
695 				decode_putfh_maxsz + \
696 				decode_link_maxsz + \
697 				decode_restorefh_maxsz + \
698 				decode_getattr_maxsz)
699 #define NFS4_enc_symlink_sz	(compound_encode_hdr_maxsz + \
700 				encode_sequence_maxsz + \
701 				encode_putfh_maxsz + \
702 				encode_symlink_maxsz + \
703 				encode_getattr_maxsz + \
704 				encode_getfh_maxsz)
705 #define NFS4_dec_symlink_sz	(compound_decode_hdr_maxsz + \
706 				decode_sequence_maxsz + \
707 				decode_putfh_maxsz + \
708 				decode_symlink_maxsz + \
709 				decode_getattr_maxsz + \
710 				decode_getfh_maxsz)
711 #define NFS4_enc_create_sz	(compound_encode_hdr_maxsz + \
712 				encode_sequence_maxsz + \
713 				encode_putfh_maxsz + \
714 				encode_create_maxsz + \
715 				encode_getfh_maxsz + \
716 				encode_getattr_maxsz)
717 #define NFS4_dec_create_sz	(compound_decode_hdr_maxsz + \
718 				decode_sequence_maxsz + \
719 				decode_putfh_maxsz + \
720 				decode_create_maxsz + \
721 				decode_getfh_maxsz + \
722 				decode_getattr_maxsz)
723 #define NFS4_enc_pathconf_sz	(compound_encode_hdr_maxsz + \
724 				encode_sequence_maxsz + \
725 				encode_putfh_maxsz + \
726 				encode_getattr_maxsz)
727 #define NFS4_dec_pathconf_sz	(compound_decode_hdr_maxsz + \
728 				decode_sequence_maxsz + \
729 				decode_putfh_maxsz + \
730 				decode_getattr_maxsz)
731 #define NFS4_enc_statfs_sz	(compound_encode_hdr_maxsz + \
732 				encode_sequence_maxsz + \
733 				encode_putfh_maxsz + \
734 				encode_statfs_maxsz)
735 #define NFS4_dec_statfs_sz	(compound_decode_hdr_maxsz + \
736 				decode_sequence_maxsz + \
737 				decode_putfh_maxsz + \
738 				decode_statfs_maxsz)
739 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
740 				encode_sequence_maxsz + \
741 				encode_putfh_maxsz + \
742 				encode_getattr_maxsz)
743 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
744 				decode_sequence_maxsz + \
745 				decode_putfh_maxsz + \
746 				decode_getattr_maxsz)
747 #define NFS4_enc_delegreturn_sz	(compound_encode_hdr_maxsz + \
748 				encode_sequence_maxsz + \
749 				encode_putfh_maxsz + \
750 				encode_layoutreturn_maxsz + \
751 				encode_delegreturn_maxsz + \
752 				encode_getattr_maxsz)
753 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
754 				decode_sequence_maxsz + \
755 				decode_putfh_maxsz + \
756 				decode_layoutreturn_maxsz + \
757 				decode_delegreturn_maxsz + \
758 				decode_getattr_maxsz)
759 #define NFS4_enc_getacl_sz	(compound_encode_hdr_maxsz + \
760 				encode_sequence_maxsz + \
761 				encode_putfh_maxsz + \
762 				encode_getacl_maxsz)
763 #define NFS4_dec_getacl_sz	(compound_decode_hdr_maxsz + \
764 				decode_sequence_maxsz + \
765 				decode_putfh_maxsz + \
766 				decode_getacl_maxsz)
767 #define NFS4_enc_setacl_sz	(compound_encode_hdr_maxsz + \
768 				encode_sequence_maxsz + \
769 				encode_putfh_maxsz + \
770 				encode_setacl_maxsz)
771 #define NFS4_dec_setacl_sz	(compound_decode_hdr_maxsz + \
772 				decode_sequence_maxsz + \
773 				decode_putfh_maxsz + \
774 				decode_setacl_maxsz)
775 #define NFS4_enc_fs_locations_sz \
776 				(compound_encode_hdr_maxsz + \
777 				 encode_sequence_maxsz + \
778 				 encode_putfh_maxsz + \
779 				 encode_lookup_maxsz + \
780 				 encode_fs_locations_maxsz + \
781 				 encode_renew_maxsz)
782 #define NFS4_dec_fs_locations_sz \
783 				(compound_decode_hdr_maxsz + \
784 				 decode_sequence_maxsz + \
785 				 decode_putfh_maxsz + \
786 				 decode_lookup_maxsz + \
787 				 decode_fs_locations_maxsz + \
788 				 decode_renew_maxsz)
789 #define NFS4_enc_secinfo_sz 	(compound_encode_hdr_maxsz + \
790 				encode_sequence_maxsz + \
791 				encode_putfh_maxsz + \
792 				encode_secinfo_maxsz)
793 #define NFS4_dec_secinfo_sz	(compound_decode_hdr_maxsz + \
794 				decode_sequence_maxsz + \
795 				decode_putfh_maxsz + \
796 				decode_secinfo_maxsz)
797 #define NFS4_enc_fsid_present_sz \
798 				(compound_encode_hdr_maxsz + \
799 				 encode_sequence_maxsz + \
800 				 encode_putfh_maxsz + \
801 				 encode_getfh_maxsz + \
802 				 encode_renew_maxsz)
803 #define NFS4_dec_fsid_present_sz \
804 				(compound_decode_hdr_maxsz + \
805 				 decode_sequence_maxsz + \
806 				 decode_putfh_maxsz + \
807 				 decode_getfh_maxsz + \
808 				 decode_renew_maxsz)
809 #if defined(CONFIG_NFS_V4_1)
810 #define NFS4_enc_bind_conn_to_session_sz \
811 				(compound_encode_hdr_maxsz + \
812 				 encode_bind_conn_to_session_maxsz)
813 #define NFS4_dec_bind_conn_to_session_sz \
814 				(compound_decode_hdr_maxsz + \
815 				 decode_bind_conn_to_session_maxsz)
816 #define NFS4_enc_exchange_id_sz \
817 				(compound_encode_hdr_maxsz + \
818 				 encode_exchange_id_maxsz)
819 #define NFS4_dec_exchange_id_sz \
820 				(compound_decode_hdr_maxsz + \
821 				 decode_exchange_id_maxsz)
822 #define NFS4_enc_create_session_sz \
823 				(compound_encode_hdr_maxsz + \
824 				 encode_create_session_maxsz)
825 #define NFS4_dec_create_session_sz \
826 				(compound_decode_hdr_maxsz + \
827 				 decode_create_session_maxsz)
828 #define NFS4_enc_destroy_session_sz	(compound_encode_hdr_maxsz + \
829 					 encode_destroy_session_maxsz)
830 #define NFS4_dec_destroy_session_sz	(compound_decode_hdr_maxsz + \
831 					 decode_destroy_session_maxsz)
832 #define NFS4_enc_destroy_clientid_sz	(compound_encode_hdr_maxsz + \
833 					 encode_destroy_clientid_maxsz)
834 #define NFS4_dec_destroy_clientid_sz	(compound_decode_hdr_maxsz + \
835 					 decode_destroy_clientid_maxsz)
836 #define NFS4_enc_sequence_sz \
837 				(compound_decode_hdr_maxsz + \
838 				 encode_sequence_maxsz)
839 #define NFS4_dec_sequence_sz \
840 				(compound_decode_hdr_maxsz + \
841 				 decode_sequence_maxsz)
842 #endif
843 #define NFS4_enc_get_lease_time_sz	(compound_encode_hdr_maxsz + \
844 					 encode_sequence_maxsz + \
845 					 encode_putrootfh_maxsz + \
846 					 encode_fsinfo_maxsz)
847 #define NFS4_dec_get_lease_time_sz	(compound_decode_hdr_maxsz + \
848 					 decode_sequence_maxsz + \
849 					 decode_putrootfh_maxsz + \
850 					 decode_fsinfo_maxsz)
851 #if defined(CONFIG_NFS_V4_1)
852 #define NFS4_enc_reclaim_complete_sz	(compound_encode_hdr_maxsz + \
853 					 encode_sequence_maxsz + \
854 					 encode_reclaim_complete_maxsz)
855 #define NFS4_dec_reclaim_complete_sz	(compound_decode_hdr_maxsz + \
856 					 decode_sequence_maxsz + \
857 					 decode_reclaim_complete_maxsz)
858 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz +    \
859 				encode_sequence_maxsz +\
860 				encode_getdeviceinfo_maxsz)
861 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz +    \
862 				decode_sequence_maxsz + \
863 				decode_getdeviceinfo_maxsz)
864 #define NFS4_enc_layoutget_sz	(compound_encode_hdr_maxsz + \
865 				encode_sequence_maxsz + \
866 				encode_putfh_maxsz +        \
867 				encode_layoutget_maxsz)
868 #define NFS4_dec_layoutget_sz	(compound_decode_hdr_maxsz + \
869 				decode_sequence_maxsz + \
870 				decode_putfh_maxsz +        \
871 				decode_layoutget_maxsz)
872 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
873 				encode_sequence_maxsz +\
874 				encode_putfh_maxsz + \
875 				encode_layoutcommit_maxsz + \
876 				encode_getattr_maxsz)
877 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
878 				decode_sequence_maxsz + \
879 				decode_putfh_maxsz + \
880 				decode_layoutcommit_maxsz + \
881 				decode_getattr_maxsz)
882 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
883 				encode_sequence_maxsz + \
884 				encode_putfh_maxsz + \
885 				encode_layoutreturn_maxsz)
886 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
887 				decode_sequence_maxsz + \
888 				decode_putfh_maxsz + \
889 				decode_layoutreturn_maxsz)
890 #define NFS4_enc_secinfo_no_name_sz	(compound_encode_hdr_maxsz + \
891 					encode_sequence_maxsz + \
892 					encode_putrootfh_maxsz +\
893 					encode_secinfo_no_name_maxsz)
894 #define NFS4_dec_secinfo_no_name_sz	(compound_decode_hdr_maxsz + \
895 					decode_sequence_maxsz + \
896 					decode_putrootfh_maxsz + \
897 					decode_secinfo_no_name_maxsz)
898 #define NFS4_enc_test_stateid_sz	(compound_encode_hdr_maxsz + \
899 					 encode_sequence_maxsz + \
900 					 encode_test_stateid_maxsz)
901 #define NFS4_dec_test_stateid_sz	(compound_decode_hdr_maxsz + \
902 					 decode_sequence_maxsz + \
903 					 decode_test_stateid_maxsz)
904 #define NFS4_enc_free_stateid_sz	(compound_encode_hdr_maxsz + \
905 					 encode_sequence_maxsz + \
906 					 encode_free_stateid_maxsz)
907 #define NFS4_dec_free_stateid_sz	(compound_decode_hdr_maxsz + \
908 					 decode_sequence_maxsz + \
909 					 decode_free_stateid_maxsz)
910 
911 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
912 				      compound_encode_hdr_maxsz +
913 				      encode_sequence_maxsz +
914 				      encode_putfh_maxsz +
915 				      encode_getattr_maxsz) *
916 				     XDR_UNIT);
917 
918 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
919 				     compound_decode_hdr_maxsz +
920 				     decode_sequence_maxsz +
921 				     decode_putfh_maxsz) *
922 				    XDR_UNIT);
923 
924 const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
925 					   compound_decode_hdr_maxsz +
926 					   decode_sequence_maxsz) *
927 					  XDR_UNIT);
928 EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
929 #endif /* CONFIG_NFS_V4_1 */
930 
931 static const umode_t nfs_type2fmt[] = {
932 	[NF4BAD] = 0,
933 	[NF4REG] = S_IFREG,
934 	[NF4DIR] = S_IFDIR,
935 	[NF4BLK] = S_IFBLK,
936 	[NF4CHR] = S_IFCHR,
937 	[NF4LNK] = S_IFLNK,
938 	[NF4SOCK] = S_IFSOCK,
939 	[NF4FIFO] = S_IFIFO,
940 	[NF4ATTRDIR] = 0,
941 	[NF4NAMEDATTR] = 0,
942 };
943 
944 struct compound_hdr {
945 	int32_t		status;
946 	uint32_t	nops;
947 	__be32 *	nops_p;
948 	uint32_t	taglen;
949 	char *		tag;
950 	uint32_t	replen;		/* expected reply words */
951 	u32		minorversion;
952 };
953 
954 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
955 {
956 	__be32 *p = xdr_reserve_space(xdr, nbytes);
957 	BUG_ON(!p);
958 	return p;
959 }
960 
961 static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
962 {
963 	WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
964 }
965 
966 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
967 {
968 	WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
969 }
970 
971 static void encode_uint32(struct xdr_stream *xdr, u32 n)
972 {
973 	WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
974 }
975 
976 static void encode_uint64(struct xdr_stream *xdr, u64 n)
977 {
978 	WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
979 }
980 
981 static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
982 		const __u32 *bitmap, size_t len)
983 {
984 	ssize_t ret;
985 
986 	/* Trim empty words */
987 	while (len > 0 && bitmap[len-1] == 0)
988 		len--;
989 	ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
990 	if (WARN_ON_ONCE(ret < 0))
991 		return ret;
992 	return len;
993 }
994 
995 static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
996 		__u32 *res, size_t len)
997 {
998 	size_t i;
999 	__u32 tmp;
1000 
1001 	while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
1002 		len--;
1003 	for (i = len; i-- > 0;) {
1004 		tmp = bitmap[i] & mask[i];
1005 		res[i] = tmp;
1006 	}
1007 	return len;
1008 }
1009 
1010 static void encode_nfs4_seqid(struct xdr_stream *xdr,
1011 		const struct nfs_seqid *seqid)
1012 {
1013 	if (seqid != NULL)
1014 		encode_uint32(xdr, seqid->sequence->counter);
1015 	else
1016 		encode_uint32(xdr, 0);
1017 }
1018 
1019 static void encode_compound_hdr(struct xdr_stream *xdr,
1020 				struct rpc_rqst *req,
1021 				struct compound_hdr *hdr)
1022 {
1023 	__be32 *p;
1024 
1025 	/* initialize running count of expected bytes in reply.
1026 	 * NOTE: the replied tag SHOULD be the same is the one sent,
1027 	 * but this is not required as a MUST for the server to do so. */
1028 	hdr->replen = 3 + hdr->taglen;
1029 
1030 	WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
1031 	encode_string(xdr, hdr->taglen, hdr->tag);
1032 	p = reserve_space(xdr, 8);
1033 	*p++ = cpu_to_be32(hdr->minorversion);
1034 	hdr->nops_p = p;
1035 	*p = cpu_to_be32(hdr->nops);
1036 }
1037 
1038 static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
1039 		uint32_t replen,
1040 		struct compound_hdr *hdr)
1041 {
1042 	encode_uint32(xdr, op);
1043 	hdr->nops++;
1044 	hdr->replen += replen;
1045 }
1046 
1047 static void encode_nops(struct compound_hdr *hdr)
1048 {
1049 	WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
1050 	*hdr->nops_p = htonl(hdr->nops);
1051 }
1052 
1053 static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1054 {
1055 	encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
1056 }
1057 
1058 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1059 {
1060 	encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
1061 }
1062 
1063 static __be32 *
1064 xdr_encode_nfstime4(__be32 *p, const struct timespec64 *t)
1065 {
1066 	p = xdr_encode_hyper(p, t->tv_sec);
1067 	*p++ = cpu_to_be32(t->tv_nsec);
1068 	return p;
1069 }
1070 
1071 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1072 				const struct nfs4_label *label,
1073 				const umode_t *umask,
1074 				const struct nfs_server *server,
1075 				const uint32_t attrmask[])
1076 {
1077 	char owner_name[IDMAP_NAMESZ];
1078 	char owner_group[IDMAP_NAMESZ];
1079 	int owner_namelen = 0;
1080 	int owner_grouplen = 0;
1081 	__be32 *p;
1082 	uint32_t len = 0;
1083 	uint32_t bmval[3] = { 0 };
1084 
1085 	/*
1086 	 * We reserve enough space to write the entire attribute buffer at once.
1087 	 */
1088 	if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
1089 		bmval[0] |= FATTR4_WORD0_SIZE;
1090 		len += 8;
1091 	}
1092 	if (iap->ia_valid & ATTR_MODE) {
1093 		if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
1094 			bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1095 			len += 8;
1096 		} else if (attrmask[1] & FATTR4_WORD1_MODE) {
1097 			bmval[1] |= FATTR4_WORD1_MODE;
1098 			len += 4;
1099 		}
1100 	}
1101 	if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
1102 		owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
1103 		if (owner_namelen < 0) {
1104 			dprintk("nfs: couldn't resolve uid %d to string\n",
1105 					from_kuid(&init_user_ns, iap->ia_uid));
1106 			/* XXX */
1107 			strcpy(owner_name, "nobody");
1108 			owner_namelen = sizeof("nobody") - 1;
1109 			/* goto out; */
1110 		}
1111 		bmval[1] |= FATTR4_WORD1_OWNER;
1112 		len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1113 	}
1114 	if ((iap->ia_valid & ATTR_GID) &&
1115 	   (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
1116 		owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
1117 		if (owner_grouplen < 0) {
1118 			dprintk("nfs: couldn't resolve gid %d to string\n",
1119 					from_kgid(&init_user_ns, iap->ia_gid));
1120 			strcpy(owner_group, "nobody");
1121 			owner_grouplen = sizeof("nobody") - 1;
1122 			/* goto out; */
1123 		}
1124 		bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
1125 		len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1126 	}
1127 	if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1128 		if (iap->ia_valid & ATTR_ATIME_SET) {
1129 			bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1130 			len += 4 + (nfstime4_maxsz << 2);
1131 		} else if (iap->ia_valid & ATTR_ATIME) {
1132 			bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1133 			len += 4;
1134 		}
1135 	}
1136 	if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1137 		if (iap->ia_valid & ATTR_MTIME_SET) {
1138 			bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1139 			len += 4 + (nfstime4_maxsz << 2);
1140 		} else if (iap->ia_valid & ATTR_MTIME) {
1141 			bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1142 			len += 4;
1143 		}
1144 	}
1145 
1146 	if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
1147 		len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1148 		bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1149 	}
1150 
1151 	xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
1152 	xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
1153 
1154 	if (bmval[0] & FATTR4_WORD0_SIZE)
1155 		p = xdr_encode_hyper(p, iap->ia_size);
1156 	if (bmval[1] & FATTR4_WORD1_MODE)
1157 		*p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1158 	if (bmval[1] & FATTR4_WORD1_OWNER)
1159 		p = xdr_encode_opaque(p, owner_name, owner_namelen);
1160 	if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1161 		p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1162 	if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1163 		if (iap->ia_valid & ATTR_ATIME_SET) {
1164 			*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1165 			p = xdr_encode_nfstime4(p, &iap->ia_atime);
1166 		} else
1167 			*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1168 	}
1169 	if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1170 		if (iap->ia_valid & ATTR_MTIME_SET) {
1171 			*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1172 			p = xdr_encode_nfstime4(p, &iap->ia_mtime);
1173 		} else
1174 			*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1175 	}
1176 	if (label && (bmval[2] & FATTR4_WORD2_SECURITY_LABEL)) {
1177 		*p++ = cpu_to_be32(label->lfs);
1178 		*p++ = cpu_to_be32(label->pi);
1179 		*p++ = cpu_to_be32(label->len);
1180 		p = xdr_encode_opaque_fixed(p, label->label, label->len);
1181 	}
1182 	if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1183 		*p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1184 		*p++ = cpu_to_be32(*umask);
1185 	}
1186 
1187 /* out: */
1188 }
1189 
1190 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1191 {
1192 	encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1193 	encode_uint32(xdr, access);
1194 }
1195 
1196 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1197 {
1198 	encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
1199 	encode_nfs4_seqid(xdr, arg->seqid);
1200 	encode_nfs4_stateid(xdr, &arg->stateid);
1201 }
1202 
1203 static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
1204 {
1205 	__be32 *p;
1206 
1207 	encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1208 	p = reserve_space(xdr, 12);
1209 	p = xdr_encode_hyper(p, args->offset);
1210 	*p = cpu_to_be32(args->count);
1211 }
1212 
1213 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1214 {
1215 	__be32 *p;
1216 
1217 	encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1218 	encode_uint32(xdr, create->ftype);
1219 
1220 	switch (create->ftype) {
1221 	case NF4LNK:
1222 		p = reserve_space(xdr, 4);
1223 		*p = cpu_to_be32(create->u.symlink.len);
1224 		xdr_write_pages(xdr, create->u.symlink.pages, 0,
1225 				create->u.symlink.len);
1226 		xdr->buf->flags |= XDRBUF_WRITE;
1227 		break;
1228 
1229 	case NF4BLK: case NF4CHR:
1230 		p = reserve_space(xdr, 8);
1231 		*p++ = cpu_to_be32(create->u.device.specdata1);
1232 		*p = cpu_to_be32(create->u.device.specdata2);
1233 		break;
1234 
1235 	default:
1236 		break;
1237 	}
1238 
1239 	encode_string(xdr, create->name->len, create->name->name);
1240 	encode_attrs(xdr, create->attrs, create->label, &create->umask,
1241 			create->server, create->server->attr_bitmask);
1242 }
1243 
1244 static void encode_getattr(struct xdr_stream *xdr,
1245 		const __u32 *bitmap, const __u32 *mask, size_t len,
1246 		struct compound_hdr *hdr)
1247 {
1248 	__u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
1249 
1250 	encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1251 	if (mask) {
1252 		if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
1253 			len = ARRAY_SIZE(masked_bitmap);
1254 		len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
1255 		bitmap = masked_bitmap;
1256 	}
1257 	xdr_encode_bitmap4(xdr, bitmap, len);
1258 }
1259 
1260 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1261 {
1262 	encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
1263 			ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
1264 }
1265 
1266 static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
1267 				 const u32 *open_bitmap,
1268 				 struct compound_hdr *hdr)
1269 {
1270 	encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
1271 }
1272 
1273 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1274 {
1275 	encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
1276 			ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
1277 }
1278 
1279 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1280 {
1281 	encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
1282 			ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
1283 }
1284 
1285 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1286 {
1287 	encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
1288 }
1289 
1290 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1291 {
1292 	encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
1293 	encode_string(xdr, name->len, name->name);
1294 }
1295 
1296 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1297 {
1298 	if (fl->fl_type == F_RDLCK)
1299 		return block ? NFS4_READW_LT : NFS4_READ_LT;
1300 	return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1301 }
1302 
1303 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1304 {
1305 	if (fl->fl_end == OFFSET_MAX)
1306 		return ~(uint64_t)0;
1307 	return fl->fl_end - fl->fl_start + 1;
1308 }
1309 
1310 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1311 {
1312 	__be32 *p;
1313 
1314 	p = reserve_space(xdr, 32);
1315 	p = xdr_encode_hyper(p, lowner->clientid);
1316 	*p++ = cpu_to_be32(20);
1317 	p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1318 	*p++ = cpu_to_be32(lowner->s_dev);
1319 	xdr_encode_hyper(p, lowner->id);
1320 }
1321 
1322 /*
1323  * opcode,type,reclaim,offset,length,new_lock_owner = 32
1324  * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1325  */
1326 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1327 {
1328 	__be32 *p;
1329 
1330 	encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1331 	p = reserve_space(xdr, 28);
1332 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1333 	*p++ = cpu_to_be32(args->reclaim);
1334 	p = xdr_encode_hyper(p, args->fl->fl_start);
1335 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1336 	*p = cpu_to_be32(args->new_lock_owner);
1337 	if (args->new_lock_owner){
1338 		encode_nfs4_seqid(xdr, args->open_seqid);
1339 		encode_nfs4_stateid(xdr, &args->open_stateid);
1340 		encode_nfs4_seqid(xdr, args->lock_seqid);
1341 		encode_lockowner(xdr, &args->lock_owner);
1342 	}
1343 	else {
1344 		encode_nfs4_stateid(xdr, &args->lock_stateid);
1345 		encode_nfs4_seqid(xdr, args->lock_seqid);
1346 	}
1347 }
1348 
1349 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1350 {
1351 	__be32 *p;
1352 
1353 	encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1354 	p = reserve_space(xdr, 20);
1355 	*p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1356 	p = xdr_encode_hyper(p, args->fl->fl_start);
1357 	p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1358 	encode_lockowner(xdr, &args->lock_owner);
1359 }
1360 
1361 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1362 {
1363 	__be32 *p;
1364 
1365 	encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1366 	encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
1367 	encode_nfs4_seqid(xdr, args->seqid);
1368 	encode_nfs4_stateid(xdr, &args->stateid);
1369 	p = reserve_space(xdr, 16);
1370 	p = xdr_encode_hyper(p, args->fl->fl_start);
1371 	xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1372 }
1373 
1374 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1375 {
1376 	encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1377 	encode_lockowner(xdr, lowner);
1378 }
1379 
1380 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1381 {
1382 	encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
1383 	encode_string(xdr, name->len, name->name);
1384 }
1385 
1386 static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
1387 {
1388 	encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
1389 }
1390 
1391 static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
1392 {
1393 	__be32 *p;
1394 
1395 	p = reserve_space(xdr, 8);
1396 	*p++ = cpu_to_be32(share_access);
1397 	*p = cpu_to_be32(0);		/* for linux, share_deny = 0 always */
1398 }
1399 
1400 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1401 {
1402 	__be32 *p;
1403  /*
1404  * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1405  * owner 4 = 32
1406  */
1407 	encode_nfs4_seqid(xdr, arg->seqid);
1408 	encode_share_access(xdr, arg->share_access);
1409 	p = reserve_space(xdr, 36);
1410 	p = xdr_encode_hyper(p, arg->clientid);
1411 	*p++ = cpu_to_be32(24);
1412 	p = xdr_encode_opaque_fixed(p, "open id:", 8);
1413 	*p++ = cpu_to_be32(arg->server->s_dev);
1414 	*p++ = cpu_to_be32(arg->id.uniquifier);
1415 	xdr_encode_hyper(p, arg->id.create_time);
1416 }
1417 
1418 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1419 {
1420 	__be32 *p;
1421 
1422 	p = reserve_space(xdr, 4);
1423 	switch(arg->createmode) {
1424 	case NFS4_CREATE_UNCHECKED:
1425 		*p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1426 		encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1427 				arg->server, arg->server->attr_bitmask);
1428 		break;
1429 	case NFS4_CREATE_GUARDED:
1430 		*p = cpu_to_be32(NFS4_CREATE_GUARDED);
1431 		encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1432 				arg->server, arg->server->attr_bitmask);
1433 		break;
1434 	case NFS4_CREATE_EXCLUSIVE:
1435 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1436 		encode_nfs4_verifier(xdr, &arg->u.verifier);
1437 		break;
1438 	case NFS4_CREATE_EXCLUSIVE4_1:
1439 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1440 		encode_nfs4_verifier(xdr, &arg->u.verifier);
1441 		encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1442 				arg->server, arg->server->exclcreat_bitmask);
1443 	}
1444 }
1445 
1446 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1447 {
1448 	__be32 *p;
1449 
1450 	p = reserve_space(xdr, 4);
1451 	switch (arg->open_flags & O_CREAT) {
1452 	case 0:
1453 		*p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1454 		break;
1455 	default:
1456 		*p = cpu_to_be32(NFS4_OPEN_CREATE);
1457 		encode_createmode(xdr, arg);
1458 	}
1459 }
1460 
1461 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1462 {
1463 	__be32 *p;
1464 
1465 	p = reserve_space(xdr, 4);
1466 	switch (delegation_type) {
1467 	case 0:
1468 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1469 		break;
1470 	case FMODE_READ:
1471 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1472 		break;
1473 	case FMODE_WRITE|FMODE_READ:
1474 		*p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1475 		break;
1476 	default:
1477 		BUG();
1478 	}
1479 }
1480 
1481 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1482 {
1483 	__be32 *p;
1484 
1485 	p = reserve_space(xdr, 4);
1486 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1487 	encode_string(xdr, name->len, name->name);
1488 }
1489 
1490 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1491 {
1492 	__be32 *p;
1493 
1494 	p = reserve_space(xdr, 4);
1495 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1496 	encode_delegation_type(xdr, type);
1497 }
1498 
1499 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1500 {
1501 	__be32 *p;
1502 
1503 	p = reserve_space(xdr, 4);
1504 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1505 	encode_nfs4_stateid(xdr, stateid);
1506 	encode_string(xdr, name->len, name->name);
1507 }
1508 
1509 static inline void encode_claim_fh(struct xdr_stream *xdr)
1510 {
1511 	__be32 *p;
1512 
1513 	p = reserve_space(xdr, 4);
1514 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1515 }
1516 
1517 static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1518 {
1519 	__be32 *p;
1520 
1521 	p = reserve_space(xdr, 4);
1522 	*p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1523 	encode_nfs4_stateid(xdr, stateid);
1524 }
1525 
1526 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1527 {
1528 	encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
1529 	encode_openhdr(xdr, arg);
1530 	encode_opentype(xdr, arg);
1531 	switch (arg->claim) {
1532 	case NFS4_OPEN_CLAIM_NULL:
1533 		encode_claim_null(xdr, arg->name);
1534 		break;
1535 	case NFS4_OPEN_CLAIM_PREVIOUS:
1536 		encode_claim_previous(xdr, arg->u.delegation_type);
1537 		break;
1538 	case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1539 		encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1540 		break;
1541 	case NFS4_OPEN_CLAIM_FH:
1542 		encode_claim_fh(xdr);
1543 		break;
1544 	case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1545 		encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1546 		break;
1547 	default:
1548 		BUG();
1549 	}
1550 }
1551 
1552 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1553 {
1554 	encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1555 	encode_nfs4_stateid(xdr, arg->stateid);
1556 	encode_nfs4_seqid(xdr, arg->seqid);
1557 }
1558 
1559 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1560 {
1561 	encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1562 	encode_nfs4_stateid(xdr, &arg->stateid);
1563 	encode_nfs4_seqid(xdr, arg->seqid);
1564 	encode_share_access(xdr, arg->share_access);
1565 }
1566 
1567 static void
1568 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1569 {
1570 	encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
1571 	encode_string(xdr, fh->size, fh->data);
1572 }
1573 
1574 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1575 {
1576 	encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
1577 }
1578 
1579 static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1580 			struct compound_hdr *hdr)
1581 {
1582 	__be32 *p;
1583 
1584 	encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
1585 	encode_nfs4_stateid(xdr, &args->stateid);
1586 
1587 	p = reserve_space(xdr, 12);
1588 	p = xdr_encode_hyper(p, args->offset);
1589 	*p = cpu_to_be32(args->count);
1590 }
1591 
1592 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1593 {
1594 	uint32_t attrs[3] = {
1595 		FATTR4_WORD0_RDATTR_ERROR,
1596 		FATTR4_WORD1_MOUNTED_ON_FILEID,
1597 	};
1598 	uint32_t dircount = readdir->count >> 1;
1599 	__be32 *p, verf[2];
1600 	uint32_t attrlen = 0;
1601 	unsigned int i;
1602 
1603 	if (readdir->plus) {
1604 		attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1605 			FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1606 		attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1607 			FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1608 			FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1609 			FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1610 		attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1611 		dircount >>= 1;
1612 	}
1613 	/* Use mounted_on_fileid only if the server supports it */
1614 	if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1615 		attrs[0] |= FATTR4_WORD0_FILEID;
1616 	for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1617 		attrs[i] &= readdir->bitmask[i];
1618 		if (attrs[i] != 0)
1619 			attrlen = i+1;
1620 	}
1621 
1622 	encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1623 	encode_uint64(xdr, readdir->cookie);
1624 	encode_nfs4_verifier(xdr, &readdir->verifier);
1625 	p = reserve_space(xdr, 12 + (attrlen << 2));
1626 	*p++ = cpu_to_be32(dircount);
1627 	*p++ = cpu_to_be32(readdir->count);
1628 	*p++ = cpu_to_be32(attrlen);
1629 	for (i = 0; i < attrlen; i++)
1630 		*p++ = cpu_to_be32(attrs[i]);
1631 	memcpy(verf, readdir->verifier.data, sizeof(verf));
1632 
1633 	dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
1634 			__func__,
1635 			(unsigned long long)readdir->cookie,
1636 			verf[0], verf[1],
1637 			attrs[0] & readdir->bitmask[0],
1638 			attrs[1] & readdir->bitmask[1],
1639 			attrs[2] & readdir->bitmask[2]);
1640 }
1641 
1642 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1643 {
1644 	encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
1645 }
1646 
1647 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1648 {
1649 	encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
1650 	encode_string(xdr, name->len, name->name);
1651 }
1652 
1653 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1654 {
1655 	encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1656 	encode_string(xdr, oldname->len, oldname->name);
1657 	encode_string(xdr, newname->len, newname->name);
1658 }
1659 
1660 static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1661 			 struct compound_hdr *hdr)
1662 {
1663 	encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1664 	encode_uint64(xdr, clid);
1665 }
1666 
1667 static void
1668 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1669 {
1670 	encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
1671 }
1672 
1673 static void
1674 encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1675 		struct compound_hdr *hdr)
1676 {
1677 	__be32 *p;
1678 
1679 	encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1680 	encode_nfs4_stateid(xdr, &zero_stateid);
1681 	p = reserve_space(xdr, 2*4);
1682 	*p++ = cpu_to_be32(1);
1683 	*p = cpu_to_be32(FATTR4_WORD0_ACL);
1684 	p = reserve_space(xdr, 4);
1685 	*p = cpu_to_be32(arg->acl_len);
1686 	xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
1687 }
1688 
1689 static void
1690 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1691 {
1692 	encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
1693 }
1694 
1695 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1696 {
1697 	encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1698 	encode_nfs4_stateid(xdr, &arg->stateid);
1699 	encode_attrs(xdr, arg->iap, arg->label, NULL, server,
1700 			server->attr_bitmask);
1701 }
1702 
1703 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1704 {
1705 	__be32 *p;
1706 
1707 	encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1708 	encode_nfs4_verifier(xdr, setclientid->sc_verifier);
1709 
1710 	encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1711 			setclientid->sc_clnt->cl_owner_id);
1712 	p = reserve_space(xdr, 4);
1713 	*p = cpu_to_be32(setclientid->sc_prog);
1714 	encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1715 	encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1716 	p = reserve_space(xdr, 4);
1717 	*p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
1718 }
1719 
1720 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1721 {
1722 	encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1723 			decode_setclientid_confirm_maxsz, hdr);
1724 	encode_uint64(xdr, arg->clientid);
1725 	encode_nfs4_verifier(xdr, &arg->confirm);
1726 }
1727 
1728 static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1729 			 struct compound_hdr *hdr)
1730 {
1731 	__be32 *p;
1732 
1733 	encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
1734 	encode_nfs4_stateid(xdr, &args->stateid);
1735 
1736 	p = reserve_space(xdr, 16);
1737 	p = xdr_encode_hyper(p, args->offset);
1738 	*p++ = cpu_to_be32(args->stable);
1739 	*p = cpu_to_be32(args->count);
1740 
1741 	xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1742 }
1743 
1744 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1745 {
1746 	encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1747 	encode_nfs4_stateid(xdr, stateid);
1748 }
1749 
1750 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1751 {
1752 	encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
1753 	encode_string(xdr, name->len, name->name);
1754 }
1755 
1756 #if defined(CONFIG_NFS_V4_1)
1757 /* NFSv4.1 operations */
1758 static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1759 				   const struct nfs41_bind_conn_to_session_args *args,
1760 				   struct compound_hdr *hdr)
1761 {
1762 	__be32 *p;
1763 
1764 	encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1765 		decode_bind_conn_to_session_maxsz, hdr);
1766 	encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
1767 	p = xdr_reserve_space(xdr, 8);
1768 	*p++ = cpu_to_be32(args->dir);
1769 	*p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
1770 }
1771 
1772 static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
1773 {
1774 	unsigned int i;
1775 	encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1776 	for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1777 		encode_uint32(xdr, op_map->u.words[i]);
1778 }
1779 
1780 static void encode_exchange_id(struct xdr_stream *xdr,
1781 			       const struct nfs41_exchange_id_args *args,
1782 			       struct compound_hdr *hdr)
1783 {
1784 	__be32 *p;
1785 	char impl_name[IMPL_NAME_LIMIT];
1786 	int len = 0;
1787 
1788 	encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1789 	encode_nfs4_verifier(xdr, &args->verifier);
1790 
1791 	encode_string(xdr, strlen(args->client->cl_owner_id),
1792 			args->client->cl_owner_id);
1793 
1794 	encode_uint32(xdr, args->flags);
1795 	encode_uint32(xdr, args->state_protect.how);
1796 
1797 	switch (args->state_protect.how) {
1798 	case SP4_NONE:
1799 		break;
1800 	case SP4_MACH_CRED:
1801 		encode_op_map(xdr, &args->state_protect.enforce);
1802 		encode_op_map(xdr, &args->state_protect.allow);
1803 		break;
1804 	default:
1805 		WARN_ON_ONCE(1);
1806 		break;
1807 	}
1808 
1809 	if (send_implementation_id &&
1810 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1811 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1812 		<= sizeof(impl_name) + 1)
1813 		len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1814 			       utsname()->sysname, utsname()->release,
1815 			       utsname()->version, utsname()->machine);
1816 
1817 	if (len > 0) {
1818 		encode_uint32(xdr, 1);	/* implementation id array length=1 */
1819 
1820 		encode_string(xdr,
1821 			sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1822 			CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1823 		encode_string(xdr, len, impl_name);
1824 		/* just send zeros for nii_date - the date is in nii_name */
1825 		p = reserve_space(xdr, 12);
1826 		p = xdr_encode_hyper(p, 0);
1827 		*p = cpu_to_be32(0);
1828 	} else
1829 		encode_uint32(xdr, 0);	/* implementation id array length=0 */
1830 }
1831 
1832 static void encode_create_session(struct xdr_stream *xdr,
1833 				  const struct nfs41_create_session_args *args,
1834 				  struct compound_hdr *hdr)
1835 {
1836 	__be32 *p;
1837 	struct nfs_client *clp = args->client;
1838 	struct rpc_clnt *clnt = clp->cl_rpcclient;
1839 	struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
1840 	u32 max_resp_sz_cached;
1841 
1842 	/*
1843 	 * Assumes OPEN is the biggest non-idempotent compound.
1844 	 * 2 is the verifier.
1845 	 */
1846 	max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
1847 				* XDR_UNIT + RPC_MAX_AUTH_SIZE;
1848 
1849 	encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1850 	p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
1851 	p = xdr_encode_hyper(p, args->clientid);
1852 	*p++ = cpu_to_be32(args->seqid);			/*Sequence id */
1853 	*p++ = cpu_to_be32(args->flags);			/*flags */
1854 
1855 	/* Fore Channel */
1856 	*p++ = cpu_to_be32(0);				/* header padding size */
1857 	*p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz);	/* max req size */
1858 	*p++ = cpu_to_be32(args->fc_attrs.max_resp_sz);	/* max resp size */
1859 	*p++ = cpu_to_be32(max_resp_sz_cached);		/* Max resp sz cached */
1860 	*p++ = cpu_to_be32(args->fc_attrs.max_ops);	/* max operations */
1861 	*p++ = cpu_to_be32(args->fc_attrs.max_reqs);	/* max requests */
1862 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1863 
1864 	/* Back Channel */
1865 	*p++ = cpu_to_be32(0);				/* header padding size */
1866 	*p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz);	/* max req size */
1867 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz);	/* max resp size */
1868 	*p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached);	/* Max resp sz cached */
1869 	*p++ = cpu_to_be32(args->bc_attrs.max_ops);	/* max operations */
1870 	*p++ = cpu_to_be32(args->bc_attrs.max_reqs);	/* max requests */
1871 	*p++ = cpu_to_be32(0);				/* rdmachannel_attrs */
1872 
1873 	*p++ = cpu_to_be32(args->cb_program);		/* cb_program */
1874 	*p++ = cpu_to_be32(1);
1875 	*p++ = cpu_to_be32(RPC_AUTH_UNIX);			/* auth_sys */
1876 
1877 	/* authsys_parms rfc1831 */
1878 	*p++ = cpu_to_be32(ktime_to_ns(nn->boot_time));	/* stamp */
1879 	p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
1880 	*p++ = cpu_to_be32(0);				/* UID */
1881 	*p++ = cpu_to_be32(0);				/* GID */
1882 	*p = cpu_to_be32(0);				/* No more gids */
1883 }
1884 
1885 static void encode_destroy_session(struct xdr_stream *xdr,
1886 				   const struct nfs4_session *session,
1887 				   struct compound_hdr *hdr)
1888 {
1889 	encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1890 	encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1891 }
1892 
1893 static void encode_destroy_clientid(struct xdr_stream *xdr,
1894 				   uint64_t clientid,
1895 				   struct compound_hdr *hdr)
1896 {
1897 	encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1898 	encode_uint64(xdr, clientid);
1899 }
1900 
1901 static void encode_reclaim_complete(struct xdr_stream *xdr,
1902 				    const struct nfs41_reclaim_complete_args *args,
1903 				    struct compound_hdr *hdr)
1904 {
1905 	encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1906 	encode_uint32(xdr, args->one_fs);
1907 }
1908 #endif /* CONFIG_NFS_V4_1 */
1909 
1910 static void encode_sequence(struct xdr_stream *xdr,
1911 			    const struct nfs4_sequence_args *args,
1912 			    struct compound_hdr *hdr)
1913 {
1914 #if defined(CONFIG_NFS_V4_1)
1915 	struct nfs4_session *session;
1916 	struct nfs4_slot_table *tp;
1917 	struct nfs4_slot *slot = args->sa_slot;
1918 	__be32 *p;
1919 
1920 	tp = slot->table;
1921 	session = tp->session;
1922 	if (!session)
1923 		return;
1924 
1925 	encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1926 
1927 	/*
1928 	 * Sessionid + seqid + slotid + max slotid + cache_this
1929 	 */
1930 	dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1931 		"max_slotid=%d cache_this=%d\n",
1932 		__func__,
1933 		((u32 *)session->sess_id.data)[0],
1934 		((u32 *)session->sess_id.data)[1],
1935 		((u32 *)session->sess_id.data)[2],
1936 		((u32 *)session->sess_id.data)[3],
1937 		slot->seq_nr, slot->slot_nr,
1938 		tp->highest_used_slotid, args->sa_cache_this);
1939 	p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
1940 	p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1941 	*p++ = cpu_to_be32(slot->seq_nr);
1942 	*p++ = cpu_to_be32(slot->slot_nr);
1943 	*p++ = cpu_to_be32(tp->highest_used_slotid);
1944 	*p = cpu_to_be32(args->sa_cache_this);
1945 #endif /* CONFIG_NFS_V4_1 */
1946 }
1947 
1948 #ifdef CONFIG_NFS_V4_1
1949 static void
1950 encode_getdeviceinfo(struct xdr_stream *xdr,
1951 		     const struct nfs4_getdeviceinfo_args *args,
1952 		     struct compound_hdr *hdr)
1953 {
1954 	__be32 *p;
1955 
1956 	encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1957 	p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
1958 	p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1959 				    NFS4_DEVICEID4_SIZE);
1960 	*p++ = cpu_to_be32(args->pdev->layout_type);
1961 	*p++ = cpu_to_be32(args->pdev->maxcount);	/* gdia_maxcount */
1962 
1963 	p = reserve_space(xdr, 4 + 4);
1964 	*p++ = cpu_to_be32(1);			/* bitmap length */
1965 	*p++ = cpu_to_be32(args->notify_types);
1966 }
1967 
1968 static void
1969 encode_layoutget(struct xdr_stream *xdr,
1970 		      const struct nfs4_layoutget_args *args,
1971 		      struct compound_hdr *hdr)
1972 {
1973 	__be32 *p;
1974 
1975 	encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1976 	p = reserve_space(xdr, 36);
1977 	*p++ = cpu_to_be32(0);     /* Signal layout available */
1978 	*p++ = cpu_to_be32(args->type);
1979 	*p++ = cpu_to_be32(args->range.iomode);
1980 	p = xdr_encode_hyper(p, args->range.offset);
1981 	p = xdr_encode_hyper(p, args->range.length);
1982 	p = xdr_encode_hyper(p, args->minlength);
1983 	encode_nfs4_stateid(xdr, &args->stateid);
1984 	encode_uint32(xdr, args->maxcount);
1985 
1986 	dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1987 		__func__,
1988 		args->type,
1989 		args->range.iomode,
1990 		(unsigned long)args->range.offset,
1991 		(unsigned long)args->range.length,
1992 		args->maxcount);
1993 }
1994 
1995 static int
1996 encode_layoutcommit(struct xdr_stream *xdr,
1997 		    struct inode *inode,
1998 		    const struct nfs4_layoutcommit_args *args,
1999 		    struct compound_hdr *hdr)
2000 {
2001 	__be32 *p;
2002 
2003 	dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2004 		NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2005 
2006 	encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2007 	p = reserve_space(xdr, 20);
2008 	/* Only whole file layouts */
2009 	p = xdr_encode_hyper(p, 0); /* offset */
2010 	p = xdr_encode_hyper(p, args->lastbytewritten + 1);	/* length */
2011 	*p = cpu_to_be32(0); /* reclaim */
2012 	encode_nfs4_stateid(xdr, &args->stateid);
2013 	if (args->lastbytewritten != U64_MAX) {
2014 		p = reserve_space(xdr, 20);
2015 		*p++ = cpu_to_be32(1); /* newoffset = TRUE */
2016 		p = xdr_encode_hyper(p, args->lastbytewritten);
2017 	} else {
2018 		p = reserve_space(xdr, 12);
2019 		*p++ = cpu_to_be32(0); /* newoffset = FALSE */
2020 	}
2021 	*p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2022 	*p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2023 
2024 	encode_uint32(xdr, args->layoutupdate_len);
2025 	if (args->layoutupdate_pages)
2026 		xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2027 				args->layoutupdate_len);
2028 
2029 	return 0;
2030 }
2031 
2032 static void
2033 encode_layoutreturn(struct xdr_stream *xdr,
2034 		    const struct nfs4_layoutreturn_args *args,
2035 		    struct compound_hdr *hdr)
2036 {
2037 	__be32 *p;
2038 
2039 	encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2040 	p = reserve_space(xdr, 16);
2041 	*p++ = cpu_to_be32(0);		/* reclaim. always 0 for now */
2042 	*p++ = cpu_to_be32(args->layout_type);
2043 	*p++ = cpu_to_be32(args->range.iomode);
2044 	*p = cpu_to_be32(RETURN_FILE);
2045 	p = reserve_space(xdr, 16);
2046 	p = xdr_encode_hyper(p, args->range.offset);
2047 	p = xdr_encode_hyper(p, args->range.length);
2048 	spin_lock(&args->inode->i_lock);
2049 	encode_nfs4_stateid(xdr, &args->stateid);
2050 	spin_unlock(&args->inode->i_lock);
2051 	if (args->ld_private->ops && args->ld_private->ops->encode)
2052 		args->ld_private->ops->encode(xdr, args, args->ld_private);
2053 	else
2054 		encode_uint32(xdr, 0);
2055 }
2056 
2057 static int
2058 encode_secinfo_no_name(struct xdr_stream *xdr,
2059 		       const struct nfs41_secinfo_no_name_args *args,
2060 		       struct compound_hdr *hdr)
2061 {
2062 	encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2063 	encode_uint32(xdr, args->style);
2064 	return 0;
2065 }
2066 
2067 static void encode_test_stateid(struct xdr_stream *xdr,
2068 				const struct nfs41_test_stateid_args *args,
2069 				struct compound_hdr *hdr)
2070 {
2071 	encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2072 	encode_uint32(xdr, 1);
2073 	encode_nfs4_stateid(xdr, args->stateid);
2074 }
2075 
2076 static void encode_free_stateid(struct xdr_stream *xdr,
2077 				const struct nfs41_free_stateid_args *args,
2078 				struct compound_hdr *hdr)
2079 {
2080 	encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
2081 	encode_nfs4_stateid(xdr, &args->stateid);
2082 }
2083 #else
2084 static inline void
2085 encode_layoutreturn(struct xdr_stream *xdr,
2086 		    const struct nfs4_layoutreturn_args *args,
2087 		    struct compound_hdr *hdr)
2088 {
2089 }
2090 
2091 static void
2092 encode_layoutget(struct xdr_stream *xdr,
2093 		      const struct nfs4_layoutget_args *args,
2094 		      struct compound_hdr *hdr)
2095 {
2096 }
2097 #endif /* CONFIG_NFS_V4_1 */
2098 
2099 /*
2100  * END OF "GENERIC" ENCODE ROUTINES.
2101  */
2102 
2103 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2104 {
2105 #if defined(CONFIG_NFS_V4_1)
2106 	struct nfs4_session *session = args->sa_slot->table->session;
2107 	if (session)
2108 		return session->clp->cl_mvops->minor_version;
2109 #endif /* CONFIG_NFS_V4_1 */
2110 	return 0;
2111 }
2112 
2113 /*
2114  * Encode an ACCESS request
2115  */
2116 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2117 				const void *data)
2118 {
2119 	const struct nfs4_accessargs *args = data;
2120 	struct compound_hdr hdr = {
2121 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2122 	};
2123 
2124 	encode_compound_hdr(xdr, req, &hdr);
2125 	encode_sequence(xdr, &args->seq_args, &hdr);
2126 	encode_putfh(xdr, args->fh, &hdr);
2127 	encode_access(xdr, args->access, &hdr);
2128 	if (args->bitmask)
2129 		encode_getfattr(xdr, args->bitmask, &hdr);
2130 	encode_nops(&hdr);
2131 }
2132 
2133 /*
2134  * Encode LOOKUP request
2135  */
2136 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2137 				const void *data)
2138 {
2139 	const struct nfs4_lookup_arg *args = data;
2140 	struct compound_hdr hdr = {
2141 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2142 	};
2143 
2144 	encode_compound_hdr(xdr, req, &hdr);
2145 	encode_sequence(xdr, &args->seq_args, &hdr);
2146 	encode_putfh(xdr, args->dir_fh, &hdr);
2147 	encode_lookup(xdr, args->name, &hdr);
2148 	encode_getfh(xdr, &hdr);
2149 	encode_getfattr(xdr, args->bitmask, &hdr);
2150 	encode_nops(&hdr);
2151 }
2152 
2153 /*
2154  * Encode LOOKUPP request
2155  */
2156 static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
2157 		const void *data)
2158 {
2159 	const struct nfs4_lookupp_arg *args = data;
2160 	struct compound_hdr hdr = {
2161 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2162 	};
2163 
2164 	encode_compound_hdr(xdr, req, &hdr);
2165 	encode_sequence(xdr, &args->seq_args, &hdr);
2166 	encode_putfh(xdr, args->fh, &hdr);
2167 	encode_lookupp(xdr, &hdr);
2168 	encode_getfh(xdr, &hdr);
2169 	encode_getfattr(xdr, args->bitmask, &hdr);
2170 	encode_nops(&hdr);
2171 }
2172 
2173 /*
2174  * Encode LOOKUP_ROOT request
2175  */
2176 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2177 				     struct xdr_stream *xdr,
2178 				     const void *data)
2179 {
2180 	const struct nfs4_lookup_root_arg *args = data;
2181 	struct compound_hdr hdr = {
2182 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2183 	};
2184 
2185 	encode_compound_hdr(xdr, req, &hdr);
2186 	encode_sequence(xdr, &args->seq_args, &hdr);
2187 	encode_putrootfh(xdr, &hdr);
2188 	encode_getfh(xdr, &hdr);
2189 	encode_getfattr(xdr, args->bitmask, &hdr);
2190 	encode_nops(&hdr);
2191 }
2192 
2193 /*
2194  * Encode REMOVE request
2195  */
2196 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2197 				const void *data)
2198 {
2199 	const struct nfs_removeargs *args = data;
2200 	struct compound_hdr hdr = {
2201 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2202 	};
2203 
2204 	encode_compound_hdr(xdr, req, &hdr);
2205 	encode_sequence(xdr, &args->seq_args, &hdr);
2206 	encode_putfh(xdr, args->fh, &hdr);
2207 	encode_remove(xdr, &args->name, &hdr);
2208 	encode_nops(&hdr);
2209 }
2210 
2211 /*
2212  * Encode RENAME request
2213  */
2214 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2215 				const void *data)
2216 {
2217 	const struct nfs_renameargs *args = data;
2218 	struct compound_hdr hdr = {
2219 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2220 	};
2221 
2222 	encode_compound_hdr(xdr, req, &hdr);
2223 	encode_sequence(xdr, &args->seq_args, &hdr);
2224 	encode_putfh(xdr, args->old_dir, &hdr);
2225 	encode_savefh(xdr, &hdr);
2226 	encode_putfh(xdr, args->new_dir, &hdr);
2227 	encode_rename(xdr, args->old_name, args->new_name, &hdr);
2228 	encode_nops(&hdr);
2229 }
2230 
2231 /*
2232  * Encode LINK request
2233  */
2234 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2235 			      const void *data)
2236 {
2237 	const struct nfs4_link_arg *args = data;
2238 	struct compound_hdr hdr = {
2239 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2240 	};
2241 
2242 	encode_compound_hdr(xdr, req, &hdr);
2243 	encode_sequence(xdr, &args->seq_args, &hdr);
2244 	encode_putfh(xdr, args->fh, &hdr);
2245 	encode_savefh(xdr, &hdr);
2246 	encode_putfh(xdr, args->dir_fh, &hdr);
2247 	encode_link(xdr, args->name, &hdr);
2248 	encode_restorefh(xdr, &hdr);
2249 	encode_getfattr(xdr, args->bitmask, &hdr);
2250 	encode_nops(&hdr);
2251 }
2252 
2253 /*
2254  * Encode CREATE request
2255  */
2256 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2257 				const void *data)
2258 {
2259 	const struct nfs4_create_arg *args = data;
2260 	struct compound_hdr hdr = {
2261 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2262 	};
2263 
2264 	encode_compound_hdr(xdr, req, &hdr);
2265 	encode_sequence(xdr, &args->seq_args, &hdr);
2266 	encode_putfh(xdr, args->dir_fh, &hdr);
2267 	encode_create(xdr, args, &hdr);
2268 	encode_getfh(xdr, &hdr);
2269 	encode_getfattr(xdr, args->bitmask, &hdr);
2270 	encode_nops(&hdr);
2271 }
2272 
2273 /*
2274  * Encode SYMLINK request
2275  */
2276 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2277 				 const void *data)
2278 {
2279 	const struct nfs4_create_arg *args = data;
2280 
2281 	nfs4_xdr_enc_create(req, xdr, args);
2282 }
2283 
2284 /*
2285  * Encode GETATTR request
2286  */
2287 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2288 				 const void *data)
2289 {
2290 	const struct nfs4_getattr_arg *args = data;
2291 	struct compound_hdr hdr = {
2292 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2293 	};
2294 
2295 	encode_compound_hdr(xdr, req, &hdr);
2296 	encode_sequence(xdr, &args->seq_args, &hdr);
2297 	encode_putfh(xdr, args->fh, &hdr);
2298 	encode_getfattr(xdr, args->bitmask, &hdr);
2299 	encode_nops(&hdr);
2300 }
2301 
2302 /*
2303  * Encode a CLOSE request
2304  */
2305 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2306 			       const void *data)
2307 {
2308 	const struct nfs_closeargs *args = data;
2309 	struct compound_hdr hdr = {
2310 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2311 	};
2312 
2313 	encode_compound_hdr(xdr, req, &hdr);
2314 	encode_sequence(xdr, &args->seq_args, &hdr);
2315 	encode_putfh(xdr, args->fh, &hdr);
2316 	if (args->lr_args)
2317 		encode_layoutreturn(xdr, args->lr_args, &hdr);
2318 	if (args->bitmask != NULL)
2319 		encode_getfattr(xdr, args->bitmask, &hdr);
2320 	encode_close(xdr, args, &hdr);
2321 	encode_nops(&hdr);
2322 }
2323 
2324 /*
2325  * Encode an OPEN request
2326  */
2327 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2328 			      const void *data)
2329 {
2330 	const struct nfs_openargs *args = data;
2331 	struct compound_hdr hdr = {
2332 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2333 	};
2334 
2335 	encode_compound_hdr(xdr, req, &hdr);
2336 	encode_sequence(xdr, &args->seq_args, &hdr);
2337 	encode_putfh(xdr, args->fh, &hdr);
2338 	encode_open(xdr, args, &hdr);
2339 	encode_getfh(xdr, &hdr);
2340 	if (args->access)
2341 		encode_access(xdr, args->access, &hdr);
2342 	encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2343 	if (args->lg_args) {
2344 		encode_layoutget(xdr, args->lg_args, &hdr);
2345 		rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2346 					args->lg_args->layout.pglen,
2347 					hdr.replen - pagepad_maxsz);
2348 	}
2349 	encode_nops(&hdr);
2350 }
2351 
2352 /*
2353  * Encode an OPEN_CONFIRM request
2354  */
2355 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2356 				      struct xdr_stream *xdr,
2357 				      const void *data)
2358 {
2359 	const struct nfs_open_confirmargs *args = data;
2360 	struct compound_hdr hdr = {
2361 		.nops   = 0,
2362 	};
2363 
2364 	encode_compound_hdr(xdr, req, &hdr);
2365 	encode_putfh(xdr, args->fh, &hdr);
2366 	encode_open_confirm(xdr, args, &hdr);
2367 	encode_nops(&hdr);
2368 }
2369 
2370 /*
2371  * Encode an OPEN request with no attributes.
2372  */
2373 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2374 				     struct xdr_stream *xdr,
2375 				     const void *data)
2376 {
2377 	const struct nfs_openargs *args = data;
2378 	struct compound_hdr hdr = {
2379 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2380 	};
2381 
2382 	encode_compound_hdr(xdr, req, &hdr);
2383 	encode_sequence(xdr, &args->seq_args, &hdr);
2384 	encode_putfh(xdr, args->fh, &hdr);
2385 	encode_open(xdr, args, &hdr);
2386 	if (args->access)
2387 		encode_access(xdr, args->access, &hdr);
2388 	encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
2389 	if (args->lg_args) {
2390 		encode_layoutget(xdr, args->lg_args, &hdr);
2391 		rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2392 					args->lg_args->layout.pglen,
2393 					hdr.replen - pagepad_maxsz);
2394 	}
2395 	encode_nops(&hdr);
2396 }
2397 
2398 /*
2399  * Encode an OPEN_DOWNGRADE request
2400  */
2401 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2402 					struct xdr_stream *xdr,
2403 					const void *data)
2404 {
2405 	const struct nfs_closeargs *args = data;
2406 	struct compound_hdr hdr = {
2407 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2408 	};
2409 
2410 	encode_compound_hdr(xdr, req, &hdr);
2411 	encode_sequence(xdr, &args->seq_args, &hdr);
2412 	encode_putfh(xdr, args->fh, &hdr);
2413 	if (args->lr_args)
2414 		encode_layoutreturn(xdr, args->lr_args, &hdr);
2415 	encode_open_downgrade(xdr, args, &hdr);
2416 	encode_nops(&hdr);
2417 }
2418 
2419 /*
2420  * Encode a LOCK request
2421  */
2422 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2423 			      const void *data)
2424 {
2425 	const struct nfs_lock_args *args = data;
2426 	struct compound_hdr hdr = {
2427 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2428 	};
2429 
2430 	encode_compound_hdr(xdr, req, &hdr);
2431 	encode_sequence(xdr, &args->seq_args, &hdr);
2432 	encode_putfh(xdr, args->fh, &hdr);
2433 	encode_lock(xdr, args, &hdr);
2434 	encode_nops(&hdr);
2435 }
2436 
2437 /*
2438  * Encode a LOCKT request
2439  */
2440 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2441 			       const void *data)
2442 {
2443 	const struct nfs_lockt_args *args = data;
2444 	struct compound_hdr hdr = {
2445 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2446 	};
2447 
2448 	encode_compound_hdr(xdr, req, &hdr);
2449 	encode_sequence(xdr, &args->seq_args, &hdr);
2450 	encode_putfh(xdr, args->fh, &hdr);
2451 	encode_lockt(xdr, args, &hdr);
2452 	encode_nops(&hdr);
2453 }
2454 
2455 /*
2456  * Encode a LOCKU request
2457  */
2458 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2459 			       const void *data)
2460 {
2461 	const struct nfs_locku_args *args = data;
2462 	struct compound_hdr hdr = {
2463 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2464 	};
2465 
2466 	encode_compound_hdr(xdr, req, &hdr);
2467 	encode_sequence(xdr, &args->seq_args, &hdr);
2468 	encode_putfh(xdr, args->fh, &hdr);
2469 	encode_locku(xdr, args, &hdr);
2470 	encode_nops(&hdr);
2471 }
2472 
2473 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2474 					   struct xdr_stream *xdr,
2475 					   const void *data)
2476 {
2477 	const struct nfs_release_lockowner_args *args = data;
2478 	struct compound_hdr hdr = {
2479 		.minorversion = 0,
2480 	};
2481 
2482 	encode_compound_hdr(xdr, req, &hdr);
2483 	encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2484 	encode_nops(&hdr);
2485 }
2486 
2487 /*
2488  * Encode a READLINK request
2489  */
2490 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2491 				  const void *data)
2492 {
2493 	const struct nfs4_readlink *args = data;
2494 	struct compound_hdr hdr = {
2495 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2496 	};
2497 
2498 	encode_compound_hdr(xdr, req, &hdr);
2499 	encode_sequence(xdr, &args->seq_args, &hdr);
2500 	encode_putfh(xdr, args->fh, &hdr);
2501 	encode_readlink(xdr, args, req, &hdr);
2502 
2503 	rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2504 				args->pglen, hdr.replen - pagepad_maxsz);
2505 	encode_nops(&hdr);
2506 }
2507 
2508 /*
2509  * Encode a READDIR request
2510  */
2511 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2512 				 const void *data)
2513 {
2514 	const struct nfs4_readdir_arg *args = data;
2515 	struct compound_hdr hdr = {
2516 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2517 	};
2518 
2519 	encode_compound_hdr(xdr, req, &hdr);
2520 	encode_sequence(xdr, &args->seq_args, &hdr);
2521 	encode_putfh(xdr, args->fh, &hdr);
2522 	encode_readdir(xdr, args, req, &hdr);
2523 
2524 	rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2525 				args->count, hdr.replen - pagepad_maxsz);
2526 	encode_nops(&hdr);
2527 }
2528 
2529 /*
2530  * Encode a READ request
2531  */
2532 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2533 			      const void *data)
2534 {
2535 	const struct nfs_pgio_args *args = data;
2536 	struct compound_hdr hdr = {
2537 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2538 	};
2539 
2540 	encode_compound_hdr(xdr, req, &hdr);
2541 	encode_sequence(xdr, &args->seq_args, &hdr);
2542 	encode_putfh(xdr, args->fh, &hdr);
2543 	encode_read(xdr, args, &hdr);
2544 
2545 	rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2546 				args->count, hdr.replen - pagepad_maxsz);
2547 	req->rq_rcv_buf.flags |= XDRBUF_READ;
2548 	encode_nops(&hdr);
2549 }
2550 
2551 /*
2552  * Encode an SETATTR request
2553  */
2554 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2555 				 const void *data)
2556 {
2557 	const struct nfs_setattrargs *args = data;
2558 	struct compound_hdr hdr = {
2559 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2560 	};
2561 
2562 	encode_compound_hdr(xdr, req, &hdr);
2563 	encode_sequence(xdr, &args->seq_args, &hdr);
2564 	encode_putfh(xdr, args->fh, &hdr);
2565 	encode_setattr(xdr, args, args->server, &hdr);
2566 	encode_getfattr(xdr, args->bitmask, &hdr);
2567 	encode_nops(&hdr);
2568 }
2569 
2570 /*
2571  * Encode a GETACL request
2572  */
2573 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2574 				const void *data)
2575 {
2576 	const struct nfs_getaclargs *args = data;
2577 	struct compound_hdr hdr = {
2578 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2579 	};
2580 	const __u32 nfs4_acl_bitmap[1] = {
2581 		[0] = FATTR4_WORD0_ACL,
2582 	};
2583 	uint32_t replen;
2584 
2585 	encode_compound_hdr(xdr, req, &hdr);
2586 	encode_sequence(xdr, &args->seq_args, &hdr);
2587 	encode_putfh(xdr, args->fh, &hdr);
2588 	replen = hdr.replen + op_decode_hdr_maxsz;
2589 	encode_getattr(xdr, nfs4_acl_bitmap, NULL,
2590 			ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
2591 
2592 	rpc_prepare_reply_pages(req, args->acl_pages, 0,
2593 				args->acl_len, replen);
2594 	encode_nops(&hdr);
2595 }
2596 
2597 /*
2598  * Encode a WRITE request
2599  */
2600 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2601 			       const void *data)
2602 {
2603 	const struct nfs_pgio_args *args = data;
2604 	struct compound_hdr hdr = {
2605 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2606 	};
2607 
2608 	encode_compound_hdr(xdr, req, &hdr);
2609 	encode_sequence(xdr, &args->seq_args, &hdr);
2610 	encode_putfh(xdr, args->fh, &hdr);
2611 	encode_write(xdr, args, &hdr);
2612 	req->rq_snd_buf.flags |= XDRBUF_WRITE;
2613 	if (args->bitmask)
2614 		encode_getfattr(xdr, args->bitmask, &hdr);
2615 	encode_nops(&hdr);
2616 }
2617 
2618 /*
2619  *  a COMMIT request
2620  */
2621 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2622 				const void *data)
2623 {
2624 	const struct nfs_commitargs *args = data;
2625 	struct compound_hdr hdr = {
2626 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2627 	};
2628 
2629 	encode_compound_hdr(xdr, req, &hdr);
2630 	encode_sequence(xdr, &args->seq_args, &hdr);
2631 	encode_putfh(xdr, args->fh, &hdr);
2632 	encode_commit(xdr, args, &hdr);
2633 	encode_nops(&hdr);
2634 }
2635 
2636 /*
2637  * FSINFO request
2638  */
2639 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2640 				const void *data)
2641 {
2642 	const struct nfs4_fsinfo_arg *args = data;
2643 	struct compound_hdr hdr = {
2644 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2645 	};
2646 
2647 	encode_compound_hdr(xdr, req, &hdr);
2648 	encode_sequence(xdr, &args->seq_args, &hdr);
2649 	encode_putfh(xdr, args->fh, &hdr);
2650 	encode_fsinfo(xdr, args->bitmask, &hdr);
2651 	encode_nops(&hdr);
2652 }
2653 
2654 /*
2655  * a PATHCONF request
2656  */
2657 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2658 				  const void *data)
2659 {
2660 	const struct nfs4_pathconf_arg *args = data;
2661 	struct compound_hdr hdr = {
2662 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2663 	};
2664 
2665 	encode_compound_hdr(xdr, req, &hdr);
2666 	encode_sequence(xdr, &args->seq_args, &hdr);
2667 	encode_putfh(xdr, args->fh, &hdr);
2668 	encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
2669 			ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
2670 	encode_nops(&hdr);
2671 }
2672 
2673 /*
2674  * a STATFS request
2675  */
2676 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2677 				const void *data)
2678 {
2679 	const struct nfs4_statfs_arg *args = data;
2680 	struct compound_hdr hdr = {
2681 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2682 	};
2683 
2684 	encode_compound_hdr(xdr, req, &hdr);
2685 	encode_sequence(xdr, &args->seq_args, &hdr);
2686 	encode_putfh(xdr, args->fh, &hdr);
2687 	encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
2688 			ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
2689 	encode_nops(&hdr);
2690 }
2691 
2692 /*
2693  * GETATTR_BITMAP request
2694  */
2695 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2696 				     struct xdr_stream *xdr,
2697 				     const void *data)
2698 {
2699 	const struct nfs4_server_caps_arg *args = data;
2700 	const u32 *bitmask = args->bitmask;
2701 	struct compound_hdr hdr = {
2702 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2703 	};
2704 
2705 	encode_compound_hdr(xdr, req, &hdr);
2706 	encode_sequence(xdr, &args->seq_args, &hdr);
2707 	encode_putfh(xdr, args->fhandle, &hdr);
2708 	encode_getattr(xdr, bitmask, NULL, 3, &hdr);
2709 	encode_nops(&hdr);
2710 }
2711 
2712 /*
2713  * a RENEW request
2714  */
2715 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2716 			       const void *data)
2717 
2718 {
2719 	const struct nfs_client *clp = data;
2720 	struct compound_hdr hdr = {
2721 		.nops	= 0,
2722 	};
2723 
2724 	encode_compound_hdr(xdr, req, &hdr);
2725 	encode_renew(xdr, clp->cl_clientid, &hdr);
2726 	encode_nops(&hdr);
2727 }
2728 
2729 /*
2730  * a SETCLIENTID request
2731  */
2732 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2733 				     struct xdr_stream *xdr,
2734 				     const void *data)
2735 {
2736 	const struct nfs4_setclientid *sc = data;
2737 	struct compound_hdr hdr = {
2738 		.nops	= 0,
2739 	};
2740 
2741 	encode_compound_hdr(xdr, req, &hdr);
2742 	encode_setclientid(xdr, sc, &hdr);
2743 	encode_nops(&hdr);
2744 }
2745 
2746 /*
2747  * a SETCLIENTID_CONFIRM request
2748  */
2749 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2750 					     struct xdr_stream *xdr,
2751 					     const void *data)
2752 {
2753 	const struct nfs4_setclientid_res *arg = data;
2754 	struct compound_hdr hdr = {
2755 		.nops	= 0,
2756 	};
2757 
2758 	encode_compound_hdr(xdr, req, &hdr);
2759 	encode_setclientid_confirm(xdr, arg, &hdr);
2760 	encode_nops(&hdr);
2761 }
2762 
2763 /*
2764  * DELEGRETURN request
2765  */
2766 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2767 				     struct xdr_stream *xdr,
2768 				     const void *data)
2769 {
2770 	const struct nfs4_delegreturnargs *args = data;
2771 	struct compound_hdr hdr = {
2772 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2773 	};
2774 
2775 	encode_compound_hdr(xdr, req, &hdr);
2776 	encode_sequence(xdr, &args->seq_args, &hdr);
2777 	encode_putfh(xdr, args->fhandle, &hdr);
2778 	if (args->lr_args)
2779 		encode_layoutreturn(xdr, args->lr_args, &hdr);
2780 	if (args->bitmask)
2781 		encode_getfattr(xdr, args->bitmask, &hdr);
2782 	encode_delegreturn(xdr, args->stateid, &hdr);
2783 	encode_nops(&hdr);
2784 }
2785 
2786 /*
2787  * Encode FS_LOCATIONS request
2788  */
2789 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2790 				      struct xdr_stream *xdr,
2791 				      const void *data)
2792 {
2793 	const struct nfs4_fs_locations_arg *args = data;
2794 	struct compound_hdr hdr = {
2795 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2796 	};
2797 	uint32_t replen;
2798 
2799 	encode_compound_hdr(xdr, req, &hdr);
2800 	encode_sequence(xdr, &args->seq_args, &hdr);
2801 	if (args->migration) {
2802 		encode_putfh(xdr, args->fh, &hdr);
2803 		replen = hdr.replen;
2804 		encode_fs_locations(xdr, args->bitmask, &hdr);
2805 		if (args->renew)
2806 			encode_renew(xdr, args->clientid, &hdr);
2807 	} else {
2808 		encode_putfh(xdr, args->dir_fh, &hdr);
2809 		encode_lookup(xdr, args->name, &hdr);
2810 		replen = hdr.replen;
2811 		encode_fs_locations(xdr, args->bitmask, &hdr);
2812 	}
2813 
2814 	rpc_prepare_reply_pages(req, (struct page **)&args->page, 0,
2815 				PAGE_SIZE, replen);
2816 	encode_nops(&hdr);
2817 }
2818 
2819 /*
2820  * Encode SECINFO request
2821  */
2822 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2823 				struct xdr_stream *xdr,
2824 				const void *data)
2825 {
2826 	const struct nfs4_secinfo_arg *args = data;
2827 	struct compound_hdr hdr = {
2828 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2829 	};
2830 
2831 	encode_compound_hdr(xdr, req, &hdr);
2832 	encode_sequence(xdr, &args->seq_args, &hdr);
2833 	encode_putfh(xdr, args->dir_fh, &hdr);
2834 	encode_secinfo(xdr, args->name, &hdr);
2835 	encode_nops(&hdr);
2836 }
2837 
2838 /*
2839  * Encode FSID_PRESENT request
2840  */
2841 static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2842 				      struct xdr_stream *xdr,
2843 				      const void *data)
2844 {
2845 	const struct nfs4_fsid_present_arg *args = data;
2846 	struct compound_hdr hdr = {
2847 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
2848 	};
2849 
2850 	encode_compound_hdr(xdr, req, &hdr);
2851 	encode_sequence(xdr, &args->seq_args, &hdr);
2852 	encode_putfh(xdr, args->fh, &hdr);
2853 	encode_getfh(xdr, &hdr);
2854 	if (args->renew)
2855 		encode_renew(xdr, args->clientid, &hdr);
2856 	encode_nops(&hdr);
2857 }
2858 
2859 #if defined(CONFIG_NFS_V4_1)
2860 /*
2861  * BIND_CONN_TO_SESSION request
2862  */
2863 static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2864 				struct xdr_stream *xdr,
2865 				const void *data)
2866 {
2867 	const struct nfs41_bind_conn_to_session_args *args = data;
2868 	struct compound_hdr hdr = {
2869 		.minorversion = args->client->cl_mvops->minor_version,
2870 	};
2871 
2872 	encode_compound_hdr(xdr, req, &hdr);
2873 	encode_bind_conn_to_session(xdr, args, &hdr);
2874 	encode_nops(&hdr);
2875 }
2876 
2877 /*
2878  * EXCHANGE_ID request
2879  */
2880 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2881 				     struct xdr_stream *xdr,
2882 				     const void *data)
2883 {
2884 	const struct nfs41_exchange_id_args *args = data;
2885 	struct compound_hdr hdr = {
2886 		.minorversion = args->client->cl_mvops->minor_version,
2887 	};
2888 
2889 	encode_compound_hdr(xdr, req, &hdr);
2890 	encode_exchange_id(xdr, args, &hdr);
2891 	encode_nops(&hdr);
2892 }
2893 
2894 /*
2895  * a CREATE_SESSION request
2896  */
2897 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2898 					struct xdr_stream *xdr,
2899 					const void *data)
2900 {
2901 	const struct nfs41_create_session_args *args = data;
2902 	struct compound_hdr hdr = {
2903 		.minorversion = args->client->cl_mvops->minor_version,
2904 	};
2905 
2906 	encode_compound_hdr(xdr, req, &hdr);
2907 	encode_create_session(xdr, args, &hdr);
2908 	encode_nops(&hdr);
2909 }
2910 
2911 /*
2912  * a DESTROY_SESSION request
2913  */
2914 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2915 					 struct xdr_stream *xdr,
2916 					 const void *data)
2917 {
2918 	const struct nfs4_session *session = data;
2919 	struct compound_hdr hdr = {
2920 		.minorversion = session->clp->cl_mvops->minor_version,
2921 	};
2922 
2923 	encode_compound_hdr(xdr, req, &hdr);
2924 	encode_destroy_session(xdr, session, &hdr);
2925 	encode_nops(&hdr);
2926 }
2927 
2928 /*
2929  * a DESTROY_CLIENTID request
2930  */
2931 static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2932 					 struct xdr_stream *xdr,
2933 					 const void *data)
2934 {
2935 	const struct nfs_client *clp = data;
2936 	struct compound_hdr hdr = {
2937 		.minorversion = clp->cl_mvops->minor_version,
2938 	};
2939 
2940 	encode_compound_hdr(xdr, req, &hdr);
2941 	encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2942 	encode_nops(&hdr);
2943 }
2944 
2945 /*
2946  * a SEQUENCE request
2947  */
2948 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2949 				  const void *data)
2950 {
2951 	const struct nfs4_sequence_args *args = data;
2952 	struct compound_hdr hdr = {
2953 		.minorversion = nfs4_xdr_minorversion(args),
2954 	};
2955 
2956 	encode_compound_hdr(xdr, req, &hdr);
2957 	encode_sequence(xdr, args, &hdr);
2958 	encode_nops(&hdr);
2959 }
2960 
2961 #endif
2962 
2963 /*
2964  * a GET_LEASE_TIME request
2965  */
2966 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2967 					struct xdr_stream *xdr,
2968 					const void *data)
2969 {
2970 	const struct nfs4_get_lease_time_args *args = data;
2971 	struct compound_hdr hdr = {
2972 		.minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2973 	};
2974 	const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2975 
2976 	encode_compound_hdr(xdr, req, &hdr);
2977 	encode_sequence(xdr, &args->la_seq_args, &hdr);
2978 	encode_putrootfh(xdr, &hdr);
2979 	encode_fsinfo(xdr, lease_bitmap, &hdr);
2980 	encode_nops(&hdr);
2981 }
2982 
2983 #ifdef CONFIG_NFS_V4_1
2984 
2985 /*
2986  * a RECLAIM_COMPLETE request
2987  */
2988 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2989 					  struct xdr_stream *xdr,
2990 					  const void *data)
2991 {
2992 	const struct nfs41_reclaim_complete_args *args = data;
2993 	struct compound_hdr hdr = {
2994 		.minorversion = nfs4_xdr_minorversion(&args->seq_args)
2995 	};
2996 
2997 	encode_compound_hdr(xdr, req, &hdr);
2998 	encode_sequence(xdr, &args->seq_args, &hdr);
2999 	encode_reclaim_complete(xdr, args, &hdr);
3000 	encode_nops(&hdr);
3001 }
3002 
3003 /*
3004  * Encode GETDEVICEINFO request
3005  */
3006 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
3007 				       struct xdr_stream *xdr,
3008 				       const void *data)
3009 {
3010 	const struct nfs4_getdeviceinfo_args *args = data;
3011 	struct compound_hdr hdr = {
3012 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3013 	};
3014 	uint32_t replen;
3015 
3016 	encode_compound_hdr(xdr, req, &hdr);
3017 	encode_sequence(xdr, &args->seq_args, &hdr);
3018 
3019 	replen = hdr.replen + op_decode_hdr_maxsz + 2;
3020 
3021 	encode_getdeviceinfo(xdr, args, &hdr);
3022 
3023 	/* set up reply kvec. device_addr4 opaque data is read into the
3024 	 * pages */
3025 	rpc_prepare_reply_pages(req, args->pdev->pages, args->pdev->pgbase,
3026 				args->pdev->pglen, replen);
3027 	encode_nops(&hdr);
3028 }
3029 
3030 /*
3031  *  Encode LAYOUTGET request
3032  */
3033 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
3034 				   struct xdr_stream *xdr,
3035 				   const void *data)
3036 {
3037 	const struct nfs4_layoutget_args *args = data;
3038 	struct compound_hdr hdr = {
3039 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3040 	};
3041 
3042 	encode_compound_hdr(xdr, req, &hdr);
3043 	encode_sequence(xdr, &args->seq_args, &hdr);
3044 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3045 	encode_layoutget(xdr, args, &hdr);
3046 
3047 	rpc_prepare_reply_pages(req, args->layout.pages, 0,
3048 				args->layout.pglen, hdr.replen - pagepad_maxsz);
3049 	encode_nops(&hdr);
3050 }
3051 
3052 /*
3053  *  Encode LAYOUTCOMMIT request
3054  */
3055 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3056 				      struct xdr_stream *xdr,
3057 				      const void *priv)
3058 {
3059 	const struct nfs4_layoutcommit_args *args = priv;
3060 	struct nfs4_layoutcommit_data *data =
3061 		container_of(args, struct nfs4_layoutcommit_data, args);
3062 	struct compound_hdr hdr = {
3063 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3064 	};
3065 
3066 	encode_compound_hdr(xdr, req, &hdr);
3067 	encode_sequence(xdr, &args->seq_args, &hdr);
3068 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3069 	encode_layoutcommit(xdr, data->args.inode, args, &hdr);
3070 	encode_getfattr(xdr, args->bitmask, &hdr);
3071 	encode_nops(&hdr);
3072 }
3073 
3074 /*
3075  * Encode LAYOUTRETURN request
3076  */
3077 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3078 				      struct xdr_stream *xdr,
3079 				      const void *data)
3080 {
3081 	const struct nfs4_layoutreturn_args *args = data;
3082 	struct compound_hdr hdr = {
3083 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3084 	};
3085 
3086 	encode_compound_hdr(xdr, req, &hdr);
3087 	encode_sequence(xdr, &args->seq_args, &hdr);
3088 	encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3089 	encode_layoutreturn(xdr, args, &hdr);
3090 	encode_nops(&hdr);
3091 }
3092 
3093 /*
3094  * Encode SECINFO_NO_NAME request
3095  */
3096 static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3097 					struct xdr_stream *xdr,
3098 					const void *data)
3099 {
3100 	const struct nfs41_secinfo_no_name_args *args = data;
3101 	struct compound_hdr hdr = {
3102 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3103 	};
3104 
3105 	encode_compound_hdr(xdr, req, &hdr);
3106 	encode_sequence(xdr, &args->seq_args, &hdr);
3107 	encode_putrootfh(xdr, &hdr);
3108 	encode_secinfo_no_name(xdr, args, &hdr);
3109 	encode_nops(&hdr);
3110 }
3111 
3112 /*
3113  *  Encode TEST_STATEID request
3114  */
3115 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3116 				      struct xdr_stream *xdr,
3117 				      const void *data)
3118 {
3119 	const struct nfs41_test_stateid_args *args = data;
3120 	struct compound_hdr hdr = {
3121 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3122 	};
3123 
3124 	encode_compound_hdr(xdr, req, &hdr);
3125 	encode_sequence(xdr, &args->seq_args, &hdr);
3126 	encode_test_stateid(xdr, args, &hdr);
3127 	encode_nops(&hdr);
3128 }
3129 
3130 /*
3131  *  Encode FREE_STATEID request
3132  */
3133 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3134 				     struct xdr_stream *xdr,
3135 				     const void *data)
3136 {
3137 	const struct nfs41_free_stateid_args *args = data;
3138 	struct compound_hdr hdr = {
3139 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
3140 	};
3141 
3142 	encode_compound_hdr(xdr, req, &hdr);
3143 	encode_sequence(xdr, &args->seq_args, &hdr);
3144 	encode_free_stateid(xdr, args, &hdr);
3145 	encode_nops(&hdr);
3146 }
3147 #endif /* CONFIG_NFS_V4_1 */
3148 
3149 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
3150 {
3151 	ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3152 			NFS4_OPAQUE_LIMIT);
3153 	if (unlikely(ret < 0))
3154 		return -EIO;
3155 	*len = ret;
3156 	return 0;
3157 }
3158 
3159 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3160 {
3161 	__be32 *p;
3162 
3163 	p = xdr_inline_decode(xdr, 8);
3164 	if (unlikely(!p))
3165 		return -EIO;
3166 	hdr->status = be32_to_cpup(p++);
3167 	hdr->taglen = be32_to_cpup(p);
3168 
3169 	p = xdr_inline_decode(xdr, hdr->taglen + 4);
3170 	if (unlikely(!p))
3171 		return -EIO;
3172 	hdr->tag = (char *)p;
3173 	p += XDR_QUADLEN(hdr->taglen);
3174 	hdr->nops = be32_to_cpup(p);
3175 	if (unlikely(hdr->nops < 1))
3176 		return nfs4_stat_to_errno(hdr->status);
3177 	return 0;
3178 }
3179 
3180 static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3181 		int *nfs_retval)
3182 {
3183 	__be32 *p;
3184 	uint32_t opnum;
3185 	int32_t nfserr;
3186 
3187 	p = xdr_inline_decode(xdr, 8);
3188 	if (unlikely(!p))
3189 		goto out_overflow;
3190 	opnum = be32_to_cpup(p++);
3191 	if (unlikely(opnum != expected))
3192 		goto out_bad_operation;
3193 	if (unlikely(*p != cpu_to_be32(NFS_OK)))
3194 		goto out_status;
3195 	*nfs_retval = 0;
3196 	return true;
3197 out_status:
3198 	nfserr = be32_to_cpup(p);
3199 	trace_nfs4_xdr_status(xdr, opnum, nfserr);
3200 	*nfs_retval = nfs4_stat_to_errno(nfserr);
3201 	return true;
3202 out_bad_operation:
3203 	dprintk("nfs: Server returned operation"
3204 		" %d but we issued a request for %d\n",
3205 			opnum, expected);
3206 	*nfs_retval = -EREMOTEIO;
3207 	return false;
3208 out_overflow:
3209 	*nfs_retval = -EIO;
3210 	return false;
3211 }
3212 
3213 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3214 {
3215 	int retval;
3216 
3217 	__decode_op_hdr(xdr, expected, &retval);
3218 	return retval;
3219 }
3220 
3221 /* Dummy routine */
3222 static int decode_ace(struct xdr_stream *xdr, void *ace)
3223 {
3224 	__be32 *p;
3225 	unsigned int strlen;
3226 	char *str;
3227 
3228 	p = xdr_inline_decode(xdr, 12);
3229 	if (unlikely(!p))
3230 		return -EIO;
3231 	return decode_opaque_inline(xdr, &strlen, &str);
3232 }
3233 
3234 static ssize_t
3235 decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
3236 {
3237 	ssize_t ret;
3238 
3239 	ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
3240 	if (likely(ret >= 0))
3241 		return ret;
3242 	if (ret != -EMSGSIZE)
3243 		return -EIO;
3244 	return sz;
3245 }
3246 
3247 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3248 {
3249 	ssize_t ret;
3250 	ret = decode_bitmap4(xdr, bitmap, 3);
3251 	return ret < 0 ? ret : 0;
3252 }
3253 
3254 static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
3255 {
3256 	__be32 *p;
3257 
3258 	p = xdr_inline_decode(xdr, 4);
3259 	if (unlikely(!p))
3260 		return -EIO;
3261 	*attrlen = be32_to_cpup(p);
3262 	*savep = xdr_stream_pos(xdr);
3263 	return 0;
3264 }
3265 
3266 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3267 {
3268 	if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3269 		int ret;
3270 		ret = decode_attr_bitmap(xdr, bitmask);
3271 		if (unlikely(ret < 0))
3272 			return ret;
3273 		bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3274 	} else
3275 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
3276 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3277 		bitmask[0], bitmask[1], bitmask[2]);
3278 	return 0;
3279 }
3280 
3281 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3282 {
3283 	__be32 *p;
3284 	int ret = 0;
3285 
3286 	*type = 0;
3287 	if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3288 		return -EIO;
3289 	if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3290 		p = xdr_inline_decode(xdr, 4);
3291 		if (unlikely(!p))
3292 			return -EIO;
3293 		*type = be32_to_cpup(p);
3294 		if (*type < NF4REG || *type > NF4NAMEDATTR) {
3295 			dprintk("%s: bad type %d\n", __func__, *type);
3296 			return -EIO;
3297 		}
3298 		bitmap[0] &= ~FATTR4_WORD0_TYPE;
3299 		ret = NFS_ATTR_FATTR_TYPE;
3300 	}
3301 	dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3302 	return ret;
3303 }
3304 
3305 static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3306 				      uint32_t *bitmap, uint32_t *type)
3307 {
3308 	__be32 *p;
3309 
3310 	*type = 0;
3311 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3312 		return -EIO;
3313 	if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3314 		p = xdr_inline_decode(xdr, 4);
3315 		if (unlikely(!p))
3316 			return -EIO;
3317 		*type = be32_to_cpup(p);
3318 		bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3319 	}
3320 	dprintk("%s: expire type=0x%x\n", __func__, *type);
3321 	return 0;
3322 }
3323 
3324 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3325 {
3326 	__be32 *p;
3327 	int ret = 0;
3328 
3329 	*change = 0;
3330 	if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3331 		return -EIO;
3332 	if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3333 		p = xdr_inline_decode(xdr, 8);
3334 		if (unlikely(!p))
3335 			return -EIO;
3336 		xdr_decode_hyper(p, change);
3337 		bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3338 		ret = NFS_ATTR_FATTR_CHANGE;
3339 	}
3340 	dprintk("%s: change attribute=%Lu\n", __func__,
3341 			(unsigned long long)*change);
3342 	return ret;
3343 }
3344 
3345 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3346 {
3347 	__be32 *p;
3348 	int ret = 0;
3349 
3350 	*size = 0;
3351 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3352 		return -EIO;
3353 	if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3354 		p = xdr_inline_decode(xdr, 8);
3355 		if (unlikely(!p))
3356 			return -EIO;
3357 		xdr_decode_hyper(p, size);
3358 		bitmap[0] &= ~FATTR4_WORD0_SIZE;
3359 		ret = NFS_ATTR_FATTR_SIZE;
3360 	}
3361 	dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3362 	return ret;
3363 }
3364 
3365 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3366 {
3367 	__be32 *p;
3368 
3369 	*res = 0;
3370 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3371 		return -EIO;
3372 	if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3373 		p = xdr_inline_decode(xdr, 4);
3374 		if (unlikely(!p))
3375 			return -EIO;
3376 		*res = be32_to_cpup(p);
3377 		bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3378 	}
3379 	dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3380 	return 0;
3381 }
3382 
3383 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3384 {
3385 	__be32 *p;
3386 
3387 	*res = 0;
3388 	if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3389 		return -EIO;
3390 	if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3391 		p = xdr_inline_decode(xdr, 4);
3392 		if (unlikely(!p))
3393 			return -EIO;
3394 		*res = be32_to_cpup(p);
3395 		bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3396 	}
3397 	dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3398 	return 0;
3399 }
3400 
3401 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3402 {
3403 	__be32 *p;
3404 	int ret = 0;
3405 
3406 	fsid->major = 0;
3407 	fsid->minor = 0;
3408 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3409 		return -EIO;
3410 	if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3411 		p = xdr_inline_decode(xdr, 16);
3412 		if (unlikely(!p))
3413 			return -EIO;
3414 		p = xdr_decode_hyper(p, &fsid->major);
3415 		xdr_decode_hyper(p, &fsid->minor);
3416 		bitmap[0] &= ~FATTR4_WORD0_FSID;
3417 		ret = NFS_ATTR_FATTR_FSID;
3418 	}
3419 	dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3420 			(unsigned long long)fsid->major,
3421 			(unsigned long long)fsid->minor);
3422 	return ret;
3423 }
3424 
3425 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3426 {
3427 	__be32 *p;
3428 
3429 	*res = 60;
3430 	if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3431 		return -EIO;
3432 	if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3433 		p = xdr_inline_decode(xdr, 4);
3434 		if (unlikely(!p))
3435 			return -EIO;
3436 		*res = be32_to_cpup(p);
3437 		bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3438 	}
3439 	dprintk("%s: lease time=%u\n", __func__, (unsigned int)*res);
3440 	return 0;
3441 }
3442 
3443 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3444 {
3445 	__be32 *p;
3446 
3447 	if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3448 		return -EIO;
3449 	if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3450 		p = xdr_inline_decode(xdr, 4);
3451 		if (unlikely(!p))
3452 			return -EIO;
3453 		bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3454 		*res = -be32_to_cpup(p);
3455 	}
3456 	return 0;
3457 }
3458 
3459 static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3460 				 uint32_t *bitmap, uint32_t *bitmask)
3461 {
3462 	if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3463 		int ret;
3464 		ret = decode_attr_bitmap(xdr, bitmask);
3465 		if (unlikely(ret < 0))
3466 			return ret;
3467 		bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3468 	} else
3469 		bitmask[0] = bitmask[1] = bitmask[2] = 0;
3470 	dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3471 		bitmask[0], bitmask[1], bitmask[2]);
3472 	return 0;
3473 }
3474 
3475 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3476 {
3477 	__be32 *p;
3478 	u32 len;
3479 
3480 	if (fh != NULL)
3481 		memset(fh, 0, sizeof(*fh));
3482 
3483 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3484 		return -EIO;
3485 	if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3486 		p = xdr_inline_decode(xdr, 4);
3487 		if (unlikely(!p))
3488 			return -EIO;
3489 		len = be32_to_cpup(p);
3490 		if (len > NFS4_FHSIZE)
3491 			return -EIO;
3492 		p = xdr_inline_decode(xdr, len);
3493 		if (unlikely(!p))
3494 			return -EIO;
3495 		if (fh != NULL) {
3496 			memcpy(fh->data, p, len);
3497 			fh->size = len;
3498 		}
3499 		bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3500 	}
3501 	return 0;
3502 }
3503 
3504 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3505 {
3506 	__be32 *p;
3507 
3508 	*res = 0;
3509 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3510 		return -EIO;
3511 	if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3512 		p = xdr_inline_decode(xdr, 4);
3513 		if (unlikely(!p))
3514 			return -EIO;
3515 		*res = be32_to_cpup(p);
3516 		bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3517 	}
3518 	dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3519 	return 0;
3520 }
3521 
3522 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3523 {
3524 	__be32 *p;
3525 	int ret = 0;
3526 
3527 	*fileid = 0;
3528 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3529 		return -EIO;
3530 	if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3531 		p = xdr_inline_decode(xdr, 8);
3532 		if (unlikely(!p))
3533 			return -EIO;
3534 		xdr_decode_hyper(p, fileid);
3535 		bitmap[0] &= ~FATTR4_WORD0_FILEID;
3536 		ret = NFS_ATTR_FATTR_FILEID;
3537 	}
3538 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3539 	return ret;
3540 }
3541 
3542 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3543 {
3544 	__be32 *p;
3545 	int ret = 0;
3546 
3547 	*fileid = 0;
3548 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3549 		return -EIO;
3550 	if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3551 		p = xdr_inline_decode(xdr, 8);
3552 		if (unlikely(!p))
3553 			return -EIO;
3554 		xdr_decode_hyper(p, fileid);
3555 		bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3556 		ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3557 	}
3558 	dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3559 	return ret;
3560 }
3561 
3562 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3563 {
3564 	__be32 *p;
3565 	int status = 0;
3566 
3567 	*res = 0;
3568 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3569 		return -EIO;
3570 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3571 		p = xdr_inline_decode(xdr, 8);
3572 		if (unlikely(!p))
3573 			return -EIO;
3574 		xdr_decode_hyper(p, res);
3575 		bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3576 	}
3577 	dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3578 	return status;
3579 }
3580 
3581 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3582 {
3583 	__be32 *p;
3584 	int status = 0;
3585 
3586 	*res = 0;
3587 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3588 		return -EIO;
3589 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3590 		p = xdr_inline_decode(xdr, 8);
3591 		if (unlikely(!p))
3592 			return -EIO;
3593 		xdr_decode_hyper(p, res);
3594 		bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3595 	}
3596 	dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3597 	return status;
3598 }
3599 
3600 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3601 {
3602 	__be32 *p;
3603 	int status = 0;
3604 
3605 	*res = 0;
3606 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3607 		return -EIO;
3608 	if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3609 		p = xdr_inline_decode(xdr, 8);
3610 		if (unlikely(!p))
3611 			return -EIO;
3612 		xdr_decode_hyper(p, res);
3613 		bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3614 	}
3615 	dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3616 	return status;
3617 }
3618 
3619 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3620 {
3621 	u32 n;
3622 	__be32 *p;
3623 	int status = 0;
3624 
3625 	p = xdr_inline_decode(xdr, 4);
3626 	if (unlikely(!p))
3627 		return -EIO;
3628 	n = be32_to_cpup(p);
3629 	if (n == 0)
3630 		goto root_path;
3631 	dprintk("pathname4: ");
3632 	if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3633 		dprintk("cannot parse %d components in path\n", n);
3634 		goto out_eio;
3635 	}
3636 	for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
3637 		struct nfs4_string *component = &path->components[path->ncomponents];
3638 		status = decode_opaque_inline(xdr, &component->len, &component->data);
3639 		if (unlikely(status != 0))
3640 			goto out_eio;
3641 		ifdebug (XDR)
3642 			pr_cont("%s%.*s ",
3643 				(path->ncomponents != n ? "/ " : ""),
3644 				component->len, component->data);
3645 	}
3646 out:
3647 	return status;
3648 root_path:
3649 /* a root pathname is sent as a zero component4 */
3650 	path->ncomponents = 1;
3651 	path->components[0].len=0;
3652 	path->components[0].data=NULL;
3653 	dprintk("pathname4: /\n");
3654 	goto out;
3655 out_eio:
3656 	dprintk(" status %d", status);
3657 	status = -EIO;
3658 	goto out;
3659 }
3660 
3661 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3662 {
3663 	int n;
3664 	__be32 *p;
3665 	int status = -EIO;
3666 
3667 	if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3668 		goto out;
3669 	status = 0;
3670 	if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3671 		goto out;
3672 	bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
3673 	status = -EIO;
3674 	/* Ignore borken servers that return unrequested attrs */
3675 	if (unlikely(res == NULL))
3676 		goto out;
3677 	dprintk("%s: fsroot:\n", __func__);
3678 	status = decode_pathname(xdr, &res->fs_path);
3679 	if (unlikely(status != 0))
3680 		goto out;
3681 	p = xdr_inline_decode(xdr, 4);
3682 	if (unlikely(!p))
3683 		goto out_eio;
3684 	n = be32_to_cpup(p);
3685 	if (n <= 0)
3686 		goto out_eio;
3687 	for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3688 		u32 m;
3689 		struct nfs4_fs_location *loc;
3690 
3691 		if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3692 			break;
3693 		loc = &res->locations[res->nlocations];
3694 		p = xdr_inline_decode(xdr, 4);
3695 		if (unlikely(!p))
3696 			goto out_eio;
3697 		m = be32_to_cpup(p);
3698 
3699 		dprintk("%s: servers:\n", __func__);
3700 		for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3701 			struct nfs4_string *server;
3702 
3703 			if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3704 				unsigned int i;
3705 				dprintk("%s: using first %u of %u servers "
3706 					"returned for location %u\n",
3707 						__func__,
3708 						NFS4_FS_LOCATION_MAXSERVERS,
3709 						m, res->nlocations);
3710 				for (i = loc->nservers; i < m; i++) {
3711 					unsigned int len;
3712 					char *data;
3713 					status = decode_opaque_inline(xdr, &len, &data);
3714 					if (unlikely(status != 0))
3715 						goto out_eio;
3716 				}
3717 				break;
3718 			}
3719 			server = &loc->servers[loc->nservers];
3720 			status = decode_opaque_inline(xdr, &server->len, &server->data);
3721 			if (unlikely(status != 0))
3722 				goto out_eio;
3723 			dprintk("%s ", server->data);
3724 		}
3725 		status = decode_pathname(xdr, &loc->rootpath);
3726 		if (unlikely(status != 0))
3727 			goto out_eio;
3728 	}
3729 	if (res->nlocations != 0)
3730 		status = NFS_ATTR_FATTR_V4_LOCATIONS;
3731 out:
3732 	dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3733 	return status;
3734 out_eio:
3735 	status = -EIO;
3736 	goto out;
3737 }
3738 
3739 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3740 {
3741 	__be32 *p;
3742 	int status = 0;
3743 
3744 	*res = 0;
3745 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3746 		return -EIO;
3747 	if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3748 		p = xdr_inline_decode(xdr, 8);
3749 		if (unlikely(!p))
3750 			return -EIO;
3751 		xdr_decode_hyper(p, res);
3752 		bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3753 	}
3754 	dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3755 	return status;
3756 }
3757 
3758 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3759 {
3760 	__be32 *p;
3761 	int status = 0;
3762 
3763 	*maxlink = 1;
3764 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3765 		return -EIO;
3766 	if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3767 		p = xdr_inline_decode(xdr, 4);
3768 		if (unlikely(!p))
3769 			return -EIO;
3770 		*maxlink = be32_to_cpup(p);
3771 		bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3772 	}
3773 	dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3774 	return status;
3775 }
3776 
3777 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3778 {
3779 	__be32 *p;
3780 	int status = 0;
3781 
3782 	*maxname = 1024;
3783 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3784 		return -EIO;
3785 	if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3786 		p = xdr_inline_decode(xdr, 4);
3787 		if (unlikely(!p))
3788 			return -EIO;
3789 		*maxname = be32_to_cpup(p);
3790 		bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3791 	}
3792 	dprintk("%s: maxname=%u\n", __func__, *maxname);
3793 	return status;
3794 }
3795 
3796 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3797 {
3798 	__be32 *p;
3799 	int status = 0;
3800 
3801 	*res = 1024;
3802 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3803 		return -EIO;
3804 	if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3805 		uint64_t maxread;
3806 		p = xdr_inline_decode(xdr, 8);
3807 		if (unlikely(!p))
3808 			return -EIO;
3809 		xdr_decode_hyper(p, &maxread);
3810 		if (maxread > 0x7FFFFFFF)
3811 			maxread = 0x7FFFFFFF;
3812 		*res = (uint32_t)maxread;
3813 		bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3814 	}
3815 	dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3816 	return status;
3817 }
3818 
3819 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3820 {
3821 	__be32 *p;
3822 	int status = 0;
3823 
3824 	*res = 1024;
3825 	if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3826 		return -EIO;
3827 	if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3828 		uint64_t maxwrite;
3829 		p = xdr_inline_decode(xdr, 8);
3830 		if (unlikely(!p))
3831 			return -EIO;
3832 		xdr_decode_hyper(p, &maxwrite);
3833 		if (maxwrite > 0x7FFFFFFF)
3834 			maxwrite = 0x7FFFFFFF;
3835 		*res = (uint32_t)maxwrite;
3836 		bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3837 	}
3838 	dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3839 	return status;
3840 }
3841 
3842 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3843 {
3844 	uint32_t tmp;
3845 	__be32 *p;
3846 	int ret = 0;
3847 
3848 	*mode = 0;
3849 	if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3850 		return -EIO;
3851 	if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3852 		p = xdr_inline_decode(xdr, 4);
3853 		if (unlikely(!p))
3854 			return -EIO;
3855 		tmp = be32_to_cpup(p);
3856 		*mode = tmp & ~S_IFMT;
3857 		bitmap[1] &= ~FATTR4_WORD1_MODE;
3858 		ret = NFS_ATTR_FATTR_MODE;
3859 	}
3860 	dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3861 	return ret;
3862 }
3863 
3864 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3865 {
3866 	__be32 *p;
3867 	int ret = 0;
3868 
3869 	*nlink = 1;
3870 	if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3871 		return -EIO;
3872 	if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3873 		p = xdr_inline_decode(xdr, 4);
3874 		if (unlikely(!p))
3875 			return -EIO;
3876 		*nlink = be32_to_cpup(p);
3877 		bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3878 		ret = NFS_ATTR_FATTR_NLINK;
3879 	}
3880 	dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3881 	return ret;
3882 }
3883 
3884 static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3885 		struct nfs4_string *name, gfp_t gfp_flags)
3886 {
3887 	ssize_t ret;
3888 
3889 	ret = xdr_stream_decode_string_dup(xdr, &name->data,
3890 			XDR_MAX_NETOBJ, gfp_flags);
3891 	name->len = 0;
3892 	if (ret > 0)
3893 		name->len = ret;
3894 	return ret;
3895 }
3896 
3897 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3898 		const struct nfs_server *server, kuid_t *uid,
3899 		struct nfs4_string *owner_name)
3900 {
3901 	ssize_t len;
3902 	char *p;
3903 
3904 	*uid = make_kuid(&init_user_ns, -2);
3905 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3906 		return -EIO;
3907 	if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3908 		return 0;
3909 	bitmap[1] &= ~FATTR4_WORD1_OWNER;
3910 
3911 	if (owner_name != NULL) {
3912 		len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
3913 		if (len <= 0)
3914 			goto out;
3915 		dprintk("%s: name=%s\n", __func__, owner_name->data);
3916 		return NFS_ATTR_FATTR_OWNER_NAME;
3917 	} else {
3918 		len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3919 				XDR_MAX_NETOBJ);
3920 		if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3921 			goto out;
3922 		dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3923 		return NFS_ATTR_FATTR_OWNER;
3924 	}
3925 out:
3926 	if (len == -EBADMSG)
3927 		return -EIO;
3928 	return 0;
3929 }
3930 
3931 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3932 		const struct nfs_server *server, kgid_t *gid,
3933 		struct nfs4_string *group_name)
3934 {
3935 	ssize_t len;
3936 	char *p;
3937 
3938 	*gid = make_kgid(&init_user_ns, -2);
3939 	if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3940 		return -EIO;
3941 	if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
3942 		return 0;
3943 	bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3944 
3945 	if (group_name != NULL) {
3946 		len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
3947 		if (len <= 0)
3948 			goto out;
3949 		dprintk("%s: name=%s\n", __func__, group_name->data);
3950 		return NFS_ATTR_FATTR_GROUP_NAME;
3951 	} else {
3952 		len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3953 				XDR_MAX_NETOBJ);
3954 		if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
3955 			goto out;
3956 		dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3957 		return NFS_ATTR_FATTR_GROUP;
3958 	}
3959 out:
3960 	if (len == -EBADMSG)
3961 		return -EIO;
3962 	return 0;
3963 }
3964 
3965 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3966 {
3967 	uint32_t major = 0, minor = 0;
3968 	__be32 *p;
3969 	int ret = 0;
3970 
3971 	*rdev = MKDEV(0,0);
3972 	if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3973 		return -EIO;
3974 	if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3975 		dev_t tmp;
3976 
3977 		p = xdr_inline_decode(xdr, 8);
3978 		if (unlikely(!p))
3979 			return -EIO;
3980 		major = be32_to_cpup(p++);
3981 		minor = be32_to_cpup(p);
3982 		tmp = MKDEV(major, minor);
3983 		if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3984 			*rdev = tmp;
3985 		bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3986 		ret = NFS_ATTR_FATTR_RDEV;
3987 	}
3988 	dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3989 	return ret;
3990 }
3991 
3992 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3993 {
3994 	__be32 *p;
3995 	int status = 0;
3996 
3997 	*res = 0;
3998 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3999 		return -EIO;
4000 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
4001 		p = xdr_inline_decode(xdr, 8);
4002 		if (unlikely(!p))
4003 			return -EIO;
4004 		xdr_decode_hyper(p, res);
4005 		bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4006 	}
4007 	dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
4008 	return status;
4009 }
4010 
4011 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4012 {
4013 	__be32 *p;
4014 	int status = 0;
4015 
4016 	*res = 0;
4017 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4018 		return -EIO;
4019 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
4020 		p = xdr_inline_decode(xdr, 8);
4021 		if (unlikely(!p))
4022 			return -EIO;
4023 		xdr_decode_hyper(p, res);
4024 		bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4025 	}
4026 	dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
4027 	return status;
4028 }
4029 
4030 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4031 {
4032 	__be32 *p;
4033 	int status = 0;
4034 
4035 	*res = 0;
4036 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4037 		return -EIO;
4038 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4039 		p = xdr_inline_decode(xdr, 8);
4040 		if (unlikely(!p))
4041 			return -EIO;
4042 		xdr_decode_hyper(p, res);
4043 		bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4044 	}
4045 	dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
4046 	return status;
4047 }
4048 
4049 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4050 {
4051 	__be32 *p;
4052 	int ret = 0;
4053 
4054 	*used = 0;
4055 	if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4056 		return -EIO;
4057 	if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4058 		p = xdr_inline_decode(xdr, 8);
4059 		if (unlikely(!p))
4060 			return -EIO;
4061 		xdr_decode_hyper(p, used);
4062 		bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4063 		ret = NFS_ATTR_FATTR_SPACE_USED;
4064 	}
4065 	dprintk("%s: space used=%Lu\n", __func__,
4066 			(unsigned long long)*used);
4067 	return ret;
4068 }
4069 
4070 static __be32 *
4071 xdr_decode_nfstime4(__be32 *p, struct timespec64 *t)
4072 {
4073 	__u64 sec;
4074 
4075 	p = xdr_decode_hyper(p, &sec);
4076 	t-> tv_sec = sec;
4077 	t->tv_nsec = be32_to_cpup(p++);
4078 	return p;
4079 }
4080 
4081 static int decode_attr_time(struct xdr_stream *xdr, struct timespec64 *time)
4082 {
4083 	__be32 *p;
4084 
4085 	p = xdr_inline_decode(xdr, nfstime4_maxsz << 2);
4086 	if (unlikely(!p))
4087 		return -EIO;
4088 	xdr_decode_nfstime4(p, time);
4089 	return 0;
4090 }
4091 
4092 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
4093 {
4094 	int status = 0;
4095 
4096 	time->tv_sec = 0;
4097 	time->tv_nsec = 0;
4098 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4099 		return -EIO;
4100 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4101 		status = decode_attr_time(xdr, time);
4102 		if (status == 0)
4103 			status = NFS_ATTR_FATTR_ATIME;
4104 		bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4105 	}
4106 	dprintk("%s: atime=%lld\n", __func__, time->tv_sec);
4107 	return status;
4108 }
4109 
4110 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
4111 {
4112 	int status = 0;
4113 
4114 	time->tv_sec = 0;
4115 	time->tv_nsec = 0;
4116 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4117 		return -EIO;
4118 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4119 		status = decode_attr_time(xdr, time);
4120 		if (status == 0)
4121 			status = NFS_ATTR_FATTR_CTIME;
4122 		bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4123 	}
4124 	dprintk("%s: ctime=%lld\n", __func__, time->tv_sec);
4125 	return status;
4126 }
4127 
4128 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4129 				  struct timespec64 *time)
4130 {
4131 	int status = 0;
4132 
4133 	time->tv_sec = 0;
4134 	time->tv_nsec = 0;
4135 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4136 		return -EIO;
4137 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4138 		status = decode_attr_time(xdr, time);
4139 		bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4140 	}
4141 	dprintk("%s: time_delta=%lld %ld\n", __func__, time->tv_sec,
4142 		time->tv_nsec);
4143 	return status;
4144 }
4145 
4146 static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4147 					struct nfs4_label *label)
4148 {
4149 	uint32_t pi = 0;
4150 	uint32_t lfs = 0;
4151 	__u32 len;
4152 	__be32 *p;
4153 	int status = 0;
4154 
4155 	if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4156 		return -EIO;
4157 	if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4158 		p = xdr_inline_decode(xdr, 4);
4159 		if (unlikely(!p))
4160 			return -EIO;
4161 		lfs = be32_to_cpup(p++);
4162 		p = xdr_inline_decode(xdr, 4);
4163 		if (unlikely(!p))
4164 			return -EIO;
4165 		pi = be32_to_cpup(p++);
4166 		p = xdr_inline_decode(xdr, 4);
4167 		if (unlikely(!p))
4168 			return -EIO;
4169 		len = be32_to_cpup(p++);
4170 		p = xdr_inline_decode(xdr, len);
4171 		if (unlikely(!p))
4172 			return -EIO;
4173 		if (len < NFS4_MAXLABELLEN) {
4174 			if (label) {
4175 				if (label->len) {
4176 					if (label->len < len)
4177 						return -ERANGE;
4178 					memcpy(label->label, p, len);
4179 				}
4180 				label->len = len;
4181 				label->pi = pi;
4182 				label->lfs = lfs;
4183 				status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4184 			}
4185 			bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4186 		} else
4187 			printk(KERN_WARNING "%s: label too long (%u)!\n",
4188 					__func__, len);
4189 	}
4190 	if (label && label->label)
4191 		dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4192 			(char *)label->label, label->len, label->pi, label->lfs);
4193 	return status;
4194 }
4195 
4196 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
4197 {
4198 	int status = 0;
4199 
4200 	time->tv_sec = 0;
4201 	time->tv_nsec = 0;
4202 	if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4203 		return -EIO;
4204 	if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4205 		status = decode_attr_time(xdr, time);
4206 		if (status == 0)
4207 			status = NFS_ATTR_FATTR_MTIME;
4208 		bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4209 	}
4210 	dprintk("%s: mtime=%lld\n", __func__, time->tv_sec);
4211 	return status;
4212 }
4213 
4214 static int decode_attr_xattrsupport(struct xdr_stream *xdr, uint32_t *bitmap,
4215 				    uint32_t *res)
4216 {
4217 	__be32 *p;
4218 
4219 	*res = 0;
4220 	if (unlikely(bitmap[2] & (FATTR4_WORD2_XATTR_SUPPORT - 1U)))
4221 		return -EIO;
4222 	if (likely(bitmap[2] & FATTR4_WORD2_XATTR_SUPPORT)) {
4223 		p = xdr_inline_decode(xdr, 4);
4224 		if (unlikely(!p))
4225 			return -EIO;
4226 		*res = be32_to_cpup(p);
4227 		bitmap[2] &= ~FATTR4_WORD2_XATTR_SUPPORT;
4228 	}
4229 	dprintk("%s: XATTR support=%s\n", __func__,
4230 		*res == 0 ? "false" : "true");
4231 	return 0;
4232 }
4233 
4234 static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
4235 {
4236 	unsigned int attrwords = XDR_QUADLEN(attrlen);
4237 	unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
4238 
4239 	if (unlikely(attrwords != nwords)) {
4240 		dprintk("%s: server returned incorrect attribute length: "
4241 			"%u %c %u\n",
4242 				__func__,
4243 				attrwords << 2,
4244 				(attrwords < nwords) ? '<' : '>',
4245 				nwords << 2);
4246 		return -EIO;
4247 	}
4248 	return 0;
4249 }
4250 
4251 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4252 {
4253 	__be32 *p;
4254 
4255 	p = xdr_inline_decode(xdr, 20);
4256 	if (unlikely(!p))
4257 		return -EIO;
4258 	cinfo->atomic = be32_to_cpup(p++);
4259 	p = xdr_decode_hyper(p, &cinfo->before);
4260 	xdr_decode_hyper(p, &cinfo->after);
4261 	return 0;
4262 }
4263 
4264 static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
4265 {
4266 	__be32 *p;
4267 	uint32_t supp, acc;
4268 	int status;
4269 
4270 	status = decode_op_hdr(xdr, OP_ACCESS);
4271 	if (status)
4272 		return status;
4273 	p = xdr_inline_decode(xdr, 8);
4274 	if (unlikely(!p))
4275 		return -EIO;
4276 	supp = be32_to_cpup(p++);
4277 	acc = be32_to_cpup(p);
4278 	*supported = supp;
4279 	*access = acc;
4280 	return 0;
4281 }
4282 
4283 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4284 {
4285 	ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4286 	if (unlikely(ret < 0))
4287 		return -EIO;
4288 	return 0;
4289 }
4290 
4291 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4292 {
4293 	return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
4294 }
4295 
4296 static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4297 {
4298 	stateid->type = NFS4_OPEN_STATEID_TYPE;
4299 	return decode_stateid(xdr, stateid);
4300 }
4301 
4302 static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4303 {
4304 	stateid->type = NFS4_LOCK_STATEID_TYPE;
4305 	return decode_stateid(xdr, stateid);
4306 }
4307 
4308 static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4309 {
4310 	stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4311 	return decode_stateid(xdr, stateid);
4312 }
4313 
4314 static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4315 {
4316 	nfs4_stateid dummy;
4317 
4318 	nfs4_stateid_copy(stateid, &invalid_stateid);
4319 	return decode_stateid(xdr, &dummy);
4320 }
4321 
4322 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4323 {
4324 	int status;
4325 
4326 	status = decode_op_hdr(xdr, OP_CLOSE);
4327 	if (status != -EIO)
4328 		nfs_increment_open_seqid(status, res->seqid);
4329 	if (!status)
4330 		status = decode_invalid_stateid(xdr, &res->stateid);
4331 	return status;
4332 }
4333 
4334 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4335 {
4336 	return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
4337 }
4338 
4339 static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4340 {
4341 	return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4342 }
4343 
4344 static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
4345 {
4346 	struct nfs_writeverf *verf = res->verf;
4347 	int status;
4348 
4349 	status = decode_op_hdr(xdr, OP_COMMIT);
4350 	if (!status)
4351 		status = decode_write_verifier(xdr, &verf->verifier);
4352 	if (!status)
4353 		verf->committed = NFS_FILE_SYNC;
4354 	return status;
4355 }
4356 
4357 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4358 {
4359 	__be32 *p;
4360 	uint32_t bmlen;
4361 	int status;
4362 
4363 	status = decode_op_hdr(xdr, OP_CREATE);
4364 	if (status)
4365 		return status;
4366 	if ((status = decode_change_info(xdr, cinfo)))
4367 		return status;
4368 	p = xdr_inline_decode(xdr, 4);
4369 	if (unlikely(!p))
4370 		return -EIO;
4371 	bmlen = be32_to_cpup(p);
4372 	p = xdr_inline_decode(xdr, bmlen << 2);
4373 	if (likely(p))
4374 		return 0;
4375 	return -EIO;
4376 }
4377 
4378 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4379 {
4380 	unsigned int savep;
4381 	uint32_t attrlen, bitmap[3] = {0};
4382 	int status;
4383 
4384 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4385 		goto xdr_error;
4386 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4387 		goto xdr_error;
4388 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4389 		goto xdr_error;
4390 	if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4391 		goto xdr_error;
4392 	if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4393 						 &res->fh_expire_type)) != 0)
4394 		goto xdr_error;
4395 	if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4396 		goto xdr_error;
4397 	if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4398 		goto xdr_error;
4399 	if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4400 		goto xdr_error;
4401 	if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4402 				res->exclcreat_bitmask)) != 0)
4403 		goto xdr_error;
4404 	status = verify_attr_len(xdr, savep, attrlen);
4405 xdr_error:
4406 	dprintk("%s: xdr returned %d!\n", __func__, -status);
4407 	return status;
4408 }
4409 
4410 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4411 {
4412 	unsigned int savep;
4413 	uint32_t attrlen, bitmap[3] = {0};
4414 	int status;
4415 
4416 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4417 		goto xdr_error;
4418 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4419 		goto xdr_error;
4420 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4421 		goto xdr_error;
4422 
4423 	if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4424 		goto xdr_error;
4425 	if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4426 		goto xdr_error;
4427 	if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4428 		goto xdr_error;
4429 
4430 	status = -EIO;
4431 	if (unlikely(bitmap[0]))
4432 		goto xdr_error;
4433 
4434 	if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4435 		goto xdr_error;
4436 	if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4437 		goto xdr_error;
4438 	if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4439 		goto xdr_error;
4440 
4441 	status = verify_attr_len(xdr, savep, attrlen);
4442 xdr_error:
4443 	dprintk("%s: xdr returned %d!\n", __func__, -status);
4444 	return status;
4445 }
4446 
4447 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4448 {
4449 	unsigned int savep;
4450 	uint32_t attrlen, bitmap[3] = {0};
4451 	int status;
4452 
4453 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4454 		goto xdr_error;
4455 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4456 		goto xdr_error;
4457 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4458 		goto xdr_error;
4459 
4460 	if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4461 		goto xdr_error;
4462 	if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4463 		goto xdr_error;
4464 
4465 	status = verify_attr_len(xdr, savep, attrlen);
4466 xdr_error:
4467 	dprintk("%s: xdr returned %d!\n", __func__, -status);
4468 	return status;
4469 }
4470 
4471 static int decode_threshold_hint(struct xdr_stream *xdr,
4472 				  uint32_t *bitmap,
4473 				  uint64_t *res,
4474 				  uint32_t hint_bit)
4475 {
4476 	__be32 *p;
4477 
4478 	*res = 0;
4479 	if (likely(bitmap[0] & hint_bit)) {
4480 		p = xdr_inline_decode(xdr, 8);
4481 		if (unlikely(!p))
4482 			return -EIO;
4483 		xdr_decode_hyper(p, res);
4484 	}
4485 	return 0;
4486 }
4487 
4488 static int decode_first_threshold_item4(struct xdr_stream *xdr,
4489 					struct nfs4_threshold *res)
4490 {
4491 	__be32 *p;
4492 	unsigned int savep;
4493 	uint32_t bitmap[3] = {0,}, attrlen;
4494 	int status;
4495 
4496 	/* layout type */
4497 	p = xdr_inline_decode(xdr, 4);
4498 	if (unlikely(!p))
4499 		return -EIO;
4500 	res->l_type = be32_to_cpup(p);
4501 
4502 	/* thi_hintset bitmap */
4503 	status = decode_attr_bitmap(xdr, bitmap);
4504 	if (status < 0)
4505 		goto xdr_error;
4506 
4507 	/* thi_hintlist length */
4508 	status = decode_attr_length(xdr, &attrlen, &savep);
4509 	if (status < 0)
4510 		goto xdr_error;
4511 	/* thi_hintlist */
4512 	status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4513 	if (status < 0)
4514 		goto xdr_error;
4515 	status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4516 	if (status < 0)
4517 		goto xdr_error;
4518 	status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4519 				       THRESHOLD_RD_IO);
4520 	if (status < 0)
4521 		goto xdr_error;
4522 	status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4523 				       THRESHOLD_WR_IO);
4524 	if (status < 0)
4525 		goto xdr_error;
4526 
4527 	status = verify_attr_len(xdr, savep, attrlen);
4528 	res->bm = bitmap[0];
4529 
4530 	dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4531 		 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4532 		res->wr_io_sz);
4533 xdr_error:
4534 	dprintk("%s ret=%d!\n", __func__, status);
4535 	return status;
4536 }
4537 
4538 /*
4539  * Thresholds on pNFS direct I/O vrs MDS I/O
4540  */
4541 static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4542 				    uint32_t *bitmap,
4543 				    struct nfs4_threshold *res)
4544 {
4545 	__be32 *p;
4546 	int status = 0;
4547 	uint32_t num;
4548 
4549 	if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4550 		return -EIO;
4551 	if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
4552 		/* Did the server return an unrequested attribute? */
4553 		if (unlikely(res == NULL))
4554 			return -EREMOTEIO;
4555 		p = xdr_inline_decode(xdr, 4);
4556 		if (unlikely(!p))
4557 			return -EIO;
4558 		num = be32_to_cpup(p);
4559 		if (num == 0)
4560 			return 0;
4561 		if (num > 1)
4562 			printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4563 				"drivers per filesystem not supported\n",
4564 				__func__);
4565 
4566 		status = decode_first_threshold_item4(xdr, res);
4567 		bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
4568 	}
4569 	return status;
4570 }
4571 
4572 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4573 		struct nfs_fattr *fattr, struct nfs_fh *fh,
4574 		struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
4575 		const struct nfs_server *server)
4576 {
4577 	int status;
4578 	umode_t fmode = 0;
4579 	uint32_t type;
4580 	int32_t err;
4581 
4582 	status = decode_attr_type(xdr, bitmap, &type);
4583 	if (status < 0)
4584 		goto xdr_error;
4585 	fattr->mode = 0;
4586 	if (status != 0) {
4587 		fattr->mode |= nfs_type2fmt[type];
4588 		fattr->valid |= status;
4589 	}
4590 
4591 	status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4592 	if (status < 0)
4593 		goto xdr_error;
4594 	fattr->valid |= status;
4595 
4596 	status = decode_attr_size(xdr, bitmap, &fattr->size);
4597 	if (status < 0)
4598 		goto xdr_error;
4599 	fattr->valid |= status;
4600 
4601 	status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4602 	if (status < 0)
4603 		goto xdr_error;
4604 	fattr->valid |= status;
4605 
4606 	err = 0;
4607 	status = decode_attr_error(xdr, bitmap, &err);
4608 	if (status < 0)
4609 		goto xdr_error;
4610 
4611 	status = decode_attr_filehandle(xdr, bitmap, fh);
4612 	if (status < 0)
4613 		goto xdr_error;
4614 
4615 	status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4616 	if (status < 0)
4617 		goto xdr_error;
4618 	fattr->valid |= status;
4619 
4620 	status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4621 	if (status < 0)
4622 		goto xdr_error;
4623 	fattr->valid |= status;
4624 
4625 	status = -EIO;
4626 	if (unlikely(bitmap[0]))
4627 		goto xdr_error;
4628 
4629 	status = decode_attr_mode(xdr, bitmap, &fmode);
4630 	if (status < 0)
4631 		goto xdr_error;
4632 	if (status != 0) {
4633 		fattr->mode |= fmode;
4634 		fattr->valid |= status;
4635 	}
4636 
4637 	status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4638 	if (status < 0)
4639 		goto xdr_error;
4640 	fattr->valid |= status;
4641 
4642 	status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4643 	if (status < 0)
4644 		goto xdr_error;
4645 	fattr->valid |= status;
4646 
4647 	status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4648 	if (status < 0)
4649 		goto xdr_error;
4650 	fattr->valid |= status;
4651 
4652 	status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4653 	if (status < 0)
4654 		goto xdr_error;
4655 	fattr->valid |= status;
4656 
4657 	status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4658 	if (status < 0)
4659 		goto xdr_error;
4660 	fattr->valid |= status;
4661 
4662 	status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4663 	if (status < 0)
4664 		goto xdr_error;
4665 	fattr->valid |= status;
4666 
4667 	status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4668 	if (status < 0)
4669 		goto xdr_error;
4670 	fattr->valid |= status;
4671 
4672 	status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4673 	if (status < 0)
4674 		goto xdr_error;
4675 	fattr->valid |= status;
4676 
4677 	status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4678 	if (status < 0)
4679 		goto xdr_error;
4680 	fattr->valid |= status;
4681 
4682 	status = -EIO;
4683 	if (unlikely(bitmap[1]))
4684 		goto xdr_error;
4685 
4686 	status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4687 	if (status < 0)
4688 		goto xdr_error;
4689 
4690 	if (label) {
4691 		status = decode_attr_security_label(xdr, bitmap, label);
4692 		if (status < 0)
4693 			goto xdr_error;
4694 		fattr->valid |= status;
4695 	}
4696 
4697 xdr_error:
4698 	dprintk("%s: xdr returned %d\n", __func__, -status);
4699 	return status;
4700 }
4701 
4702 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4703 		struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4704 		struct nfs4_label *label, const struct nfs_server *server)
4705 {
4706 	unsigned int savep;
4707 	uint32_t attrlen,
4708 		 bitmap[3] = {0};
4709 	int status;
4710 
4711 	status = decode_op_hdr(xdr, OP_GETATTR);
4712 	if (status < 0)
4713 		goto xdr_error;
4714 
4715 	status = decode_attr_bitmap(xdr, bitmap);
4716 	if (status < 0)
4717 		goto xdr_error;
4718 
4719 	status = decode_attr_length(xdr, &attrlen, &savep);
4720 	if (status < 0)
4721 		goto xdr_error;
4722 
4723 	status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4724 					label, server);
4725 	if (status < 0)
4726 		goto xdr_error;
4727 
4728 	status = verify_attr_len(xdr, savep, attrlen);
4729 xdr_error:
4730 	dprintk("%s: xdr returned %d\n", __func__, -status);
4731 	return status;
4732 }
4733 
4734 static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4735 		struct nfs4_label *label, const struct nfs_server *server)
4736 {
4737 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4738 }
4739 
4740 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4741 		const struct nfs_server *server)
4742 {
4743 	return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
4744 }
4745 
4746 /*
4747  * Decode potentially multiple layout types.
4748  */
4749 static int decode_pnfs_layout_types(struct xdr_stream *xdr,
4750 				    struct nfs_fsinfo *fsinfo)
4751 {
4752 	__be32 *p;
4753 	uint32_t i;
4754 
4755 	p = xdr_inline_decode(xdr, 4);
4756 	if (unlikely(!p))
4757 		return -EIO;
4758 	fsinfo->nlayouttypes = be32_to_cpup(p);
4759 
4760 	/* pNFS is not supported by the underlying file system */
4761 	if (fsinfo->nlayouttypes == 0)
4762 		return 0;
4763 
4764 	/* Decode and set first layout type, move xdr->p past unused types */
4765 	p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
4766 	if (unlikely(!p))
4767 		return -EIO;
4768 
4769 	/* If we get too many, then just cap it at the max */
4770 	if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4771 		printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4772 			__func__, fsinfo->nlayouttypes);
4773 		fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4774 	}
4775 
4776 	for(i = 0; i < fsinfo->nlayouttypes; ++i)
4777 		fsinfo->layouttype[i] = be32_to_cpup(p++);
4778 	return 0;
4779 }
4780 
4781 /*
4782  * The type of file system exported.
4783  * Note we must ensure that layouttype is set in any non-error case.
4784  */
4785 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4786 				struct nfs_fsinfo *fsinfo)
4787 {
4788 	int status = 0;
4789 
4790 	dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4791 	if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4792 		return -EIO;
4793 	if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4794 		status = decode_pnfs_layout_types(xdr, fsinfo);
4795 		bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4796 	}
4797 	return status;
4798 }
4799 
4800 /*
4801  * The prefered block size for layout directed io
4802  */
4803 static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4804 				      uint32_t *res)
4805 {
4806 	__be32 *p;
4807 
4808 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4809 	*res = 0;
4810 	if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4811 		p = xdr_inline_decode(xdr, 4);
4812 		if (unlikely(!p))
4813 			return -EIO;
4814 		*res = be32_to_cpup(p);
4815 		bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4816 	}
4817 	return 0;
4818 }
4819 
4820 /*
4821  * The granularity of a CLONE operation.
4822  */
4823 static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4824 				     uint32_t *res)
4825 {
4826 	__be32 *p;
4827 
4828 	dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4829 	*res = 0;
4830 	if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4831 		p = xdr_inline_decode(xdr, 4);
4832 		if (unlikely(!p))
4833 			return -EIO;
4834 		*res = be32_to_cpup(p);
4835 		bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4836 	}
4837 	return 0;
4838 }
4839 
4840 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4841 {
4842 	unsigned int savep;
4843 	uint32_t attrlen, bitmap[3];
4844 	int status;
4845 
4846 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4847 		goto xdr_error;
4848 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4849 		goto xdr_error;
4850 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4851 		goto xdr_error;
4852 
4853 	fsinfo->rtmult = fsinfo->wtmult = 512;	/* ??? */
4854 
4855 	if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4856 		goto xdr_error;
4857 	if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4858 		goto xdr_error;
4859 	if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4860 		goto xdr_error;
4861 	fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4862 	if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4863 		goto xdr_error;
4864 	fsinfo->wtpref = fsinfo->wtmax;
4865 
4866 	status = -EIO;
4867 	if (unlikely(bitmap[0]))
4868 		goto xdr_error;
4869 
4870 	status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4871 	if (status != 0)
4872 		goto xdr_error;
4873 	status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
4874 	if (status != 0)
4875 		goto xdr_error;
4876 
4877 	status = -EIO;
4878 	if (unlikely(bitmap[1]))
4879 		goto xdr_error;
4880 
4881 	status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4882 	if (status)
4883 		goto xdr_error;
4884 	status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4885 	if (status)
4886 		goto xdr_error;
4887 
4888 	status = decode_attr_xattrsupport(xdr, bitmap,
4889 					  &fsinfo->xattr_support);
4890 	if (status)
4891 		goto xdr_error;
4892 
4893 	status = verify_attr_len(xdr, savep, attrlen);
4894 xdr_error:
4895 	dprintk("%s: xdr returned %d!\n", __func__, -status);
4896 	return status;
4897 }
4898 
4899 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4900 {
4901 	__be32 *p;
4902 	uint32_t len;
4903 	int status;
4904 
4905 	/* Zero handle first to allow comparisons */
4906 	memset(fh, 0, sizeof(*fh));
4907 
4908 	status = decode_op_hdr(xdr, OP_GETFH);
4909 	if (status)
4910 		return status;
4911 
4912 	p = xdr_inline_decode(xdr, 4);
4913 	if (unlikely(!p))
4914 		return -EIO;
4915 	len = be32_to_cpup(p);
4916 	if (len > NFS4_FHSIZE)
4917 		return -EIO;
4918 	fh->size = len;
4919 	p = xdr_inline_decode(xdr, len);
4920 	if (unlikely(!p))
4921 		return -EIO;
4922 	memcpy(fh->data, p, len);
4923 	return 0;
4924 }
4925 
4926 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4927 {
4928 	int status;
4929 
4930 	status = decode_op_hdr(xdr, OP_LINK);
4931 	if (status)
4932 		return status;
4933 	return decode_change_info(xdr, cinfo);
4934 }
4935 
4936 /*
4937  * We create the owner, so we know a proper owner.id length is 4.
4938  */
4939 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4940 {
4941 	uint64_t offset, length, clientid;
4942 	__be32 *p;
4943 	uint32_t namelen, type;
4944 
4945 	p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4946 	if (unlikely(!p))
4947 		return -EIO;
4948 	p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4949 	p = xdr_decode_hyper(p, &length);
4950 	type = be32_to_cpup(p++); /* 4 byte read */
4951 	if (fl != NULL) { /* manipulate file lock */
4952 		fl->fl_start = (loff_t)offset;
4953 		fl->fl_end = fl->fl_start + (loff_t)length - 1;
4954 		if (length == ~(uint64_t)0)
4955 			fl->fl_end = OFFSET_MAX;
4956 		fl->fl_type = F_WRLCK;
4957 		if (type & 1)
4958 			fl->fl_type = F_RDLCK;
4959 		fl->fl_pid = 0;
4960 	}
4961 	p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4962 	namelen = be32_to_cpup(p); /* read 4 bytes */  /* have read all 32 bytes now */
4963 	p = xdr_inline_decode(xdr, namelen); /* variable size field */
4964 	if (likely(!p))
4965 		return -EIO;
4966 	return -NFS4ERR_DENIED;
4967 }
4968 
4969 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4970 {
4971 	int status;
4972 
4973 	status = decode_op_hdr(xdr, OP_LOCK);
4974 	if (status == -EIO)
4975 		goto out;
4976 	if (status == 0) {
4977 		status = decode_lock_stateid(xdr, &res->stateid);
4978 		if (unlikely(status))
4979 			goto out;
4980 	} else if (status == -NFS4ERR_DENIED)
4981 		status = decode_lock_denied(xdr, NULL);
4982 	if (res->open_seqid != NULL)
4983 		nfs_increment_open_seqid(status, res->open_seqid);
4984 	nfs_increment_lock_seqid(status, res->lock_seqid);
4985 out:
4986 	return status;
4987 }
4988 
4989 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4990 {
4991 	int status;
4992 	status = decode_op_hdr(xdr, OP_LOCKT);
4993 	if (status == -NFS4ERR_DENIED)
4994 		return decode_lock_denied(xdr, res->denied);
4995 	return status;
4996 }
4997 
4998 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
4999 {
5000 	int status;
5001 
5002 	status = decode_op_hdr(xdr, OP_LOCKU);
5003 	if (status != -EIO)
5004 		nfs_increment_lock_seqid(status, res->seqid);
5005 	if (status == 0)
5006 		status = decode_lock_stateid(xdr, &res->stateid);
5007 	return status;
5008 }
5009 
5010 static int decode_release_lockowner(struct xdr_stream *xdr)
5011 {
5012 	return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5013 }
5014 
5015 static int decode_lookup(struct xdr_stream *xdr)
5016 {
5017 	return decode_op_hdr(xdr, OP_LOOKUP);
5018 }
5019 
5020 static int decode_lookupp(struct xdr_stream *xdr)
5021 {
5022 	return decode_op_hdr(xdr, OP_LOOKUPP);
5023 }
5024 
5025 /* This is too sick! */
5026 static int decode_space_limit(struct xdr_stream *xdr,
5027 		unsigned long *pagemod_limit)
5028 {
5029 	__be32 *p;
5030 	uint32_t limit_type, nblocks, blocksize;
5031 	u64 maxsize = 0;
5032 
5033 	p = xdr_inline_decode(xdr, 12);
5034 	if (unlikely(!p))
5035 		return -EIO;
5036 	limit_type = be32_to_cpup(p++);
5037 	switch (limit_type) {
5038 	case NFS4_LIMIT_SIZE:
5039 		xdr_decode_hyper(p, &maxsize);
5040 		break;
5041 	case NFS4_LIMIT_BLOCKS:
5042 		nblocks = be32_to_cpup(p++);
5043 		blocksize = be32_to_cpup(p);
5044 		maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
5045 	}
5046 	maxsize >>= PAGE_SHIFT;
5047 	*pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
5048 	return 0;
5049 }
5050 
5051 static int decode_rw_delegation(struct xdr_stream *xdr,
5052 		uint32_t delegation_type,
5053 		struct nfs_openres *res)
5054 {
5055 	__be32 *p;
5056 	int status;
5057 
5058 	status = decode_delegation_stateid(xdr, &res->delegation);
5059 	if (unlikely(status))
5060 		return status;
5061 	p = xdr_inline_decode(xdr, 4);
5062 	if (unlikely(!p))
5063 		return -EIO;
5064 	res->do_recall = be32_to_cpup(p);
5065 
5066 	switch (delegation_type) {
5067 	case NFS4_OPEN_DELEGATE_READ:
5068 		res->delegation_type = FMODE_READ;
5069 		break;
5070 	case NFS4_OPEN_DELEGATE_WRITE:
5071 		res->delegation_type = FMODE_WRITE|FMODE_READ;
5072 		if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
5073 				return -EIO;
5074 	}
5075 	return decode_ace(xdr, NULL);
5076 }
5077 
5078 static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5079 {
5080 	__be32 *p;
5081 	uint32_t why_no_delegation;
5082 
5083 	p = xdr_inline_decode(xdr, 4);
5084 	if (unlikely(!p))
5085 		return -EIO;
5086 	why_no_delegation = be32_to_cpup(p);
5087 	switch (why_no_delegation) {
5088 		case WND4_CONTENTION:
5089 		case WND4_RESOURCE:
5090 			xdr_inline_decode(xdr, 4);
5091 			/* Ignore for now */
5092 	}
5093 	return 0;
5094 }
5095 
5096 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5097 {
5098 	__be32 *p;
5099 	uint32_t delegation_type;
5100 
5101 	p = xdr_inline_decode(xdr, 4);
5102 	if (unlikely(!p))
5103 		return -EIO;
5104 	delegation_type = be32_to_cpup(p);
5105 	res->delegation_type = 0;
5106 	switch (delegation_type) {
5107 	case NFS4_OPEN_DELEGATE_NONE:
5108 		return 0;
5109 	case NFS4_OPEN_DELEGATE_READ:
5110 	case NFS4_OPEN_DELEGATE_WRITE:
5111 		return decode_rw_delegation(xdr, delegation_type, res);
5112 	case NFS4_OPEN_DELEGATE_NONE_EXT:
5113 		return decode_no_delegation(xdr, res);
5114 	}
5115 	return -EIO;
5116 }
5117 
5118 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5119 {
5120 	__be32 *p;
5121 	uint32_t savewords, bmlen, i;
5122 	int status;
5123 
5124 	if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5125 		return status;
5126 	nfs_increment_open_seqid(status, res->seqid);
5127 	if (status)
5128 		return status;
5129 	status = decode_open_stateid(xdr, &res->stateid);
5130 	if (unlikely(status))
5131 		return status;
5132 
5133 	decode_change_info(xdr, &res->cinfo);
5134 
5135 	p = xdr_inline_decode(xdr, 8);
5136 	if (unlikely(!p))
5137 		return -EIO;
5138 	res->rflags = be32_to_cpup(p++);
5139 	bmlen = be32_to_cpup(p);
5140 	if (bmlen > 10)
5141 		goto xdr_error;
5142 
5143 	p = xdr_inline_decode(xdr, bmlen << 2);
5144 	if (unlikely(!p))
5145 		return -EIO;
5146 	savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5147 	for (i = 0; i < savewords; ++i)
5148 		res->attrset[i] = be32_to_cpup(p++);
5149 	for (; i < NFS4_BITMAP_SIZE; i++)
5150 		res->attrset[i] = 0;
5151 
5152 	return decode_delegation(xdr, res);
5153 xdr_error:
5154 	dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
5155 	return -EIO;
5156 }
5157 
5158 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5159 {
5160 	int status;
5161 
5162 	status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5163 	if (status != -EIO)
5164 		nfs_increment_open_seqid(status, res->seqid);
5165 	if (!status)
5166 		status = decode_open_stateid(xdr, &res->stateid);
5167 	return status;
5168 }
5169 
5170 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5171 {
5172 	int status;
5173 
5174 	status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5175 	if (status != -EIO)
5176 		nfs_increment_open_seqid(status, res->seqid);
5177 	if (!status)
5178 		status = decode_open_stateid(xdr, &res->stateid);
5179 	return status;
5180 }
5181 
5182 static int decode_putfh(struct xdr_stream *xdr)
5183 {
5184 	return decode_op_hdr(xdr, OP_PUTFH);
5185 }
5186 
5187 static int decode_putrootfh(struct xdr_stream *xdr)
5188 {
5189 	return decode_op_hdr(xdr, OP_PUTROOTFH);
5190 }
5191 
5192 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5193 		       struct nfs_pgio_res *res)
5194 {
5195 	__be32 *p;
5196 	uint32_t count, eof, recvd;
5197 	int status;
5198 
5199 	status = decode_op_hdr(xdr, OP_READ);
5200 	if (status)
5201 		return status;
5202 	p = xdr_inline_decode(xdr, 8);
5203 	if (unlikely(!p))
5204 		return -EIO;
5205 	eof = be32_to_cpup(p++);
5206 	count = be32_to_cpup(p);
5207 	recvd = xdr_read_pages(xdr, count);
5208 	if (count > recvd) {
5209 		dprintk("NFS: server cheating in read reply: "
5210 				"count %u > recvd %u\n", count, recvd);
5211 		count = recvd;
5212 		eof = 0;
5213 	}
5214 	res->eof = eof;
5215 	res->count = count;
5216 	return 0;
5217 }
5218 
5219 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5220 {
5221 	int		status;
5222 	__be32		verf[2];
5223 
5224 	status = decode_op_hdr(xdr, OP_READDIR);
5225 	if (!status)
5226 		status = decode_verifier(xdr, readdir->verifier.data);
5227 	if (unlikely(status))
5228 		return status;
5229 	memcpy(verf, readdir->verifier.data, sizeof(verf));
5230 	dprintk("%s: verifier = %08x:%08x\n",
5231 			__func__, verf[0], verf[1]);
5232 	return xdr_read_pages(xdr, xdr->buf->page_len);
5233 }
5234 
5235 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5236 {
5237 	struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5238 	u32 len, recvd;
5239 	__be32 *p;
5240 	int status;
5241 
5242 	status = decode_op_hdr(xdr, OP_READLINK);
5243 	if (status)
5244 		return status;
5245 
5246 	/* Convert length of symlink */
5247 	p = xdr_inline_decode(xdr, 4);
5248 	if (unlikely(!p))
5249 		return -EIO;
5250 	len = be32_to_cpup(p);
5251 	if (len >= rcvbuf->page_len || len <= 0) {
5252 		dprintk("nfs: server returned giant symlink!\n");
5253 		return -ENAMETOOLONG;
5254 	}
5255 	recvd = xdr_read_pages(xdr, len);
5256 	if (recvd < len) {
5257 		dprintk("NFS: server cheating in readlink reply: "
5258 				"count %u > recvd %u\n", len, recvd);
5259 		return -EIO;
5260 	}
5261 	/*
5262 	 * The XDR encode routine has set things up so that
5263 	 * the link text will be copied directly into the
5264 	 * buffer.  We just have to do overflow-checking,
5265 	 * and null-terminate the text (the VFS expects
5266 	 * null-termination).
5267 	 */
5268 	xdr_terminate_string(rcvbuf, len);
5269 	return 0;
5270 }
5271 
5272 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5273 {
5274 	int status;
5275 
5276 	status = decode_op_hdr(xdr, OP_REMOVE);
5277 	if (status)
5278 		goto out;
5279 	status = decode_change_info(xdr, cinfo);
5280 out:
5281 	return status;
5282 }
5283 
5284 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5285 	      struct nfs4_change_info *new_cinfo)
5286 {
5287 	int status;
5288 
5289 	status = decode_op_hdr(xdr, OP_RENAME);
5290 	if (status)
5291 		goto out;
5292 	if ((status = decode_change_info(xdr, old_cinfo)))
5293 		goto out;
5294 	status = decode_change_info(xdr, new_cinfo);
5295 out:
5296 	return status;
5297 }
5298 
5299 static int decode_renew(struct xdr_stream *xdr)
5300 {
5301 	return decode_op_hdr(xdr, OP_RENEW);
5302 }
5303 
5304 static int
5305 decode_restorefh(struct xdr_stream *xdr)
5306 {
5307 	return decode_op_hdr(xdr, OP_RESTOREFH);
5308 }
5309 
5310 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5311 			 struct nfs_getaclres *res)
5312 {
5313 	unsigned int savep;
5314 	uint32_t attrlen,
5315 		 bitmap[3] = {0};
5316 	int status;
5317 
5318 	res->acl_len = 0;
5319 	if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5320 		goto out;
5321 
5322 	xdr_enter_page(xdr, xdr->buf->page_len);
5323 
5324 	if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5325 		goto out;
5326 	if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5327 		goto out;
5328 
5329 	if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5330 		return -EIO;
5331 	if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5332 
5333 		/* The bitmap (xdr len + bitmaps) and the attr xdr len words
5334 		 * are stored with the acl data to handle the problem of
5335 		 * variable length bitmaps.*/
5336 		res->acl_data_offset = xdr_page_pos(xdr);
5337 		res->acl_len = attrlen;
5338 
5339 		/* Check for receive buffer overflow */
5340 		if (res->acl_len > xdr_stream_remaining(xdr) ||
5341 		    res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5342 			res->acl_flags |= NFS4_ACL_TRUNC;
5343 			dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
5344 				attrlen, xdr_stream_remaining(xdr));
5345 		}
5346 	} else
5347 		status = -EOPNOTSUPP;
5348 
5349 out:
5350 	return status;
5351 }
5352 
5353 static int
5354 decode_savefh(struct xdr_stream *xdr)
5355 {
5356 	return decode_op_hdr(xdr, OP_SAVEFH);
5357 }
5358 
5359 static int decode_setattr(struct xdr_stream *xdr)
5360 {
5361 	int status;
5362 
5363 	status = decode_op_hdr(xdr, OP_SETATTR);
5364 	if (status)
5365 		return status;
5366 	if (decode_bitmap4(xdr, NULL, 0) >= 0)
5367 		return 0;
5368 	return -EIO;
5369 }
5370 
5371 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
5372 {
5373 	__be32 *p;
5374 	uint32_t opnum;
5375 	int32_t nfserr;
5376 
5377 	p = xdr_inline_decode(xdr, 8);
5378 	if (unlikely(!p))
5379 		return -EIO;
5380 	opnum = be32_to_cpup(p++);
5381 	if (opnum != OP_SETCLIENTID) {
5382 		dprintk("nfs: decode_setclientid: Server returned operation"
5383 			" %d\n", opnum);
5384 		return -EIO;
5385 	}
5386 	nfserr = be32_to_cpup(p);
5387 	if (nfserr == NFS_OK) {
5388 		p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5389 		if (unlikely(!p))
5390 			return -EIO;
5391 		p = xdr_decode_hyper(p, &res->clientid);
5392 		memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
5393 	} else if (nfserr == NFSERR_CLID_INUSE) {
5394 		uint32_t len;
5395 
5396 		/* skip netid string */
5397 		p = xdr_inline_decode(xdr, 4);
5398 		if (unlikely(!p))
5399 			return -EIO;
5400 		len = be32_to_cpup(p);
5401 		p = xdr_inline_decode(xdr, len);
5402 		if (unlikely(!p))
5403 			return -EIO;
5404 
5405 		/* skip uaddr string */
5406 		p = xdr_inline_decode(xdr, 4);
5407 		if (unlikely(!p))
5408 			return -EIO;
5409 		len = be32_to_cpup(p);
5410 		p = xdr_inline_decode(xdr, len);
5411 		if (unlikely(!p))
5412 			return -EIO;
5413 		return -NFSERR_CLID_INUSE;
5414 	} else
5415 		return nfs4_stat_to_errno(nfserr);
5416 
5417 	return 0;
5418 }
5419 
5420 static int decode_setclientid_confirm(struct xdr_stream *xdr)
5421 {
5422 	return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5423 }
5424 
5425 static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
5426 {
5427 	__be32 *p;
5428 	int status;
5429 
5430 	status = decode_op_hdr(xdr, OP_WRITE);
5431 	if (status)
5432 		return status;
5433 
5434 	p = xdr_inline_decode(xdr, 8);
5435 	if (unlikely(!p))
5436 		return -EIO;
5437 	res->count = be32_to_cpup(p++);
5438 	res->verf->committed = be32_to_cpup(p++);
5439 	return decode_write_verifier(xdr, &res->verf->verifier);
5440 }
5441 
5442 static int decode_delegreturn(struct xdr_stream *xdr)
5443 {
5444 	return decode_op_hdr(xdr, OP_DELEGRETURN);
5445 }
5446 
5447 static int decode_secinfo_gss(struct xdr_stream *xdr,
5448 			      struct nfs4_secinfo4 *flavor)
5449 {
5450 	u32 oid_len;
5451 	__be32 *p;
5452 
5453 	p = xdr_inline_decode(xdr, 4);
5454 	if (unlikely(!p))
5455 		return -EIO;
5456 	oid_len = be32_to_cpup(p);
5457 	if (oid_len > GSS_OID_MAX_LEN)
5458 		return -EINVAL;
5459 
5460 	p = xdr_inline_decode(xdr, oid_len);
5461 	if (unlikely(!p))
5462 		return -EIO;
5463 	memcpy(flavor->flavor_info.oid.data, p, oid_len);
5464 	flavor->flavor_info.oid.len = oid_len;
5465 
5466 	p = xdr_inline_decode(xdr, 8);
5467 	if (unlikely(!p))
5468 		return -EIO;
5469 	flavor->flavor_info.qop = be32_to_cpup(p++);
5470 	flavor->flavor_info.service = be32_to_cpup(p);
5471 
5472 	return 0;
5473 }
5474 
5475 static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5476 {
5477 	struct nfs4_secinfo4 *sec_flavor;
5478 	unsigned int i, num_flavors;
5479 	int status;
5480 	__be32 *p;
5481 
5482 	p = xdr_inline_decode(xdr, 4);
5483 	if (unlikely(!p))
5484 		return -EIO;
5485 
5486 	res->flavors->num_flavors = 0;
5487 	num_flavors = be32_to_cpup(p);
5488 
5489 	for (i = 0; i < num_flavors; i++) {
5490 		sec_flavor = &res->flavors->flavors[i];
5491 		if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5492 			break;
5493 
5494 		p = xdr_inline_decode(xdr, 4);
5495 		if (unlikely(!p))
5496 			return -EIO;
5497 		sec_flavor->flavor = be32_to_cpup(p);
5498 
5499 		if (sec_flavor->flavor == RPC_AUTH_GSS) {
5500 			status = decode_secinfo_gss(xdr, sec_flavor);
5501 			if (status)
5502 				goto out;
5503 		}
5504 		res->flavors->num_flavors++;
5505 	}
5506 
5507 	status = 0;
5508 out:
5509 	return status;
5510 }
5511 
5512 static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5513 {
5514 	int status = decode_op_hdr(xdr, OP_SECINFO);
5515 	if (status)
5516 		return status;
5517 	return decode_secinfo_common(xdr, res);
5518 }
5519 
5520 #if defined(CONFIG_NFS_V4_1)
5521 static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5522 {
5523 	int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5524 	if (status)
5525 		return status;
5526 	return decode_secinfo_common(xdr, res);
5527 }
5528 
5529 static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5530 {
5531 	__be32 *p;
5532 	uint32_t bitmap_words;
5533 	unsigned int i;
5534 
5535 	p = xdr_inline_decode(xdr, 4);
5536 	if (!p)
5537 		return -EIO;
5538 	bitmap_words = be32_to_cpup(p++);
5539 	if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5540 		return -EIO;
5541 	p = xdr_inline_decode(xdr, 4 * bitmap_words);
5542 	for (i = 0; i < bitmap_words; i++)
5543 		op_map->u.words[i] = be32_to_cpup(p++);
5544 
5545 	return 0;
5546 }
5547 
5548 static int decode_exchange_id(struct xdr_stream *xdr,
5549 			      struct nfs41_exchange_id_res *res)
5550 {
5551 	__be32 *p;
5552 	uint32_t dummy;
5553 	char *dummy_str;
5554 	int status;
5555 	uint32_t impl_id_count;
5556 
5557 	status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5558 	if (status)
5559 		return status;
5560 
5561 	p = xdr_inline_decode(xdr, 8);
5562 	if (unlikely(!p))
5563 		return -EIO;
5564 	xdr_decode_hyper(p, &res->clientid);
5565 	p = xdr_inline_decode(xdr, 12);
5566 	if (unlikely(!p))
5567 		return -EIO;
5568 	res->seqid = be32_to_cpup(p++);
5569 	res->flags = be32_to_cpup(p++);
5570 
5571 	res->state_protect.how = be32_to_cpup(p);
5572 	switch (res->state_protect.how) {
5573 	case SP4_NONE:
5574 		break;
5575 	case SP4_MACH_CRED:
5576 		status = decode_op_map(xdr, &res->state_protect.enforce);
5577 		if (status)
5578 			return status;
5579 		status = decode_op_map(xdr, &res->state_protect.allow);
5580 		if (status)
5581 			return status;
5582 		break;
5583 	default:
5584 		WARN_ON_ONCE(1);
5585 		return -EIO;
5586 	}
5587 
5588 	/* server_owner4.so_minor_id */
5589 	p = xdr_inline_decode(xdr, 8);
5590 	if (unlikely(!p))
5591 		return -EIO;
5592 	p = xdr_decode_hyper(p, &res->server_owner->minor_id);
5593 
5594 	/* server_owner4.so_major_id */
5595 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5596 	if (unlikely(status))
5597 		return status;
5598 	memcpy(res->server_owner->major_id, dummy_str, dummy);
5599 	res->server_owner->major_id_sz = dummy;
5600 
5601 	/* server_scope4 */
5602 	status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5603 	if (unlikely(status))
5604 		return status;
5605 	memcpy(res->server_scope->server_scope, dummy_str, dummy);
5606 	res->server_scope->server_scope_sz = dummy;
5607 
5608 	/* Implementation Id */
5609 	p = xdr_inline_decode(xdr, 4);
5610 	if (unlikely(!p))
5611 		return -EIO;
5612 	impl_id_count = be32_to_cpup(p++);
5613 
5614 	if (impl_id_count) {
5615 		/* nii_domain */
5616 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5617 		if (unlikely(status))
5618 			return status;
5619 		memcpy(res->impl_id->domain, dummy_str, dummy);
5620 
5621 		/* nii_name */
5622 		status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5623 		if (unlikely(status))
5624 			return status;
5625 		memcpy(res->impl_id->name, dummy_str, dummy);
5626 
5627 		/* nii_date */
5628 		p = xdr_inline_decode(xdr, 12);
5629 		if (unlikely(!p))
5630 			return -EIO;
5631 		p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5632 		res->impl_id->date.nseconds = be32_to_cpup(p);
5633 
5634 		/* if there's more than one entry, ignore the rest */
5635 	}
5636 	return 0;
5637 }
5638 
5639 static int decode_chan_attrs(struct xdr_stream *xdr,
5640 			     struct nfs4_channel_attrs *attrs)
5641 {
5642 	__be32 *p;
5643 	u32 nr_attrs, val;
5644 
5645 	p = xdr_inline_decode(xdr, 28);
5646 	if (unlikely(!p))
5647 		return -EIO;
5648 	val = be32_to_cpup(p++);	/* headerpadsz */
5649 	if (val)
5650 		return -EINVAL;		/* no support for header padding yet */
5651 	attrs->max_rqst_sz = be32_to_cpup(p++);
5652 	attrs->max_resp_sz = be32_to_cpup(p++);
5653 	attrs->max_resp_sz_cached = be32_to_cpup(p++);
5654 	attrs->max_ops = be32_to_cpup(p++);
5655 	attrs->max_reqs = be32_to_cpup(p++);
5656 	nr_attrs = be32_to_cpup(p);
5657 	if (unlikely(nr_attrs > 1)) {
5658 		printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5659 			"count %u\n", __func__, nr_attrs);
5660 		return -EINVAL;
5661 	}
5662 	if (nr_attrs == 1) {
5663 		p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5664 		if (unlikely(!p))
5665 			return -EIO;
5666 	}
5667 	return 0;
5668 }
5669 
5670 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5671 {
5672 	return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5673 }
5674 
5675 static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5676 				struct nfs41_bind_conn_to_session_res *res)
5677 {
5678 	__be32 *p;
5679 	int status;
5680 
5681 	status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5682 	if (!status)
5683 		status = decode_sessionid(xdr, &res->sessionid);
5684 	if (unlikely(status))
5685 		return status;
5686 
5687 	/* dir flags, rdma mode bool */
5688 	p = xdr_inline_decode(xdr, 8);
5689 	if (unlikely(!p))
5690 		return -EIO;
5691 
5692 	res->dir = be32_to_cpup(p++);
5693 	if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5694 		return -EIO;
5695 	if (be32_to_cpup(p) == 0)
5696 		res->use_conn_in_rdma_mode = false;
5697 	else
5698 		res->use_conn_in_rdma_mode = true;
5699 
5700 	return 0;
5701 }
5702 
5703 static int decode_create_session(struct xdr_stream *xdr,
5704 				 struct nfs41_create_session_res *res)
5705 {
5706 	__be32 *p;
5707 	int status;
5708 
5709 	status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5710 	if (!status)
5711 		status = decode_sessionid(xdr, &res->sessionid);
5712 	if (unlikely(status))
5713 		return status;
5714 
5715 	/* seqid, flags */
5716 	p = xdr_inline_decode(xdr, 8);
5717 	if (unlikely(!p))
5718 		return -EIO;
5719 	res->seqid = be32_to_cpup(p++);
5720 	res->flags = be32_to_cpup(p);
5721 
5722 	/* Channel attributes */
5723 	status = decode_chan_attrs(xdr, &res->fc_attrs);
5724 	if (!status)
5725 		status = decode_chan_attrs(xdr, &res->bc_attrs);
5726 	return status;
5727 }
5728 
5729 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5730 {
5731 	return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5732 }
5733 
5734 static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5735 {
5736 	return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5737 }
5738 
5739 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5740 {
5741 	return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5742 }
5743 #endif /* CONFIG_NFS_V4_1 */
5744 
5745 static int decode_sequence(struct xdr_stream *xdr,
5746 			   struct nfs4_sequence_res *res,
5747 			   struct rpc_rqst *rqstp)
5748 {
5749 #if defined(CONFIG_NFS_V4_1)
5750 	struct nfs4_session *session;
5751 	struct nfs4_sessionid id;
5752 	u32 dummy;
5753 	int status;
5754 	__be32 *p;
5755 
5756 	if (res->sr_slot == NULL)
5757 		return 0;
5758 	if (!res->sr_slot->table->session)
5759 		return 0;
5760 
5761 	status = decode_op_hdr(xdr, OP_SEQUENCE);
5762 	if (!status)
5763 		status = decode_sessionid(xdr, &id);
5764 	if (unlikely(status))
5765 		goto out_err;
5766 
5767 	/*
5768 	 * If the server returns different values for sessionID, slotID or
5769 	 * sequence number, the server is looney tunes.
5770 	 */
5771 	status = -EREMOTEIO;
5772 	session = res->sr_slot->table->session;
5773 
5774 	if (memcmp(id.data, session->sess_id.data,
5775 		   NFS4_MAX_SESSIONID_LEN)) {
5776 		dprintk("%s Invalid session id\n", __func__);
5777 		goto out_err;
5778 	}
5779 
5780 	p = xdr_inline_decode(xdr, 20);
5781 	if (unlikely(!p))
5782 		goto out_overflow;
5783 
5784 	/* seqid */
5785 	dummy = be32_to_cpup(p++);
5786 	if (dummy != res->sr_slot->seq_nr) {
5787 		dprintk("%s Invalid sequence number\n", __func__);
5788 		goto out_err;
5789 	}
5790 	/* slot id */
5791 	dummy = be32_to_cpup(p++);
5792 	if (dummy != res->sr_slot->slot_nr) {
5793 		dprintk("%s Invalid slot id\n", __func__);
5794 		goto out_err;
5795 	}
5796 	/* highest slot id */
5797 	res->sr_highest_slotid = be32_to_cpup(p++);
5798 	/* target highest slot id */
5799 	res->sr_target_highest_slotid = be32_to_cpup(p++);
5800 	/* result flags */
5801 	res->sr_status_flags = be32_to_cpup(p);
5802 	status = 0;
5803 out_err:
5804 	res->sr_status = status;
5805 	return status;
5806 out_overflow:
5807 	status = -EIO;
5808 	goto out_err;
5809 #else  /* CONFIG_NFS_V4_1 */
5810 	return 0;
5811 #endif /* CONFIG_NFS_V4_1 */
5812 }
5813 
5814 #if defined(CONFIG_NFS_V4_1)
5815 static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5816 {
5817 	stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5818 	return decode_stateid(xdr, stateid);
5819 }
5820 
5821 static int decode_getdeviceinfo(struct xdr_stream *xdr,
5822 				struct nfs4_getdeviceinfo_res *res)
5823 {
5824 	struct pnfs_device *pdev = res->pdev;
5825 	__be32 *p;
5826 	uint32_t len, type;
5827 	int status;
5828 
5829 	status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5830 	if (status) {
5831 		if (status == -ETOOSMALL) {
5832 			p = xdr_inline_decode(xdr, 4);
5833 			if (unlikely(!p))
5834 				return -EIO;
5835 			pdev->mincount = be32_to_cpup(p);
5836 			dprintk("%s: Min count too small. mincnt = %u\n",
5837 				__func__, pdev->mincount);
5838 		}
5839 		return status;
5840 	}
5841 
5842 	p = xdr_inline_decode(xdr, 8);
5843 	if (unlikely(!p))
5844 		return -EIO;
5845 	type = be32_to_cpup(p++);
5846 	if (type != pdev->layout_type) {
5847 		dprintk("%s: layout mismatch req: %u pdev: %u\n",
5848 			__func__, pdev->layout_type, type);
5849 		return -EINVAL;
5850 	}
5851 	/*
5852 	 * Get the length of the opaque device_addr4. xdr_read_pages places
5853 	 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5854 	 * and places the remaining xdr data in xdr_buf->tail
5855 	 */
5856 	pdev->mincount = be32_to_cpup(p);
5857 	if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5858 		return -EIO;
5859 
5860 	/* Parse notification bitmap, verifying that it is zero. */
5861 	p = xdr_inline_decode(xdr, 4);
5862 	if (unlikely(!p))
5863 		return -EIO;
5864 	len = be32_to_cpup(p);
5865 	if (len) {
5866 		uint32_t i;
5867 
5868 		p = xdr_inline_decode(xdr, 4 * len);
5869 		if (unlikely(!p))
5870 			return -EIO;
5871 
5872 		res->notification = be32_to_cpup(p++);
5873 		for (i = 1; i < len; i++) {
5874 			if (be32_to_cpup(p++)) {
5875 				dprintk("%s: unsupported notification\n",
5876 					__func__);
5877 				return -EIO;
5878 			}
5879 		}
5880 	}
5881 	return 0;
5882 }
5883 
5884 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5885 			    struct nfs4_layoutget_res *res)
5886 {
5887 	__be32 *p;
5888 	int status;
5889 	u32 layout_count;
5890 	u32 recvd;
5891 
5892 	status = decode_op_hdr(xdr, OP_LAYOUTGET);
5893 	if (status)
5894 		goto out;
5895 	p = xdr_inline_decode(xdr, 4);
5896 	if (unlikely(!p))
5897 		goto out_overflow;
5898 	res->return_on_close = be32_to_cpup(p);
5899 	decode_layout_stateid(xdr, &res->stateid);
5900 	p = xdr_inline_decode(xdr, 4);
5901 	if (unlikely(!p))
5902 		goto out_overflow;
5903 	layout_count = be32_to_cpup(p);
5904 	if (!layout_count) {
5905 		dprintk("%s: server responded with empty layout array\n",
5906 			__func__);
5907 		status = -EINVAL;
5908 		goto out;
5909 	}
5910 
5911 	p = xdr_inline_decode(xdr, 28);
5912 	if (unlikely(!p))
5913 		goto out_overflow;
5914 	p = xdr_decode_hyper(p, &res->range.offset);
5915 	p = xdr_decode_hyper(p, &res->range.length);
5916 	res->range.iomode = be32_to_cpup(p++);
5917 	res->type = be32_to_cpup(p++);
5918 	res->layoutp->len = be32_to_cpup(p);
5919 
5920 	dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5921 		__func__,
5922 		(unsigned long)res->range.offset,
5923 		(unsigned long)res->range.length,
5924 		res->range.iomode,
5925 		res->type,
5926 		res->layoutp->len);
5927 
5928 	recvd = xdr_read_pages(xdr, res->layoutp->len);
5929 	if (res->layoutp->len > recvd) {
5930 		dprintk("NFS: server cheating in layoutget reply: "
5931 				"layout len %u > recvd %u\n",
5932 				res->layoutp->len, recvd);
5933 		status = -EINVAL;
5934 		goto out;
5935 	}
5936 
5937 	if (layout_count > 1) {
5938 		/* We only handle a length one array at the moment.  Any
5939 		 * further entries are just ignored.  Note that this means
5940 		 * the client may see a response that is less than the
5941 		 * minimum it requested.
5942 		 */
5943 		dprintk("%s: server responded with %d layouts, dropping tail\n",
5944 			__func__, layout_count);
5945 	}
5946 
5947 out:
5948 	res->status = status;
5949 	return status;
5950 out_overflow:
5951 	status = -EIO;
5952 	goto out;
5953 }
5954 
5955 static int decode_layoutreturn(struct xdr_stream *xdr,
5956 			       struct nfs4_layoutreturn_res *res)
5957 {
5958 	__be32 *p;
5959 	int status;
5960 
5961 	status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5962 	if (status)
5963 		return status;
5964 	p = xdr_inline_decode(xdr, 4);
5965 	if (unlikely(!p))
5966 		return -EIO;
5967 	res->lrs_present = be32_to_cpup(p);
5968 	if (res->lrs_present)
5969 		status = decode_layout_stateid(xdr, &res->stateid);
5970 	else
5971 		nfs4_stateid_copy(&res->stateid, &invalid_stateid);
5972 	return status;
5973 }
5974 
5975 static int decode_layoutcommit(struct xdr_stream *xdr,
5976 			       struct rpc_rqst *req,
5977 			       struct nfs4_layoutcommit_res *res)
5978 {
5979 	__be32 *p;
5980 	__u32 sizechanged;
5981 	int status;
5982 
5983 	status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5984 	res->status = status;
5985 	if (status)
5986 		return status;
5987 
5988 	p = xdr_inline_decode(xdr, 4);
5989 	if (unlikely(!p))
5990 		return -EIO;
5991 	sizechanged = be32_to_cpup(p);
5992 
5993 	if (sizechanged) {
5994 		/* throw away new size */
5995 		p = xdr_inline_decode(xdr, 8);
5996 		if (unlikely(!p))
5997 			return -EIO;
5998 	}
5999 	return 0;
6000 }
6001 
6002 static int decode_test_stateid(struct xdr_stream *xdr,
6003 			       struct nfs41_test_stateid_res *res)
6004 {
6005 	__be32 *p;
6006 	int status;
6007 	int num_res;
6008 
6009 	status = decode_op_hdr(xdr, OP_TEST_STATEID);
6010 	if (status)
6011 		return status;
6012 
6013 	p = xdr_inline_decode(xdr, 4);
6014 	if (unlikely(!p))
6015 		return -EIO;
6016 	num_res = be32_to_cpup(p++);
6017 	if (num_res != 1)
6018 		return -EIO;
6019 
6020 	p = xdr_inline_decode(xdr, 4);
6021 	if (unlikely(!p))
6022 		return -EIO;
6023 	res->status = be32_to_cpup(p++);
6024 
6025 	return status;
6026 }
6027 
6028 static int decode_free_stateid(struct xdr_stream *xdr,
6029 			       struct nfs41_free_stateid_res *res)
6030 {
6031 	res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
6032 	return res->status;
6033 }
6034 #else
6035 static inline
6036 int decode_layoutreturn(struct xdr_stream *xdr,
6037 			       struct nfs4_layoutreturn_res *res)
6038 {
6039 	return 0;
6040 }
6041 
6042 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6043 			    struct nfs4_layoutget_res *res)
6044 {
6045 	return 0;
6046 }
6047 
6048 #endif /* CONFIG_NFS_V4_1 */
6049 
6050 /*
6051  * END OF "GENERIC" DECODE ROUTINES.
6052  */
6053 
6054 /*
6055  * Decode OPEN_DOWNGRADE response
6056  */
6057 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6058 				       struct xdr_stream *xdr,
6059 				       void *data)
6060 {
6061 	struct nfs_closeres *res = data;
6062 	struct compound_hdr hdr;
6063 	int status;
6064 
6065 	status = decode_compound_hdr(xdr, &hdr);
6066 	if (status)
6067 		goto out;
6068 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6069 	if (status)
6070 		goto out;
6071 	status = decode_putfh(xdr);
6072 	if (status)
6073 		goto out;
6074 	if (res->lr_res) {
6075 		status = decode_layoutreturn(xdr, res->lr_res);
6076 		res->lr_ret = status;
6077 		if (status)
6078 			goto out;
6079 	}
6080 	status = decode_open_downgrade(xdr, res);
6081 out:
6082 	return status;
6083 }
6084 
6085 /*
6086  * Decode ACCESS response
6087  */
6088 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6089 			       void *data)
6090 {
6091 	struct nfs4_accessres *res = data;
6092 	struct compound_hdr hdr;
6093 	int status;
6094 
6095 	status = decode_compound_hdr(xdr, &hdr);
6096 	if (status)
6097 		goto out;
6098 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6099 	if (status)
6100 		goto out;
6101 	status = decode_putfh(xdr);
6102 	if (status != 0)
6103 		goto out;
6104 	status = decode_access(xdr, &res->supported, &res->access);
6105 	if (status != 0)
6106 		goto out;
6107 	if (res->fattr)
6108 		decode_getfattr(xdr, res->fattr, res->server);
6109 out:
6110 	return status;
6111 }
6112 
6113 /*
6114  * Decode LOOKUP response
6115  */
6116 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6117 			       void *data)
6118 {
6119 	struct nfs4_lookup_res *res = data;
6120 	struct compound_hdr hdr;
6121 	int status;
6122 
6123 	status = decode_compound_hdr(xdr, &hdr);
6124 	if (status)
6125 		goto out;
6126 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6127 	if (status)
6128 		goto out;
6129 	status = decode_putfh(xdr);
6130 	if (status)
6131 		goto out;
6132 	status = decode_lookup(xdr);
6133 	if (status)
6134 		goto out;
6135 	status = decode_getfh(xdr, res->fh);
6136 	if (status)
6137 		goto out;
6138 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6139 out:
6140 	return status;
6141 }
6142 
6143 /*
6144  * Decode LOOKUPP response
6145  */
6146 static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6147 		void *data)
6148 {
6149 	struct nfs4_lookupp_res *res = data;
6150 	struct compound_hdr hdr;
6151 	int status;
6152 
6153 	status = decode_compound_hdr(xdr, &hdr);
6154 	if (status)
6155 		goto out;
6156 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6157 	if (status)
6158 		goto out;
6159 	status = decode_putfh(xdr);
6160 	if (status)
6161 		goto out;
6162 	status = decode_lookupp(xdr);
6163 	if (status)
6164 		goto out;
6165 	status = decode_getfh(xdr, res->fh);
6166 	if (status)
6167 		goto out;
6168 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6169 out:
6170 	return status;
6171 }
6172 
6173 /*
6174  * Decode LOOKUP_ROOT response
6175  */
6176 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6177 				    struct xdr_stream *xdr,
6178 				    void *data)
6179 {
6180 	struct nfs4_lookup_res *res = data;
6181 	struct compound_hdr hdr;
6182 	int status;
6183 
6184 	status = decode_compound_hdr(xdr, &hdr);
6185 	if (status)
6186 		goto out;
6187 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6188 	if (status)
6189 		goto out;
6190 	status = decode_putrootfh(xdr);
6191 	if (status)
6192 		goto out;
6193 	status = decode_getfh(xdr, res->fh);
6194 	if (status == 0)
6195 		status = decode_getfattr_label(xdr, res->fattr,
6196 						res->label, res->server);
6197 out:
6198 	return status;
6199 }
6200 
6201 /*
6202  * Decode REMOVE response
6203  */
6204 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6205 			       void *data)
6206 {
6207 	struct nfs_removeres *res = data;
6208 	struct compound_hdr hdr;
6209 	int status;
6210 
6211 	status = decode_compound_hdr(xdr, &hdr);
6212 	if (status)
6213 		goto out;
6214 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6215 	if (status)
6216 		goto out;
6217 	status = decode_putfh(xdr);
6218 	if (status)
6219 		goto out;
6220 	status = decode_remove(xdr, &res->cinfo);
6221 out:
6222 	return status;
6223 }
6224 
6225 /*
6226  * Decode RENAME response
6227  */
6228 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6229 			       void *data)
6230 {
6231 	struct nfs_renameres *res = data;
6232 	struct compound_hdr hdr;
6233 	int status;
6234 
6235 	status = decode_compound_hdr(xdr, &hdr);
6236 	if (status)
6237 		goto out;
6238 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6239 	if (status)
6240 		goto out;
6241 	status = decode_putfh(xdr);
6242 	if (status)
6243 		goto out;
6244 	status = decode_savefh(xdr);
6245 	if (status)
6246 		goto out;
6247 	status = decode_putfh(xdr);
6248 	if (status)
6249 		goto out;
6250 	status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
6251 out:
6252 	return status;
6253 }
6254 
6255 /*
6256  * Decode LINK response
6257  */
6258 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6259 			     void *data)
6260 {
6261 	struct nfs4_link_res *res = data;
6262 	struct compound_hdr hdr;
6263 	int status;
6264 
6265 	status = decode_compound_hdr(xdr, &hdr);
6266 	if (status)
6267 		goto out;
6268 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6269 	if (status)
6270 		goto out;
6271 	status = decode_putfh(xdr);
6272 	if (status)
6273 		goto out;
6274 	status = decode_savefh(xdr);
6275 	if (status)
6276 		goto out;
6277 	status = decode_putfh(xdr);
6278 	if (status)
6279 		goto out;
6280 	status = decode_link(xdr, &res->cinfo);
6281 	if (status)
6282 		goto out;
6283 	/*
6284 	 * Note order: OP_LINK leaves the directory as the current
6285 	 *             filehandle.
6286 	 */
6287 	status = decode_restorefh(xdr);
6288 	if (status)
6289 		goto out;
6290 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6291 out:
6292 	return status;
6293 }
6294 
6295 /*
6296  * Decode CREATE response
6297  */
6298 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6299 			       void *data)
6300 {
6301 	struct nfs4_create_res *res = data;
6302 	struct compound_hdr hdr;
6303 	int status;
6304 
6305 	status = decode_compound_hdr(xdr, &hdr);
6306 	if (status)
6307 		goto out;
6308 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6309 	if (status)
6310 		goto out;
6311 	status = decode_putfh(xdr);
6312 	if (status)
6313 		goto out;
6314 	status = decode_create(xdr, &res->dir_cinfo);
6315 	if (status)
6316 		goto out;
6317 	status = decode_getfh(xdr, res->fh);
6318 	if (status)
6319 		goto out;
6320 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6321 out:
6322 	return status;
6323 }
6324 
6325 /*
6326  * Decode SYMLINK response
6327  */
6328 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6329 				void *res)
6330 {
6331 	return nfs4_xdr_dec_create(rqstp, xdr, res);
6332 }
6333 
6334 /*
6335  * Decode GETATTR response
6336  */
6337 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6338 				void *data)
6339 {
6340 	struct nfs4_getattr_res *res = data;
6341 	struct compound_hdr hdr;
6342 	int status;
6343 
6344 	status = decode_compound_hdr(xdr, &hdr);
6345 	if (status)
6346 		goto out;
6347 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6348 	if (status)
6349 		goto out;
6350 	status = decode_putfh(xdr);
6351 	if (status)
6352 		goto out;
6353 	status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6354 out:
6355 	return status;
6356 }
6357 
6358 /*
6359  * Encode an SETACL request
6360  */
6361 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6362 				const void *data)
6363 {
6364 	const struct nfs_setaclargs *args = data;
6365 	struct compound_hdr hdr = {
6366 		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
6367 	};
6368 
6369 	encode_compound_hdr(xdr, req, &hdr);
6370 	encode_sequence(xdr, &args->seq_args, &hdr);
6371 	encode_putfh(xdr, args->fh, &hdr);
6372 	encode_setacl(xdr, args, &hdr);
6373 	encode_nops(&hdr);
6374 }
6375 
6376 /*
6377  * Decode SETACL response
6378  */
6379 static int
6380 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6381 		    void *data)
6382 {
6383 	struct nfs_setaclres *res = data;
6384 	struct compound_hdr hdr;
6385 	int status;
6386 
6387 	status = decode_compound_hdr(xdr, &hdr);
6388 	if (status)
6389 		goto out;
6390 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6391 	if (status)
6392 		goto out;
6393 	status = decode_putfh(xdr);
6394 	if (status)
6395 		goto out;
6396 	status = decode_setattr(xdr);
6397 out:
6398 	return status;
6399 }
6400 
6401 /*
6402  * Decode GETACL response
6403  */
6404 static int
6405 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6406 		    void *data)
6407 {
6408 	struct nfs_getaclres *res = data;
6409 	struct compound_hdr hdr;
6410 	int status;
6411 
6412 	if (res->acl_scratch != NULL)
6413 		xdr_set_scratch_page(xdr, res->acl_scratch);
6414 	status = decode_compound_hdr(xdr, &hdr);
6415 	if (status)
6416 		goto out;
6417 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6418 	if (status)
6419 		goto out;
6420 	status = decode_putfh(xdr);
6421 	if (status)
6422 		goto out;
6423 	status = decode_getacl(xdr, rqstp, res);
6424 
6425 out:
6426 	return status;
6427 }
6428 
6429 /*
6430  * Decode CLOSE response
6431  */
6432 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6433 			      void *data)
6434 {
6435 	struct nfs_closeres *res = data;
6436 	struct compound_hdr hdr;
6437 	int status;
6438 
6439 	status = decode_compound_hdr(xdr, &hdr);
6440 	if (status)
6441 		goto out;
6442 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6443 	if (status)
6444 		goto out;
6445 	status = decode_putfh(xdr);
6446 	if (status)
6447 		goto out;
6448 	if (res->lr_res) {
6449 		status = decode_layoutreturn(xdr, res->lr_res);
6450 		res->lr_ret = status;
6451 		if (status)
6452 			goto out;
6453 	}
6454 	if (res->fattr != NULL) {
6455 		status = decode_getfattr(xdr, res->fattr, res->server);
6456 		if (status != 0)
6457 			goto out;
6458 	}
6459 	status = decode_close(xdr, res);
6460 out:
6461 	return status;
6462 }
6463 
6464 /*
6465  * Decode OPEN response
6466  */
6467 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6468 			     void *data)
6469 {
6470 	struct nfs_openres *res = data;
6471 	struct compound_hdr hdr;
6472 	int status;
6473 
6474 	status = decode_compound_hdr(xdr, &hdr);
6475 	if (status)
6476 		goto out;
6477 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6478 	if (status)
6479 		goto out;
6480 	status = decode_putfh(xdr);
6481 	if (status)
6482 		goto out;
6483 	status = decode_open(xdr, res);
6484 	if (status)
6485 		goto out;
6486 	status = decode_getfh(xdr, &res->fh);
6487 	if (status)
6488 		goto out;
6489 	if (res->access_request)
6490 		decode_access(xdr, &res->access_supported, &res->access_result);
6491 	decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
6492 	if (res->lg_res)
6493 		decode_layoutget(xdr, rqstp, res->lg_res);
6494 out:
6495 	return status;
6496 }
6497 
6498 /*
6499  * Decode OPEN_CONFIRM response
6500  */
6501 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6502 				     struct xdr_stream *xdr,
6503 				     void *data)
6504 {
6505 	struct nfs_open_confirmres *res = data;
6506 	struct compound_hdr hdr;
6507 	int status;
6508 
6509 	status = decode_compound_hdr(xdr, &hdr);
6510 	if (status)
6511 		goto out;
6512 	status = decode_putfh(xdr);
6513 	if (status)
6514 		goto out;
6515 	status = decode_open_confirm(xdr, res);
6516 out:
6517 	return status;
6518 }
6519 
6520 /*
6521  * Decode OPEN response
6522  */
6523 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6524 				    struct xdr_stream *xdr,
6525 				    void *data)
6526 {
6527 	struct nfs_openres *res = data;
6528 	struct compound_hdr hdr;
6529 	int status;
6530 
6531 	status = decode_compound_hdr(xdr, &hdr);
6532 	if (status)
6533 		goto out;
6534 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6535 	if (status)
6536 		goto out;
6537 	status = decode_putfh(xdr);
6538 	if (status)
6539 		goto out;
6540 	status = decode_open(xdr, res);
6541 	if (status)
6542 		goto out;
6543 	if (res->access_request)
6544 		decode_access(xdr, &res->access_supported, &res->access_result);
6545 	decode_getfattr(xdr, res->f_attr, res->server);
6546 	if (res->lg_res)
6547 		decode_layoutget(xdr, rqstp, res->lg_res);
6548 out:
6549 	return status;
6550 }
6551 
6552 /*
6553  * Decode SETATTR response
6554  */
6555 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6556 				struct xdr_stream *xdr,
6557 				void *data)
6558 {
6559 	struct nfs_setattrres *res = data;
6560 	struct compound_hdr hdr;
6561 	int status;
6562 
6563 	status = decode_compound_hdr(xdr, &hdr);
6564 	if (status)
6565 		goto out;
6566 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6567 	if (status)
6568 		goto out;
6569 	status = decode_putfh(xdr);
6570 	if (status)
6571 		goto out;
6572 	status = decode_setattr(xdr);
6573 	if (status)
6574 		goto out;
6575 	decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6576 out:
6577 	return status;
6578 }
6579 
6580 /*
6581  * Decode LOCK response
6582  */
6583 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6584 			     void *data)
6585 {
6586 	struct nfs_lock_res *res = data;
6587 	struct compound_hdr hdr;
6588 	int status;
6589 
6590 	status = decode_compound_hdr(xdr, &hdr);
6591 	if (status)
6592 		goto out;
6593 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6594 	if (status)
6595 		goto out;
6596 	status = decode_putfh(xdr);
6597 	if (status)
6598 		goto out;
6599 	status = decode_lock(xdr, res);
6600 out:
6601 	return status;
6602 }
6603 
6604 /*
6605  * Decode LOCKT response
6606  */
6607 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6608 			      void *data)
6609 {
6610 	struct nfs_lockt_res *res = data;
6611 	struct compound_hdr hdr;
6612 	int status;
6613 
6614 	status = decode_compound_hdr(xdr, &hdr);
6615 	if (status)
6616 		goto out;
6617 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6618 	if (status)
6619 		goto out;
6620 	status = decode_putfh(xdr);
6621 	if (status)
6622 		goto out;
6623 	status = decode_lockt(xdr, res);
6624 out:
6625 	return status;
6626 }
6627 
6628 /*
6629  * Decode LOCKU response
6630  */
6631 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6632 			      void *data)
6633 {
6634 	struct nfs_locku_res *res = data;
6635 	struct compound_hdr hdr;
6636 	int status;
6637 
6638 	status = decode_compound_hdr(xdr, &hdr);
6639 	if (status)
6640 		goto out;
6641 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6642 	if (status)
6643 		goto out;
6644 	status = decode_putfh(xdr);
6645 	if (status)
6646 		goto out;
6647 	status = decode_locku(xdr, res);
6648 out:
6649 	return status;
6650 }
6651 
6652 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6653 					  struct xdr_stream *xdr, void *dummy)
6654 {
6655 	struct compound_hdr hdr;
6656 	int status;
6657 
6658 	status = decode_compound_hdr(xdr, &hdr);
6659 	if (!status)
6660 		status = decode_release_lockowner(xdr);
6661 	return status;
6662 }
6663 
6664 /*
6665  * Decode READLINK response
6666  */
6667 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6668 				 struct xdr_stream *xdr,
6669 				 void *data)
6670 {
6671 	struct nfs4_readlink_res *res = data;
6672 	struct compound_hdr hdr;
6673 	int status;
6674 
6675 	status = decode_compound_hdr(xdr, &hdr);
6676 	if (status)
6677 		goto out;
6678 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6679 	if (status)
6680 		goto out;
6681 	status = decode_putfh(xdr);
6682 	if (status)
6683 		goto out;
6684 	status = decode_readlink(xdr, rqstp);
6685 out:
6686 	return status;
6687 }
6688 
6689 /*
6690  * Decode READDIR response
6691  */
6692 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6693 				void *data)
6694 {
6695 	struct nfs4_readdir_res *res = data;
6696 	struct compound_hdr hdr;
6697 	int status;
6698 
6699 	status = decode_compound_hdr(xdr, &hdr);
6700 	if (status)
6701 		goto out;
6702 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6703 	if (status)
6704 		goto out;
6705 	status = decode_putfh(xdr);
6706 	if (status)
6707 		goto out;
6708 	status = decode_readdir(xdr, rqstp, res);
6709 out:
6710 	return status;
6711 }
6712 
6713 /*
6714  * Decode Read response
6715  */
6716 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6717 			     void *data)
6718 {
6719 	struct nfs_pgio_res *res = data;
6720 	struct compound_hdr hdr;
6721 	int status;
6722 
6723 	status = decode_compound_hdr(xdr, &hdr);
6724 	res->op_status = hdr.status;
6725 	if (status)
6726 		goto out;
6727 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6728 	if (status)
6729 		goto out;
6730 	status = decode_putfh(xdr);
6731 	if (status)
6732 		goto out;
6733 	status = decode_read(xdr, rqstp, res);
6734 	if (!status)
6735 		status = res->count;
6736 out:
6737 	return status;
6738 }
6739 
6740 /*
6741  * Decode WRITE response
6742  */
6743 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6744 			      void *data)
6745 {
6746 	struct nfs_pgio_res *res = data;
6747 	struct compound_hdr hdr;
6748 	int status;
6749 
6750 	status = decode_compound_hdr(xdr, &hdr);
6751 	res->op_status = hdr.status;
6752 	if (status)
6753 		goto out;
6754 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6755 	if (status)
6756 		goto out;
6757 	status = decode_putfh(xdr);
6758 	if (status)
6759 		goto out;
6760 	status = decode_write(xdr, res);
6761 	if (status)
6762 		goto out;
6763 	if (res->fattr)
6764 		decode_getfattr(xdr, res->fattr, res->server);
6765 	if (!status)
6766 		status = res->count;
6767 out:
6768 	return status;
6769 }
6770 
6771 /*
6772  * Decode COMMIT response
6773  */
6774 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6775 			       void *data)
6776 {
6777 	struct nfs_commitres *res = data;
6778 	struct compound_hdr hdr;
6779 	int status;
6780 
6781 	status = decode_compound_hdr(xdr, &hdr);
6782 	res->op_status = hdr.status;
6783 	if (status)
6784 		goto out;
6785 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6786 	if (status)
6787 		goto out;
6788 	status = decode_putfh(xdr);
6789 	if (status)
6790 		goto out;
6791 	status = decode_commit(xdr, res);
6792 out:
6793 	return status;
6794 }
6795 
6796 /*
6797  * Decode FSINFO response
6798  */
6799 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6800 			       void *data)
6801 {
6802 	struct nfs4_fsinfo_res *res = data;
6803 	struct compound_hdr hdr;
6804 	int status;
6805 
6806 	status = decode_compound_hdr(xdr, &hdr);
6807 	if (!status)
6808 		status = decode_sequence(xdr, &res->seq_res, req);
6809 	if (!status)
6810 		status = decode_putfh(xdr);
6811 	if (!status)
6812 		status = decode_fsinfo(xdr, res->fsinfo);
6813 	return status;
6814 }
6815 
6816 /*
6817  * Decode PATHCONF response
6818  */
6819 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6820 				 void *data)
6821 {
6822 	struct nfs4_pathconf_res *res = data;
6823 	struct compound_hdr hdr;
6824 	int status;
6825 
6826 	status = decode_compound_hdr(xdr, &hdr);
6827 	if (!status)
6828 		status = decode_sequence(xdr, &res->seq_res, req);
6829 	if (!status)
6830 		status = decode_putfh(xdr);
6831 	if (!status)
6832 		status = decode_pathconf(xdr, res->pathconf);
6833 	return status;
6834 }
6835 
6836 /*
6837  * Decode STATFS response
6838  */
6839 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6840 			       void *data)
6841 {
6842 	struct nfs4_statfs_res *res = data;
6843 	struct compound_hdr hdr;
6844 	int status;
6845 
6846 	status = decode_compound_hdr(xdr, &hdr);
6847 	if (!status)
6848 		status = decode_sequence(xdr, &res->seq_res, req);
6849 	if (!status)
6850 		status = decode_putfh(xdr);
6851 	if (!status)
6852 		status = decode_statfs(xdr, res->fsstat);
6853 	return status;
6854 }
6855 
6856 /*
6857  * Decode GETATTR_BITMAP response
6858  */
6859 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6860 				    struct xdr_stream *xdr,
6861 				    void *data)
6862 {
6863 	struct nfs4_server_caps_res *res = data;
6864 	struct compound_hdr hdr;
6865 	int status;
6866 
6867 	status = decode_compound_hdr(xdr, &hdr);
6868 	if (status)
6869 		goto out;
6870 	status = decode_sequence(xdr, &res->seq_res, req);
6871 	if (status)
6872 		goto out;
6873 	status = decode_putfh(xdr);
6874 	if (status)
6875 		goto out;
6876 	status = decode_server_caps(xdr, res);
6877 out:
6878 	return status;
6879 }
6880 
6881 /*
6882  * Decode RENEW response
6883  */
6884 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6885 			      void *__unused)
6886 {
6887 	struct compound_hdr hdr;
6888 	int status;
6889 
6890 	status = decode_compound_hdr(xdr, &hdr);
6891 	if (!status)
6892 		status = decode_renew(xdr);
6893 	return status;
6894 }
6895 
6896 /*
6897  * Decode SETCLIENTID response
6898  */
6899 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6900 				    struct xdr_stream *xdr,
6901 				    void *data)
6902 {
6903 	struct nfs4_setclientid_res *res = data;
6904 	struct compound_hdr hdr;
6905 	int status;
6906 
6907 	status = decode_compound_hdr(xdr, &hdr);
6908 	if (!status)
6909 		status = decode_setclientid(xdr, res);
6910 	return status;
6911 }
6912 
6913 /*
6914  * Decode SETCLIENTID_CONFIRM response
6915  */
6916 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6917 					    struct xdr_stream *xdr,
6918 					    void *data)
6919 {
6920 	struct compound_hdr hdr;
6921 	int status;
6922 
6923 	status = decode_compound_hdr(xdr, &hdr);
6924 	if (!status)
6925 		status = decode_setclientid_confirm(xdr);
6926 	return status;
6927 }
6928 
6929 /*
6930  * Decode DELEGRETURN response
6931  */
6932 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6933 				    struct xdr_stream *xdr,
6934 				    void *data)
6935 {
6936 	struct nfs4_delegreturnres *res = data;
6937 	struct compound_hdr hdr;
6938 	int status;
6939 
6940 	status = decode_compound_hdr(xdr, &hdr);
6941 	if (status)
6942 		goto out;
6943 	status = decode_sequence(xdr, &res->seq_res, rqstp);
6944 	if (status)
6945 		goto out;
6946 	status = decode_putfh(xdr);
6947 	if (status != 0)
6948 		goto out;
6949 	if (res->lr_res) {
6950 		status = decode_layoutreturn(xdr, res->lr_res);
6951 		res->lr_ret = status;
6952 		if (status)
6953 			goto out;
6954 	}
6955 	if (res->fattr) {
6956 		status = decode_getfattr(xdr, res->fattr, res->server);
6957 		if (status != 0)
6958 			goto out;
6959 	}
6960 	status = decode_delegreturn(xdr);
6961 out:
6962 	return status;
6963 }
6964 
6965 /*
6966  * Decode FS_LOCATIONS response
6967  */
6968 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6969 				     struct xdr_stream *xdr,
6970 				     void *data)
6971 {
6972 	struct nfs4_fs_locations_res *res = data;
6973 	struct compound_hdr hdr;
6974 	int status;
6975 
6976 	status = decode_compound_hdr(xdr, &hdr);
6977 	if (status)
6978 		goto out;
6979 	status = decode_sequence(xdr, &res->seq_res, req);
6980 	if (status)
6981 		goto out;
6982 	status = decode_putfh(xdr);
6983 	if (status)
6984 		goto out;
6985 	if (res->migration) {
6986 		xdr_enter_page(xdr, PAGE_SIZE);
6987 		status = decode_getfattr_generic(xdr,
6988 					&res->fs_locations->fattr,
6989 					 NULL, res->fs_locations,
6990 					 NULL, res->fs_locations->server);
6991 		if (status)
6992 			goto out;
6993 		if (res->renew)
6994 			status = decode_renew(xdr);
6995 	} else {
6996 		status = decode_lookup(xdr);
6997 		if (status)
6998 			goto out;
6999 		xdr_enter_page(xdr, PAGE_SIZE);
7000 		status = decode_getfattr_generic(xdr,
7001 					&res->fs_locations->fattr,
7002 					 NULL, res->fs_locations,
7003 					 NULL, res->fs_locations->server);
7004 	}
7005 out:
7006 	return status;
7007 }
7008 
7009 /*
7010  * Decode SECINFO response
7011  */
7012 static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7013 				struct xdr_stream *xdr,
7014 				void *data)
7015 {
7016 	struct nfs4_secinfo_res *res = data;
7017 	struct compound_hdr hdr;
7018 	int status;
7019 
7020 	status = decode_compound_hdr(xdr, &hdr);
7021 	if (status)
7022 		goto out;
7023 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7024 	if (status)
7025 		goto out;
7026 	status = decode_putfh(xdr);
7027 	if (status)
7028 		goto out;
7029 	status = decode_secinfo(xdr, res);
7030 out:
7031 	return status;
7032 }
7033 
7034 /*
7035  * Decode FSID_PRESENT response
7036  */
7037 static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7038 				     struct xdr_stream *xdr,
7039 				     void *data)
7040 {
7041 	struct nfs4_fsid_present_res *res = data;
7042 	struct compound_hdr hdr;
7043 	int status;
7044 
7045 	status = decode_compound_hdr(xdr, &hdr);
7046 	if (status)
7047 		goto out;
7048 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7049 	if (status)
7050 		goto out;
7051 	status = decode_putfh(xdr);
7052 	if (status)
7053 		goto out;
7054 	status = decode_getfh(xdr, res->fh);
7055 	if (status)
7056 		goto out;
7057 	if (res->renew)
7058 		status = decode_renew(xdr);
7059 out:
7060 	return status;
7061 }
7062 
7063 #if defined(CONFIG_NFS_V4_1)
7064 /*
7065  * Decode BIND_CONN_TO_SESSION response
7066  */
7067 static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7068 					struct xdr_stream *xdr,
7069 					void *res)
7070 {
7071 	struct compound_hdr hdr;
7072 	int status;
7073 
7074 	status = decode_compound_hdr(xdr, &hdr);
7075 	if (!status)
7076 		status = decode_bind_conn_to_session(xdr, res);
7077 	return status;
7078 }
7079 
7080 /*
7081  * Decode EXCHANGE_ID response
7082  */
7083 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7084 				    struct xdr_stream *xdr,
7085 				    void *res)
7086 {
7087 	struct compound_hdr hdr;
7088 	int status;
7089 
7090 	status = decode_compound_hdr(xdr, &hdr);
7091 	if (!status)
7092 		status = decode_exchange_id(xdr, res);
7093 	return status;
7094 }
7095 
7096 /*
7097  * Decode CREATE_SESSION response
7098  */
7099 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7100 				       struct xdr_stream *xdr,
7101 				       void *res)
7102 {
7103 	struct compound_hdr hdr;
7104 	int status;
7105 
7106 	status = decode_compound_hdr(xdr, &hdr);
7107 	if (!status)
7108 		status = decode_create_session(xdr, res);
7109 	return status;
7110 }
7111 
7112 /*
7113  * Decode DESTROY_SESSION response
7114  */
7115 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7116 					struct xdr_stream *xdr,
7117 					void *res)
7118 {
7119 	struct compound_hdr hdr;
7120 	int status;
7121 
7122 	status = decode_compound_hdr(xdr, &hdr);
7123 	if (!status)
7124 		status = decode_destroy_session(xdr, res);
7125 	return status;
7126 }
7127 
7128 /*
7129  * Decode DESTROY_CLIENTID response
7130  */
7131 static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7132 					struct xdr_stream *xdr,
7133 					void *res)
7134 {
7135 	struct compound_hdr hdr;
7136 	int status;
7137 
7138 	status = decode_compound_hdr(xdr, &hdr);
7139 	if (!status)
7140 		status = decode_destroy_clientid(xdr, res);
7141 	return status;
7142 }
7143 
7144 /*
7145  * Decode SEQUENCE response
7146  */
7147 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7148 				 struct xdr_stream *xdr,
7149 				 void *res)
7150 {
7151 	struct compound_hdr hdr;
7152 	int status;
7153 
7154 	status = decode_compound_hdr(xdr, &hdr);
7155 	if (!status)
7156 		status = decode_sequence(xdr, res, rqstp);
7157 	return status;
7158 }
7159 
7160 #endif
7161 
7162 /*
7163  * Decode GET_LEASE_TIME response
7164  */
7165 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7166 				       struct xdr_stream *xdr,
7167 				       void *data)
7168 {
7169 	struct nfs4_get_lease_time_res *res = data;
7170 	struct compound_hdr hdr;
7171 	int status;
7172 
7173 	status = decode_compound_hdr(xdr, &hdr);
7174 	if (!status)
7175 		status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
7176 	if (!status)
7177 		status = decode_putrootfh(xdr);
7178 	if (!status)
7179 		status = decode_fsinfo(xdr, res->lr_fsinfo);
7180 	return status;
7181 }
7182 
7183 #ifdef CONFIG_NFS_V4_1
7184 
7185 /*
7186  * Decode RECLAIM_COMPLETE response
7187  */
7188 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7189 					 struct xdr_stream *xdr,
7190 					 void *data)
7191 {
7192 	struct nfs41_reclaim_complete_res *res = data;
7193 	struct compound_hdr hdr;
7194 	int status;
7195 
7196 	status = decode_compound_hdr(xdr, &hdr);
7197 	if (!status)
7198 		status = decode_sequence(xdr, &res->seq_res, rqstp);
7199 	if (!status)
7200 		status = decode_reclaim_complete(xdr, NULL);
7201 	return status;
7202 }
7203 
7204 /*
7205  * Decode GETDEVINFO response
7206  */
7207 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7208 				      struct xdr_stream *xdr,
7209 				      void *data)
7210 {
7211 	struct nfs4_getdeviceinfo_res *res = data;
7212 	struct compound_hdr hdr;
7213 	int status;
7214 
7215 	status = decode_compound_hdr(xdr, &hdr);
7216 	if (status != 0)
7217 		goto out;
7218 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7219 	if (status != 0)
7220 		goto out;
7221 	status = decode_getdeviceinfo(xdr, res);
7222 out:
7223 	return status;
7224 }
7225 
7226 /*
7227  * Decode LAYOUTGET response
7228  */
7229 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7230 				  struct xdr_stream *xdr,
7231 				  void *data)
7232 {
7233 	struct nfs4_layoutget_res *res = data;
7234 	struct compound_hdr hdr;
7235 	int status;
7236 
7237 	status = decode_compound_hdr(xdr, &hdr);
7238 	if (status)
7239 		goto out;
7240 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7241 	if (status)
7242 		goto out;
7243 	status = decode_putfh(xdr);
7244 	if (status)
7245 		goto out;
7246 	status = decode_layoutget(xdr, rqstp, res);
7247 out:
7248 	return status;
7249 }
7250 
7251 /*
7252  * Decode LAYOUTRETURN response
7253  */
7254 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7255 				     struct xdr_stream *xdr,
7256 				     void *data)
7257 {
7258 	struct nfs4_layoutreturn_res *res = data;
7259 	struct compound_hdr hdr;
7260 	int status;
7261 
7262 	status = decode_compound_hdr(xdr, &hdr);
7263 	if (status)
7264 		goto out;
7265 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7266 	if (status)
7267 		goto out;
7268 	status = decode_putfh(xdr);
7269 	if (status)
7270 		goto out;
7271 	status = decode_layoutreturn(xdr, res);
7272 out:
7273 	return status;
7274 }
7275 
7276 /*
7277  * Decode LAYOUTCOMMIT response
7278  */
7279 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7280 				     struct xdr_stream *xdr,
7281 				     void *data)
7282 {
7283 	struct nfs4_layoutcommit_res *res = data;
7284 	struct compound_hdr hdr;
7285 	int status;
7286 
7287 	status = decode_compound_hdr(xdr, &hdr);
7288 	if (status)
7289 		goto out;
7290 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7291 	if (status)
7292 		goto out;
7293 	status = decode_putfh(xdr);
7294 	if (status)
7295 		goto out;
7296 	status = decode_layoutcommit(xdr, rqstp, res);
7297 	if (status)
7298 		goto out;
7299 	decode_getfattr(xdr, res->fattr, res->server);
7300 out:
7301 	return status;
7302 }
7303 
7304 /*
7305  * Decode SECINFO_NO_NAME response
7306  */
7307 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7308 					struct xdr_stream *xdr,
7309 					void *data)
7310 {
7311 	struct nfs4_secinfo_res *res = data;
7312 	struct compound_hdr hdr;
7313 	int status;
7314 
7315 	status = decode_compound_hdr(xdr, &hdr);
7316 	if (status)
7317 		goto out;
7318 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7319 	if (status)
7320 		goto out;
7321 	status = decode_putrootfh(xdr);
7322 	if (status)
7323 		goto out;
7324 	status = decode_secinfo_no_name(xdr, res);
7325 out:
7326 	return status;
7327 }
7328 
7329 /*
7330  * Decode TEST_STATEID response
7331  */
7332 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7333 				     struct xdr_stream *xdr,
7334 				     void *data)
7335 {
7336 	struct nfs41_test_stateid_res *res = data;
7337 	struct compound_hdr hdr;
7338 	int status;
7339 
7340 	status = decode_compound_hdr(xdr, &hdr);
7341 	if (status)
7342 		goto out;
7343 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7344 	if (status)
7345 		goto out;
7346 	status = decode_test_stateid(xdr, res);
7347 out:
7348 	return status;
7349 }
7350 
7351 /*
7352  * Decode FREE_STATEID response
7353  */
7354 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7355 				     struct xdr_stream *xdr,
7356 				     void *data)
7357 {
7358 	struct nfs41_free_stateid_res *res = data;
7359 	struct compound_hdr hdr;
7360 	int status;
7361 
7362 	status = decode_compound_hdr(xdr, &hdr);
7363 	if (status)
7364 		goto out;
7365 	status = decode_sequence(xdr, &res->seq_res, rqstp);
7366 	if (status)
7367 		goto out;
7368 	status = decode_free_stateid(xdr, res);
7369 out:
7370 	return status;
7371 }
7372 #endif /* CONFIG_NFS_V4_1 */
7373 
7374 /**
7375  * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7376  *                      the local page cache.
7377  * @xdr: XDR stream where entry resides
7378  * @entry: buffer to fill in with entry data
7379  * @plus: boolean indicating whether this should be a readdirplus entry
7380  *
7381  * Returns zero if successful, otherwise a negative errno value is
7382  * returned.
7383  *
7384  * This function is not invoked during READDIR reply decoding, but
7385  * rather whenever an application invokes the getdents(2) system call
7386  * on a directory already in our cache.
7387  */
7388 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7389 		       bool plus)
7390 {
7391 	unsigned int savep;
7392 	uint32_t bitmap[3] = {0};
7393 	uint32_t len;
7394 	uint64_t new_cookie;
7395 	__be32 *p = xdr_inline_decode(xdr, 4);
7396 	if (unlikely(!p))
7397 		return -EAGAIN;
7398 	if (*p == xdr_zero) {
7399 		p = xdr_inline_decode(xdr, 4);
7400 		if (unlikely(!p))
7401 			return -EAGAIN;
7402 		if (*p == xdr_zero)
7403 			return -EAGAIN;
7404 		entry->eof = 1;
7405 		return -EBADCOOKIE;
7406 	}
7407 
7408 	p = xdr_inline_decode(xdr, 12);
7409 	if (unlikely(!p))
7410 		return -EAGAIN;
7411 	p = xdr_decode_hyper(p, &new_cookie);
7412 	entry->len = be32_to_cpup(p);
7413 
7414 	p = xdr_inline_decode(xdr, entry->len);
7415 	if (unlikely(!p))
7416 		return -EAGAIN;
7417 	entry->name = (const char *) p;
7418 
7419 	/*
7420 	 * In case the server doesn't return an inode number,
7421 	 * we fake one here.  (We don't use inode number 0,
7422 	 * since glibc seems to choke on it...)
7423 	 */
7424 	entry->ino = 1;
7425 	entry->fattr->valid = 0;
7426 
7427 	if (decode_attr_bitmap(xdr, bitmap) < 0)
7428 		return -EAGAIN;
7429 
7430 	if (decode_attr_length(xdr, &len, &savep) < 0)
7431 		return -EAGAIN;
7432 
7433 	if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7434 			NULL, entry->label, entry->server) < 0)
7435 		return -EAGAIN;
7436 	if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7437 		entry->ino = entry->fattr->mounted_on_fileid;
7438 	else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
7439 		entry->ino = entry->fattr->fileid;
7440 
7441 	entry->d_type = DT_UNKNOWN;
7442 	if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7443 		entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7444 
7445 	entry->prev_cookie = entry->cookie;
7446 	entry->cookie = new_cookie;
7447 
7448 	return 0;
7449 }
7450 
7451 /*
7452  * We need to translate between nfs status return values and
7453  * the local errno values which may not be the same.
7454  */
7455 static struct {
7456 	int stat;
7457 	int errno;
7458 } nfs_errtbl[] = {
7459 	{ NFS4_OK,		0		},
7460 	{ NFS4ERR_PERM,		-EPERM		},
7461 	{ NFS4ERR_NOENT,	-ENOENT		},
7462 	{ NFS4ERR_IO,		-errno_NFSERR_IO},
7463 	{ NFS4ERR_NXIO,		-ENXIO		},
7464 	{ NFS4ERR_ACCESS,	-EACCES		},
7465 	{ NFS4ERR_EXIST,	-EEXIST		},
7466 	{ NFS4ERR_XDEV,		-EXDEV		},
7467 	{ NFS4ERR_NOTDIR,	-ENOTDIR	},
7468 	{ NFS4ERR_ISDIR,	-EISDIR		},
7469 	{ NFS4ERR_INVAL,	-EINVAL		},
7470 	{ NFS4ERR_FBIG,		-EFBIG		},
7471 	{ NFS4ERR_NOSPC,	-ENOSPC		},
7472 	{ NFS4ERR_ROFS,		-EROFS		},
7473 	{ NFS4ERR_MLINK,	-EMLINK		},
7474 	{ NFS4ERR_NAMETOOLONG,	-ENAMETOOLONG	},
7475 	{ NFS4ERR_NOTEMPTY,	-ENOTEMPTY	},
7476 	{ NFS4ERR_DQUOT,	-EDQUOT		},
7477 	{ NFS4ERR_STALE,	-ESTALE		},
7478 	{ NFS4ERR_BADHANDLE,	-EBADHANDLE	},
7479 	{ NFS4ERR_BAD_COOKIE,	-EBADCOOKIE	},
7480 	{ NFS4ERR_NOTSUPP,	-ENOTSUPP	},
7481 	{ NFS4ERR_TOOSMALL,	-ETOOSMALL	},
7482 	{ NFS4ERR_SERVERFAULT,	-EREMOTEIO	},
7483 	{ NFS4ERR_BADTYPE,	-EBADTYPE	},
7484 	{ NFS4ERR_LOCKED,	-EAGAIN		},
7485 	{ NFS4ERR_SYMLINK,	-ELOOP		},
7486 	{ NFS4ERR_OP_ILLEGAL,	-EOPNOTSUPP	},
7487 	{ NFS4ERR_DEADLOCK,	-EDEADLK	},
7488 	{ NFS4ERR_NOXATTR,	-ENODATA	},
7489 	{ NFS4ERR_XATTR2BIG,	-E2BIG		},
7490 	{ -1,			-EIO		}
7491 };
7492 
7493 /*
7494  * Convert an NFS error code to a local one.
7495  * This one is used jointly by NFSv2 and NFSv3.
7496  */
7497 static int
7498 nfs4_stat_to_errno(int stat)
7499 {
7500 	int i;
7501 	for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7502 		if (nfs_errtbl[i].stat == stat)
7503 			return nfs_errtbl[i].errno;
7504 	}
7505 	if (stat <= 10000 || stat > 10100) {
7506 		/* The server is looney tunes. */
7507 		return -EREMOTEIO;
7508 	}
7509 	/* If we cannot translate the error, the recovery routines should
7510 	 * handle it.
7511 	 * Note: remaining NFSv4 error codes have values > 10000, so should
7512 	 * not conflict with native Linux error codes.
7513 	 */
7514 	return -stat;
7515 }
7516 
7517 #ifdef CONFIG_NFS_V4_2
7518 #include "nfs42xdr.c"
7519 #endif /* CONFIG_NFS_V4_2 */
7520 
7521 #define PROC(proc, argtype, restype)				\
7522 [NFSPROC4_CLNT_##proc] = {					\
7523 	.p_proc   = NFSPROC4_COMPOUND,				\
7524 	.p_encode = nfs4_xdr_##argtype,				\
7525 	.p_decode = nfs4_xdr_##restype,				\
7526 	.p_arglen = NFS4_##argtype##_sz,			\
7527 	.p_replen = NFS4_##restype##_sz,			\
7528 	.p_statidx = NFSPROC4_CLNT_##proc,			\
7529 	.p_name   = #proc,					\
7530 }
7531 
7532 #define STUB(proc)		\
7533 [NFSPROC4_CLNT_##proc] = {	\
7534 	.p_name = #proc,	\
7535 }
7536 
7537 #if defined(CONFIG_NFS_V4_1)
7538 #define PROC41(proc, argtype, restype)				\
7539 	PROC(proc, argtype, restype)
7540 #else
7541 #define PROC41(proc, argtype, restype)				\
7542 	STUB(proc)
7543 #endif
7544 
7545 #if defined(CONFIG_NFS_V4_2)
7546 #define PROC42(proc, argtype, restype)				\
7547 	PROC(proc, argtype, restype)
7548 #else
7549 #define PROC42(proc, argtype, restype)				\
7550 	STUB(proc)
7551 #endif
7552 
7553 const struct rpc_procinfo nfs4_procedures[] = {
7554 	PROC(READ,		enc_read,		dec_read),
7555 	PROC(WRITE,		enc_write,		dec_write),
7556 	PROC(COMMIT,		enc_commit,		dec_commit),
7557 	PROC(OPEN,		enc_open,		dec_open),
7558 	PROC(OPEN_CONFIRM,	enc_open_confirm,	dec_open_confirm),
7559 	PROC(OPEN_NOATTR,	enc_open_noattr,	dec_open_noattr),
7560 	PROC(OPEN_DOWNGRADE,	enc_open_downgrade,	dec_open_downgrade),
7561 	PROC(CLOSE,		enc_close,		dec_close),
7562 	PROC(SETATTR,		enc_setattr,		dec_setattr),
7563 	PROC(FSINFO,		enc_fsinfo,		dec_fsinfo),
7564 	PROC(RENEW,		enc_renew,		dec_renew),
7565 	PROC(SETCLIENTID,	enc_setclientid,	dec_setclientid),
7566 	PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7567 	PROC(LOCK,		enc_lock,		dec_lock),
7568 	PROC(LOCKT,		enc_lockt,		dec_lockt),
7569 	PROC(LOCKU,		enc_locku,		dec_locku),
7570 	PROC(ACCESS,		enc_access,		dec_access),
7571 	PROC(GETATTR,		enc_getattr,		dec_getattr),
7572 	PROC(LOOKUP,		enc_lookup,		dec_lookup),
7573 	PROC(LOOKUP_ROOT,	enc_lookup_root,	dec_lookup_root),
7574 	PROC(REMOVE,		enc_remove,		dec_remove),
7575 	PROC(RENAME,		enc_rename,		dec_rename),
7576 	PROC(LINK,		enc_link,		dec_link),
7577 	PROC(SYMLINK,		enc_symlink,		dec_symlink),
7578 	PROC(CREATE,		enc_create,		dec_create),
7579 	PROC(PATHCONF,		enc_pathconf,		dec_pathconf),
7580 	PROC(STATFS,		enc_statfs,		dec_statfs),
7581 	PROC(READLINK,		enc_readlink,		dec_readlink),
7582 	PROC(READDIR,		enc_readdir,		dec_readdir),
7583 	PROC(SERVER_CAPS,	enc_server_caps,	dec_server_caps),
7584 	PROC(DELEGRETURN,	enc_delegreturn,	dec_delegreturn),
7585 	PROC(GETACL,		enc_getacl,		dec_getacl),
7586 	PROC(SETACL,		enc_setacl,		dec_setacl),
7587 	PROC(FS_LOCATIONS,	enc_fs_locations,	dec_fs_locations),
7588 	PROC(RELEASE_LOCKOWNER,	enc_release_lockowner,	dec_release_lockowner),
7589 	PROC(SECINFO,		enc_secinfo,		dec_secinfo),
7590 	PROC(FSID_PRESENT,	enc_fsid_present,	dec_fsid_present),
7591 	PROC41(EXCHANGE_ID,	enc_exchange_id,	dec_exchange_id),
7592 	PROC41(CREATE_SESSION,	enc_create_session,	dec_create_session),
7593 	PROC41(DESTROY_SESSION,	enc_destroy_session,	dec_destroy_session),
7594 	PROC41(SEQUENCE,	enc_sequence,		dec_sequence),
7595 	PROC(GET_LEASE_TIME,	enc_get_lease_time,	dec_get_lease_time),
7596 	PROC41(RECLAIM_COMPLETE,enc_reclaim_complete,	dec_reclaim_complete),
7597 	PROC41(GETDEVICEINFO,	enc_getdeviceinfo,	dec_getdeviceinfo),
7598 	PROC41(LAYOUTGET,	enc_layoutget,		dec_layoutget),
7599 	PROC41(LAYOUTCOMMIT,	enc_layoutcommit,	dec_layoutcommit),
7600 	PROC41(LAYOUTRETURN,	enc_layoutreturn,	dec_layoutreturn),
7601 	PROC41(SECINFO_NO_NAME,	enc_secinfo_no_name,	dec_secinfo_no_name),
7602 	PROC41(TEST_STATEID,	enc_test_stateid,	dec_test_stateid),
7603 	PROC41(FREE_STATEID,	enc_free_stateid,	dec_free_stateid),
7604 	STUB(GETDEVICELIST),
7605 	PROC41(BIND_CONN_TO_SESSION,
7606 			enc_bind_conn_to_session, dec_bind_conn_to_session),
7607 	PROC41(DESTROY_CLIENTID,enc_destroy_clientid,	dec_destroy_clientid),
7608 	PROC42(SEEK,		enc_seek,		dec_seek),
7609 	PROC42(ALLOCATE,	enc_allocate,		dec_allocate),
7610 	PROC42(DEALLOCATE,	enc_deallocate,		dec_deallocate),
7611 	PROC42(LAYOUTSTATS,	enc_layoutstats,	dec_layoutstats),
7612 	PROC42(CLONE,		enc_clone,		dec_clone),
7613 	PROC42(COPY,		enc_copy,		dec_copy),
7614 	PROC42(OFFLOAD_CANCEL,	enc_offload_cancel,	dec_offload_cancel),
7615 	PROC42(COPY_NOTIFY,	enc_copy_notify,	dec_copy_notify),
7616 	PROC(LOOKUPP,		enc_lookupp,		dec_lookupp),
7617 	PROC42(LAYOUTERROR,	enc_layouterror,	dec_layouterror),
7618 	PROC42(GETXATTR,	enc_getxattr,		dec_getxattr),
7619 	PROC42(SETXATTR,	enc_setxattr,		dec_setxattr),
7620 	PROC42(LISTXATTRS,	enc_listxattrs,		dec_listxattrs),
7621 	PROC42(REMOVEXATTR,	enc_removexattr,	dec_removexattr),
7622 	PROC42(READ_PLUS,	enc_read_plus,		dec_read_plus),
7623 };
7624 
7625 static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
7626 const struct rpc_version nfs_version4 = {
7627 	.number			= 4,
7628 	.nrprocs		= ARRAY_SIZE(nfs4_procedures),
7629 	.procs			= nfs4_procedures,
7630 	.counts			= nfs_version4_counts,
7631 };
7632 
7633 /*
7634  * Local variables:
7635  *  c-basic-offset: 8
7636  * End:
7637  */
7638