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