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