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