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