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