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