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