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