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