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