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