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