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