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