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

source code of linux/fs/nfs/nfs4xdr.c