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