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