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