NFS: check xdr_decode for errors
[deliverable/linux.git] / fs / nfs / nfs4xdr.c
CommitLineData
1da177e4
LT
1/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
6c0195a4 11 *
1da177e4
LT
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
1da177e4
LT
41#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
47#include <linux/sunrpc/clnt.h>
2449ea2e 48#include <linux/sunrpc/msg_prot.h>
1da177e4
LT
49#include <linux/nfs.h>
50#include <linux/nfs4.h>
51#include <linux/nfs_fs.h>
52#include <linux/nfs_idmap.h>
4ce79717 53#include "nfs4_fs.h"
4882ef72 54#include "internal.h"
1da177e4
LT
55
56#define NFSDBG_FACILITY NFSDBG_XDR
57
58/* Mapping from NFS error code to "errno" error code. */
59#define errno_NFSERR_IO EIO
60
0a8ea437 61static int nfs4_stat_to_errno(int);
1da177e4
LT
62
63/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
64#ifdef DEBUG
65#define NFS4_MAXTAGLEN 20
66#else
67#define NFS4_MAXTAGLEN 0
68#endif
69
6c0195a4 70/* lock,open owner id:
9f958ab8 71 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
1da177e4 72 */
9f958ab8
TM
73#define open_owner_id_maxsz (1 + 4)
74#define lock_owner_id_maxsz (1 + 4)
9104a55d 75#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
1da177e4
LT
76#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78#define op_encode_hdr_maxsz (1)
79#define op_decode_hdr_maxsz (2)
9104a55d
TM
80#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
1da177e4
LT
84#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
85 (NFS4_FHSIZE >> 2))
86#define decode_putfh_maxsz (op_decode_hdr_maxsz)
87#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89#define encode_getfh_maxsz (op_encode_hdr_maxsz)
90#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
96928206
BF
92#define nfs4_fattr_bitmap_maxsz 3
93#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
1da177e4
LT
94#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
bd625ba8
TM
96#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
96928206
BF
98/* This is based on getfattr, which uses the most attributes: */
99#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
bd625ba8 100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
96928206
BF
101#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
9104a55d
TM
104#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
105 1 + 2 + 1 + \
106 nfs4_owner_maxsz + \
107 nfs4_group_maxsz + \
108 4 + 4)
1da177e4
LT
109#define encode_savefh_maxsz (op_encode_hdr_maxsz)
110#define decode_savefh_maxsz (op_decode_hdr_maxsz)
56ae19f3
TM
111#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
2f42b5d0 113#define encode_fsinfo_maxsz (encode_getattr_maxsz)
1da177e4
LT
114#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116#define decode_renew_maxsz (op_decode_hdr_maxsz)
117#define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
cc38bac3
CL
119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
121 1 /* sc_prog */ + \
122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
124 1) /* sc_cb_ident */
1da177e4
LT
125#define decode_setclientid_maxsz \
126 (op_decode_hdr_maxsz + \
127 2 + \
128 1024) /* large value for CLID_INUSE */
129#define encode_setclientid_confirm_maxsz \
130 (op_encode_hdr_maxsz + \
131 3 + (NFS4_VERIFIER_SIZE >> 2))
132#define decode_setclientid_confirm_maxsz \
133 (op_decode_hdr_maxsz)
e6889620
TM
134#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135#define decode_lookup_maxsz (op_decode_hdr_maxsz)
2cebf828
TM
136#define encode_share_access_maxsz \
137 (2)
4882ef72 138#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
2cebf828
TM
139#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141#define encode_open_maxsz (op_encode_hdr_maxsz + \
142 2 + encode_share_access_maxsz + 2 + \
143 open_owner_id_maxsz + \
144 encode_opentype_maxsz + \
145 encode_claim_null_maxsz)
146#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
9104a55d 147#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
2cebf828
TM
148 decode_ace_maxsz)
149#define decode_change_info_maxsz (5)
150#define decode_open_maxsz (op_decode_hdr_maxsz + \
9104a55d 151 decode_stateid_maxsz + \
2cebf828
TM
152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
9104a55d
TM
155#define encode_open_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 encode_stateid_maxsz + 1)
158#define decode_open_confirm_maxsz \
159 (op_decode_hdr_maxsz + \
160 decode_stateid_maxsz)
161#define encode_open_downgrade_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1 + \
164 encode_share_access_maxsz)
165#define decode_open_downgrade_maxsz \
166 (op_decode_hdr_maxsz + \
167 decode_stateid_maxsz)
168#define encode_close_maxsz (op_encode_hdr_maxsz + \
169 1 + encode_stateid_maxsz)
170#define decode_close_maxsz (op_decode_hdr_maxsz + \
171 decode_stateid_maxsz)
172#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + \
174 encode_attrs_maxsz)
175#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
176 nfs4_fattr_bitmap_maxsz)
177#define encode_read_maxsz (op_encode_hdr_maxsz + \
178 encode_stateid_maxsz + 3)
179#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
180#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
181 2 + encode_verifier_maxsz + 5)
182#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
183 decode_verifier_maxsz)
184#define encode_readlink_maxsz (op_encode_hdr_maxsz)
185#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
186#define encode_write_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 4)
188#define decode_write_maxsz (op_decode_hdr_maxsz + \
189 2 + decode_verifier_maxsz)
190#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
191#define decode_commit_maxsz (op_decode_hdr_maxsz + \
192 decode_verifier_maxsz)
1da177e4
LT
193#define encode_remove_maxsz (op_encode_hdr_maxsz + \
194 nfs4_name_maxsz)
6ce18391
BH
195#define decode_remove_maxsz (op_decode_hdr_maxsz + \
196 decode_change_info_maxsz)
1da177e4
LT
197#define encode_rename_maxsz (op_encode_hdr_maxsz + \
198 2 * nfs4_name_maxsz)
6ce18391
BH
199#define decode_rename_maxsz (op_decode_hdr_maxsz + \
200 decode_change_info_maxsz + \
201 decode_change_info_maxsz)
1da177e4
LT
202#define encode_link_maxsz (op_encode_hdr_maxsz + \
203 nfs4_name_maxsz)
6ce18391 204#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
daccbded 205#define encode_lockowner_maxsz (7)
9104a55d
TM
206#define encode_lock_maxsz (op_encode_hdr_maxsz + \
207 7 + \
daccbded
TM
208 1 + encode_stateid_maxsz + 1 + \
209 encode_lockowner_maxsz)
9104a55d
TM
210#define decode_lock_denied_maxsz \
211 (8 + decode_lockowner_maxsz)
212#define decode_lock_maxsz (op_decode_hdr_maxsz + \
213 decode_lock_denied_maxsz)
daccbded
TM
214#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
215 encode_lockowner_maxsz)
9104a55d
TM
216#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
217 decode_lock_denied_maxsz)
218#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
219 encode_stateid_maxsz + \
220 4)
221#define decode_locku_maxsz (op_decode_hdr_maxsz + \
222 decode_stateid_maxsz)
d3c7b7cc
TM
223#define encode_release_lockowner_maxsz \
224 (op_encode_hdr_maxsz + \
225 encode_lockowner_maxsz)
226#define decode_release_lockowner_maxsz \
227 (op_decode_hdr_maxsz)
9104a55d
TM
228#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
229#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
1da177e4
LT
230#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
231 1 + nfs4_name_maxsz + \
94a6d753 232 1 + \
96928206 233 nfs4_fattr_maxsz)
1da177e4
LT
234#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
235#define encode_create_maxsz (op_encode_hdr_maxsz + \
9104a55d
TM
236 1 + 2 + nfs4_name_maxsz + \
237 encode_attrs_maxsz)
2cebf828
TM
238#define decode_create_maxsz (op_decode_hdr_maxsz + \
239 decode_change_info_maxsz + \
240 nfs4_fattr_bitmap_maxsz)
9104a55d
TM
241#define encode_statfs_maxsz (encode_getattr_maxsz)
242#define decode_statfs_maxsz (decode_getattr_maxsz)
1da177e4
LT
243#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
244#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
9104a55d
TM
245#define encode_getacl_maxsz (encode_getattr_maxsz)
246#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
247 nfs4_fattr_bitmap_maxsz + 1)
248#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
249 encode_stateid_maxsz + 3)
250#define decode_setacl_maxsz (decode_setattr_maxsz)
e6889620
TM
251#define encode_fs_locations_maxsz \
252 (encode_getattr_maxsz)
253#define decode_fs_locations_maxsz \
254 (0)
9b7b9fcc
AA
255
256#if defined(CONFIG_NFS_V4_1)
fc931582
AA
257#define NFS4_MAX_MACHINE_NAME_LEN (64)
258
99fe60d0
BH
259#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
260 encode_verifier_maxsz + \
261 1 /* co_ownerid.len */ + \
262 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
263 1 /* flags */ + \
264 1 /* spa_how */ + \
265 0 /* SP4_NONE (for now) */ + \
266 1 /* zero implemetation id array */)
267#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
268 2 /* eir_clientid */ + \
269 1 /* eir_sequenceid */ + \
270 1 /* eir_flags */ + \
271 1 /* spr_how */ + \
272 0 /* SP4_NONE (for now) */ + \
273 2 /* eir_server_owner.so_minor_id */ + \
274 /* eir_server_owner.so_major_id<> */ \
275 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
276 /* eir_server_scope<> */ \
277 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
278 1 /* eir_server_impl_id array length */ + \
279 0 /* ignored eir_server_impl_id contents */)
fc931582
AA
280#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
281#define decode_channel_attrs_maxsz (6 + \
282 1 /* ca_rdma_ird.len */ + \
283 1 /* ca_rdma_ird */)
284#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
285 2 /* csa_clientid */ + \
286 1 /* csa_sequence */ + \
287 1 /* csa_flags */ + \
288 encode_channel_attrs_maxsz + \
289 encode_channel_attrs_maxsz + \
290 1 /* csa_cb_program */ + \
291 1 /* csa_sec_parms.len (1) */ + \
292 1 /* cb_secflavor (AUTH_SYS) */ + \
293 1 /* stamp */ + \
294 1 /* machinename.len */ + \
295 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
296 1 /* uid */ + \
297 1 /* gid */ + \
298 1 /* gids.len (0) */)
299#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
300 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
301 1 /* csr_sequence */ + \
302 1 /* csr_flags */ + \
303 decode_channel_attrs_maxsz + \
304 decode_channel_attrs_maxsz)
0f3e66c6
AA
305#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
306#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
fc01cea9
AA
307#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
308 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
309#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
310 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
18019753
RL
311#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
312#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
9b7b9fcc
AA
313#else /* CONFIG_NFS_V4_1 */
314#define encode_sequence_maxsz 0
315#define decode_sequence_maxsz 0
316#endif /* CONFIG_NFS_V4_1 */
317
1da177e4
LT
318#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
319#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
320#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 321 encode_sequence_maxsz + \
1da177e4 322 encode_putfh_maxsz + \
9104a55d 323 encode_read_maxsz)
1da177e4 324#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 325 decode_sequence_maxsz + \
1da177e4 326 decode_putfh_maxsz + \
9104a55d 327 decode_read_maxsz)
1da177e4 328#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 329 encode_sequence_maxsz + \
1da177e4 330 encode_putfh_maxsz + \
9104a55d 331 encode_readlink_maxsz)
1da177e4 332#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 333 decode_sequence_maxsz + \
1da177e4 334 decode_putfh_maxsz + \
9104a55d 335 decode_readlink_maxsz)
1da177e4 336#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 337 encode_sequence_maxsz + \
1da177e4 338 encode_putfh_maxsz + \
9104a55d 339 encode_readdir_maxsz)
1da177e4 340#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 341 decode_sequence_maxsz + \
1da177e4 342 decode_putfh_maxsz + \
9104a55d 343 decode_readdir_maxsz)
1da177e4 344#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 345 encode_sequence_maxsz + \
1da177e4 346 encode_putfh_maxsz + \
9104a55d 347 encode_write_maxsz + \
4f9838c7 348 encode_getattr_maxsz)
1da177e4 349#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 350 decode_sequence_maxsz + \
1da177e4 351 decode_putfh_maxsz + \
9104a55d 352 decode_write_maxsz + \
4f9838c7 353 decode_getattr_maxsz)
1da177e4 354#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 355 encode_sequence_maxsz + \
1da177e4 356 encode_putfh_maxsz + \
9104a55d 357 encode_commit_maxsz + \
4f9838c7 358 encode_getattr_maxsz)
1da177e4 359#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 360 decode_sequence_maxsz + \
1da177e4 361 decode_putfh_maxsz + \
9104a55d 362 decode_commit_maxsz + \
4f9838c7 363 decode_getattr_maxsz)
1da177e4 364#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 365 encode_sequence_maxsz + \
2cebf828
TM
366 encode_putfh_maxsz + \
367 encode_savefh_maxsz + \
368 encode_open_maxsz + \
369 encode_getfh_maxsz + \
370 encode_getattr_maxsz + \
371 encode_restorefh_maxsz + \
372 encode_getattr_maxsz)
1da177e4 373#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 374 decode_sequence_maxsz + \
2cebf828
TM
375 decode_putfh_maxsz + \
376 decode_savefh_maxsz + \
377 decode_open_maxsz + \
378 decode_getfh_maxsz + \
379 decode_getattr_maxsz + \
380 decode_restorefh_maxsz + \
381 decode_getattr_maxsz)
9104a55d
TM
382#define NFS4_enc_open_confirm_sz \
383 (compound_encode_hdr_maxsz + \
384 encode_putfh_maxsz + \
385 encode_open_confirm_maxsz)
386#define NFS4_dec_open_confirm_sz \
387 (compound_decode_hdr_maxsz + \
388 decode_putfh_maxsz + \
389 decode_open_confirm_maxsz)
1da177e4 390#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 391 encode_sequence_maxsz + \
1da177e4 392 encode_putfh_maxsz + \
2cebf828
TM
393 encode_open_maxsz + \
394 encode_getattr_maxsz)
1da177e4 395#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 396 decode_sequence_maxsz + \
1da177e4 397 decode_putfh_maxsz + \
2cebf828
TM
398 decode_open_maxsz + \
399 decode_getattr_maxsz)
1da177e4
LT
400#define NFS4_enc_open_downgrade_sz \
401 (compound_encode_hdr_maxsz + \
9b7b9fcc 402 encode_sequence_maxsz + \
9104a55d
TM
403 encode_putfh_maxsz + \
404 encode_open_downgrade_maxsz + \
405 encode_getattr_maxsz)
1da177e4
LT
406#define NFS4_dec_open_downgrade_sz \
407 (compound_decode_hdr_maxsz + \
9b7b9fcc 408 decode_sequence_maxsz + \
9104a55d
TM
409 decode_putfh_maxsz + \
410 decode_open_downgrade_maxsz + \
411 decode_getattr_maxsz)
412#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 413 encode_sequence_maxsz + \
9104a55d
TM
414 encode_putfh_maxsz + \
415 encode_close_maxsz + \
416 encode_getattr_maxsz)
417#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 418 decode_sequence_maxsz + \
9104a55d
TM
419 decode_putfh_maxsz + \
420 decode_close_maxsz + \
421 decode_getattr_maxsz)
422#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 423 encode_sequence_maxsz + \
9104a55d
TM
424 encode_putfh_maxsz + \
425 encode_setattr_maxsz + \
426 encode_getattr_maxsz)
427#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 428 decode_sequence_maxsz + \
9104a55d
TM
429 decode_putfh_maxsz + \
430 decode_setattr_maxsz + \
431 decode_getattr_maxsz)
1da177e4 432#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 433 encode_sequence_maxsz + \
1da177e4
LT
434 encode_putfh_maxsz + \
435 encode_fsinfo_maxsz)
436#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 437 decode_sequence_maxsz + \
1da177e4
LT
438 decode_putfh_maxsz + \
439 decode_fsinfo_maxsz)
440#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
441 encode_renew_maxsz)
442#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
443 decode_renew_maxsz)
444#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
445 encode_setclientid_maxsz)
446#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
447 decode_setclientid_maxsz)
448#define NFS4_enc_setclientid_confirm_sz \
449 (compound_encode_hdr_maxsz + \
450 encode_setclientid_confirm_maxsz + \
451 encode_putrootfh_maxsz + \
452 encode_fsinfo_maxsz)
453#define NFS4_dec_setclientid_confirm_sz \
454 (compound_decode_hdr_maxsz + \
455 decode_setclientid_confirm_maxsz + \
456 decode_putrootfh_maxsz + \
457 decode_fsinfo_maxsz)
458#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 459 encode_sequence_maxsz + \
1da177e4 460 encode_putfh_maxsz + \
9104a55d 461 encode_lock_maxsz)
1da177e4 462#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 463 decode_sequence_maxsz + \
1da177e4 464 decode_putfh_maxsz + \
9104a55d 465 decode_lock_maxsz)
1da177e4 466#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 467 encode_sequence_maxsz + \
1da177e4 468 encode_putfh_maxsz + \
9104a55d
TM
469 encode_lockt_maxsz)
470#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 471 decode_sequence_maxsz + \
9104a55d
TM
472 decode_putfh_maxsz + \
473 decode_lockt_maxsz)
1da177e4 474#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 475 encode_sequence_maxsz + \
1da177e4 476 encode_putfh_maxsz + \
9104a55d 477 encode_locku_maxsz)
1da177e4 478#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 479 decode_sequence_maxsz + \
1da177e4 480 decode_putfh_maxsz + \
9104a55d 481 decode_locku_maxsz)
d3c7b7cc
TM
482#define NFS4_enc_release_lockowner_sz \
483 (compound_encode_hdr_maxsz + \
484 encode_lockowner_maxsz)
485#define NFS4_dec_release_lockowner_sz \
486 (compound_decode_hdr_maxsz + \
487 decode_lockowner_maxsz)
1da177e4 488#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 489 encode_sequence_maxsz + \
1da177e4 490 encode_putfh_maxsz + \
76b32999
TM
491 encode_access_maxsz + \
492 encode_getattr_maxsz)
1da177e4 493#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 494 decode_sequence_maxsz + \
1da177e4 495 decode_putfh_maxsz + \
76b32999
TM
496 decode_access_maxsz + \
497 decode_getattr_maxsz)
1da177e4 498#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 499 encode_sequence_maxsz + \
1da177e4
LT
500 encode_putfh_maxsz + \
501 encode_getattr_maxsz)
502#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 503 decode_sequence_maxsz + \
1da177e4
LT
504 decode_putfh_maxsz + \
505 decode_getattr_maxsz)
506#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 507 encode_sequence_maxsz + \
1da177e4
LT
508 encode_putfh_maxsz + \
509 encode_lookup_maxsz + \
510 encode_getattr_maxsz + \
511 encode_getfh_maxsz)
512#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 513 decode_sequence_maxsz + \
1da177e4 514 decode_putfh_maxsz + \
e6889620 515 decode_lookup_maxsz + \
1da177e4
LT
516 decode_getattr_maxsz + \
517 decode_getfh_maxsz)
518#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 519 encode_sequence_maxsz + \
1da177e4
LT
520 encode_putrootfh_maxsz + \
521 encode_getattr_maxsz + \
522 encode_getfh_maxsz)
523#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 524 decode_sequence_maxsz + \
1da177e4
LT
525 decode_putrootfh_maxsz + \
526 decode_getattr_maxsz + \
527 decode_getfh_maxsz)
528#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 529 encode_sequence_maxsz + \
1da177e4 530 encode_putfh_maxsz + \
16e42959
TM
531 encode_remove_maxsz + \
532 encode_getattr_maxsz)
1da177e4 533#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 534 decode_sequence_maxsz + \
1da177e4 535 decode_putfh_maxsz + \
6ce18391 536 decode_remove_maxsz + \
16e42959 537 decode_getattr_maxsz)
1da177e4 538#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 539 encode_sequence_maxsz + \
1da177e4
LT
540 encode_putfh_maxsz + \
541 encode_savefh_maxsz + \
542 encode_putfh_maxsz + \
6caf2c82
TM
543 encode_rename_maxsz + \
544 encode_getattr_maxsz + \
545 encode_restorefh_maxsz + \
546 encode_getattr_maxsz)
1da177e4 547#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 548 decode_sequence_maxsz + \
1da177e4
LT
549 decode_putfh_maxsz + \
550 decode_savefh_maxsz + \
551 decode_putfh_maxsz + \
6caf2c82
TM
552 decode_rename_maxsz + \
553 decode_getattr_maxsz + \
554 decode_restorefh_maxsz + \
555 decode_getattr_maxsz)
1da177e4 556#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 557 encode_sequence_maxsz + \
1da177e4
LT
558 encode_putfh_maxsz + \
559 encode_savefh_maxsz + \
560 encode_putfh_maxsz + \
91ba2eee
TM
561 encode_link_maxsz + \
562 decode_getattr_maxsz + \
563 encode_restorefh_maxsz + \
564 decode_getattr_maxsz)
1da177e4 565#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 566 decode_sequence_maxsz + \
1da177e4
LT
567 decode_putfh_maxsz + \
568 decode_savefh_maxsz + \
569 decode_putfh_maxsz + \
91ba2eee
TM
570 decode_link_maxsz + \
571 decode_getattr_maxsz + \
572 decode_restorefh_maxsz + \
573 decode_getattr_maxsz)
1da177e4 574#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 575 encode_sequence_maxsz + \
1da177e4
LT
576 encode_putfh_maxsz + \
577 encode_symlink_maxsz + \
578 encode_getattr_maxsz + \
579 encode_getfh_maxsz)
580#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 581 decode_sequence_maxsz + \
1da177e4
LT
582 decode_putfh_maxsz + \
583 decode_symlink_maxsz + \
584 decode_getattr_maxsz + \
585 decode_getfh_maxsz)
586#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 587 encode_sequence_maxsz + \
1da177e4 588 encode_putfh_maxsz + \
56ae19f3 589 encode_savefh_maxsz + \
1da177e4 590 encode_create_maxsz + \
56ae19f3 591 encode_getfh_maxsz + \
1da177e4 592 encode_getattr_maxsz + \
56ae19f3
TM
593 encode_restorefh_maxsz + \
594 encode_getattr_maxsz)
1da177e4 595#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 596 decode_sequence_maxsz + \
1da177e4 597 decode_putfh_maxsz + \
56ae19f3 598 decode_savefh_maxsz + \
1da177e4 599 decode_create_maxsz + \
56ae19f3 600 decode_getfh_maxsz + \
1da177e4 601 decode_getattr_maxsz + \
56ae19f3
TM
602 decode_restorefh_maxsz + \
603 decode_getattr_maxsz)
1da177e4 604#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 605 encode_sequence_maxsz + \
1da177e4
LT
606 encode_putfh_maxsz + \
607 encode_getattr_maxsz)
608#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 609 decode_sequence_maxsz + \
1da177e4
LT
610 decode_putfh_maxsz + \
611 decode_getattr_maxsz)
612#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 613 encode_sequence_maxsz + \
1da177e4 614 encode_putfh_maxsz + \
9104a55d 615 encode_statfs_maxsz)
1da177e4 616#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 617 decode_sequence_maxsz + \
1da177e4 618 decode_putfh_maxsz + \
9104a55d 619 decode_statfs_maxsz)
1da177e4 620#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 621 encode_sequence_maxsz + \
ab91f264 622 encode_putfh_maxsz + \
1da177e4
LT
623 encode_getattr_maxsz)
624#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 625 decode_sequence_maxsz + \
ab91f264 626 decode_putfh_maxsz + \
1da177e4
LT
627 decode_getattr_maxsz)
628#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 629 encode_sequence_maxsz + \
1da177e4 630 encode_putfh_maxsz + \
fa178f29
TM
631 encode_delegreturn_maxsz + \
632 encode_getattr_maxsz)
1da177e4 633#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 634 decode_sequence_maxsz + \
fa178f29
TM
635 decode_delegreturn_maxsz + \
636 decode_getattr_maxsz)
029d105e 637#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 638 encode_sequence_maxsz + \
029d105e 639 encode_putfh_maxsz + \
9104a55d 640 encode_getacl_maxsz)
029d105e 641#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 642 decode_sequence_maxsz + \
029d105e 643 decode_putfh_maxsz + \
9104a55d 644 decode_getacl_maxsz)
23ec6965 645#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
9b7b9fcc 646 encode_sequence_maxsz + \
23ec6965 647 encode_putfh_maxsz + \
9104a55d 648 encode_setacl_maxsz)
23ec6965 649#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
9b7b9fcc 650 decode_sequence_maxsz + \
23ec6965 651 decode_putfh_maxsz + \
9104a55d 652 decode_setacl_maxsz)
683b57b4
TM
653#define NFS4_enc_fs_locations_sz \
654 (compound_encode_hdr_maxsz + \
9b7b9fcc 655 encode_sequence_maxsz + \
683b57b4 656 encode_putfh_maxsz + \
e6889620
TM
657 encode_lookup_maxsz + \
658 encode_fs_locations_maxsz)
683b57b4
TM
659#define NFS4_dec_fs_locations_sz \
660 (compound_decode_hdr_maxsz + \
9b7b9fcc 661 decode_sequence_maxsz + \
683b57b4 662 decode_putfh_maxsz + \
e6889620
TM
663 decode_lookup_maxsz + \
664 decode_fs_locations_maxsz)
99fe60d0
BH
665#if defined(CONFIG_NFS_V4_1)
666#define NFS4_enc_exchange_id_sz \
667 (compound_encode_hdr_maxsz + \
668 encode_exchange_id_maxsz)
669#define NFS4_dec_exchange_id_sz \
670 (compound_decode_hdr_maxsz + \
671 decode_exchange_id_maxsz)
fc931582
AA
672#define NFS4_enc_create_session_sz \
673 (compound_encode_hdr_maxsz + \
674 encode_create_session_maxsz)
675#define NFS4_dec_create_session_sz \
676 (compound_decode_hdr_maxsz + \
677 decode_create_session_maxsz)
0f3e66c6
AA
678#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
679 encode_destroy_session_maxsz)
680#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
681 decode_destroy_session_maxsz)
fc01cea9
AA
682#define NFS4_enc_sequence_sz \
683 (compound_decode_hdr_maxsz + \
684 encode_sequence_maxsz)
685#define NFS4_dec_sequence_sz \
686 (compound_decode_hdr_maxsz + \
687 decode_sequence_maxsz)
2050f0cc
AA
688#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
689 encode_sequence_maxsz + \
690 encode_putrootfh_maxsz + \
691 encode_fsinfo_maxsz)
692#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
693 decode_sequence_maxsz + \
694 decode_putrootfh_maxsz + \
695 decode_fsinfo_maxsz)
18019753
RL
696#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
697 encode_sequence_maxsz + \
698 encode_reclaim_complete_maxsz)
699#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
700 decode_sequence_maxsz + \
701 decode_reclaim_complete_maxsz)
2449ea2e
AB
702
703const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
704 compound_encode_hdr_maxsz +
705 encode_sequence_maxsz +
706 encode_putfh_maxsz +
707 encode_getattr_maxsz) *
708 XDR_UNIT);
709
710const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
711 compound_decode_hdr_maxsz +
712 decode_sequence_maxsz +
713 decode_putfh_maxsz) *
714 XDR_UNIT);
99fe60d0 715#endif /* CONFIG_NFS_V4_1 */
1da177e4 716
bca79478
TM
717static const umode_t nfs_type2fmt[] = {
718 [NF4BAD] = 0,
719 [NF4REG] = S_IFREG,
720 [NF4DIR] = S_IFDIR,
721 [NF4BLK] = S_IFBLK,
722 [NF4CHR] = S_IFCHR,
723 [NF4LNK] = S_IFLNK,
724 [NF4SOCK] = S_IFSOCK,
725 [NF4FIFO] = S_IFIFO,
726 [NF4ATTRDIR] = 0,
727 [NF4NAMEDATTR] = 0,
1da177e4
LT
728};
729
730struct compound_hdr {
731 int32_t status;
732 uint32_t nops;
d017931c 733 __be32 * nops_p;
1da177e4
LT
734 uint32_t taglen;
735 char * tag;
0c4e8c18 736 uint32_t replen; /* expected reply words */
66cc0429 737 u32 minorversion;
1da177e4
LT
738};
739
13c65ce9
BH
740static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
741{
742 __be32 *p = xdr_reserve_space(xdr, nbytes);
743 BUG_ON(!p);
744 return p;
745}
1da177e4
LT
746
747static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
748{
8687b63a 749 __be32 *p;
1da177e4
LT
750
751 p = xdr_reserve_space(xdr, 4 + len);
752 BUG_ON(p == NULL);
753 xdr_encode_opaque(p, str, len);
754}
755
0c4e8c18
BH
756static void encode_compound_hdr(struct xdr_stream *xdr,
757 struct rpc_rqst *req,
758 struct compound_hdr *hdr)
1da177e4 759{
8687b63a 760 __be32 *p;
a17c2153 761 struct rpc_auth *auth = req->rq_cred->cr_auth;
0c4e8c18
BH
762
763 /* initialize running count of expected bytes in reply.
764 * NOTE: the replied tag SHOULD be the same is the one sent,
765 * but this is not required as a MUST for the server to do so. */
766 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
1da177e4
LT
767
768 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
769 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
811652bd
BH
770 p = reserve_space(xdr, 4 + hdr->taglen + 8);
771 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
e75bc1c8 772 *p++ = cpu_to_be32(hdr->minorversion);
d017931c 773 hdr->nops_p = p;
34558513 774 *p = cpu_to_be32(hdr->nops);
d017931c
AA
775}
776
777static void encode_nops(struct compound_hdr *hdr)
778{
fc931582 779 BUG_ON(hdr->nops > NFS4_MAX_OPS);
d017931c 780 *hdr->nops_p = htonl(hdr->nops);
1da177e4
LT
781}
782
783static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
784{
8687b63a 785 __be32 *p;
1da177e4
LT
786
787 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
788 BUG_ON(p == NULL);
789 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
790}
791
cf8cdbe5 792static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
1da177e4
LT
793{
794 char owner_name[IDMAP_NAMESZ];
795 char owner_group[IDMAP_NAMESZ];
796 int owner_namelen = 0;
797 int owner_grouplen = 0;
8687b63a
AV
798 __be32 *p;
799 __be32 *q;
1da177e4
LT
800 int len;
801 uint32_t bmval0 = 0;
802 uint32_t bmval1 = 0;
1da177e4
LT
803
804 /*
805 * We reserve enough space to write the entire attribute buffer at once.
806 * In the worst-case, this would be
807 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
808 * = 36 bytes, plus any contribution from variable-length fields
23ec6965 809 * such as owner/group.
1da177e4
LT
810 */
811 len = 16;
812
813 /* Sigh */
814 if (iap->ia_valid & ATTR_SIZE)
815 len += 8;
816 if (iap->ia_valid & ATTR_MODE)
817 len += 4;
818 if (iap->ia_valid & ATTR_UID) {
955a857e 819 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name, IDMAP_NAMESZ);
1da177e4 820 if (owner_namelen < 0) {
fe82a183
CL
821 dprintk("nfs: couldn't resolve uid %d to string\n",
822 iap->ia_uid);
1da177e4
LT
823 /* XXX */
824 strcpy(owner_name, "nobody");
825 owner_namelen = sizeof("nobody") - 1;
826 /* goto out; */
827 }
828 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
829 }
830 if (iap->ia_valid & ATTR_GID) {
955a857e 831 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group, IDMAP_NAMESZ);
1da177e4 832 if (owner_grouplen < 0) {
fe82a183
CL
833 dprintk("nfs: couldn't resolve gid %d to string\n",
834 iap->ia_gid);
1da177e4
LT
835 strcpy(owner_group, "nobody");
836 owner_grouplen = sizeof("nobody") - 1;
837 /* goto out; */
838 }
839 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
840 }
841 if (iap->ia_valid & ATTR_ATIME_SET)
842 len += 16;
843 else if (iap->ia_valid & ATTR_ATIME)
844 len += 4;
845 if (iap->ia_valid & ATTR_MTIME_SET)
846 len += 16;
847 else if (iap->ia_valid & ATTR_MTIME)
848 len += 4;
13c65ce9 849 p = reserve_space(xdr, len);
1da177e4
LT
850
851 /*
852 * We write the bitmap length now, but leave the bitmap and the attribute
853 * buffer length to be backfilled at the end of this routine.
854 */
e75bc1c8 855 *p++ = cpu_to_be32(2);
1da177e4
LT
856 q = p;
857 p += 3;
858
859 if (iap->ia_valid & ATTR_SIZE) {
860 bmval0 |= FATTR4_WORD0_SIZE;
b95be5a9 861 p = xdr_encode_hyper(p, iap->ia_size);
1da177e4
LT
862 }
863 if (iap->ia_valid & ATTR_MODE) {
864 bmval1 |= FATTR4_WORD1_MODE;
e75bc1c8 865 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1da177e4
LT
866 }
867 if (iap->ia_valid & ATTR_UID) {
868 bmval1 |= FATTR4_WORD1_OWNER;
811652bd 869 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1da177e4
LT
870 }
871 if (iap->ia_valid & ATTR_GID) {
872 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
811652bd 873 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1da177e4
LT
874 }
875 if (iap->ia_valid & ATTR_ATIME_SET) {
876 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
e75bc1c8
BH
877 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
878 *p++ = cpu_to_be32(0);
d3f6baaa
TM
879 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
880 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1da177e4
LT
881 }
882 else if (iap->ia_valid & ATTR_ATIME) {
883 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
e75bc1c8 884 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1da177e4
LT
885 }
886 if (iap->ia_valid & ATTR_MTIME_SET) {
887 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
e75bc1c8
BH
888 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
889 *p++ = cpu_to_be32(0);
890 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
891 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1da177e4
LT
892 }
893 else if (iap->ia_valid & ATTR_MTIME) {
894 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
e75bc1c8 895 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1da177e4 896 }
6c0195a4 897
1da177e4
LT
898 /*
899 * Now we backfill the bitmap and the attribute buffer length.
900 */
901 if (len != ((char *)p - (char *)q) + 4) {
fe82a183 902 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
1da177e4
LT
903 len, ((char *)p - (char *)q) + 4);
904 BUG();
905 }
906 len = (char *)p - (char *)q - 12;
907 *q++ = htonl(bmval0);
908 *q++ = htonl(bmval1);
34558513 909 *q = htonl(len);
1da177e4 910
1da177e4 911/* out: */
1da177e4
LT
912}
913
cf8cdbe5 914static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1da177e4 915{
8687b63a 916 __be32 *p;
1da177e4 917
13c65ce9 918 p = reserve_space(xdr, 8);
e75bc1c8 919 *p++ = cpu_to_be32(OP_ACCESS);
34558513 920 *p = cpu_to_be32(access);
d017931c 921 hdr->nops++;
dadf0c27 922 hdr->replen += decode_access_maxsz;
1da177e4
LT
923}
924
cf8cdbe5 925static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1da177e4 926{
8687b63a 927 __be32 *p;
1da177e4 928
13c65ce9 929 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
e75bc1c8
BH
930 *p++ = cpu_to_be32(OP_CLOSE);
931 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
34558513 932 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
d017931c 933 hdr->nops++;
dadf0c27 934 hdr->replen += decode_close_maxsz;
1da177e4
LT
935}
936
cf8cdbe5 937static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1da177e4 938{
8687b63a 939 __be32 *p;
6c0195a4 940
13c65ce9 941 p = reserve_space(xdr, 16);
e75bc1c8 942 *p++ = cpu_to_be32(OP_COMMIT);
b95be5a9 943 p = xdr_encode_hyper(p, args->offset);
34558513 944 *p = cpu_to_be32(args->count);
d017931c 945 hdr->nops++;
dadf0c27 946 hdr->replen += decode_commit_maxsz;
1da177e4
LT
947}
948
cf8cdbe5 949static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1da177e4 950{
8687b63a 951 __be32 *p;
6c0195a4 952
13c65ce9 953 p = reserve_space(xdr, 8);
e75bc1c8 954 *p++ = cpu_to_be32(OP_CREATE);
34558513 955 *p = cpu_to_be32(create->ftype);
1da177e4
LT
956
957 switch (create->ftype) {
958 case NF4LNK:
13c65ce9 959 p = reserve_space(xdr, 4);
34558513 960 *p = cpu_to_be32(create->u.symlink.len);
94a6d753 961 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1da177e4
LT
962 break;
963
964 case NF4BLK: case NF4CHR:
13c65ce9 965 p = reserve_space(xdr, 8);
e75bc1c8 966 *p++ = cpu_to_be32(create->u.device.specdata1);
34558513 967 *p = cpu_to_be32(create->u.device.specdata2);
1da177e4
LT
968 break;
969
970 default:
971 break;
972 }
973
811652bd 974 encode_string(xdr, create->name->len, create->name->name);
d017931c 975 hdr->nops++;
dadf0c27 976 hdr->replen += decode_create_maxsz;
1da177e4 977
cf8cdbe5 978 encode_attrs(xdr, create->attrs, create->server);
1da177e4
LT
979}
980
cf8cdbe5 981static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1da177e4 982{
05d564fe 983 __be32 *p;
1da177e4 984
13c65ce9 985 p = reserve_space(xdr, 12);
e75bc1c8
BH
986 *p++ = cpu_to_be32(OP_GETATTR);
987 *p++ = cpu_to_be32(1);
34558513 988 *p = cpu_to_be32(bitmap);
d017931c 989 hdr->nops++;
dadf0c27 990 hdr->replen += decode_getattr_maxsz;
1da177e4
LT
991}
992
cf8cdbe5 993static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1da177e4 994{
05d564fe 995 __be32 *p;
1da177e4 996
13c65ce9 997 p = reserve_space(xdr, 16);
e75bc1c8
BH
998 *p++ = cpu_to_be32(OP_GETATTR);
999 *p++ = cpu_to_be32(2);
1000 *p++ = cpu_to_be32(bm0);
34558513 1001 *p = cpu_to_be32(bm1);
d017931c 1002 hdr->nops++;
dadf0c27 1003 hdr->replen += decode_getattr_maxsz;
1da177e4
LT
1004}
1005
cf8cdbe5 1006static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1da177e4 1007{
cf8cdbe5
AA
1008 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1009 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
1da177e4
LT
1010}
1011
cf8cdbe5 1012static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1da177e4 1013{
cf8cdbe5
AA
1014 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1015 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
1da177e4
LT
1016}
1017
cf8cdbe5 1018static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
830b8e33 1019{
cf8cdbe5
AA
1020 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1021 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
830b8e33
MN
1022}
1023
cf8cdbe5 1024static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1da177e4 1025{
8687b63a 1026 __be32 *p;
1da177e4 1027
13c65ce9 1028 p = reserve_space(xdr, 4);
34558513 1029 *p = cpu_to_be32(OP_GETFH);
d017931c 1030 hdr->nops++;
dadf0c27 1031 hdr->replen += decode_getfh_maxsz;
1da177e4
LT
1032}
1033
cf8cdbe5 1034static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1da177e4 1035{
8687b63a 1036 __be32 *p;
1da177e4 1037
13c65ce9 1038 p = reserve_space(xdr, 8 + name->len);
e75bc1c8 1039 *p++ = cpu_to_be32(OP_LINK);
811652bd 1040 xdr_encode_opaque(p, name->name, name->len);
d017931c 1041 hdr->nops++;
dadf0c27 1042 hdr->replen += decode_link_maxsz;
1da177e4
LT
1043}
1044
911d1aaf
TM
1045static inline int nfs4_lock_type(struct file_lock *fl, int block)
1046{
1047 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1048 return block ? NFS4_READW_LT : NFS4_READ_LT;
1049 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1050}
1051
1052static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1053{
1054 if (fl->fl_end == OFFSET_MAX)
1055 return ~(uint64_t)0;
1056 return fl->fl_end - fl->fl_start + 1;
1057}
1058
daccbded
TM
1059static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1060{
1061 __be32 *p;
1062
1063 p = reserve_space(xdr, 28);
1064 p = xdr_encode_hyper(p, lowner->clientid);
1065 *p++ = cpu_to_be32(16);
1066 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1067 xdr_encode_hyper(p, lowner->id);
1068}
1069
1da177e4
LT
1070/*
1071 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1072 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1073 */
cf8cdbe5 1074static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1da177e4 1075{
8687b63a 1076 __be32 *p;
1da177e4 1077
13c65ce9 1078 p = reserve_space(xdr, 32);
e75bc1c8
BH
1079 *p++ = cpu_to_be32(OP_LOCK);
1080 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1081 *p++ = cpu_to_be32(args->reclaim);
b95be5a9
BH
1082 p = xdr_encode_hyper(p, args->fl->fl_start);
1083 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
34558513 1084 *p = cpu_to_be32(args->new_lock_owner);
911d1aaf 1085 if (args->new_lock_owner){
daccbded 1086 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
e75bc1c8 1087 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
93f0cf25 1088 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
e75bc1c8 1089 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
daccbded 1090 encode_lockowner(xdr, &args->lock_owner);
1da177e4
LT
1091 }
1092 else {
13c65ce9 1093 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
93f0cf25 1094 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
34558513 1095 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
1da177e4 1096 }
d017931c 1097 hdr->nops++;
dadf0c27 1098 hdr->replen += decode_lock_maxsz;
1da177e4
LT
1099}
1100
cf8cdbe5 1101static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1da177e4 1102{
8687b63a 1103 __be32 *p;
1da177e4 1104
daccbded 1105 p = reserve_space(xdr, 24);
e75bc1c8
BH
1106 *p++ = cpu_to_be32(OP_LOCKT);
1107 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
b95be5a9
BH
1108 p = xdr_encode_hyper(p, args->fl->fl_start);
1109 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
daccbded 1110 encode_lockowner(xdr, &args->lock_owner);
d017931c 1111 hdr->nops++;
dadf0c27 1112 hdr->replen += decode_lockt_maxsz;
1da177e4
LT
1113}
1114
cf8cdbe5 1115static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1da177e4 1116{
8687b63a 1117 __be32 *p;
1da177e4 1118
13c65ce9 1119 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
e75bc1c8
BH
1120 *p++ = cpu_to_be32(OP_LOCKU);
1121 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1122 *p++ = cpu_to_be32(args->seqid->sequence->counter);
93f0cf25 1123 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
b95be5a9 1124 p = xdr_encode_hyper(p, args->fl->fl_start);
34558513 1125 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
d017931c 1126 hdr->nops++;
dadf0c27 1127 hdr->replen += decode_locku_maxsz;
1da177e4
LT
1128}
1129
d3c7b7cc
TM
1130static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1131{
1132 __be32 *p;
1133
1134 p = reserve_space(xdr, 4);
1135 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1136 encode_lockowner(xdr, lowner);
1137 hdr->nops++;
1138 hdr->replen += decode_release_lockowner_maxsz;
1139}
1140
cf8cdbe5 1141static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1da177e4
LT
1142{
1143 int len = name->len;
8687b63a 1144 __be32 *p;
1da177e4 1145
13c65ce9 1146 p = reserve_space(xdr, 8 + len);
e75bc1c8 1147 *p++ = cpu_to_be32(OP_LOOKUP);
811652bd 1148 xdr_encode_opaque(p, name->name, len);
d017931c 1149 hdr->nops++;
dadf0c27 1150 hdr->replen += decode_lookup_maxsz;
1da177e4
LT
1151}
1152
dc0b027d 1153static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1da177e4 1154{
8687b63a 1155 __be32 *p;
1da177e4 1156
13c65ce9 1157 p = reserve_space(xdr, 8);
dc0b027d 1158 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
05d564fe 1159 case FMODE_READ:
e75bc1c8 1160 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
05d564fe
AA
1161 break;
1162 case FMODE_WRITE:
e75bc1c8 1163 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
05d564fe
AA
1164 break;
1165 case FMODE_READ|FMODE_WRITE:
e75bc1c8 1166 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
05d564fe
AA
1167 break;
1168 default:
e75bc1c8 1169 *p++ = cpu_to_be32(0);
1da177e4 1170 }
34558513 1171 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1da177e4
LT
1172}
1173
1174static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1175{
8687b63a 1176 __be32 *p;
1da177e4
LT
1177 /*
1178 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1179 * owner 4 = 32
1180 */
13c65ce9 1181 p = reserve_space(xdr, 8);
e75bc1c8 1182 *p++ = cpu_to_be32(OP_OPEN);
34558513 1183 *p = cpu_to_be32(arg->seqid->sequence->counter);
dc0b027d 1184 encode_share_access(xdr, arg->fmode);
13c65ce9 1185 p = reserve_space(xdr, 28);
b95be5a9 1186 p = xdr_encode_hyper(p, arg->clientid);
e75bc1c8 1187 *p++ = cpu_to_be32(16);
93f0cf25 1188 p = xdr_encode_opaque_fixed(p, "open id:", 8);
34558513 1189 xdr_encode_hyper(p, arg->id);
1da177e4
LT
1190}
1191
1192static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1193{
8687b63a 1194 __be32 *p;
4882ef72 1195 struct nfs_client *clp;
1da177e4 1196
13c65ce9 1197 p = reserve_space(xdr, 4);
1da177e4 1198 switch(arg->open_flags & O_EXCL) {
05d564fe 1199 case 0:
34558513 1200 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
05d564fe
AA
1201 encode_attrs(xdr, arg->u.attrs, arg->server);
1202 break;
1203 default:
4882ef72 1204 clp = arg->server->nfs_client;
a4432345 1205 if (clp->cl_mvops->minor_version > 0) {
4882ef72
AB
1206 if (nfs4_has_persistent_session(clp)) {
1207 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1208 encode_attrs(xdr, arg->u.attrs, arg->server);
1209 } else {
1210 struct iattr dummy;
1211
1212 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1213 encode_nfs4_verifier(xdr, &arg->u.verifier);
1214 dummy.ia_valid = 0;
1215 encode_attrs(xdr, &dummy, arg->server);
1216 }
1217 } else {
1218 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1219 encode_nfs4_verifier(xdr, &arg->u.verifier);
1220 }
1da177e4
LT
1221 }
1222}
1223
1224static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1225{
8687b63a 1226 __be32 *p;
1da177e4 1227
13c65ce9 1228 p = reserve_space(xdr, 4);
1da177e4 1229 switch (arg->open_flags & O_CREAT) {
05d564fe 1230 case 0:
34558513 1231 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
05d564fe
AA
1232 break;
1233 default:
1234 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
34558513 1235 *p = cpu_to_be32(NFS4_OPEN_CREATE);
05d564fe 1236 encode_createmode(xdr, arg);
1da177e4
LT
1237 }
1238}
1239
bd7bf9d5 1240static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1da177e4 1241{
8687b63a 1242 __be32 *p;
1da177e4 1243
13c65ce9 1244 p = reserve_space(xdr, 4);
1da177e4 1245 switch (delegation_type) {
05d564fe 1246 case 0:
34558513 1247 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
05d564fe
AA
1248 break;
1249 case FMODE_READ:
34558513 1250 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
05d564fe
AA
1251 break;
1252 case FMODE_WRITE|FMODE_READ:
34558513 1253 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
05d564fe
AA
1254 break;
1255 default:
1256 BUG();
1da177e4
LT
1257 }
1258}
1259
1260static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1261{
8687b63a 1262 __be32 *p;
1da177e4 1263
13c65ce9 1264 p = reserve_space(xdr, 4);
34558513 1265 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1da177e4
LT
1266 encode_string(xdr, name->len, name->name);
1267}
1268
bd7bf9d5 1269static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1da177e4 1270{
8687b63a 1271 __be32 *p;
1da177e4 1272
13c65ce9 1273 p = reserve_space(xdr, 4);
34558513 1274 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1da177e4
LT
1275 encode_delegation_type(xdr, type);
1276}
1277
1278static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1279{
8687b63a 1280 __be32 *p;
1da177e4 1281
13c65ce9 1282 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
e75bc1c8 1283 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
34558513 1284 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1da177e4
LT
1285 encode_string(xdr, name->len, name->name);
1286}
1287
cf8cdbe5 1288static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1da177e4
LT
1289{
1290 encode_openhdr(xdr, arg);
1291 encode_opentype(xdr, arg);
1292 switch (arg->claim) {
05d564fe
AA
1293 case NFS4_OPEN_CLAIM_NULL:
1294 encode_claim_null(xdr, arg->name);
1295 break;
1296 case NFS4_OPEN_CLAIM_PREVIOUS:
1297 encode_claim_previous(xdr, arg->u.delegation_type);
1298 break;
1299 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1300 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1301 break;
1302 default:
1303 BUG();
1da177e4 1304 }
d017931c 1305 hdr->nops++;
dadf0c27 1306 hdr->replen += decode_open_maxsz;
1da177e4
LT
1307}
1308
cf8cdbe5 1309static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1da177e4 1310{
8687b63a 1311 __be32 *p;
1da177e4 1312
13c65ce9 1313 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
e75bc1c8 1314 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
93f0cf25 1315 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
34558513 1316 *p = cpu_to_be32(arg->seqid->sequence->counter);
d017931c 1317 hdr->nops++;
dadf0c27 1318 hdr->replen += decode_open_confirm_maxsz;
1da177e4
LT
1319}
1320
cf8cdbe5 1321static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1da177e4 1322{
8687b63a 1323 __be32 *p;
1da177e4 1324
13c65ce9 1325 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
e75bc1c8 1326 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
93f0cf25 1327 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
34558513 1328 *p = cpu_to_be32(arg->seqid->sequence->counter);
dc0b027d 1329 encode_share_access(xdr, arg->fmode);
d017931c 1330 hdr->nops++;
dadf0c27 1331 hdr->replen += decode_open_downgrade_maxsz;
1da177e4
LT
1332}
1333
cf8cdbe5 1334static void
d017931c 1335encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1da177e4
LT
1336{
1337 int len = fh->size;
8687b63a 1338 __be32 *p;
1da177e4 1339
13c65ce9 1340 p = reserve_space(xdr, 8 + len);
e75bc1c8 1341 *p++ = cpu_to_be32(OP_PUTFH);
811652bd 1342 xdr_encode_opaque(p, fh->data, len);
d017931c 1343 hdr->nops++;
dadf0c27 1344 hdr->replen += decode_putfh_maxsz;
1da177e4
LT
1345}
1346
cf8cdbe5 1347static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1da177e4 1348{
05d564fe 1349 __be32 *p;
6c0195a4 1350
13c65ce9 1351 p = reserve_space(xdr, 4);
34558513 1352 *p = cpu_to_be32(OP_PUTROOTFH);
d017931c 1353 hdr->nops++;
dadf0c27 1354 hdr->replen += decode_putrootfh_maxsz;
1da177e4
LT
1355}
1356
f11ac8db 1357static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx)
1da177e4 1358{
1da177e4 1359 nfs4_stateid stateid;
8687b63a 1360 __be32 *p;
1da177e4 1361
13c65ce9 1362 p = reserve_space(xdr, NFS4_STATEID_SIZE);
1da177e4 1363 if (ctx->state != NULL) {
77041ed9 1364 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
34558513 1365 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
1da177e4 1366 } else
34558513 1367 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1da177e4
LT
1368}
1369
cf8cdbe5 1370static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1da177e4 1371{
8687b63a 1372 __be32 *p;
1da177e4 1373
13c65ce9 1374 p = reserve_space(xdr, 4);
34558513 1375 *p = cpu_to_be32(OP_READ);
1da177e4 1376
f11ac8db 1377 encode_stateid(xdr, args->context, args->lock_context);
1da177e4 1378
13c65ce9 1379 p = reserve_space(xdr, 12);
b95be5a9 1380 p = xdr_encode_hyper(p, args->offset);
34558513 1381 *p = cpu_to_be32(args->count);
d017931c 1382 hdr->nops++;
dadf0c27 1383 hdr->replen += decode_read_maxsz;
1da177e4
LT
1384}
1385
cf8cdbe5 1386static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1da177e4 1387{
97d312d0
MN
1388 uint32_t attrs[2] = {
1389 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1390 FATTR4_WORD1_MOUNTED_ON_FILEID,
1391 };
8687b63a 1392 __be32 *p;
1da177e4 1393
13c65ce9 1394 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
e75bc1c8 1395 *p++ = cpu_to_be32(OP_READDIR);
b95be5a9 1396 p = xdr_encode_hyper(p, readdir->cookie);
93f0cf25 1397 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
e75bc1c8
BH
1398 *p++ = cpu_to_be32(readdir->count >> 1); /* We're not doing readdirplus */
1399 *p++ = cpu_to_be32(readdir->count);
1400 *p++ = cpu_to_be32(2);
97d312d0
MN
1401 /* Switch to mounted_on_fileid if the server supports it */
1402 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1403 attrs[0] &= ~FATTR4_WORD0_FILEID;
1404 else
1405 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
e75bc1c8 1406 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
34558513 1407 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
d017931c 1408 hdr->nops++;
dadf0c27 1409 hdr->replen += decode_readdir_maxsz;
44109241
FI
1410 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1411 __func__,
eadf4598
TM
1412 (unsigned long long)readdir->cookie,
1413 ((u32 *)readdir->verifier.data)[0],
1414 ((u32 *)readdir->verifier.data)[1],
1415 attrs[0] & readdir->bitmask[0],
1416 attrs[1] & readdir->bitmask[1]);
1da177e4
LT
1417}
1418
cf8cdbe5 1419static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1da177e4 1420{
8687b63a 1421 __be32 *p;
1da177e4 1422
13c65ce9 1423 p = reserve_space(xdr, 4);
34558513 1424 *p = cpu_to_be32(OP_READLINK);
d017931c 1425 hdr->nops++;
dadf0c27 1426 hdr->replen += decode_readlink_maxsz;
1da177e4
LT
1427}
1428
cf8cdbe5 1429static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1da177e4 1430{
8687b63a 1431 __be32 *p;
1da177e4 1432
13c65ce9 1433 p = reserve_space(xdr, 8 + name->len);
e75bc1c8 1434 *p++ = cpu_to_be32(OP_REMOVE);
811652bd 1435 xdr_encode_opaque(p, name->name, name->len);
d017931c 1436 hdr->nops++;
dadf0c27 1437 hdr->replen += decode_remove_maxsz;
1da177e4
LT
1438}
1439
cf8cdbe5 1440static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1da177e4 1441{
8687b63a 1442 __be32 *p;
1da177e4 1443
811652bd
BH
1444 p = reserve_space(xdr, 4);
1445 *p = cpu_to_be32(OP_RENAME);
1446 encode_string(xdr, oldname->len, oldname->name);
1447 encode_string(xdr, newname->len, newname->name);
d017931c 1448 hdr->nops++;
dadf0c27 1449 hdr->replen += decode_rename_maxsz;
1da177e4
LT
1450}
1451
cf8cdbe5 1452static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1da177e4 1453{
8687b63a 1454 __be32 *p;
1da177e4 1455
13c65ce9 1456 p = reserve_space(xdr, 12);
e75bc1c8 1457 *p++ = cpu_to_be32(OP_RENEW);
34558513 1458 xdr_encode_hyper(p, client_stateid->cl_clientid);
d017931c 1459 hdr->nops++;
dadf0c27 1460 hdr->replen += decode_renew_maxsz;
1da177e4
LT
1461}
1462
cf8cdbe5 1463static void
d017931c 1464encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
56ae19f3 1465{
8687b63a 1466 __be32 *p;
56ae19f3 1467
13c65ce9 1468 p = reserve_space(xdr, 4);
34558513 1469 *p = cpu_to_be32(OP_RESTOREFH);
d017931c 1470 hdr->nops++;
dadf0c27 1471 hdr->replen += decode_restorefh_maxsz;
56ae19f3
TM
1472}
1473
23ec6965 1474static int
d017931c 1475encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
23ec6965 1476{
8687b63a 1477 __be32 *p;
23ec6965 1478
13c65ce9 1479 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
e75bc1c8 1480 *p++ = cpu_to_be32(OP_SETATTR);
34558513 1481 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
13c65ce9 1482 p = reserve_space(xdr, 2*4);
e75bc1c8 1483 *p++ = cpu_to_be32(1);
34558513 1484 *p = cpu_to_be32(FATTR4_WORD0_ACL);
23ec6965
BF
1485 if (arg->acl_len % 4)
1486 return -EINVAL;
13c65ce9 1487 p = reserve_space(xdr, 4);
34558513 1488 *p = cpu_to_be32(arg->acl_len);
23ec6965 1489 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
d017931c 1490 hdr->nops++;
dadf0c27 1491 hdr->replen += decode_setacl_maxsz;
23ec6965
BF
1492 return 0;
1493}
1494
cf8cdbe5 1495static void
d017931c 1496encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1da177e4 1497{
8687b63a 1498 __be32 *p;
1da177e4 1499
13c65ce9 1500 p = reserve_space(xdr, 4);
34558513 1501 *p = cpu_to_be32(OP_SAVEFH);
d017931c 1502 hdr->nops++;
dadf0c27 1503 hdr->replen += decode_savefh_maxsz;
1da177e4
LT
1504}
1505
cf8cdbe5 1506static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1da177e4 1507{
8687b63a 1508 __be32 *p;
6c0195a4 1509
13c65ce9 1510 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
e75bc1c8 1511 *p++ = cpu_to_be32(OP_SETATTR);
34558513 1512 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
d017931c 1513 hdr->nops++;
dadf0c27 1514 hdr->replen += decode_setattr_maxsz;
cf8cdbe5 1515 encode_attrs(xdr, arg->iap, server);
1da177e4
LT
1516}
1517
cf8cdbe5 1518static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1da177e4 1519{
8687b63a 1520 __be32 *p;
1da177e4 1521
13c65ce9 1522 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
e75bc1c8 1523 *p++ = cpu_to_be32(OP_SETCLIENTID);
34558513 1524 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1da177e4
LT
1525
1526 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
13c65ce9 1527 p = reserve_space(xdr, 4);
34558513 1528 *p = cpu_to_be32(setclientid->sc_prog);
1da177e4
LT
1529 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1530 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
13c65ce9 1531 p = reserve_space(xdr, 4);
34558513 1532 *p = cpu_to_be32(setclientid->sc_cb_ident);
d017931c 1533 hdr->nops++;
dadf0c27 1534 hdr->replen += decode_setclientid_maxsz;
1da177e4
LT
1535}
1536
bb8b27e5 1537static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1da177e4 1538{
05d564fe 1539 __be32 *p;
1da177e4 1540
13c65ce9 1541 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
e75bc1c8 1542 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
bb8b27e5
TM
1543 p = xdr_encode_hyper(p, arg->clientid);
1544 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
d017931c 1545 hdr->nops++;
dadf0c27 1546 hdr->replen += decode_setclientid_confirm_maxsz;
1da177e4
LT
1547}
1548
cf8cdbe5 1549static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1da177e4 1550{
8687b63a 1551 __be32 *p;
1da177e4 1552
13c65ce9 1553 p = reserve_space(xdr, 4);
34558513 1554 *p = cpu_to_be32(OP_WRITE);
1da177e4 1555
f11ac8db 1556 encode_stateid(xdr, args->context, args->lock_context);
1da177e4 1557
13c65ce9 1558 p = reserve_space(xdr, 16);
b95be5a9 1559 p = xdr_encode_hyper(p, args->offset);
e75bc1c8 1560 *p++ = cpu_to_be32(args->stable);
34558513 1561 *p = cpu_to_be32(args->count);
1da177e4
LT
1562
1563 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
d017931c 1564 hdr->nops++;
dadf0c27 1565 hdr->replen += decode_write_maxsz;
1da177e4
LT
1566}
1567
cf8cdbe5 1568static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1da177e4 1569{
8687b63a 1570 __be32 *p;
1da177e4 1571
13c65ce9 1572 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1da177e4 1573
e75bc1c8 1574 *p++ = cpu_to_be32(OP_DELEGRETURN);
34558513 1575 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
d017931c 1576 hdr->nops++;
dadf0c27 1577 hdr->replen += decode_delegreturn_maxsz;
1da177e4 1578}
9b7b9fcc 1579
99fe60d0 1580#if defined(CONFIG_NFS_V4_1)
9b7b9fcc 1581/* NFSv4.1 operations */
99fe60d0
BH
1582static void encode_exchange_id(struct xdr_stream *xdr,
1583 struct nfs41_exchange_id_args *args,
1584 struct compound_hdr *hdr)
1585{
1586 __be32 *p;
1587
13c65ce9 1588 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
e75bc1c8 1589 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
34558513 1590 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
99fe60d0
BH
1591
1592 encode_string(xdr, args->id_len, args->id);
1593
13c65ce9 1594 p = reserve_space(xdr, 12);
e75bc1c8
BH
1595 *p++ = cpu_to_be32(args->flags);
1596 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
34558513 1597 *p = cpu_to_be32(0); /* zero length implementation id array */
99fe60d0
BH
1598 hdr->nops++;
1599 hdr->replen += decode_exchange_id_maxsz;
1600}
fc931582
AA
1601
1602static void encode_create_session(struct xdr_stream *xdr,
1603 struct nfs41_create_session_args *args,
1604 struct compound_hdr *hdr)
1605{
1606 __be32 *p;
1607 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1608 uint32_t len;
1609 struct nfs_client *clp = args->client;
8e0d46e1
MS
1610 u32 max_resp_sz_cached;
1611
1612 /*
1613 * Assumes OPEN is the biggest non-idempotent compound.
1614 * 2 is the verifier.
1615 */
1616 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1617 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
fc931582 1618
42edd698
BH
1619 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1620 clp->cl_ipaddr);
fc931582 1621
13c65ce9 1622 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
42edd698 1623 *p++ = cpu_to_be32(OP_CREATE_SESSION);
b95be5a9 1624 p = xdr_encode_hyper(p, clp->cl_ex_clid);
e75bc1c8
BH
1625 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1626 *p++ = cpu_to_be32(args->flags); /*flags */
fc931582 1627
fc931582 1628 /* Fore Channel */
e75bc1c8
BH
1629 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1630 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1631 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
8e0d46e1 1632 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
e75bc1c8
BH
1633 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1634 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1635 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
fc931582
AA
1636
1637 /* Back Channel */
e75bc1c8
BH
1638 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1639 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1640 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1641 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1642 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1643 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1644 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
fc931582 1645
e75bc1c8 1646 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
e75bc1c8 1647 *p++ = cpu_to_be32(1);
e75bc1c8 1648 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
fc931582
AA
1649
1650 /* authsys_parms rfc1831 */
e75bc1c8 1651 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
811652bd 1652 p = xdr_encode_opaque(p, machine_name, len);
e75bc1c8
BH
1653 *p++ = cpu_to_be32(0); /* UID */
1654 *p++ = cpu_to_be32(0); /* GID */
34558513 1655 *p = cpu_to_be32(0); /* No more gids */
fc931582
AA
1656 hdr->nops++;
1657 hdr->replen += decode_create_session_maxsz;
1658}
0f3e66c6
AA
1659
1660static void encode_destroy_session(struct xdr_stream *xdr,
1661 struct nfs4_session *session,
1662 struct compound_hdr *hdr)
1663{
1664 __be32 *p;
13c65ce9 1665 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
e75bc1c8 1666 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
34558513 1667 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
0f3e66c6
AA
1668 hdr->nops++;
1669 hdr->replen += decode_destroy_session_maxsz;
1670}
18019753
RL
1671
1672static void encode_reclaim_complete(struct xdr_stream *xdr,
1673 struct nfs41_reclaim_complete_args *args,
1674 struct compound_hdr *hdr)
1675{
1676 __be32 *p;
1677
1678 p = reserve_space(xdr, 8);
1679 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1680 *p++ = cpu_to_be32(args->one_fs);
1681 hdr->nops++;
1682 hdr->replen += decode_reclaim_complete_maxsz;
1683}
99fe60d0
BH
1684#endif /* CONFIG_NFS_V4_1 */
1685
9b7b9fcc
AA
1686static void encode_sequence(struct xdr_stream *xdr,
1687 const struct nfs4_sequence_args *args,
1688 struct compound_hdr *hdr)
1689{
1690#if defined(CONFIG_NFS_V4_1)
1691 struct nfs4_session *session = args->sa_session;
fc01cea9
AA
1692 struct nfs4_slot_table *tp;
1693 struct nfs4_slot *slot;
1694 __be32 *p;
9b7b9fcc
AA
1695
1696 if (!session)
1697 return;
1698
fc01cea9
AA
1699 tp = &session->fc_slot_table;
1700
1701 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1702 slot = tp->slots + args->sa_slotid;
1703
13c65ce9 1704 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
e75bc1c8 1705 *p++ = cpu_to_be32(OP_SEQUENCE);
fc01cea9
AA
1706
1707 /*
1708 * Sessionid + seqid + slotid + max slotid + cache_this
1709 */
1710 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1711 "max_slotid=%d cache_this=%d\n",
1712 __func__,
1713 ((u32 *)session->sess_id.data)[0],
1714 ((u32 *)session->sess_id.data)[1],
1715 ((u32 *)session->sess_id.data)[2],
1716 ((u32 *)session->sess_id.data)[3],
1717 slot->seq_nr, args->sa_slotid,
1718 tp->highest_used_slotid, args->sa_cache_this);
93f0cf25 1719 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
e75bc1c8
BH
1720 *p++ = cpu_to_be32(slot->seq_nr);
1721 *p++ = cpu_to_be32(args->sa_slotid);
1722 *p++ = cpu_to_be32(tp->highest_used_slotid);
34558513 1723 *p = cpu_to_be32(args->sa_cache_this);
9b7b9fcc
AA
1724 hdr->nops++;
1725 hdr->replen += decode_sequence_maxsz;
1726#endif /* CONFIG_NFS_V4_1 */
1727}
1728
1da177e4
LT
1729/*
1730 * END OF "GENERIC" ENCODE ROUTINES.
1731 */
1732
66cc0429
BH
1733static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1734{
1735#if defined(CONFIG_NFS_V4_1)
1736 if (args->sa_session)
a4432345 1737 return args->sa_session->clp->cl_mvops->minor_version;
66cc0429
BH
1738#endif /* CONFIG_NFS_V4_1 */
1739 return 0;
1740}
1741
1da177e4
LT
1742/*
1743 * Encode an ACCESS request
1744 */
8687b63a 1745static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1da177e4
LT
1746{
1747 struct xdr_stream xdr;
1748 struct compound_hdr hdr = {
66cc0429 1749 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1750 };
1da177e4
LT
1751
1752 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1753 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1754 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1755 encode_putfh(&xdr, args->fh, &hdr);
1756 encode_access(&xdr, args->access, &hdr);
1757 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1758 encode_nops(&hdr);
cf8cdbe5 1759 return 0;
1da177e4
LT
1760}
1761
1762/*
1763 * Encode LOOKUP request
1764 */
8687b63a 1765static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1da177e4
LT
1766{
1767 struct xdr_stream xdr;
1768 struct compound_hdr hdr = {
66cc0429 1769 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1770 };
1da177e4
LT
1771
1772 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1773 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1774 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1775 encode_putfh(&xdr, args->dir_fh, &hdr);
1776 encode_lookup(&xdr, args->name, &hdr);
1777 encode_getfh(&xdr, &hdr);
1778 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1779 encode_nops(&hdr);
cf8cdbe5 1780 return 0;
1da177e4
LT
1781}
1782
1783/*
1784 * Encode LOOKUP_ROOT request
1785 */
8687b63a 1786static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1da177e4
LT
1787{
1788 struct xdr_stream xdr;
1789 struct compound_hdr hdr = {
66cc0429 1790 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1791 };
1da177e4
LT
1792
1793 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1794 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1795 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1796 encode_putrootfh(&xdr, &hdr);
1797 encode_getfh(&xdr, &hdr);
1798 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1799 encode_nops(&hdr);
cf8cdbe5 1800 return 0;
1da177e4
LT
1801}
1802
1803/*
1804 * Encode REMOVE request
1805 */
4fdc17b2 1806static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
1da177e4
LT
1807{
1808 struct xdr_stream xdr;
1809 struct compound_hdr hdr = {
66cc0429 1810 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1811 };
1da177e4
LT
1812
1813 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1814 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1815 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1816 encode_putfh(&xdr, args->fh, &hdr);
1817 encode_remove(&xdr, &args->name, &hdr);
1818 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1819 encode_nops(&hdr);
cf8cdbe5 1820 return 0;
1da177e4
LT
1821}
1822
1823/*
1824 * Encode RENAME request
1825 */
920769f0 1826static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs_renameargs *args)
1da177e4
LT
1827{
1828 struct xdr_stream xdr;
1829 struct compound_hdr hdr = {
66cc0429 1830 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1831 };
1da177e4
LT
1832
1833 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1834 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1835 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1836 encode_putfh(&xdr, args->old_dir, &hdr);
1837 encode_savefh(&xdr, &hdr);
1838 encode_putfh(&xdr, args->new_dir, &hdr);
1839 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1840 encode_getfattr(&xdr, args->bitmask, &hdr);
1841 encode_restorefh(&xdr, &hdr);
1842 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1843 encode_nops(&hdr);
cf8cdbe5 1844 return 0;
1da177e4
LT
1845}
1846
1847/*
1848 * Encode LINK request
1849 */
8687b63a 1850static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1da177e4
LT
1851{
1852 struct xdr_stream xdr;
1853 struct compound_hdr hdr = {
66cc0429 1854 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1855 };
1da177e4
LT
1856
1857 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1858 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1859 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1860 encode_putfh(&xdr, args->fh, &hdr);
1861 encode_savefh(&xdr, &hdr);
1862 encode_putfh(&xdr, args->dir_fh, &hdr);
1863 encode_link(&xdr, args->name, &hdr);
1864 encode_getfattr(&xdr, args->bitmask, &hdr);
1865 encode_restorefh(&xdr, &hdr);
1866 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1867 encode_nops(&hdr);
cf8cdbe5 1868 return 0;
1da177e4
LT
1869}
1870
1871/*
1872 * Encode CREATE request
1873 */
8687b63a 1874static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1da177e4
LT
1875{
1876 struct xdr_stream xdr;
1877 struct compound_hdr hdr = {
66cc0429 1878 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1879 };
1da177e4
LT
1880
1881 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1882 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1883 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1884 encode_putfh(&xdr, args->dir_fh, &hdr);
1885 encode_savefh(&xdr, &hdr);
1886 encode_create(&xdr, args, &hdr);
1887 encode_getfh(&xdr, &hdr);
1888 encode_getfattr(&xdr, args->bitmask, &hdr);
1889 encode_restorefh(&xdr, &hdr);
1890 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1891 encode_nops(&hdr);
cf8cdbe5 1892 return 0;
1da177e4
LT
1893}
1894
1895/*
1896 * Encode SYMLINK request
1897 */
8687b63a 1898static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1da177e4
LT
1899{
1900 return nfs4_xdr_enc_create(req, p, args);
1901}
1902
1903/*
1904 * Encode GETATTR request
1905 */
8687b63a 1906static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1da177e4
LT
1907{
1908 struct xdr_stream xdr;
1909 struct compound_hdr hdr = {
66cc0429 1910 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1911 };
1da177e4
LT
1912
1913 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1914 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1915 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1916 encode_putfh(&xdr, args->fh, &hdr);
1917 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1918 encode_nops(&hdr);
cf8cdbe5 1919 return 0;
1da177e4
LT
1920}
1921
1922/*
1923 * Encode a CLOSE request
1924 */
8687b63a 1925static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1da177e4 1926{
05d564fe
AA
1927 struct xdr_stream xdr;
1928 struct compound_hdr hdr = {
66cc0429 1929 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
05d564fe 1930 };
05d564fe
AA
1931
1932 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1933 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1934 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1935 encode_putfh(&xdr, args->fh, &hdr);
1936 encode_close(&xdr, args, &hdr);
1937 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1938 encode_nops(&hdr);
cf8cdbe5 1939 return 0;
1da177e4
LT
1940}
1941
1942/*
1943 * Encode an OPEN request
1944 */
8687b63a 1945static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1da177e4
LT
1946{
1947 struct xdr_stream xdr;
1948 struct compound_hdr hdr = {
66cc0429 1949 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1950 };
1da177e4
LT
1951
1952 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1953 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1954 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1955 encode_putfh(&xdr, args->fh, &hdr);
1956 encode_savefh(&xdr, &hdr);
1957 encode_open(&xdr, args, &hdr);
1958 encode_getfh(&xdr, &hdr);
1959 encode_getfattr(&xdr, args->bitmask, &hdr);
1960 encode_restorefh(&xdr, &hdr);
1961 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 1962 encode_nops(&hdr);
cf8cdbe5 1963 return 0;
1da177e4
LT
1964}
1965
1966/*
1967 * Encode an OPEN_CONFIRM request
1968 */
8687b63a 1969static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1da177e4
LT
1970{
1971 struct xdr_stream xdr;
1972 struct compound_hdr hdr = {
d017931c 1973 .nops = 0,
1da177e4 1974 };
1da177e4
LT
1975
1976 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1977 encode_compound_hdr(&xdr, req, &hdr);
cf8cdbe5
AA
1978 encode_putfh(&xdr, args->fh, &hdr);
1979 encode_open_confirm(&xdr, args, &hdr);
d017931c 1980 encode_nops(&hdr);
cf8cdbe5 1981 return 0;
1da177e4
LT
1982}
1983
1984/*
1985 * Encode an OPEN request with no attributes.
1986 */
8687b63a 1987static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1da177e4
LT
1988{
1989 struct xdr_stream xdr;
1990 struct compound_hdr hdr = {
66cc0429 1991 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 1992 };
1da177e4
LT
1993
1994 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 1995 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 1996 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
1997 encode_putfh(&xdr, args->fh, &hdr);
1998 encode_open(&xdr, args, &hdr);
1999 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 2000 encode_nops(&hdr);
cf8cdbe5 2001 return 0;
1da177e4
LT
2002}
2003
2004/*
2005 * Encode an OPEN_DOWNGRADE request
2006 */
8687b63a 2007static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1da177e4
LT
2008{
2009 struct xdr_stream xdr;
2010 struct compound_hdr hdr = {
66cc0429 2011 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2012 };
1da177e4
LT
2013
2014 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2015 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2016 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2017 encode_putfh(&xdr, args->fh, &hdr);
2018 encode_open_downgrade(&xdr, args, &hdr);
2019 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 2020 encode_nops(&hdr);
cf8cdbe5 2021 return 0;
1da177e4
LT
2022}
2023
2024/*
2025 * Encode a LOCK request
2026 */
8687b63a 2027static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1da177e4
LT
2028{
2029 struct xdr_stream xdr;
2030 struct compound_hdr hdr = {
66cc0429 2031 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2032 };
1da177e4
LT
2033
2034 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2035 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2036 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2037 encode_putfh(&xdr, args->fh, &hdr);
2038 encode_lock(&xdr, args, &hdr);
d017931c 2039 encode_nops(&hdr);
cf8cdbe5 2040 return 0;
1da177e4
LT
2041}
2042
2043/*
2044 * Encode a LOCKT request
2045 */
8687b63a 2046static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1da177e4
LT
2047{
2048 struct xdr_stream xdr;
2049 struct compound_hdr hdr = {
66cc0429 2050 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2051 };
1da177e4
LT
2052
2053 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2054 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2055 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2056 encode_putfh(&xdr, args->fh, &hdr);
2057 encode_lockt(&xdr, args, &hdr);
d017931c 2058 encode_nops(&hdr);
cf8cdbe5 2059 return 0;
1da177e4
LT
2060}
2061
2062/*
2063 * Encode a LOCKU request
2064 */
8687b63a 2065static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1da177e4
LT
2066{
2067 struct xdr_stream xdr;
2068 struct compound_hdr hdr = {
66cc0429 2069 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2070 };
1da177e4
LT
2071
2072 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2073 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2074 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2075 encode_putfh(&xdr, args->fh, &hdr);
2076 encode_locku(&xdr, args, &hdr);
d017931c 2077 encode_nops(&hdr);
cf8cdbe5 2078 return 0;
1da177e4
LT
2079}
2080
d3c7b7cc
TM
2081static int nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, __be32 *p, struct nfs_release_lockowner_args *args)
2082{
2083 struct xdr_stream xdr;
2084 struct compound_hdr hdr = {
2085 .minorversion = 0,
2086 };
2087
2088 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2089 encode_compound_hdr(&xdr, req, &hdr);
2090 encode_release_lockowner(&xdr, &args->lock_owner, &hdr);
2091 encode_nops(&hdr);
2092 return 0;
2093}
2094
1da177e4
LT
2095/*
2096 * Encode a READLINK request
2097 */
8687b63a 2098static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1da177e4
LT
2099{
2100 struct xdr_stream xdr;
2101 struct compound_hdr hdr = {
66cc0429 2102 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2103 };
1da177e4
LT
2104
2105 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2106 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2107 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2108 encode_putfh(&xdr, args->fh, &hdr);
2109 encode_readlink(&xdr, args, req, &hdr);
e3a535e1 2110
28f56694 2111 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
e3a535e1 2112 args->pgbase, args->pglen);
d017931c 2113 encode_nops(&hdr);
cf8cdbe5 2114 return 0;
1da177e4
LT
2115}
2116
2117/*
2118 * Encode a READDIR request
2119 */
8687b63a 2120static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1da177e4
LT
2121{
2122 struct xdr_stream xdr;
2123 struct compound_hdr hdr = {
66cc0429 2124 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2125 };
1da177e4
LT
2126
2127 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2128 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2129 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2130 encode_putfh(&xdr, args->fh, &hdr);
2131 encode_readdir(&xdr, args, req, &hdr);
d6ac02df 2132
28f56694 2133 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
d6ac02df
TM
2134 args->pgbase, args->count);
2135 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
28f56694 2136 __func__, hdr.replen << 2, args->pages,
d6ac02df 2137 args->pgbase, args->count);
d017931c 2138 encode_nops(&hdr);
cf8cdbe5 2139 return 0;
1da177e4
LT
2140}
2141
2142/*
2143 * Encode a READ request
2144 */
8687b63a 2145static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1da177e4 2146{
1da177e4
LT
2147 struct xdr_stream xdr;
2148 struct compound_hdr hdr = {
66cc0429 2149 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2150 };
1da177e4
LT
2151
2152 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2153 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2154 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2155 encode_putfh(&xdr, args->fh, &hdr);
2156 encode_read(&xdr, args, &hdr);
1da177e4 2157
28f56694 2158 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
1da177e4 2159 args->pages, args->pgbase, args->count);
4f22ccc3 2160 req->rq_rcv_buf.flags |= XDRBUF_READ;
d017931c 2161 encode_nops(&hdr);
cf8cdbe5 2162 return 0;
1da177e4
LT
2163}
2164
2165/*
2166 * Encode an SETATTR request
2167 */
8687b63a 2168static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1da177e4 2169{
05d564fe
AA
2170 struct xdr_stream xdr;
2171 struct compound_hdr hdr = {
66cc0429 2172 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
05d564fe 2173 };
05d564fe
AA
2174
2175 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2176 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2177 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2178 encode_putfh(&xdr, args->fh, &hdr);
2179 encode_setattr(&xdr, args, args->server, &hdr);
2180 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 2181 encode_nops(&hdr);
cf8cdbe5 2182 return 0;
1da177e4
LT
2183}
2184
029d105e
BF
2185/*
2186 * Encode a GETACL request
2187 */
2188static int
8687b63a 2189nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
029d105e
BF
2190 struct nfs_getaclargs *args)
2191{
2192 struct xdr_stream xdr;
029d105e 2193 struct compound_hdr hdr = {
66cc0429 2194 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
029d105e 2195 };
28f56694 2196 uint32_t replen;
029d105e
BF
2197
2198 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2199 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2200 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5 2201 encode_putfh(&xdr, args->fh, &hdr);
d327cf74 2202 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
cf8cdbe5
AA
2203 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2204
28f56694 2205 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
029d105e 2206 args->acl_pages, args->acl_pgbase, args->acl_len);
d017931c 2207 encode_nops(&hdr);
cf8cdbe5 2208 return 0;
029d105e
BF
2209}
2210
1da177e4
LT
2211/*
2212 * Encode a WRITE request
2213 */
8687b63a 2214static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1da177e4
LT
2215{
2216 struct xdr_stream xdr;
2217 struct compound_hdr hdr = {
66cc0429 2218 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2219 };
1da177e4
LT
2220
2221 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2222 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2223 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2224 encode_putfh(&xdr, args->fh, &hdr);
2225 encode_write(&xdr, args, &hdr);
4f22ccc3 2226 req->rq_snd_buf.flags |= XDRBUF_WRITE;
cf8cdbe5 2227 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 2228 encode_nops(&hdr);
cf8cdbe5 2229 return 0;
1da177e4
LT
2230}
2231
2232/*
2233 * a COMMIT request
2234 */
8687b63a 2235static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1da177e4
LT
2236{
2237 struct xdr_stream xdr;
2238 struct compound_hdr hdr = {
66cc0429 2239 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2240 };
1da177e4
LT
2241
2242 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2243 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2244 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2245 encode_putfh(&xdr, args->fh, &hdr);
2246 encode_commit(&xdr, args, &hdr);
2247 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 2248 encode_nops(&hdr);
cf8cdbe5 2249 return 0;
1da177e4
LT
2250}
2251
2252/*
2253 * FSINFO request
2254 */
8687b63a 2255static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
1da177e4
LT
2256{
2257 struct xdr_stream xdr;
2258 struct compound_hdr hdr = {
66cc0429 2259 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2260 };
1da177e4
LT
2261
2262 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2263 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2264 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2265 encode_putfh(&xdr, args->fh, &hdr);
2266 encode_fsinfo(&xdr, args->bitmask, &hdr);
d017931c 2267 encode_nops(&hdr);
cf8cdbe5 2268 return 0;
1da177e4
LT
2269}
2270
2271/*
2272 * a PATHCONF request
2273 */
8687b63a 2274static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
1da177e4 2275{
1da177e4
LT
2276 struct xdr_stream xdr;
2277 struct compound_hdr hdr = {
66cc0429 2278 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2279 };
1da177e4
LT
2280
2281 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2282 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2283 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2284 encode_putfh(&xdr, args->fh, &hdr);
2285 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2286 &hdr);
d017931c 2287 encode_nops(&hdr);
cf8cdbe5 2288 return 0;
1da177e4
LT
2289}
2290
2291/*
2292 * a STATFS request
2293 */
8687b63a 2294static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
1da177e4 2295{
1da177e4
LT
2296 struct xdr_stream xdr;
2297 struct compound_hdr hdr = {
66cc0429 2298 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2299 };
1da177e4
LT
2300
2301 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2302 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2303 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2304 encode_putfh(&xdr, args->fh, &hdr);
2305 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2306 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
d017931c 2307 encode_nops(&hdr);
cf8cdbe5 2308 return 0;
1da177e4
LT
2309}
2310
2311/*
2312 * GETATTR_BITMAP request
2313 */
43652ad5
BH
2314static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2315 struct nfs4_server_caps_arg *args)
1da177e4
LT
2316{
2317 struct xdr_stream xdr;
2318 struct compound_hdr hdr = {
66cc0429 2319 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2320 };
1da177e4
LT
2321
2322 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2323 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2324 encode_sequence(&xdr, &args->seq_args, &hdr);
43652ad5 2325 encode_putfh(&xdr, args->fhandle, &hdr);
cf8cdbe5
AA
2326 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2327 FATTR4_WORD0_LINK_SUPPORT|
2328 FATTR4_WORD0_SYMLINK_SUPPORT|
2329 FATTR4_WORD0_ACLSUPPORT, &hdr);
d017931c 2330 encode_nops(&hdr);
cf8cdbe5 2331 return 0;
1da177e4
LT
2332}
2333
2334/*
2335 * a RENEW request
2336 */
8687b63a 2337static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1da177e4
LT
2338{
2339 struct xdr_stream xdr;
2340 struct compound_hdr hdr = {
d017931c 2341 .nops = 0,
1da177e4
LT
2342 };
2343
2344 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2345 encode_compound_hdr(&xdr, req, &hdr);
cf8cdbe5 2346 encode_renew(&xdr, clp, &hdr);
d017931c 2347 encode_nops(&hdr);
cf8cdbe5 2348 return 0;
1da177e4
LT
2349}
2350
2351/*
2352 * a SETCLIENTID request
2353 */
8687b63a 2354static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
1da177e4
LT
2355{
2356 struct xdr_stream xdr;
2357 struct compound_hdr hdr = {
d017931c 2358 .nops = 0,
1da177e4
LT
2359 };
2360
2361 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2362 encode_compound_hdr(&xdr, req, &hdr);
cf8cdbe5 2363 encode_setclientid(&xdr, sc, &hdr);
d017931c 2364 encode_nops(&hdr);
cf8cdbe5 2365 return 0;
1da177e4
LT
2366}
2367
2368/*
2369 * a SETCLIENTID_CONFIRM request
2370 */
bb8b27e5 2371static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid_res *arg)
1da177e4
LT
2372{
2373 struct xdr_stream xdr;
2374 struct compound_hdr hdr = {
d017931c 2375 .nops = 0,
1da177e4
LT
2376 };
2377 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1da177e4
LT
2378
2379 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2380 encode_compound_hdr(&xdr, req, &hdr);
bb8b27e5 2381 encode_setclientid_confirm(&xdr, arg, &hdr);
cf8cdbe5
AA
2382 encode_putrootfh(&xdr, &hdr);
2383 encode_fsinfo(&xdr, lease_bitmap, &hdr);
d017931c 2384 encode_nops(&hdr);
cf8cdbe5 2385 return 0;
1da177e4
LT
2386}
2387
2388/*
2389 * DELEGRETURN request
2390 */
8687b63a 2391static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
1da177e4
LT
2392{
2393 struct xdr_stream xdr;
2394 struct compound_hdr hdr = {
66cc0429 2395 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1da177e4 2396 };
1da177e4
LT
2397
2398 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2399 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2400 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2401 encode_putfh(&xdr, args->fhandle, &hdr);
2402 encode_delegreturn(&xdr, args->stateid, &hdr);
2403 encode_getfattr(&xdr, args->bitmask, &hdr);
d017931c 2404 encode_nops(&hdr);
cf8cdbe5 2405 return 0;
1da177e4
LT
2406}
2407
683b57b4
TM
2408/*
2409 * Encode FS_LOCATIONS request
2410 */
8687b63a 2411static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
683b57b4
TM
2412{
2413 struct xdr_stream xdr;
2414 struct compound_hdr hdr = {
66cc0429 2415 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
683b57b4 2416 };
28f56694 2417 uint32_t replen;
683b57b4
TM
2418
2419 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 2420 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 2421 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5
AA
2422 encode_putfh(&xdr, args->dir_fh, &hdr);
2423 encode_lookup(&xdr, args->name, &hdr);
28f56694 2424 replen = hdr.replen; /* get the attribute into args->page */
cf8cdbe5
AA
2425 encode_fs_locations(&xdr, args->bitmask, &hdr);
2426
28f56694 2427 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
683b57b4 2428 0, PAGE_SIZE);
d017931c 2429 encode_nops(&hdr);
cf8cdbe5 2430 return 0;
683b57b4
TM
2431}
2432
99fe60d0
BH
2433#if defined(CONFIG_NFS_V4_1)
2434/*
2435 * EXCHANGE_ID request
2436 */
2437static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2438 struct nfs41_exchange_id_args *args)
2439{
2440 struct xdr_stream xdr;
2441 struct compound_hdr hdr = {
a4432345 2442 .minorversion = args->client->cl_mvops->minor_version,
99fe60d0
BH
2443 };
2444
2445 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2446 encode_compound_hdr(&xdr, req, &hdr);
2447 encode_exchange_id(&xdr, args, &hdr);
2448 encode_nops(&hdr);
2449 return 0;
2450}
2050f0cc 2451
fc931582
AA
2452/*
2453 * a CREATE_SESSION request
2454 */
2455static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2456 struct nfs41_create_session_args *args)
2457{
2458 struct xdr_stream xdr;
2459 struct compound_hdr hdr = {
a4432345 2460 .minorversion = args->client->cl_mvops->minor_version,
fc931582
AA
2461 };
2462
2463 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2464 encode_compound_hdr(&xdr, req, &hdr);
2465 encode_create_session(&xdr, args, &hdr);
2466 encode_nops(&hdr);
2467 return 0;
2468}
2469
0f3e66c6
AA
2470/*
2471 * a DESTROY_SESSION request
2472 */
2473static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2474 struct nfs4_session *session)
2475{
2476 struct xdr_stream xdr;
2477 struct compound_hdr hdr = {
a4432345 2478 .minorversion = session->clp->cl_mvops->minor_version,
0f3e66c6
AA
2479 };
2480
2481 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2482 encode_compound_hdr(&xdr, req, &hdr);
2483 encode_destroy_session(&xdr, session, &hdr);
2484 encode_nops(&hdr);
2485 return 0;
2486}
2487
fc01cea9
AA
2488/*
2489 * a SEQUENCE request
2490 */
2491static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p,
2492 struct nfs4_sequence_args *args)
2493{
2494 struct xdr_stream xdr;
2495 struct compound_hdr hdr = {
2496 .minorversion = nfs4_xdr_minorversion(args),
2497 };
2498
2499 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2500 encode_compound_hdr(&xdr, req, &hdr);
2501 encode_sequence(&xdr, args, &hdr);
2502 encode_nops(&hdr);
2503 return 0;
2504}
2505
2050f0cc
AA
2506/*
2507 * a GET_LEASE_TIME request
2508 */
2509static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2510 struct nfs4_get_lease_time_args *args)
2511{
2512 struct xdr_stream xdr;
2513 struct compound_hdr hdr = {
2514 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2515 };
2516 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2517
2518 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2519 encode_compound_hdr(&xdr, req, &hdr);
2520 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2521 encode_putrootfh(&xdr, &hdr);
2522 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2523 encode_nops(&hdr);
2524 return 0;
2525}
18019753
RL
2526
2527/*
2528 * a RECLAIM_COMPLETE request
2529 */
2530static int nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, uint32_t *p,
2531 struct nfs41_reclaim_complete_args *args)
2532{
2533 struct xdr_stream xdr;
2534 struct compound_hdr hdr = {
2535 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2536 };
2537
2538 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2539 encode_compound_hdr(&xdr, req, &hdr);
2540 encode_sequence(&xdr, &args->seq_args, &hdr);
2541 encode_reclaim_complete(&xdr, args, &hdr);
2542 encode_nops(&hdr);
2543 return 0;
2544}
2545
99fe60d0
BH
2546#endif /* CONFIG_NFS_V4_1 */
2547
686841b3
BH
2548static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2549{
2550 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2551 "Remaining buffer length is %tu words.\n",
2552 func, xdr->end - xdr->p);
2553}
1da177e4 2554
683b57b4 2555static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
1da177e4 2556{
8687b63a 2557 __be32 *p;
1da177e4 2558
c0eae66e
BH
2559 p = xdr_inline_decode(xdr, 4);
2560 if (unlikely(!p))
2561 goto out_overflow;
cccddf4f 2562 *len = be32_to_cpup(p);
c0eae66e
BH
2563 p = xdr_inline_decode(xdr, *len);
2564 if (unlikely(!p))
2565 goto out_overflow;
1da177e4
LT
2566 *string = (char *)p;
2567 return 0;
c0eae66e
BH
2568out_overflow:
2569 print_overflow_msg(__func__, xdr);
2570 return -EIO;
1da177e4
LT
2571}
2572
2573static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2574{
8687b63a 2575 __be32 *p;
1da177e4 2576
c0eae66e
BH
2577 p = xdr_inline_decode(xdr, 8);
2578 if (unlikely(!p))
2579 goto out_overflow;
6f723f77 2580 hdr->status = be32_to_cpup(p++);
cccddf4f 2581 hdr->taglen = be32_to_cpup(p);
6c0195a4 2582
c0eae66e
BH
2583 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2584 if (unlikely(!p))
2585 goto out_overflow;
1da177e4
LT
2586 hdr->tag = (char *)p;
2587 p += XDR_QUADLEN(hdr->taglen);
cccddf4f 2588 hdr->nops = be32_to_cpup(p);
aadf6152
BH
2589 if (unlikely(hdr->nops < 1))
2590 return nfs4_stat_to_errno(hdr->status);
1da177e4 2591 return 0;
c0eae66e
BH
2592out_overflow:
2593 print_overflow_msg(__func__, xdr);
2594 return -EIO;
1da177e4
LT
2595}
2596
2597static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2598{
8687b63a 2599 __be32 *p;
1da177e4
LT
2600 uint32_t opnum;
2601 int32_t nfserr;
2602
c0eae66e
BH
2603 p = xdr_inline_decode(xdr, 8);
2604 if (unlikely(!p))
2605 goto out_overflow;
6f723f77 2606 opnum = be32_to_cpup(p++);
1da177e4 2607 if (opnum != expected) {
fe82a183
CL
2608 dprintk("nfs: Server returned operation"
2609 " %d but we issued a request for %d\n",
1da177e4
LT
2610 opnum, expected);
2611 return -EIO;
2612 }
cccddf4f 2613 nfserr = be32_to_cpup(p);
1da177e4 2614 if (nfserr != NFS_OK)
856dff3d 2615 return nfs4_stat_to_errno(nfserr);
1da177e4 2616 return 0;
c0eae66e
BH
2617out_overflow:
2618 print_overflow_msg(__func__, xdr);
2619 return -EIO;
1da177e4
LT
2620}
2621
2622/* Dummy routine */
adfa6f98 2623static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
1da177e4 2624{
8687b63a 2625 __be32 *p;
683b57b4 2626 unsigned int strlen;
1da177e4
LT
2627 char *str;
2628
c0eae66e
BH
2629 p = xdr_inline_decode(xdr, 12);
2630 if (likely(p))
2631 return decode_opaque_inline(xdr, &strlen, &str);
2632 print_overflow_msg(__func__, xdr);
2633 return -EIO;
1da177e4
LT
2634}
2635
2636static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2637{
8687b63a
AV
2638 uint32_t bmlen;
2639 __be32 *p;
1da177e4 2640
c0eae66e
BH
2641 p = xdr_inline_decode(xdr, 4);
2642 if (unlikely(!p))
2643 goto out_overflow;
cccddf4f 2644 bmlen = be32_to_cpup(p);
1da177e4
LT
2645
2646 bitmap[0] = bitmap[1] = 0;
c0eae66e
BH
2647 p = xdr_inline_decode(xdr, (bmlen << 2));
2648 if (unlikely(!p))
2649 goto out_overflow;
1da177e4 2650 if (bmlen > 0) {
6f723f77 2651 bitmap[0] = be32_to_cpup(p++);
1da177e4 2652 if (bmlen > 1)
cccddf4f 2653 bitmap[1] = be32_to_cpup(p);
1da177e4
LT
2654 }
2655 return 0;
c0eae66e
BH
2656out_overflow:
2657 print_overflow_msg(__func__, xdr);
2658 return -EIO;
1da177e4
LT
2659}
2660
8687b63a 2661static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
1da177e4 2662{
8687b63a 2663 __be32 *p;
1da177e4 2664
c0eae66e
BH
2665 p = xdr_inline_decode(xdr, 4);
2666 if (unlikely(!p))
2667 goto out_overflow;
cccddf4f 2668 *attrlen = be32_to_cpup(p);
1da177e4
LT
2669 *savep = xdr->p;
2670 return 0;
c0eae66e
BH
2671out_overflow:
2672 print_overflow_msg(__func__, xdr);
2673 return -EIO;
1da177e4
LT
2674}
2675
2676static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2677{
2678 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2679 decode_attr_bitmap(xdr, bitmask);
2680 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2681 } else
2682 bitmask[0] = bitmask[1] = 0;
44109241 2683 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
1da177e4
LT
2684 return 0;
2685}
2686
2687static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2688{
8687b63a 2689 __be32 *p;
409924e4 2690 int ret = 0;
1da177e4
LT
2691
2692 *type = 0;
2693 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2694 return -EIO;
2695 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
c0eae66e
BH
2696 p = xdr_inline_decode(xdr, 4);
2697 if (unlikely(!p))
2698 goto out_overflow;
cccddf4f 2699 *type = be32_to_cpup(p);
1da177e4 2700 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3110ff80 2701 dprintk("%s: bad type %d\n", __func__, *type);
1da177e4
LT
2702 return -EIO;
2703 }
2704 bitmap[0] &= ~FATTR4_WORD0_TYPE;
409924e4 2705 ret = NFS_ATTR_FATTR_TYPE;
1da177e4 2706 }
bca79478 2707 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
409924e4 2708 return ret;
c0eae66e
BH
2709out_overflow:
2710 print_overflow_msg(__func__, xdr);
2711 return -EIO;
1da177e4
LT
2712}
2713
2714static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2715{
8687b63a 2716 __be32 *p;
409924e4 2717 int ret = 0;
1da177e4
LT
2718
2719 *change = 0;
2720 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2721 return -EIO;
2722 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
c0eae66e
BH
2723 p = xdr_inline_decode(xdr, 8);
2724 if (unlikely(!p))
2725 goto out_overflow;
cccddf4f 2726 xdr_decode_hyper(p, change);
1da177e4 2727 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
409924e4 2728 ret = NFS_ATTR_FATTR_CHANGE;
1da177e4 2729 }
3110ff80 2730 dprintk("%s: change attribute=%Lu\n", __func__,
1da177e4 2731 (unsigned long long)*change);
409924e4 2732 return ret;
c0eae66e
BH
2733out_overflow:
2734 print_overflow_msg(__func__, xdr);
2735 return -EIO;
1da177e4
LT
2736}
2737
2738static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2739{
8687b63a 2740 __be32 *p;
409924e4 2741 int ret = 0;
1da177e4
LT
2742
2743 *size = 0;
2744 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2745 return -EIO;
2746 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
c0eae66e
BH
2747 p = xdr_inline_decode(xdr, 8);
2748 if (unlikely(!p))
2749 goto out_overflow;
cccddf4f 2750 xdr_decode_hyper(p, size);
1da177e4 2751 bitmap[0] &= ~FATTR4_WORD0_SIZE;
409924e4 2752 ret = NFS_ATTR_FATTR_SIZE;
1da177e4 2753 }
3110ff80 2754 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
409924e4 2755 return ret;
c0eae66e
BH
2756out_overflow:
2757 print_overflow_msg(__func__, xdr);
2758 return -EIO;
1da177e4
LT
2759}
2760
2761static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2762{
8687b63a 2763 __be32 *p;
1da177e4
LT
2764
2765 *res = 0;
2766 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2767 return -EIO;
2768 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
c0eae66e
BH
2769 p = xdr_inline_decode(xdr, 4);
2770 if (unlikely(!p))
2771 goto out_overflow;
cccddf4f 2772 *res = be32_to_cpup(p);
1da177e4
LT
2773 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2774 }
3110ff80 2775 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
1da177e4 2776 return 0;
c0eae66e
BH
2777out_overflow:
2778 print_overflow_msg(__func__, xdr);
2779 return -EIO;
1da177e4
LT
2780}
2781
2782static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2783{
8687b63a 2784 __be32 *p;
1da177e4
LT
2785
2786 *res = 0;
2787 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2788 return -EIO;
2789 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
c0eae66e
BH
2790 p = xdr_inline_decode(xdr, 4);
2791 if (unlikely(!p))
2792 goto out_overflow;
cccddf4f 2793 *res = be32_to_cpup(p);
1da177e4
LT
2794 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2795 }
3110ff80 2796 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
1da177e4 2797 return 0;
c0eae66e
BH
2798out_overflow:
2799 print_overflow_msg(__func__, xdr);
2800 return -EIO;
1da177e4
LT
2801}
2802
8b4bdcf8 2803static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
1da177e4 2804{
8687b63a 2805 __be32 *p;
409924e4 2806 int ret = 0;
1da177e4
LT
2807
2808 fsid->major = 0;
2809 fsid->minor = 0;
2810 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2811 return -EIO;
2812 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
c0eae66e
BH
2813 p = xdr_inline_decode(xdr, 16);
2814 if (unlikely(!p))
2815 goto out_overflow;
3ceb4dbb 2816 p = xdr_decode_hyper(p, &fsid->major);
cccddf4f 2817 xdr_decode_hyper(p, &fsid->minor);
1da177e4 2818 bitmap[0] &= ~FATTR4_WORD0_FSID;
409924e4 2819 ret = NFS_ATTR_FATTR_FSID;
1da177e4 2820 }
3110ff80 2821 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
1da177e4
LT
2822 (unsigned long long)fsid->major,
2823 (unsigned long long)fsid->minor);
409924e4 2824 return ret;
c0eae66e
BH
2825out_overflow:
2826 print_overflow_msg(__func__, xdr);
2827 return -EIO;
1da177e4
LT
2828}
2829
2830static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2831{
8687b63a 2832 __be32 *p;
1da177e4
LT
2833
2834 *res = 60;
2835 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2836 return -EIO;
2837 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
c0eae66e
BH
2838 p = xdr_inline_decode(xdr, 4);
2839 if (unlikely(!p))
2840 goto out_overflow;
cccddf4f 2841 *res = be32_to_cpup(p);
1da177e4
LT
2842 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2843 }
3110ff80 2844 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
1da177e4 2845 return 0;
c0eae66e
BH
2846out_overflow:
2847 print_overflow_msg(__func__, xdr);
2848 return -EIO;
1da177e4
LT
2849}
2850
2851static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2852{
8687b63a 2853 __be32 *p;
1da177e4
LT
2854
2855 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2856 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2857 return -EIO;
2858 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
c0eae66e
BH
2859 p = xdr_inline_decode(xdr, 4);
2860 if (unlikely(!p))
2861 goto out_overflow;
cccddf4f 2862 *res = be32_to_cpup(p);
1da177e4
LT
2863 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2864 }
3110ff80 2865 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
1da177e4 2866 return 0;
c0eae66e
BH
2867out_overflow:
2868 print_overflow_msg(__func__, xdr);
2869 return -EIO;
1da177e4
LT
2870}
2871
2872static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2873{
8687b63a 2874 __be32 *p;
409924e4 2875 int ret = 0;
1da177e4
LT
2876
2877 *fileid = 0;
2878 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2879 return -EIO;
2880 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
c0eae66e
BH
2881 p = xdr_inline_decode(xdr, 8);
2882 if (unlikely(!p))
2883 goto out_overflow;
cccddf4f 2884 xdr_decode_hyper(p, fileid);
1da177e4 2885 bitmap[0] &= ~FATTR4_WORD0_FILEID;
409924e4 2886 ret = NFS_ATTR_FATTR_FILEID;
1da177e4 2887 }
3110ff80 2888 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
409924e4 2889 return ret;
c0eae66e
BH
2890out_overflow:
2891 print_overflow_msg(__func__, xdr);
2892 return -EIO;
1da177e4
LT
2893}
2894
99baf625
MN
2895static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2896{
8687b63a 2897 __be32 *p;
409924e4 2898 int ret = 0;
99baf625
MN
2899
2900 *fileid = 0;
2901 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2902 return -EIO;
2903 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
c0eae66e
BH
2904 p = xdr_inline_decode(xdr, 8);
2905 if (unlikely(!p))
2906 goto out_overflow;
cccddf4f 2907 xdr_decode_hyper(p, fileid);
99baf625 2908 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
409924e4 2909 ret = NFS_ATTR_FATTR_FILEID;
99baf625 2910 }
3110ff80 2911 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
409924e4 2912 return ret;
c0eae66e
BH
2913out_overflow:
2914 print_overflow_msg(__func__, xdr);
2915 return -EIO;
99baf625
MN
2916}
2917
1da177e4
LT
2918static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2919{
8687b63a 2920 __be32 *p;
1da177e4
LT
2921 int status = 0;
2922
2923 *res = 0;
2924 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2925 return -EIO;
2926 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
c0eae66e
BH
2927 p = xdr_inline_decode(xdr, 8);
2928 if (unlikely(!p))
2929 goto out_overflow;
cccddf4f 2930 xdr_decode_hyper(p, res);
1da177e4
LT
2931 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2932 }
3110ff80 2933 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
1da177e4 2934 return status;
c0eae66e
BH
2935out_overflow:
2936 print_overflow_msg(__func__, xdr);
2937 return -EIO;
1da177e4
LT
2938}
2939
2940static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2941{
8687b63a 2942 __be32 *p;
1da177e4
LT
2943 int status = 0;
2944
2945 *res = 0;
2946 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2947 return -EIO;
2948 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
c0eae66e
BH
2949 p = xdr_inline_decode(xdr, 8);
2950 if (unlikely(!p))
2951 goto out_overflow;
cccddf4f 2952 xdr_decode_hyper(p, res);
1da177e4
LT
2953 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2954 }
3110ff80 2955 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
1da177e4 2956 return status;
c0eae66e
BH
2957out_overflow:
2958 print_overflow_msg(__func__, xdr);
2959 return -EIO;
1da177e4
LT
2960}
2961
2962static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2963{
8687b63a 2964 __be32 *p;
1da177e4
LT
2965 int status = 0;
2966
2967 *res = 0;
2968 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2969 return -EIO;
2970 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
c0eae66e
BH
2971 p = xdr_inline_decode(xdr, 8);
2972 if (unlikely(!p))
2973 goto out_overflow;
cccddf4f 2974 xdr_decode_hyper(p, res);
1da177e4
LT
2975 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2976 }
3110ff80 2977 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
1da177e4 2978 return status;
c0eae66e
BH
2979out_overflow:
2980 print_overflow_msg(__func__, xdr);
2981 return -EIO;
1da177e4
LT
2982}
2983
7aaa0b3b
MN
2984static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2985{
464ad6b1 2986 u32 n;
8687b63a 2987 __be32 *p;
7aaa0b3b
MN
2988 int status = 0;
2989
c0eae66e
BH
2990 p = xdr_inline_decode(xdr, 4);
2991 if (unlikely(!p))
2992 goto out_overflow;
cccddf4f 2993 n = be32_to_cpup(p);
33a43f28
AA
2994 if (n == 0)
2995 goto root_path;
7aaa0b3b
MN
2996 dprintk("path ");
2997 path->ncomponents = 0;
2998 while (path->ncomponents < n) {
2999 struct nfs4_string *component = &path->components[path->ncomponents];
3000 status = decode_opaque_inline(xdr, &component->len, &component->data);
3001 if (unlikely(status != 0))
3002 goto out_eio;
3003 if (path->ncomponents != n)
3004 dprintk("/");
3005 dprintk("%s", component->data);
3006 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3007 path->ncomponents++;
3008 else {
3009 dprintk("cannot parse %d components in path\n", n);
3010 goto out_eio;
3011 }
3012 }
3013out:
3014 dprintk("\n");
3015 return status;
33a43f28
AA
3016root_path:
3017/* a root pathname is sent as a zero component4 */
3018 path->ncomponents = 1;
3019 path->components[0].len=0;
3020 path->components[0].data=NULL;
3021 dprintk("path /\n");
3022 goto out;
7aaa0b3b
MN
3023out_eio:
3024 dprintk(" status %d", status);
3025 status = -EIO;
3026 goto out;
c0eae66e
BH
3027out_overflow:
3028 print_overflow_msg(__func__, xdr);
3029 return -EIO;
7aaa0b3b
MN
3030}
3031
3032static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
683b57b4
TM
3033{
3034 int n;
8687b63a 3035 __be32 *p;
683b57b4
TM
3036 int status = -EIO;
3037
3038 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3039 goto out;
3040 status = 0;
3041 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3042 goto out;
3110ff80 3043 dprintk("%s: fsroot ", __func__);
7aaa0b3b 3044 status = decode_pathname(xdr, &res->fs_path);
683b57b4
TM
3045 if (unlikely(status != 0))
3046 goto out;
c0eae66e
BH
3047 p = xdr_inline_decode(xdr, 4);
3048 if (unlikely(!p))
3049 goto out_overflow;
cccddf4f 3050 n = be32_to_cpup(p);
683b57b4
TM
3051 if (n <= 0)
3052 goto out_eio;
3053 res->nlocations = 0;
3054 while (res->nlocations < n) {
464ad6b1 3055 u32 m;
7aaa0b3b 3056 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
683b57b4 3057
c0eae66e
BH
3058 p = xdr_inline_decode(xdr, 4);
3059 if (unlikely(!p))
3060 goto out_overflow;
cccddf4f 3061 m = be32_to_cpup(p);
7aaa0b3b
MN
3062
3063 loc->nservers = 0;
3110ff80 3064 dprintk("%s: servers ", __func__);
7aaa0b3b
MN
3065 while (loc->nservers < m) {
3066 struct nfs4_string *server = &loc->servers[loc->nservers];
3067 status = decode_opaque_inline(xdr, &server->len, &server->data);
3068 if (unlikely(status != 0))
3069 goto out_eio;
3070 dprintk("%s ", server->data);
3071 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3072 loc->nservers++;
3073 else {
464ad6b1
CL
3074 unsigned int i;
3075 dprintk("%s: using first %u of %u servers "
3076 "returned for location %u\n",
3110ff80 3077 __func__,
464ad6b1
CL
3078 NFS4_FS_LOCATION_MAXSERVERS,
3079 m, res->nlocations);
7aaa0b3b 3080 for (i = loc->nservers; i < m; i++) {
2e42c3e2 3081 unsigned int len;
7aaa0b3b
MN
3082 char *data;
3083 status = decode_opaque_inline(xdr, &len, &data);
3084 if (unlikely(status != 0))
3085 goto out_eio;
3086 }
3087 }
3088 }
3089 status = decode_pathname(xdr, &loc->rootpath);
683b57b4
TM
3090 if (unlikely(status != 0))
3091 goto out_eio;
7aaa0b3b 3092 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
683b57b4
TM
3093 res->nlocations++;
3094 }
409924e4
TM
3095 if (res->nlocations != 0)
3096 status = NFS_ATTR_FATTR_V4_REFERRAL;
683b57b4 3097out:
3110ff80 3098 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
683b57b4 3099 return status;
c0eae66e
BH
3100out_overflow:
3101 print_overflow_msg(__func__, xdr);
683b57b4
TM
3102out_eio:
3103 status = -EIO;
3104 goto out;
3105}
3106
1da177e4
LT
3107static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3108{
8687b63a 3109 __be32 *p;
1da177e4
LT
3110 int status = 0;
3111
3112 *res = 0;
3113 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3114 return -EIO;
3115 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
c0eae66e
BH
3116 p = xdr_inline_decode(xdr, 8);
3117 if (unlikely(!p))
3118 goto out_overflow;
cccddf4f 3119 xdr_decode_hyper(p, res);
1da177e4
LT
3120 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3121 }
3110ff80 3122 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
1da177e4 3123 return status;
c0eae66e
BH
3124out_overflow:
3125 print_overflow_msg(__func__, xdr);
3126 return -EIO;
1da177e4
LT
3127}
3128
3129static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3130{
8687b63a 3131 __be32 *p;
1da177e4
LT
3132 int status = 0;
3133
3134 *maxlink = 1;
3135 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3136 return -EIO;
3137 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
c0eae66e
BH
3138 p = xdr_inline_decode(xdr, 4);
3139 if (unlikely(!p))
3140 goto out_overflow;
cccddf4f 3141 *maxlink = be32_to_cpup(p);
1da177e4
LT
3142 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3143 }
3110ff80 3144 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
1da177e4 3145 return status;
c0eae66e
BH
3146out_overflow:
3147 print_overflow_msg(__func__, xdr);
3148 return -EIO;
1da177e4
LT
3149}
3150
3151static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3152{
8687b63a 3153 __be32 *p;
1da177e4
LT
3154 int status = 0;
3155
3156 *maxname = 1024;
3157 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3158 return -EIO;
3159 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
c0eae66e
BH
3160 p = xdr_inline_decode(xdr, 4);
3161 if (unlikely(!p))
3162 goto out_overflow;
cccddf4f 3163 *maxname = be32_to_cpup(p);
1da177e4
LT
3164 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3165 }
3110ff80 3166 dprintk("%s: maxname=%u\n", __func__, *maxname);
1da177e4 3167 return status;
c0eae66e
BH
3168out_overflow:
3169 print_overflow_msg(__func__, xdr);
3170 return -EIO;
1da177e4
LT
3171}
3172
3173static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3174{
8687b63a 3175 __be32 *p;
1da177e4
LT
3176 int status = 0;
3177
3178 *res = 1024;
3179 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3180 return -EIO;
3181 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3182 uint64_t maxread;
c0eae66e
BH
3183 p = xdr_inline_decode(xdr, 8);
3184 if (unlikely(!p))
3185 goto out_overflow;
cccddf4f 3186 xdr_decode_hyper(p, &maxread);
1da177e4
LT
3187 if (maxread > 0x7FFFFFFF)
3188 maxread = 0x7FFFFFFF;
3189 *res = (uint32_t)maxread;
3190 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3191 }
3110ff80 3192 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
1da177e4 3193 return status;
c0eae66e
BH
3194out_overflow:
3195 print_overflow_msg(__func__, xdr);
3196 return -EIO;
1da177e4
LT
3197}
3198
3199static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3200{
8687b63a 3201 __be32 *p;
1da177e4
LT
3202 int status = 0;
3203
3204 *res = 1024;
3205 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3206 return -EIO;
3207 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3208 uint64_t maxwrite;
c0eae66e
BH
3209 p = xdr_inline_decode(xdr, 8);
3210 if (unlikely(!p))
3211 goto out_overflow;
cccddf4f 3212 xdr_decode_hyper(p, &maxwrite);
1da177e4
LT
3213 if (maxwrite > 0x7FFFFFFF)
3214 maxwrite = 0x7FFFFFFF;
3215 *res = (uint32_t)maxwrite;
3216 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3217 }
3110ff80 3218 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
1da177e4 3219 return status;
c0eae66e
BH
3220out_overflow:
3221 print_overflow_msg(__func__, xdr);
3222 return -EIO;
1da177e4
LT
3223}
3224
bca79478 3225static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
1da177e4 3226{
bca79478 3227 uint32_t tmp;
8687b63a 3228 __be32 *p;
409924e4 3229 int ret = 0;
1da177e4
LT
3230
3231 *mode = 0;
3232 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3233 return -EIO;
3234 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
c0eae66e
BH
3235 p = xdr_inline_decode(xdr, 4);
3236 if (unlikely(!p))
3237 goto out_overflow;
cccddf4f 3238 tmp = be32_to_cpup(p);
bca79478 3239 *mode = tmp & ~S_IFMT;
1da177e4 3240 bitmap[1] &= ~FATTR4_WORD1_MODE;
409924e4 3241 ret = NFS_ATTR_FATTR_MODE;
1da177e4 3242 }
3110ff80 3243 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
409924e4 3244 return ret;
c0eae66e
BH
3245out_overflow:
3246 print_overflow_msg(__func__, xdr);
3247 return -EIO;
1da177e4
LT
3248}
3249
3250static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3251{
8687b63a 3252 __be32 *p;
409924e4 3253 int ret = 0;
1da177e4
LT
3254
3255 *nlink = 1;
3256 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3257 return -EIO;
3258 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
c0eae66e
BH
3259 p = xdr_inline_decode(xdr, 4);
3260 if (unlikely(!p))
3261 goto out_overflow;
cccddf4f 3262 *nlink = be32_to_cpup(p);
1da177e4 3263 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
409924e4 3264 ret = NFS_ATTR_FATTR_NLINK;
1da177e4 3265 }
3110ff80 3266 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
409924e4 3267 return ret;
c0eae66e
BH
3268out_overflow:
3269 print_overflow_msg(__func__, xdr);
3270 return -EIO;
1da177e4
LT
3271}
3272
80e52ace
TM
3273static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3274 struct nfs_client *clp, uint32_t *uid, int may_sleep)
1da177e4 3275{
8687b63a
AV
3276 uint32_t len;
3277 __be32 *p;
409924e4 3278 int ret = 0;
1da177e4
LT
3279
3280 *uid = -2;
3281 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3282 return -EIO;
3283 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
c0eae66e
BH
3284 p = xdr_inline_decode(xdr, 4);
3285 if (unlikely(!p))
3286 goto out_overflow;
cccddf4f 3287 len = be32_to_cpup(p);
c0eae66e
BH
3288 p = xdr_inline_decode(xdr, len);
3289 if (unlikely(!p))
3290 goto out_overflow;
80e52ace
TM
3291 if (!may_sleep) {
3292 /* do nothing */
3293 } else if (len < XDR_MAX_NETOBJ) {
409924e4
TM
3294 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3295 ret = NFS_ATTR_FATTR_OWNER;
3296 else
1da177e4 3297 dprintk("%s: nfs_map_name_to_uid failed!\n",
3110ff80 3298 __func__);
1da177e4 3299 } else
fe82a183 3300 dprintk("%s: name too long (%u)!\n",
3110ff80 3301 __func__, len);
1da177e4
LT
3302 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3303 }
3110ff80 3304 dprintk("%s: uid=%d\n", __func__, (int)*uid);
409924e4 3305 return ret;
c0eae66e
BH
3306out_overflow:
3307 print_overflow_msg(__func__, xdr);
3308 return -EIO;
1da177e4
LT
3309}
3310
80e52ace
TM
3311static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3312 struct nfs_client *clp, uint32_t *gid, int may_sleep)
1da177e4 3313{
8687b63a
AV
3314 uint32_t len;
3315 __be32 *p;
409924e4 3316 int ret = 0;
1da177e4
LT
3317
3318 *gid = -2;
3319 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3320 return -EIO;
3321 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
c0eae66e
BH
3322 p = xdr_inline_decode(xdr, 4);
3323 if (unlikely(!p))
3324 goto out_overflow;
cccddf4f 3325 len = be32_to_cpup(p);
c0eae66e
BH
3326 p = xdr_inline_decode(xdr, len);
3327 if (unlikely(!p))
3328 goto out_overflow;
80e52ace
TM
3329 if (!may_sleep) {
3330 /* do nothing */
3331 } else if (len < XDR_MAX_NETOBJ) {
409924e4
TM
3332 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3333 ret = NFS_ATTR_FATTR_GROUP;
3334 else
1da177e4 3335 dprintk("%s: nfs_map_group_to_gid failed!\n",
3110ff80 3336 __func__);
1da177e4 3337 } else
fe82a183 3338 dprintk("%s: name too long (%u)!\n",
3110ff80 3339 __func__, len);
1da177e4
LT
3340 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3341 }
3110ff80 3342 dprintk("%s: gid=%d\n", __func__, (int)*gid);
409924e4 3343 return ret;
c0eae66e
BH
3344out_overflow:
3345 print_overflow_msg(__func__, xdr);
3346 return -EIO;
1da177e4
LT
3347}
3348
3349static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3350{
8687b63a
AV
3351 uint32_t major = 0, minor = 0;
3352 __be32 *p;
409924e4 3353 int ret = 0;
1da177e4
LT
3354
3355 *rdev = MKDEV(0,0);
3356 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3357 return -EIO;
3358 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3359 dev_t tmp;
3360
c0eae66e
BH
3361 p = xdr_inline_decode(xdr, 8);
3362 if (unlikely(!p))
3363 goto out_overflow;
6f723f77 3364 major = be32_to_cpup(p++);
cccddf4f 3365 minor = be32_to_cpup(p);
1da177e4
LT
3366 tmp = MKDEV(major, minor);
3367 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3368 *rdev = tmp;
3369 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
409924e4 3370 ret = NFS_ATTR_FATTR_RDEV;
1da177e4 3371 }
3110ff80 3372 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
409924e4 3373 return ret;
c0eae66e
BH
3374out_overflow:
3375 print_overflow_msg(__func__, xdr);
3376 return -EIO;
1da177e4
LT
3377}
3378
3379static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3380{
8687b63a 3381 __be32 *p;
1da177e4
LT
3382 int status = 0;
3383
3384 *res = 0;
3385 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3386 return -EIO;
3387 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
c0eae66e
BH
3388 p = xdr_inline_decode(xdr, 8);
3389 if (unlikely(!p))
3390 goto out_overflow;
cccddf4f 3391 xdr_decode_hyper(p, res);
1da177e4
LT
3392 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3393 }
3110ff80 3394 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
1da177e4 3395 return status;
c0eae66e
BH
3396out_overflow:
3397 print_overflow_msg(__func__, xdr);
3398 return -EIO;
1da177e4
LT
3399}
3400
3401static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3402{
8687b63a 3403 __be32 *p;
1da177e4
LT
3404 int status = 0;
3405
3406 *res = 0;
3407 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3408 return -EIO;
3409 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
c0eae66e
BH
3410 p = xdr_inline_decode(xdr, 8);
3411 if (unlikely(!p))
3412 goto out_overflow;
cccddf4f 3413 xdr_decode_hyper(p, res);
1da177e4
LT
3414 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3415 }
3110ff80 3416 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
1da177e4 3417 return status;
c0eae66e
BH
3418out_overflow:
3419 print_overflow_msg(__func__, xdr);
3420 return -EIO;
1da177e4
LT
3421}
3422
3423static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3424{
8687b63a 3425 __be32 *p;
1da177e4
LT
3426 int status = 0;
3427
3428 *res = 0;
3429 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3430 return -EIO;
3431 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
c0eae66e
BH
3432 p = xdr_inline_decode(xdr, 8);
3433 if (unlikely(!p))
3434 goto out_overflow;
cccddf4f 3435 xdr_decode_hyper(p, res);
1da177e4
LT
3436 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3437 }
3110ff80 3438 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
1da177e4 3439 return status;
c0eae66e
BH
3440out_overflow:
3441 print_overflow_msg(__func__, xdr);
3442 return -EIO;
1da177e4
LT
3443}
3444
3445static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3446{
8687b63a 3447 __be32 *p;
409924e4 3448 int ret = 0;
1da177e4
LT
3449
3450 *used = 0;
3451 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3452 return -EIO;
3453 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
c0eae66e
BH
3454 p = xdr_inline_decode(xdr, 8);
3455 if (unlikely(!p))
3456 goto out_overflow;
cccddf4f 3457 xdr_decode_hyper(p, used);
1da177e4 3458 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
409924e4 3459 ret = NFS_ATTR_FATTR_SPACE_USED;
1da177e4 3460 }
3110ff80 3461 dprintk("%s: space used=%Lu\n", __func__,
1da177e4 3462 (unsigned long long)*used);
409924e4 3463 return ret;
c0eae66e
BH
3464out_overflow:
3465 print_overflow_msg(__func__, xdr);
3466 return -EIO;
1da177e4
LT
3467}
3468
3469static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3470{
8687b63a 3471 __be32 *p;
1da177e4
LT
3472 uint64_t sec;
3473 uint32_t nsec;
3474
c0eae66e
BH
3475 p = xdr_inline_decode(xdr, 12);
3476 if (unlikely(!p))
3477 goto out_overflow;
3ceb4dbb 3478 p = xdr_decode_hyper(p, &sec);
cccddf4f 3479 nsec = be32_to_cpup(p);
1da177e4
LT
3480 time->tv_sec = (time_t)sec;
3481 time->tv_nsec = (long)nsec;
3482 return 0;
c0eae66e
BH
3483out_overflow:
3484 print_overflow_msg(__func__, xdr);
3485 return -EIO;
1da177e4
LT
3486}
3487
3488static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3489{
3490 int status = 0;
3491
3492 time->tv_sec = 0;
3493 time->tv_nsec = 0;
3494 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3495 return -EIO;
3496 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3497 status = decode_attr_time(xdr, time);
409924e4
TM
3498 if (status == 0)
3499 status = NFS_ATTR_FATTR_ATIME;
1da177e4
LT
3500 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3501 }
3110ff80 3502 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
1da177e4
LT
3503 return status;
3504}
3505
3506static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3507{
3508 int status = 0;
3509
3510 time->tv_sec = 0;
3511 time->tv_nsec = 0;
3512 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3513 return -EIO;
3514 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3515 status = decode_attr_time(xdr, time);
409924e4
TM
3516 if (status == 0)
3517 status = NFS_ATTR_FATTR_CTIME;
1da177e4
LT
3518 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3519 }
3110ff80 3520 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
1da177e4
LT
3521 return status;
3522}
3523
3524static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3525{
3526 int status = 0;
3527
3528 time->tv_sec = 0;
3529 time->tv_nsec = 0;
3530 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3531 return -EIO;
3532 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3533 status = decode_attr_time(xdr, time);
409924e4
TM
3534 if (status == 0)
3535 status = NFS_ATTR_FATTR_MTIME;
1da177e4
LT
3536 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3537 }
3110ff80 3538 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
1da177e4
LT
3539 return status;
3540}
3541
8687b63a 3542static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
1da177e4
LT
3543{
3544 unsigned int attrwords = XDR_QUADLEN(attrlen);
3545 unsigned int nwords = xdr->p - savep;
3546
3547 if (unlikely(attrwords != nwords)) {
fe82a183
CL
3548 dprintk("%s: server returned incorrect attribute length: "
3549 "%u %c %u\n",
3110ff80 3550 __func__,
1da177e4
LT
3551 attrwords << 2,
3552 (attrwords < nwords) ? '<' : '>',
3553 nwords << 2);
3554 return -EIO;
3555 }
3556 return 0;
3557}
3558
3559static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3560{
8687b63a 3561 __be32 *p;
1da177e4 3562
c0eae66e
BH
3563 p = xdr_inline_decode(xdr, 20);
3564 if (unlikely(!p))
3565 goto out_overflow;
6f723f77 3566 cinfo->atomic = be32_to_cpup(p++);
3ceb4dbb 3567 p = xdr_decode_hyper(p, &cinfo->before);
cccddf4f 3568 xdr_decode_hyper(p, &cinfo->after);
1da177e4 3569 return 0;
c0eae66e
BH
3570out_overflow:
3571 print_overflow_msg(__func__, xdr);
3572 return -EIO;
1da177e4
LT
3573}
3574
3575static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3576{
8687b63a 3577 __be32 *p;
1da177e4
LT
3578 uint32_t supp, acc;
3579 int status;
3580
3581 status = decode_op_hdr(xdr, OP_ACCESS);
3582 if (status)
3583 return status;
c0eae66e
BH
3584 p = xdr_inline_decode(xdr, 8);
3585 if (unlikely(!p))
3586 goto out_overflow;
6f723f77 3587 supp = be32_to_cpup(p++);
cccddf4f 3588 acc = be32_to_cpup(p);
1da177e4
LT
3589 access->supported = supp;
3590 access->access = acc;
3591 return 0;
c0eae66e
BH
3592out_overflow:
3593 print_overflow_msg(__func__, xdr);
3594 return -EIO;
1da177e4
LT
3595}
3596
07d30434 3597static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
1da177e4 3598{
8687b63a 3599 __be32 *p;
07d30434
BH
3600
3601 p = xdr_inline_decode(xdr, len);
3602 if (likely(p)) {
3603 memcpy(buf, p, len);
3604 return 0;
3605 }
3606 print_overflow_msg(__func__, xdr);
3607 return -EIO;
3608}
3609
3610static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3611{
3612 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
3613}
3614
3615static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3616{
1da177e4
LT
3617 int status;
3618
3619 status = decode_op_hdr(xdr, OP_CLOSE);
c1d51931
TM
3620 if (status != -EIO)
3621 nfs_increment_open_seqid(status, res->seqid);
07d30434
BH
3622 if (!status)
3623 status = decode_stateid(xdr, &res->stateid);
3624 return status;
1da177e4
LT
3625}
3626
db942bbd
BH
3627static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3628{
3629 return decode_opaque_fixed(xdr, verifier, 8);
1da177e4
LT
3630}
3631
3632static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3633{
1da177e4
LT
3634 int status;
3635
3636 status = decode_op_hdr(xdr, OP_COMMIT);
db942bbd
BH
3637 if (!status)
3638 status = decode_verifier(xdr, res->verf->verifier);
3639 return status;
1da177e4
LT
3640}
3641
3642static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3643{
8687b63a 3644 __be32 *p;
1da177e4
LT
3645 uint32_t bmlen;
3646 int status;
3647
3648 status = decode_op_hdr(xdr, OP_CREATE);
3649 if (status)
3650 return status;
3651 if ((status = decode_change_info(xdr, cinfo)))
3652 return status;
c0eae66e
BH
3653 p = xdr_inline_decode(xdr, 4);
3654 if (unlikely(!p))
3655 goto out_overflow;
cccddf4f 3656 bmlen = be32_to_cpup(p);
c0eae66e
BH
3657 p = xdr_inline_decode(xdr, bmlen << 2);
3658 if (likely(p))
3659 return 0;
3660out_overflow:
3661 print_overflow_msg(__func__, xdr);
3662 return -EIO;
1da177e4
LT
3663}
3664
3665static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3666{
8687b63a 3667 __be32 *savep;
6c0195a4 3668 uint32_t attrlen, bitmap[2] = {0};
1da177e4
LT
3669 int status;
3670
3671 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3672 goto xdr_error;
3673 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3674 goto xdr_error;
3675 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3676 goto xdr_error;
3677 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3678 goto xdr_error;
3679 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3680 goto xdr_error;
3681 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3682 goto xdr_error;
3683 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3684 goto xdr_error;
3685 status = verify_attr_len(xdr, savep, attrlen);
3686xdr_error:
3110ff80 3687 dprintk("%s: xdr returned %d!\n", __func__, -status);
1da177e4
LT
3688 return status;
3689}
6c0195a4 3690
1da177e4
LT
3691static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3692{
8687b63a 3693 __be32 *savep;
6c0195a4 3694 uint32_t attrlen, bitmap[2] = {0};
1da177e4 3695 int status;
6c0195a4 3696
1da177e4
LT
3697 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3698 goto xdr_error;
3699 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3700 goto xdr_error;
3701 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3702 goto xdr_error;
3703
3704 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3705 goto xdr_error;
3706 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3707 goto xdr_error;
3708 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3709 goto xdr_error;
3710 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3711 goto xdr_error;
3712 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3713 goto xdr_error;
3714 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3715 goto xdr_error;
3716
3717 status = verify_attr_len(xdr, savep, attrlen);
3718xdr_error:
3110ff80 3719 dprintk("%s: xdr returned %d!\n", __func__, -status);
1da177e4
LT
3720 return status;
3721}
3722
3723static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3724{
8687b63a 3725 __be32 *savep;
6c0195a4 3726 uint32_t attrlen, bitmap[2] = {0};
1da177e4 3727 int status;
6c0195a4 3728
1da177e4
LT
3729 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3730 goto xdr_error;
3731 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3732 goto xdr_error;
3733 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3734 goto xdr_error;
3735
3736 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3737 goto xdr_error;
3738 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3739 goto xdr_error;
3740
3741 status = verify_attr_len(xdr, savep, attrlen);
3742xdr_error:
3110ff80 3743 dprintk("%s: xdr returned %d!\n", __func__, -status);
1da177e4
LT
3744 return status;
3745}
3746
80e52ace
TM
3747static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3748 const struct nfs_server *server, int may_sleep)
1da177e4 3749{
8687b63a 3750 __be32 *savep;
1da177e4
LT
3751 uint32_t attrlen,
3752 bitmap[2] = {0},
3753 type;
bca79478
TM
3754 int status;
3755 umode_t fmode = 0;
99baf625 3756 uint64_t fileid;
1da177e4 3757
f26c7a78
TM
3758 status = decode_op_hdr(xdr, OP_GETATTR);
3759 if (status < 0)
1da177e4 3760 goto xdr_error;
f26c7a78
TM
3761
3762 status = decode_attr_bitmap(xdr, bitmap);
3763 if (status < 0)
1da177e4
LT
3764 goto xdr_error;
3765
f26c7a78
TM
3766 status = decode_attr_length(xdr, &attrlen, &savep);
3767 if (status < 0)
1da177e4
LT
3768 goto xdr_error;
3769
3770
f26c7a78
TM
3771 status = decode_attr_type(xdr, bitmap, &type);
3772 if (status < 0)
1da177e4 3773 goto xdr_error;
409924e4
TM
3774 fattr->mode = 0;
3775 if (status != 0) {
3776 fattr->mode |= nfs_type2fmt[type];
3777 fattr->valid |= status;
3778 }
1da177e4 3779
f26c7a78
TM
3780 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3781 if (status < 0)
1da177e4 3782 goto xdr_error;
409924e4 3783 fattr->valid |= status;
f26c7a78
TM
3784
3785 status = decode_attr_size(xdr, bitmap, &fattr->size);
3786 if (status < 0)
1da177e4 3787 goto xdr_error;
409924e4 3788 fattr->valid |= status;
f26c7a78
TM
3789
3790 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3791 if (status < 0)
1da177e4 3792 goto xdr_error;
409924e4 3793 fattr->valid |= status;
f26c7a78
TM
3794
3795 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3796 if (status < 0)
1da177e4 3797 goto xdr_error;
409924e4 3798 fattr->valid |= status;
f26c7a78
TM
3799
3800 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
7aaa0b3b 3801 struct nfs4_fs_locations,
f26c7a78
TM
3802 fattr));
3803 if (status < 0)
683b57b4 3804 goto xdr_error;
409924e4 3805 fattr->valid |= status;
f26c7a78
TM
3806
3807 status = decode_attr_mode(xdr, bitmap, &fmode);
3808 if (status < 0)
1da177e4 3809 goto xdr_error;
409924e4
TM
3810 if (status != 0) {
3811 fattr->mode |= fmode;
3812 fattr->valid |= status;
3813 }
f26c7a78
TM
3814
3815 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3816 if (status < 0)
1da177e4 3817 goto xdr_error;
409924e4 3818 fattr->valid |= status;
f26c7a78 3819
80e52ace
TM
3820 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3821 &fattr->uid, may_sleep);
f26c7a78 3822 if (status < 0)
1da177e4 3823 goto xdr_error;
409924e4 3824 fattr->valid |= status;
f26c7a78 3825
80e52ace
TM
3826 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3827 &fattr->gid, may_sleep);
f26c7a78 3828 if (status < 0)
1da177e4 3829 goto xdr_error;
409924e4 3830 fattr->valid |= status;
f26c7a78
TM
3831
3832 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3833 if (status < 0)
1da177e4 3834 goto xdr_error;
409924e4 3835 fattr->valid |= status;
f26c7a78
TM
3836
3837 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3838 if (status < 0)
1da177e4 3839 goto xdr_error;
409924e4 3840 fattr->valid |= status;
f26c7a78
TM
3841
3842 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3843 if (status < 0)
1da177e4 3844 goto xdr_error;
409924e4 3845 fattr->valid |= status;
f26c7a78
TM
3846
3847 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3848 if (status < 0)
1da177e4 3849 goto xdr_error;
409924e4 3850 fattr->valid |= status;
f26c7a78
TM
3851
3852 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3853 if (status < 0)
1da177e4 3854 goto xdr_error;
409924e4 3855 fattr->valid |= status;
f26c7a78
TM
3856
3857 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3858 if (status < 0)
99baf625 3859 goto xdr_error;
409924e4 3860 if (status != 0 && !(fattr->valid & status)) {
99baf625 3861 fattr->fileid = fileid;
409924e4
TM
3862 fattr->valid |= status;
3863 }
f26c7a78
TM
3864
3865 status = verify_attr_len(xdr, savep, attrlen);
1da177e4 3866xdr_error:
3110ff80 3867 dprintk("%s: xdr returned %d\n", __func__, -status);
1da177e4
LT
3868 return status;
3869}
3870
3871
3872static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3873{
8687b63a 3874 __be32 *savep;
1da177e4
LT
3875 uint32_t attrlen, bitmap[2];
3876 int status;
3877
3878 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3879 goto xdr_error;
3880 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3881 goto xdr_error;
3882 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3883 goto xdr_error;
3884
3885 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3886
3887 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3888 goto xdr_error;
3889 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3890 goto xdr_error;
3891 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3892 goto xdr_error;
3893 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3894 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3895 goto xdr_error;
3896 fsinfo->wtpref = fsinfo->wtmax;
3897
3898 status = verify_attr_len(xdr, savep, attrlen);
3899xdr_error:
3110ff80 3900 dprintk("%s: xdr returned %d!\n", __func__, -status);
1da177e4
LT
3901 return status;
3902}
3903
3904static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3905{
8687b63a 3906 __be32 *p;
1da177e4
LT
3907 uint32_t len;
3908 int status;
3909
9936781d
TM
3910 /* Zero handle first to allow comparisons */
3911 memset(fh, 0, sizeof(*fh));
3912
1da177e4
LT
3913 status = decode_op_hdr(xdr, OP_GETFH);
3914 if (status)
3915 return status;
1da177e4 3916
c0eae66e
BH
3917 p = xdr_inline_decode(xdr, 4);
3918 if (unlikely(!p))
3919 goto out_overflow;
cccddf4f 3920 len = be32_to_cpup(p);
1da177e4
LT
3921 if (len > NFS4_FHSIZE)
3922 return -EIO;
3923 fh->size = len;
c0eae66e
BH
3924 p = xdr_inline_decode(xdr, len);
3925 if (unlikely(!p))
3926 goto out_overflow;
99398d06 3927 memcpy(fh->data, p, len);
1da177e4 3928 return 0;
c0eae66e
BH
3929out_overflow:
3930 print_overflow_msg(__func__, xdr);
3931 return -EIO;
1da177e4
LT
3932}
3933
3934static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3935{
3936 int status;
6c0195a4 3937
1da177e4
LT
3938 status = decode_op_hdr(xdr, OP_LINK);
3939 if (status)
3940 return status;
3941 return decode_change_info(xdr, cinfo);
3942}
3943
3944/*
3945 * We create the owner, so we know a proper owner.id length is 4.
3946 */
911d1aaf 3947static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
1da177e4 3948{
911d1aaf 3949 uint64_t offset, length, clientid;
8687b63a 3950 __be32 *p;
911d1aaf 3951 uint32_t namelen, type;
1da177e4 3952
babddc72 3953 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
c0eae66e
BH
3954 if (unlikely(!p))
3955 goto out_overflow;
babddc72 3956 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
3ceb4dbb 3957 p = xdr_decode_hyper(p, &length);
babddc72
BS
3958 type = be32_to_cpup(p++); /* 4 byte read */
3959 if (fl != NULL) { /* manipulate file lock */
911d1aaf
TM
3960 fl->fl_start = (loff_t)offset;
3961 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3962 if (length == ~(uint64_t)0)
3963 fl->fl_end = OFFSET_MAX;
3964 fl->fl_type = F_WRLCK;
3965 if (type & 1)
3966 fl->fl_type = F_RDLCK;
3967 fl->fl_pid = 0;
3968 }
babddc72
BS
3969 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
3970 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
3971 p = xdr_inline_decode(xdr, namelen); /* variable size field */
c0eae66e
BH
3972 if (likely(p))
3973 return -NFS4ERR_DENIED;
3974out_overflow:
3975 print_overflow_msg(__func__, xdr);
3976 return -EIO;
1da177e4
LT
3977}
3978
911d1aaf 3979static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
1da177e4 3980{
1da177e4
LT
3981 int status;
3982
3983 status = decode_op_hdr(xdr, OP_LOCK);
c1d51931
TM
3984 if (status == -EIO)
3985 goto out;
1da177e4 3986 if (status == 0) {
07d30434
BH
3987 status = decode_stateid(xdr, &res->stateid);
3988 if (unlikely(status))
3989 goto out;
1da177e4 3990 } else if (status == -NFS4ERR_DENIED)
c1d51931
TM
3991 status = decode_lock_denied(xdr, NULL);
3992 if (res->open_seqid != NULL)
3993 nfs_increment_open_seqid(status, res->open_seqid);
3994 nfs_increment_lock_seqid(status, res->lock_seqid);
3995out:
1da177e4
LT
3996 return status;
3997}
3998
911d1aaf 3999static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
1da177e4
LT
4000{
4001 int status;
4002 status = decode_op_hdr(xdr, OP_LOCKT);
4003 if (status == -NFS4ERR_DENIED)
911d1aaf 4004 return decode_lock_denied(xdr, res->denied);
1da177e4
LT
4005 return status;
4006}
4007
911d1aaf 4008static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
1da177e4 4009{
1da177e4
LT
4010 int status;
4011
4012 status = decode_op_hdr(xdr, OP_LOCKU);
c1d51931
TM
4013 if (status != -EIO)
4014 nfs_increment_lock_seqid(status, res->seqid);
07d30434
BH
4015 if (status == 0)
4016 status = decode_stateid(xdr, &res->stateid);
1da177e4
LT
4017 return status;
4018}
4019
d3c7b7cc
TM
4020static int decode_release_lockowner(struct xdr_stream *xdr)
4021{
4022 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4023}
4024
1da177e4
LT
4025static int decode_lookup(struct xdr_stream *xdr)
4026{
4027 return decode_op_hdr(xdr, OP_LOOKUP);
4028}
4029
4030/* This is too sick! */
4031static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4032{
05d564fe 4033 __be32 *p;
1da177e4
LT
4034 uint32_t limit_type, nblocks, blocksize;
4035
c0eae66e
BH
4036 p = xdr_inline_decode(xdr, 12);
4037 if (unlikely(!p))
4038 goto out_overflow;
6f723f77 4039 limit_type = be32_to_cpup(p++);
1da177e4 4040 switch (limit_type) {
05d564fe 4041 case 1:
cccddf4f 4042 xdr_decode_hyper(p, maxsize);
05d564fe
AA
4043 break;
4044 case 2:
6f723f77 4045 nblocks = be32_to_cpup(p++);
cccddf4f 4046 blocksize = be32_to_cpup(p);
05d564fe 4047 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
1da177e4
LT
4048 }
4049 return 0;
c0eae66e
BH
4050out_overflow:
4051 print_overflow_msg(__func__, xdr);
4052 return -EIO;
1da177e4
LT
4053}
4054
4055static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4056{
05d564fe
AA
4057 __be32 *p;
4058 uint32_t delegation_type;
07d30434 4059 int status;
1da177e4 4060
c0eae66e
BH
4061 p = xdr_inline_decode(xdr, 4);
4062 if (unlikely(!p))
4063 goto out_overflow;
cccddf4f 4064 delegation_type = be32_to_cpup(p);
1da177e4
LT
4065 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4066 res->delegation_type = 0;
4067 return 0;
4068 }
07d30434
BH
4069 status = decode_stateid(xdr, &res->delegation);
4070 if (unlikely(status))
4071 return status;
c0eae66e
BH
4072 p = xdr_inline_decode(xdr, 4);
4073 if (unlikely(!p))
4074 goto out_overflow;
cccddf4f 4075 res->do_recall = be32_to_cpup(p);
05d564fe 4076
1da177e4 4077 switch (delegation_type) {
05d564fe
AA
4078 case NFS4_OPEN_DELEGATE_READ:
4079 res->delegation_type = FMODE_READ;
4080 break;
4081 case NFS4_OPEN_DELEGATE_WRITE:
4082 res->delegation_type = FMODE_WRITE|FMODE_READ;
4083 if (decode_space_limit(xdr, &res->maxsize) < 0)
1da177e4
LT
4084 return -EIO;
4085 }
7539bbab 4086 return decode_ace(xdr, NULL, res->server->nfs_client);
c0eae66e
BH
4087out_overflow:
4088 print_overflow_msg(__func__, xdr);
4089 return -EIO;
1da177e4
LT
4090}
4091
4092static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4093{
05d564fe 4094 __be32 *p;
aa53ed54 4095 uint32_t savewords, bmlen, i;
05d564fe 4096 int status;
1da177e4 4097
05d564fe 4098 status = decode_op_hdr(xdr, OP_OPEN);
c1d51931
TM
4099 if (status != -EIO)
4100 nfs_increment_open_seqid(status, res->seqid);
07d30434
BH
4101 if (!status)
4102 status = decode_stateid(xdr, &res->stateid);
4103 if (unlikely(status))
05d564fe 4104 return status;
1da177e4 4105
05d564fe 4106 decode_change_info(xdr, &res->cinfo);
1da177e4 4107
c0eae66e
BH
4108 p = xdr_inline_decode(xdr, 8);
4109 if (unlikely(!p))
4110 goto out_overflow;
6f723f77 4111 res->rflags = be32_to_cpup(p++);
cccddf4f 4112 bmlen = be32_to_cpup(p);
05d564fe
AA
4113 if (bmlen > 10)
4114 goto xdr_error;
1da177e4 4115
c0eae66e
BH
4116 p = xdr_inline_decode(xdr, bmlen << 2);
4117 if (unlikely(!p))
4118 goto out_overflow;
aa53ed54
JL
4119 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4120 for (i = 0; i < savewords; ++i)
6f723f77 4121 res->attrset[i] = be32_to_cpup(p++);
aa53ed54
JL
4122 for (; i < NFS4_BITMAP_SIZE; i++)
4123 res->attrset[i] = 0;
4124
1da177e4
LT
4125 return decode_delegation(xdr, res);
4126xdr_error:
3110ff80 4127 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
1da177e4 4128 return -EIO;
c0eae66e
BH
4129out_overflow:
4130 print_overflow_msg(__func__, xdr);
4131 return -EIO;
1da177e4
LT
4132}
4133
4134static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4135{
1da177e4
LT
4136 int status;
4137
05d564fe 4138 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
c1d51931
TM
4139 if (status != -EIO)
4140 nfs_increment_open_seqid(status, res->seqid);
07d30434
BH
4141 if (!status)
4142 status = decode_stateid(xdr, &res->stateid);
4143 return status;
1da177e4
LT
4144}
4145
4146static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4147{
1da177e4
LT
4148 int status;
4149
4150 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
c1d51931
TM
4151 if (status != -EIO)
4152 nfs_increment_open_seqid(status, res->seqid);
07d30434
BH
4153 if (!status)
4154 status = decode_stateid(xdr, &res->stateid);
4155 return status;
1da177e4
LT
4156}
4157
4158static int decode_putfh(struct xdr_stream *xdr)
4159{
4160 return decode_op_hdr(xdr, OP_PUTFH);
4161}
4162
4163static int decode_putrootfh(struct xdr_stream *xdr)
4164{
4165 return decode_op_hdr(xdr, OP_PUTROOTFH);
4166}
4167
4168static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4169{
4170 struct kvec *iov = req->rq_rcv_buf.head;
8687b63a 4171 __be32 *p;
1da177e4
LT
4172 uint32_t count, eof, recvd, hdrlen;
4173 int status;
4174
4175 status = decode_op_hdr(xdr, OP_READ);
4176 if (status)
4177 return status;
c0eae66e
BH
4178 p = xdr_inline_decode(xdr, 8);
4179 if (unlikely(!p))
4180 goto out_overflow;
6f723f77 4181 eof = be32_to_cpup(p++);
cccddf4f 4182 count = be32_to_cpup(p);
1da177e4
LT
4183 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
4184 recvd = req->rq_rcv_buf.len - hdrlen;
4185 if (count > recvd) {
fe82a183 4186 dprintk("NFS: server cheating in read reply: "
1da177e4
LT
4187 "count %u > recvd %u\n", count, recvd);
4188 count = recvd;
4189 eof = 0;
4190 }
4191 xdr_read_pages(xdr, count);
4192 res->eof = eof;
4193 res->count = count;
4194 return 0;
c0eae66e
BH
4195out_overflow:
4196 print_overflow_msg(__func__, xdr);
4197 return -EIO;
1da177e4
LT
4198}
4199
4200static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4201{
4202 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
1da177e4 4203 struct kvec *iov = rcvbuf->head;
bcecff77
CL
4204 size_t hdrlen;
4205 u32 recvd, pglen = rcvbuf->page_len;
bcecff77 4206 int status;
1da177e4
LT
4207
4208 status = decode_op_hdr(xdr, OP_READDIR);
db942bbd
BH
4209 if (!status)
4210 status = decode_verifier(xdr, readdir->verifier.data);
4211 if (unlikely(status))
1da177e4 4212 return status;
44109241
FI
4213 dprintk("%s: verifier = %08x:%08x\n",
4214 __func__,
eadf4598
TM
4215 ((u32 *)readdir->verifier.data)[0],
4216 ((u32 *)readdir->verifier.data)[1]);
4217
1da177e4 4218
db942bbd 4219 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
1da177e4
LT
4220 recvd = rcvbuf->len - hdrlen;
4221 if (pglen > recvd)
4222 pglen = recvd;
4223 xdr_read_pages(xdr, pglen);
4224
afa8ccc9 4225
1da177e4 4226 return 0;
1da177e4
LT
4227}
4228
4229static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4230{
4231 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4232 struct kvec *iov = rcvbuf->head;
bcecff77
CL
4233 size_t hdrlen;
4234 u32 len, recvd;
8687b63a 4235 __be32 *p;
1da177e4
LT
4236 int status;
4237
4238 status = decode_op_hdr(xdr, OP_READLINK);
4239 if (status)
4240 return status;
4241
4242 /* Convert length of symlink */
c0eae66e
BH
4243 p = xdr_inline_decode(xdr, 4);
4244 if (unlikely(!p))
4245 goto out_overflow;
cccddf4f 4246 len = be32_to_cpup(p);
1da177e4 4247 if (len >= rcvbuf->page_len || len <= 0) {
fe82a183 4248 dprintk("nfs: server returned giant symlink!\n");
1da177e4
LT
4249 return -ENAMETOOLONG;
4250 }
4251 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4252 recvd = req->rq_rcv_buf.len - hdrlen;
4253 if (recvd < len) {
fe82a183 4254 dprintk("NFS: server cheating in readlink reply: "
1da177e4
LT
4255 "count %u > recvd %u\n", len, recvd);
4256 return -EIO;
4257 }
4258 xdr_read_pages(xdr, len);
4259 /*
4260 * The XDR encode routine has set things up so that
4261 * the link text will be copied directly into the
4262 * buffer. We just have to do overflow-checking,
4263 * and and null-terminate the text (the VFS expects
4264 * null-termination).
4265 */
b4687da7 4266 xdr_terminate_string(rcvbuf, len);
1da177e4 4267 return 0;
c0eae66e
BH
4268out_overflow:
4269 print_overflow_msg(__func__, xdr);
4270 return -EIO;
1da177e4
LT
4271}
4272
4273static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4274{
4275 int status;
4276
4277 status = decode_op_hdr(xdr, OP_REMOVE);
4278 if (status)
4279 goto out;
4280 status = decode_change_info(xdr, cinfo);
4281out:
4282 return status;
4283}
4284
4285static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4286 struct nfs4_change_info *new_cinfo)
4287{
4288 int status;
4289
4290 status = decode_op_hdr(xdr, OP_RENAME);
4291 if (status)
4292 goto out;
4293 if ((status = decode_change_info(xdr, old_cinfo)))
4294 goto out;
4295 status = decode_change_info(xdr, new_cinfo);
4296out:
4297 return status;
4298}
4299
4300static int decode_renew(struct xdr_stream *xdr)
4301{
4302 return decode_op_hdr(xdr, OP_RENEW);
4303}
4304
56ae19f3
TM
4305static int
4306decode_restorefh(struct xdr_stream *xdr)
4307{
4308 return decode_op_hdr(xdr, OP_RESTOREFH);
4309}
4310
029d105e
BF
4311static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4312 size_t *acl_len)
4313{
8687b63a 4314 __be32 *savep;
029d105e
BF
4315 uint32_t attrlen,
4316 bitmap[2] = {0};
4317 struct kvec *iov = req->rq_rcv_buf.head;
4318 int status;
4319
4320 *acl_len = 0;
4321 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4322 goto out;
4323 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4324 goto out;
4325 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4326 goto out;
4327
4328 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4329 return -EIO;
4330 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
bcecff77
CL
4331 size_t hdrlen;
4332 u32 recvd;
029d105e
BF
4333
4334 /* We ignore &savep and don't do consistency checks on
4335 * the attr length. Let userspace figure it out.... */
4336 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4337 recvd = req->rq_rcv_buf.len - hdrlen;
4338 if (attrlen > recvd) {
fe82a183 4339 dprintk("NFS: server cheating in getattr"
029d105e
BF
4340 " acl reply: attrlen %u > recvd %u\n",
4341 attrlen, recvd);
4342 return -EINVAL;
4343 }
c04871e6 4344 xdr_read_pages(xdr, attrlen);
029d105e 4345 *acl_len = attrlen;
8c233cf9
BF
4346 } else
4347 status = -EOPNOTSUPP;
029d105e
BF
4348
4349out:
4350 return status;
4351}
4352
1da177e4
LT
4353static int
4354decode_savefh(struct xdr_stream *xdr)
4355{
4356 return decode_op_hdr(xdr, OP_SAVEFH);
4357}
4358
9e9ecc03 4359static int decode_setattr(struct xdr_stream *xdr)
1da177e4 4360{
8687b63a 4361 __be32 *p;
1da177e4
LT
4362 uint32_t bmlen;
4363 int status;
4364
1da177e4
LT
4365 status = decode_op_hdr(xdr, OP_SETATTR);
4366 if (status)
4367 return status;
c0eae66e
BH
4368 p = xdr_inline_decode(xdr, 4);
4369 if (unlikely(!p))
4370 goto out_overflow;
cccddf4f 4371 bmlen = be32_to_cpup(p);
c0eae66e
BH
4372 p = xdr_inline_decode(xdr, bmlen << 2);
4373 if (likely(p))
4374 return 0;
4375out_overflow:
4376 print_overflow_msg(__func__, xdr);
4377 return -EIO;
1da177e4
LT
4378}
4379
bb8b27e5 4380static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
1da177e4 4381{
8687b63a 4382 __be32 *p;
1da177e4
LT
4383 uint32_t opnum;
4384 int32_t nfserr;
4385
c0eae66e
BH
4386 p = xdr_inline_decode(xdr, 8);
4387 if (unlikely(!p))
4388 goto out_overflow;
6f723f77 4389 opnum = be32_to_cpup(p++);
1da177e4 4390 if (opnum != OP_SETCLIENTID) {
fe82a183 4391 dprintk("nfs: decode_setclientid: Server returned operation"
6c0195a4 4392 " %d\n", opnum);
1da177e4
LT
4393 return -EIO;
4394 }
cccddf4f 4395 nfserr = be32_to_cpup(p);
1da177e4 4396 if (nfserr == NFS_OK) {
c0eae66e
BH
4397 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4398 if (unlikely(!p))
4399 goto out_overflow;
bb8b27e5
TM
4400 p = xdr_decode_hyper(p, &res->clientid);
4401 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
1da177e4
LT
4402 } else if (nfserr == NFSERR_CLID_INUSE) {
4403 uint32_t len;
4404
4405 /* skip netid string */
c0eae66e
BH
4406 p = xdr_inline_decode(xdr, 4);
4407 if (unlikely(!p))
4408 goto out_overflow;
cccddf4f 4409 len = be32_to_cpup(p);
c0eae66e
BH
4410 p = xdr_inline_decode(xdr, len);
4411 if (unlikely(!p))
4412 goto out_overflow;
1da177e4
LT
4413
4414 /* skip uaddr string */
c0eae66e
BH
4415 p = xdr_inline_decode(xdr, 4);
4416 if (unlikely(!p))
4417 goto out_overflow;
cccddf4f 4418 len = be32_to_cpup(p);
c0eae66e
BH
4419 p = xdr_inline_decode(xdr, len);
4420 if (unlikely(!p))
4421 goto out_overflow;
1da177e4
LT
4422 return -NFSERR_CLID_INUSE;
4423 } else
856dff3d 4424 return nfs4_stat_to_errno(nfserr);
1da177e4
LT
4425
4426 return 0;
c0eae66e
BH
4427out_overflow:
4428 print_overflow_msg(__func__, xdr);
4429 return -EIO;
1da177e4
LT
4430}
4431
4432static int decode_setclientid_confirm(struct xdr_stream *xdr)
4433{
4434 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4435}
4436
4437static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4438{
8687b63a 4439 __be32 *p;
1da177e4
LT
4440 int status;
4441
4442 status = decode_op_hdr(xdr, OP_WRITE);
4443 if (status)
4444 return status;
4445
c0eae66e
BH
4446 p = xdr_inline_decode(xdr, 16);
4447 if (unlikely(!p))
4448 goto out_overflow;
6f723f77
BH
4449 res->count = be32_to_cpup(p++);
4450 res->verf->committed = be32_to_cpup(p++);
99398d06 4451 memcpy(res->verf->verifier, p, 8);
1da177e4 4452 return 0;
c0eae66e
BH
4453out_overflow:
4454 print_overflow_msg(__func__, xdr);
4455 return -EIO;
1da177e4
LT
4456}
4457
4458static int decode_delegreturn(struct xdr_stream *xdr)
4459{
4460 return decode_op_hdr(xdr, OP_DELEGRETURN);
4461}
4462
99fe60d0
BH
4463#if defined(CONFIG_NFS_V4_1)
4464static int decode_exchange_id(struct xdr_stream *xdr,
4465 struct nfs41_exchange_id_res *res)
4466{
4467 __be32 *p;
4468 uint32_t dummy;
2460ba57 4469 char *dummy_str;
99fe60d0
BH
4470 int status;
4471 struct nfs_client *clp = res->client;
4472
4473 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4474 if (status)
4475 return status;
4476
c0eae66e
BH
4477 p = xdr_inline_decode(xdr, 8);
4478 if (unlikely(!p))
4479 goto out_overflow;
cccddf4f 4480 xdr_decode_hyper(p, &clp->cl_ex_clid);
c0eae66e
BH
4481 p = xdr_inline_decode(xdr, 12);
4482 if (unlikely(!p))
4483 goto out_overflow;
6f723f77
BH
4484 clp->cl_seqid = be32_to_cpup(p++);
4485 clp->cl_exchange_flags = be32_to_cpup(p++);
99fe60d0
BH
4486
4487 /* We ask for SP4_NONE */
cccddf4f 4488 dummy = be32_to_cpup(p);
99fe60d0
BH
4489 if (dummy != SP4_NONE)
4490 return -EIO;
4491
4492 /* Throw away minor_id */
c0eae66e
BH
4493 p = xdr_inline_decode(xdr, 8);
4494 if (unlikely(!p))
4495 goto out_overflow;
99fe60d0
BH
4496
4497 /* Throw away Major id */
2460ba57
BH
4498 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4499 if (unlikely(status))
4500 return status;
99fe60d0
BH
4501
4502 /* Throw away server_scope */
2460ba57
BH
4503 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4504 if (unlikely(status))
4505 return status;
99fe60d0
BH
4506
4507 /* Throw away Implementation id array */
2460ba57
BH
4508 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4509 if (unlikely(status))
4510 return status;
99fe60d0
BH
4511
4512 return 0;
c0eae66e
BH
4513out_overflow:
4514 print_overflow_msg(__func__, xdr);
4515 return -EIO;
99fe60d0 4516}
fc931582
AA
4517
4518static int decode_chan_attrs(struct xdr_stream *xdr,
4519 struct nfs4_channel_attrs *attrs)
4520{
4521 __be32 *p;
4522 u32 nr_attrs;
4523
c0eae66e
BH
4524 p = xdr_inline_decode(xdr, 28);
4525 if (unlikely(!p))
4526 goto out_overflow;
6f723f77
BH
4527 attrs->headerpadsz = be32_to_cpup(p++);
4528 attrs->max_rqst_sz = be32_to_cpup(p++);
4529 attrs->max_resp_sz = be32_to_cpup(p++);
4530 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4531 attrs->max_ops = be32_to_cpup(p++);
4532 attrs->max_reqs = be32_to_cpup(p++);
cccddf4f 4533 nr_attrs = be32_to_cpup(p);
fc931582
AA
4534 if (unlikely(nr_attrs > 1)) {
4535 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4536 __func__, nr_attrs);
4537 return -EINVAL;
4538 }
c0eae66e
BH
4539 if (nr_attrs == 1) {
4540 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4541 if (unlikely(!p))
4542 goto out_overflow;
4543 }
fc931582 4544 return 0;
c0eae66e
BH
4545out_overflow:
4546 print_overflow_msg(__func__, xdr);
4547 return -EIO;
fc931582
AA
4548}
4549
e78291e4
BH
4550static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4551{
4552 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
fc931582
AA
4553}
4554
4555static int decode_create_session(struct xdr_stream *xdr,
4556 struct nfs41_create_session_res *res)
4557{
4558 __be32 *p;
4559 int status;
4560 struct nfs_client *clp = res->client;
4561 struct nfs4_session *session = clp->cl_session;
4562
4563 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
e78291e4
BH
4564 if (!status)
4565 status = decode_sessionid(xdr, &session->sess_id);
4566 if (unlikely(status))
fc931582
AA
4567 return status;
4568
fc931582 4569 /* seqid, flags */
c0eae66e
BH
4570 p = xdr_inline_decode(xdr, 8);
4571 if (unlikely(!p))
4572 goto out_overflow;
6f723f77 4573 clp->cl_seqid = be32_to_cpup(p++);
cccddf4f 4574 session->flags = be32_to_cpup(p);
fc931582
AA
4575
4576 /* Channel attributes */
4577 status = decode_chan_attrs(xdr, &session->fc_attrs);
4578 if (!status)
4579 status = decode_chan_attrs(xdr, &session->bc_attrs);
4580 return status;
c0eae66e
BH
4581out_overflow:
4582 print_overflow_msg(__func__, xdr);
4583 return -EIO;
fc931582 4584}
0f3e66c6
AA
4585
4586static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4587{
4588 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4589}
18019753
RL
4590
4591static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
4592{
4593 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
4594}
99fe60d0
BH
4595#endif /* CONFIG_NFS_V4_1 */
4596
9b7b9fcc
AA
4597static int decode_sequence(struct xdr_stream *xdr,
4598 struct nfs4_sequence_res *res,
4599 struct rpc_rqst *rqstp)
4600{
4601#if defined(CONFIG_NFS_V4_1)
fc01cea9
AA
4602 struct nfs4_sessionid id;
4603 u32 dummy;
4604 int status;
4605 __be32 *p;
4606
9b7b9fcc
AA
4607 if (!res->sr_session)
4608 return 0;
4609
fc01cea9 4610 status = decode_op_hdr(xdr, OP_SEQUENCE);
e78291e4
BH
4611 if (!status)
4612 status = decode_sessionid(xdr, &id);
4613 if (unlikely(status))
fc01cea9 4614 goto out_err;
9b7b9fcc 4615
fc01cea9
AA
4616 /*
4617 * If the server returns different values for sessionID, slotID or
4618 * sequence number, the server is looney tunes.
4619 */
fdcb4577 4620 status = -EREMOTEIO;
fc01cea9 4621
fc01cea9
AA
4622 if (memcmp(id.data, res->sr_session->sess_id.data,
4623 NFS4_MAX_SESSIONID_LEN)) {
4624 dprintk("%s Invalid session id\n", __func__);
4625 goto out_err;
4626 }
e78291e4 4627
c0eae66e
BH
4628 p = xdr_inline_decode(xdr, 20);
4629 if (unlikely(!p))
4630 goto out_overflow;
e78291e4 4631
fc01cea9 4632 /* seqid */
6f723f77 4633 dummy = be32_to_cpup(p++);
dfb4f309 4634 if (dummy != res->sr_slot->seq_nr) {
fc01cea9
AA
4635 dprintk("%s Invalid sequence number\n", __func__);
4636 goto out_err;
4637 }
4638 /* slot id */
6f723f77 4639 dummy = be32_to_cpup(p++);
dfb4f309 4640 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
fc01cea9
AA
4641 dprintk("%s Invalid slot id\n", __func__);
4642 goto out_err;
4643 }
4644 /* highest slot id - currently not processed */
6f723f77 4645 dummy = be32_to_cpup(p++);
fc01cea9 4646 /* target highest slot id - currently not processed */
6f723f77 4647 dummy = be32_to_cpup(p++);
0629e370
AB
4648 /* result flags */
4649 res->sr_status_flags = be32_to_cpup(p);
fc01cea9
AA
4650 status = 0;
4651out_err:
4652 res->sr_status = status;
4653 return status;
c0eae66e
BH
4654out_overflow:
4655 print_overflow_msg(__func__, xdr);
4656 status = -EIO;
4657 goto out_err;
fc01cea9 4658#else /* CONFIG_NFS_V4_1 */
9b7b9fcc 4659 return 0;
fc01cea9 4660#endif /* CONFIG_NFS_V4_1 */
9b7b9fcc
AA
4661}
4662
49c2559e
BH
4663/*
4664 * END OF "GENERIC" DECODE ROUTINES.
4665 */
4666
1da177e4
LT
4667/*
4668 * Decode OPEN_DOWNGRADE response
4669 */
8687b63a 4670static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
1da177e4 4671{
05d564fe
AA
4672 struct xdr_stream xdr;
4673 struct compound_hdr hdr;
4674 int status;
4675
4676 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4677 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4678 if (status)
4679 goto out;
4680 status = decode_sequence(&xdr, &res->seq_res, rqstp);
05d564fe
AA
4681 if (status)
4682 goto out;
4683 status = decode_putfh(&xdr);
4684 if (status)
4685 goto out;
4686 status = decode_open_downgrade(&xdr, res);
516a6af6
TM
4687 if (status != 0)
4688 goto out;
80e52ace
TM
4689 decode_getfattr(&xdr, res->fattr, res->server,
4690 !RPC_IS_ASYNC(rqstp->rq_task));
1da177e4 4691out:
05d564fe 4692 return status;
1da177e4
LT
4693}
4694
1da177e4
LT
4695/*
4696 * Decode ACCESS response
4697 */
8687b63a 4698static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
1da177e4
LT
4699{
4700 struct xdr_stream xdr;
4701 struct compound_hdr hdr;
4702 int status;
6c0195a4 4703
1da177e4 4704 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
9b7b9fcc
AA
4705 status = decode_compound_hdr(&xdr, &hdr);
4706 if (status)
4707 goto out;
4708 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4709 if (status)
1da177e4 4710 goto out;
76b32999
TM
4711 status = decode_putfh(&xdr);
4712 if (status != 0)
4713 goto out;
4714 status = decode_access(&xdr, res);
4715 if (status != 0)
4716 goto out;
80e52ace
TM
4717 decode_getfattr(&xdr, res->fattr, res->server,
4718 !RPC_IS_ASYNC(rqstp->rq_task));
1da177e4
LT
4719out:
4720 return status;
4721}
4722
4723/*
4724 * Decode LOOKUP response
4725 */
8687b63a 4726static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
1da177e4
LT
4727{
4728 struct xdr_stream xdr;
4729 struct compound_hdr hdr;
4730 int status;
6c0195a4 4731
1da177e4 4732 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
9b7b9fcc
AA
4733 status = decode_compound_hdr(&xdr, &hdr);
4734 if (status)
4735 goto out;
4736 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4737 if (status)
1da177e4
LT
4738 goto out;
4739 if ((status = decode_putfh(&xdr)) != 0)
4740 goto out;
4741 if ((status = decode_lookup(&xdr)) != 0)
4742 goto out;
4743 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4744 goto out;
80e52ace
TM
4745 status = decode_getfattr(&xdr, res->fattr, res->server
4746 ,!RPC_IS_ASYNC(rqstp->rq_task));
1da177e4
LT
4747out:
4748 return status;
4749}
4750
4751/*
4752 * Decode LOOKUP_ROOT response
4753 */
8687b63a 4754static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
1da177e4
LT
4755{
4756 struct xdr_stream xdr;
4757 struct compound_hdr hdr;
4758 int status;
6c0195a4 4759
1da177e4 4760 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
9b7b9fcc
AA
4761 status = decode_compound_hdr(&xdr, &hdr);
4762 if (status)
4763 goto out;
4764 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4765 if (status)
1da177e4
LT
4766 goto out;
4767 if ((status = decode_putrootfh(&xdr)) != 0)
4768 goto out;
4769 if ((status = decode_getfh(&xdr, res->fh)) == 0)
80e52ace
TM
4770 status = decode_getfattr(&xdr, res->fattr, res->server,
4771 !RPC_IS_ASYNC(rqstp->rq_task));
1da177e4
LT
4772out:
4773 return status;
4774}
4775
4776/*
4777 * Decode REMOVE response
4778 */
4fdc17b2 4779static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
1da177e4
LT
4780{
4781 struct xdr_stream xdr;
4782 struct compound_hdr hdr;
4783 int status;
6c0195a4 4784
1da177e4 4785 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
9b7b9fcc
AA
4786 status = decode_compound_hdr(&xdr, &hdr);
4787 if (status)
4788 goto out;
4789 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4790 if (status)
1da177e4 4791 goto out;
16e42959
TM
4792 if ((status = decode_putfh(&xdr)) != 0)
4793 goto out;
4794 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4795 goto out;
d346890b 4796 decode_getfattr(&xdr, res->dir_attr, res->server,
80e52ace 4797 !RPC_IS_ASYNC(rqstp->rq_task));
1da177e4
LT
4798out:
4799 return status;
4800}
4801
4802/*
4803 * Decode RENAME response
4804 */
e8582a8b 4805static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs_renameres *res)
1da177e4
LT
4806{
4807 struct xdr_stream xdr;
4808 struct compound_hdr hdr;
4809 int status;
6c0195a4 4810
1da177e4 4811 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
9b7b9fcc
AA
4812 status = decode_compound_hdr(&xdr, &hdr);
4813 if (status)
4814 goto out;
4815 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4816 if (status)
1da177e4
LT
4817 goto out;
4818 if ((status = decode_putfh(&xdr)) != 0)
4819 goto out;
4820 if ((status = decode_savefh(&xdr)) != 0)
4821 goto out;
4822 if ((status = decode_putfh(&xdr)) != 0)
4823 goto out;
6caf2c82
TM
4824 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4825 goto out;
4826 /* Current FH is target directory */
80e52ace
TM
4827 if (decode_getfattr(&xdr, res->new_fattr, res->server,
4828 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
6caf2c82
TM
4829 goto out;
4830 if ((status = decode_restorefh(&xdr)) != 0)
4831 goto out;
80e52ace
TM
4832 decode_getfattr(&xdr, res->old_fattr, res->server,
4833 !RPC_IS_ASYNC(rqstp->rq_task));
1da177e4
LT
4834out:
4835 return status;
4836}
4837
4838/*
4839 * Decode LINK response
4840 */
8687b63a 4841static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
1da177e4
LT
4842{
4843 struct xdr_stream xdr;
4844 struct compound_hdr hdr;
4845 int status;
6c0195a4 4846
1da177e4 4847 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
9b7b9fcc
AA
4848 status = decode_compound_hdr(&xdr, &hdr);
4849 if (status)
4850 goto out;
4851 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4852 if (status)
1da177e4
LT
4853 goto out;
4854 if ((status = decode_putfh(&xdr)) != 0)
4855 goto out;
4856 if ((status = decode_savefh(&xdr)) != 0)
4857 goto out;
4858 if ((status = decode_putfh(&xdr)) != 0)
4859 goto out;
91ba2eee
TM
4860 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4861 goto out;
4862 /*
4863 * Note order: OP_LINK leaves the directory as the current
4864 * filehandle.
4865 */
80e52ace
TM
4866 if (decode_getfattr(&xdr, res->dir_attr, res->server,
4867 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
91ba2eee
TM
4868 goto out;
4869 if ((status = decode_restorefh(&xdr)) != 0)
4870 goto out;
80e52ace
TM
4871 decode_getfattr(&xdr, res->fattr, res->server,
4872 !RPC_IS_ASYNC(rqstp->rq_task));
1da177e4
LT
4873out:
4874 return status;
4875}
4876
4877/*
4878 * Decode CREATE response
4879 */
8687b63a 4880static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
1da177e4
LT
4881{
4882 struct xdr_stream xdr;
4883 struct compound_hdr hdr;
4884 int status;
6c0195a4 4885
1da177e4 4886 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
9b7b9fcc
AA
4887 status = decode_compound_hdr(&xdr, &hdr);
4888 if (status)
4889 goto out;
4890 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4891 if (status)
1da177e4
LT
4892 goto out;
4893 if ((status = decode_putfh(&xdr)) != 0)
4894 goto out;
56ae19f3
TM
4895 if ((status = decode_savefh(&xdr)) != 0)
4896 goto out;
1da177e4
LT
4897 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4898 goto out;
4899 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4900 goto out;
80e52ace
TM
4901 if (decode_getfattr(&xdr, res->fattr, res->server,
4902 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
56ae19f3
TM
4903 goto out;
4904 if ((status = decode_restorefh(&xdr)) != 0)
4905 goto out;
80e52ace
TM
4906 decode_getfattr(&xdr, res->dir_fattr, res->server,
4907 !RPC_IS_ASYNC(rqstp->rq_task));
1da177e4
LT
4908out:
4909 return status;
4910}
4911
4912/*
4913 * Decode SYMLINK response
4914 */
8687b63a 4915static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
1da177e4
LT
4916{
4917 return nfs4_xdr_dec_create(rqstp, p, res);
4918}
4919
4920/*
4921 * Decode GETATTR response
4922 */
8687b63a 4923static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
1da177e4
LT
4924{
4925 struct xdr_stream xdr;
4926 struct compound_hdr hdr;
4927 int status;
6c0195a4 4928
1da177e4
LT
4929 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4930 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4931 if (status)
4932 goto out;
4933 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
4934 if (status)
4935 goto out;
4936 status = decode_putfh(&xdr);
4937 if (status)
4938 goto out;
80e52ace
TM
4939 status = decode_getfattr(&xdr, res->fattr, res->server,
4940 !RPC_IS_ASYNC(rqstp->rq_task));
1da177e4
LT
4941out:
4942 return status;
1da177e4
LT
4943}
4944
23ec6965
BF
4945/*
4946 * Encode an SETACL request
4947 */
4948static int
8687b63a 4949nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
23ec6965 4950{
05d564fe
AA
4951 struct xdr_stream xdr;
4952 struct compound_hdr hdr = {
66cc0429 4953 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
05d564fe
AA
4954 };
4955 int status;
4956
4957 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
0c4e8c18 4958 encode_compound_hdr(&xdr, req, &hdr);
9b7b9fcc 4959 encode_sequence(&xdr, &args->seq_args, &hdr);
cf8cdbe5 4960 encode_putfh(&xdr, args->fh, &hdr);
d017931c 4961 status = encode_setacl(&xdr, args, &hdr);
d017931c 4962 encode_nops(&hdr);
05d564fe 4963 return status;
23ec6965 4964}
05d564fe 4965
23ec6965
BF
4966/*
4967 * Decode SETACL response
4968 */
4969static int
73c403a9
BH
4970nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4971 struct nfs_setaclres *res)
23ec6965
BF
4972{
4973 struct xdr_stream xdr;
4974 struct compound_hdr hdr;
4975 int status;
4976
4977 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4978 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
4979 if (status)
4980 goto out;
4981 status = decode_sequence(&xdr, &res->seq_res, rqstp);
23ec6965
BF
4982 if (status)
4983 goto out;
4984 status = decode_putfh(&xdr);
4985 if (status)
4986 goto out;
9e9ecc03 4987 status = decode_setattr(&xdr);
23ec6965
BF
4988out:
4989 return status;
4990}
1da177e4 4991
029d105e
BF
4992/*
4993 * Decode GETACL response
4994 */
4995static int
663c79b3
BH
4996nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4997 struct nfs_getaclres *res)
029d105e
BF
4998{
4999 struct xdr_stream xdr;
5000 struct compound_hdr hdr;
5001 int status;
5002
5003 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5004 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5005 if (status)
5006 goto out;
5007 status = decode_sequence(&xdr, &res->seq_res, rqstp);
029d105e
BF
5008 if (status)
5009 goto out;
5010 status = decode_putfh(&xdr);
5011 if (status)
5012 goto out;
663c79b3 5013 status = decode_getacl(&xdr, rqstp, &res->acl_len);
029d105e
BF
5014
5015out:
5016 return status;
5017}
5018
1da177e4
LT
5019/*
5020 * Decode CLOSE response
5021 */
8687b63a 5022static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
1da177e4 5023{
05d564fe
AA
5024 struct xdr_stream xdr;
5025 struct compound_hdr hdr;
5026 int status;
5027
5028 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5029 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5030 if (status)
5031 goto out;
5032 status = decode_sequence(&xdr, &res->seq_res, rqstp);
05d564fe
AA
5033 if (status)
5034 goto out;
5035 status = decode_putfh(&xdr);
5036 if (status)
5037 goto out;
5038 status = decode_close(&xdr, res);
516a6af6
TM
5039 if (status != 0)
5040 goto out;
5041 /*
5042 * Note: Server may do delete on close for this file
5043 * in which case the getattr call will fail with
5044 * an ESTALE error. Shouldn't be a problem,
5045 * though, since fattr->valid will remain unset.
5046 */
80e52ace
TM
5047 decode_getfattr(&xdr, res->fattr, res->server,
5048 !RPC_IS_ASYNC(rqstp->rq_task));
1da177e4 5049out:
05d564fe 5050 return status;
1da177e4
LT
5051}
5052
5053/*
5054 * Decode OPEN response
5055 */
8687b63a 5056static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
1da177e4 5057{
05d564fe
AA
5058 struct xdr_stream xdr;
5059 struct compound_hdr hdr;
5060 int status;
5061
5062 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5063 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5064 if (status)
5065 goto out;
5066 status = decode_sequence(&xdr, &res->seq_res, rqstp);
05d564fe
AA
5067 if (status)
5068 goto out;
5069 status = decode_putfh(&xdr);
5070 if (status)
5071 goto out;
5072 status = decode_savefh(&xdr);
5073 if (status)
5074 goto out;
5075 status = decode_open(&xdr, res);
56ae19f3
TM
5076 if (status)
5077 goto out;
9936781d 5078 if (decode_getfh(&xdr, &res->fh) != 0)
1da177e4 5079 goto out;
80e52ace
TM
5080 if (decode_getfattr(&xdr, res->f_attr, res->server,
5081 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
56ae19f3 5082 goto out;
365c8f58 5083 if (decode_restorefh(&xdr) != 0)
56ae19f3 5084 goto out;
80e52ace
TM
5085 decode_getfattr(&xdr, res->dir_attr, res->server,
5086 !RPC_IS_ASYNC(rqstp->rq_task));
1da177e4 5087out:
05d564fe 5088 return status;
1da177e4
LT
5089}
5090
5091/*
5092 * Decode OPEN_CONFIRM response
5093 */
8687b63a 5094static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
1da177e4 5095{
05d564fe
AA
5096 struct xdr_stream xdr;
5097 struct compound_hdr hdr;
5098 int status;
5099
5100 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5101 status = decode_compound_hdr(&xdr, &hdr);
5102 if (status)
5103 goto out;
5104 status = decode_putfh(&xdr);
5105 if (status)
5106 goto out;
5107 status = decode_open_confirm(&xdr, res);
1da177e4 5108out:
05d564fe 5109 return status;
1da177e4
LT
5110}
5111
5112/*
5113 * Decode OPEN response
5114 */
8687b63a 5115static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
1da177e4 5116{
05d564fe
AA
5117 struct xdr_stream xdr;
5118 struct compound_hdr hdr;
5119 int status;
5120
5121 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5122 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5123 if (status)
5124 goto out;
5125 status = decode_sequence(&xdr, &res->seq_res, rqstp);
05d564fe
AA
5126 if (status)
5127 goto out;
5128 status = decode_putfh(&xdr);
5129 if (status)
5130 goto out;
5131 status = decode_open(&xdr, res);
5132 if (status)
5133 goto out;
80e52ace
TM
5134 decode_getfattr(&xdr, res->f_attr, res->server,
5135 !RPC_IS_ASYNC(rqstp->rq_task));
1da177e4 5136out:
05d564fe 5137 return status;
1da177e4
LT
5138}
5139
5140/*
5141 * Decode SETATTR response
5142 */
8687b63a 5143static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
1da177e4 5144{
05d564fe
AA
5145 struct xdr_stream xdr;
5146 struct compound_hdr hdr;
5147 int status;
5148
5149 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5150 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5151 if (status)
5152 goto out;
5153 status = decode_sequence(&xdr, &res->seq_res, rqstp);
05d564fe
AA
5154 if (status)
5155 goto out;
5156 status = decode_putfh(&xdr);
5157 if (status)
5158 goto out;
9e9ecc03 5159 status = decode_setattr(&xdr);
05d564fe
AA
5160 if (status)
5161 goto out;
80e52ace
TM
5162 decode_getfattr(&xdr, res->fattr, res->server,
5163 !RPC_IS_ASYNC(rqstp->rq_task));
1da177e4 5164out:
05d564fe 5165 return status;
1da177e4
LT
5166}
5167
5168/*
5169 * Decode LOCK response
5170 */
8687b63a 5171static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
1da177e4
LT
5172{
5173 struct xdr_stream xdr;
5174 struct compound_hdr hdr;
5175 int status;
5176
5177 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5178 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5179 if (status)
5180 goto out;
5181 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
5182 if (status)
5183 goto out;
5184 status = decode_putfh(&xdr);
5185 if (status)
5186 goto out;
5187 status = decode_lock(&xdr, res);
5188out:
5189 return status;
5190}
5191
5192/*
5193 * Decode LOCKT response
5194 */
8687b63a 5195static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
1da177e4
LT
5196{
5197 struct xdr_stream xdr;
5198 struct compound_hdr hdr;
5199 int status;
5200
5201 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5202 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5203 if (status)
5204 goto out;
5205 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
5206 if (status)
5207 goto out;
5208 status = decode_putfh(&xdr);
5209 if (status)
5210 goto out;
5211 status = decode_lockt(&xdr, res);
5212out:
5213 return status;
5214}
5215
5216/*
5217 * Decode LOCKU response
5218 */
8687b63a 5219static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
1da177e4
LT
5220{
5221 struct xdr_stream xdr;
5222 struct compound_hdr hdr;
5223 int status;
5224
5225 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5226 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5227 if (status)
5228 goto out;
5229 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
5230 if (status)
5231 goto out;
5232 status = decode_putfh(&xdr);
5233 if (status)
5234 goto out;
5235 status = decode_locku(&xdr, res);
5236out:
5237 return status;
5238}
5239
d3c7b7cc
TM
5240static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
5241{
5242 struct xdr_stream xdr;
5243 struct compound_hdr hdr;
5244 int status;
5245
5246 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5247 status = decode_compound_hdr(&xdr, &hdr);
5248 if (!status)
5249 status = decode_release_lockowner(&xdr);
5250 return status;
5251}
5252
1da177e4
LT
5253/*
5254 * Decode READLINK response
5255 */
f50c7000
BH
5256static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
5257 struct nfs4_readlink_res *res)
1da177e4
LT
5258{
5259 struct xdr_stream xdr;
5260 struct compound_hdr hdr;
5261 int status;
5262
5263 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5264 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5265 if (status)
5266 goto out;
5267 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
5268 if (status)
5269 goto out;
5270 status = decode_putfh(&xdr);
5271 if (status)
5272 goto out;
5273 status = decode_readlink(&xdr, rqstp);
5274out:
5275 return status;
5276}
5277
5278/*
5279 * Decode READDIR response
5280 */
8687b63a 5281static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
1da177e4
LT
5282{
5283 struct xdr_stream xdr;
5284 struct compound_hdr hdr;
5285 int status;
5286
5287 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5288 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5289 if (status)
5290 goto out;
5291 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
5292 if (status)
5293 goto out;
5294 status = decode_putfh(&xdr);
5295 if (status)
5296 goto out;
5297 status = decode_readdir(&xdr, rqstp, res);
5298out:
5299 return status;
5300}
5301
5302/*
5303 * Decode Read response
5304 */
8687b63a 5305static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
1da177e4
LT
5306{
5307 struct xdr_stream xdr;
5308 struct compound_hdr hdr;
5309 int status;
5310
5311 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5312 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5313 if (status)
5314 goto out;
5315 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
5316 if (status)
5317 goto out;
5318 status = decode_putfh(&xdr);
5319 if (status)
5320 goto out;
5321 status = decode_read(&xdr, rqstp, res);
5322 if (!status)
5323 status = res->count;
5324out:
5325 return status;
5326}
5327
5328/*
5329 * Decode WRITE response
5330 */
8687b63a 5331static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
1da177e4
LT
5332{
5333 struct xdr_stream xdr;
5334 struct compound_hdr hdr;
5335 int status;
5336
5337 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5338 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5339 if (status)
5340 goto out;
5341 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
5342 if (status)
5343 goto out;
5344 status = decode_putfh(&xdr);
5345 if (status)
5346 goto out;
5347 status = decode_write(&xdr, res);
4f9838c7
TM
5348 if (status)
5349 goto out;
80e52ace
TM
5350 decode_getfattr(&xdr, res->fattr, res->server,
5351 !RPC_IS_ASYNC(rqstp->rq_task));
1da177e4
LT
5352 if (!status)
5353 status = res->count;
5354out:
5355 return status;
5356}
5357
5358/*
5359 * Decode COMMIT response
5360 */
8687b63a 5361static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
1da177e4
LT
5362{
5363 struct xdr_stream xdr;
5364 struct compound_hdr hdr;
5365 int status;
5366
5367 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5368 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5369 if (status)
5370 goto out;
5371 status = decode_sequence(&xdr, &res->seq_res, rqstp);
1da177e4
LT
5372 if (status)
5373 goto out;
5374 status = decode_putfh(&xdr);
5375 if (status)
5376 goto out;
5377 status = decode_commit(&xdr, res);
4f9838c7
TM
5378 if (status)
5379 goto out;
80e52ace
TM
5380 decode_getfattr(&xdr, res->fattr, res->server,
5381 !RPC_IS_ASYNC(rqstp->rq_task));
1da177e4
LT
5382out:
5383 return status;
5384}
5385
5386/*
8b173218 5387 * Decode FSINFO response
1da177e4 5388 */
3dda5e43
BH
5389static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
5390 struct nfs4_fsinfo_res *res)
1da177e4
LT
5391{
5392 struct xdr_stream xdr;
5393 struct compound_hdr hdr;
5394 int status;
5395
5396 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5397 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5398 if (!status)
5399 status = decode_sequence(&xdr, &res->seq_res, req);
1da177e4
LT
5400 if (!status)
5401 status = decode_putfh(&xdr);
5402 if (!status)
3dda5e43 5403 status = decode_fsinfo(&xdr, res->fsinfo);
1da177e4
LT
5404 return status;
5405}
5406
5407/*
8b173218 5408 * Decode PATHCONF response
1da177e4 5409 */
d45b2989
BH
5410static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
5411 struct nfs4_pathconf_res *res)
1da177e4
LT
5412{
5413 struct xdr_stream xdr;
5414 struct compound_hdr hdr;
5415 int status;
5416
5417 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5418 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5419 if (!status)
5420 status = decode_sequence(&xdr, &res->seq_res, req);
1da177e4
LT
5421 if (!status)
5422 status = decode_putfh(&xdr);
5423 if (!status)
d45b2989 5424 status = decode_pathconf(&xdr, res->pathconf);
1da177e4
LT
5425 return status;
5426}
5427
5428/*
8b173218 5429 * Decode STATFS response
1da177e4 5430 */
24ad148a
BH
5431static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
5432 struct nfs4_statfs_res *res)
1da177e4
LT
5433{
5434 struct xdr_stream xdr;
5435 struct compound_hdr hdr;
5436 int status;
5437
5438 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5439 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5440 if (!status)
5441 status = decode_sequence(&xdr, &res->seq_res, req);
1da177e4
LT
5442 if (!status)
5443 status = decode_putfh(&xdr);
5444 if (!status)
24ad148a 5445 status = decode_statfs(&xdr, res->fsstat);
1da177e4
LT
5446 return status;
5447}
5448
5449/*
8b173218 5450 * Decode GETATTR_BITMAP response
1da177e4 5451 */
8687b63a 5452static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
1da177e4
LT
5453{
5454 struct xdr_stream xdr;
5455 struct compound_hdr hdr;
5456 int status;
5457
5458 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
9b7b9fcc
AA
5459 status = decode_compound_hdr(&xdr, &hdr);
5460 if (status)
5461 goto out;
5462 status = decode_sequence(&xdr, &res->seq_res, req);
5463 if (status)
1da177e4
LT
5464 goto out;
5465 if ((status = decode_putfh(&xdr)) != 0)
5466 goto out;
5467 status = decode_server_caps(&xdr, res);
5468out:
5469 return status;
5470}
5471
5472/*
5473 * Decode RENEW response
5474 */
8687b63a 5475static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
1da177e4
LT
5476{
5477 struct xdr_stream xdr;
5478 struct compound_hdr hdr;
5479 int status;
5480
5481 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5482 status = decode_compound_hdr(&xdr, &hdr);
5483 if (!status)
5484 status = decode_renew(&xdr);
5485 return status;
5486}
5487
5488/*
8b173218 5489 * Decode SETCLIENTID response
1da177e4 5490 */
8687b63a 5491static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
bb8b27e5 5492 struct nfs4_setclientid_res *res)
1da177e4
LT
5493{
5494 struct xdr_stream xdr;
5495 struct compound_hdr hdr;
5496 int status;
5497
5498 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5499 status = decode_compound_hdr(&xdr, &hdr);
5500 if (!status)
bb8b27e5 5501 status = decode_setclientid(&xdr, res);
1da177e4
LT
5502 return status;
5503}
5504
5505/*
8b173218 5506 * Decode SETCLIENTID_CONFIRM response
1da177e4 5507 */
8687b63a 5508static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
1da177e4
LT
5509{
5510 struct xdr_stream xdr;
5511 struct compound_hdr hdr;
5512 int status;
5513
5514 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5515 status = decode_compound_hdr(&xdr, &hdr);
5516 if (!status)
5517 status = decode_setclientid_confirm(&xdr);
5518 if (!status)
5519 status = decode_putrootfh(&xdr);
5520 if (!status)
5521 status = decode_fsinfo(&xdr, fsinfo);
1da177e4
LT
5522 return status;
5523}
5524
5525/*
8b173218 5526 * Decode DELEGRETURN response
1da177e4 5527 */
8687b63a 5528static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
1da177e4
LT
5529{
5530 struct xdr_stream xdr;
5531 struct compound_hdr hdr;
5532 int status;
5533
5534 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5535 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5536 if (status)
5537 goto out;
5538 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5539 if (status)
fa178f29
TM
5540 goto out;
5541 status = decode_putfh(&xdr);
5542 if (status != 0)
5543 goto out;
5544 status = decode_delegreturn(&xdr);
556ae3bb
JL
5545 if (status != 0)
5546 goto out;
80e52ace
TM
5547 decode_getfattr(&xdr, res->fattr, res->server,
5548 !RPC_IS_ASYNC(rqstp->rq_task));
fa178f29 5549out:
1da177e4
LT
5550 return status;
5551}
5552
683b57b4 5553/*
8b173218 5554 * Decode FS_LOCATIONS response
683b57b4 5555 */
22958463
BH
5556static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
5557 struct nfs4_fs_locations_res *res)
683b57b4
TM
5558{
5559 struct xdr_stream xdr;
5560 struct compound_hdr hdr;
5561 int status;
5562
5563 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5564 status = decode_compound_hdr(&xdr, &hdr);
9b7b9fcc
AA
5565 if (status)
5566 goto out;
5567 status = decode_sequence(&xdr, &res->seq_res, req);
5568 if (status)
683b57b4
TM
5569 goto out;
5570 if ((status = decode_putfh(&xdr)) != 0)
5571 goto out;
5572 if ((status = decode_lookup(&xdr)) != 0)
5573 goto out;
5574 xdr_enter_page(&xdr, PAGE_SIZE);
22958463 5575 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
80e52ace
TM
5576 res->fs_locations->server,
5577 !RPC_IS_ASYNC(req->rq_task));
683b57b4
TM
5578out:
5579 return status;
5580}
5581
99fe60d0
BH
5582#if defined(CONFIG_NFS_V4_1)
5583/*
8b173218 5584 * Decode EXCHANGE_ID response
99fe60d0
BH
5585 */
5586static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
5587 void *res)
5588{
5589 struct xdr_stream xdr;
5590 struct compound_hdr hdr;
5591 int status;
5592
5593 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5594 status = decode_compound_hdr(&xdr, &hdr);
5595 if (!status)
5596 status = decode_exchange_id(&xdr, res);
5597 return status;
5598}
2050f0cc 5599
fc931582 5600/*
8b173218 5601 * Decode CREATE_SESSION response
fc931582
AA
5602 */
5603static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
5604 struct nfs41_create_session_res *res)
5605{
5606 struct xdr_stream xdr;
5607 struct compound_hdr hdr;
5608 int status;
5609
5610 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5611 status = decode_compound_hdr(&xdr, &hdr);
5612 if (!status)
5613 status = decode_create_session(&xdr, res);
5614 return status;
5615}
5616
0f3e66c6 5617/*
8b173218 5618 * Decode DESTROY_SESSION response
0f3e66c6
AA
5619 */
5620static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
5621 void *dummy)
5622{
5623 struct xdr_stream xdr;
5624 struct compound_hdr hdr;
5625 int status;
5626
5627 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5628 status = decode_compound_hdr(&xdr, &hdr);
5629 if (!status)
5630 status = decode_destroy_session(&xdr, dummy);
5631 return status;
5632}
5633
fc01cea9 5634/*
8b173218 5635 * Decode SEQUENCE response
fc01cea9
AA
5636 */
5637static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p,
5638 struct nfs4_sequence_res *res)
5639{
5640 struct xdr_stream xdr;
5641 struct compound_hdr hdr;
5642 int status;
5643
5644 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5645 status = decode_compound_hdr(&xdr, &hdr);
5646 if (!status)
5647 status = decode_sequence(&xdr, res, rqstp);
5648 return status;
5649}
5650
2050f0cc 5651/*
8b173218 5652 * Decode GET_LEASE_TIME response
2050f0cc
AA
5653 */
5654static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
5655 struct nfs4_get_lease_time_res *res)
5656{
5657 struct xdr_stream xdr;
5658 struct compound_hdr hdr;
5659 int status;
5660
5661 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5662 status = decode_compound_hdr(&xdr, &hdr);
5663 if (!status)
5664 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
5665 if (!status)
5666 status = decode_putrootfh(&xdr);
5667 if (!status)
5668 status = decode_fsinfo(&xdr, res->lr_fsinfo);
5669 return status;
5670}
18019753
RL
5671
5672/*
5673 * Decode RECLAIM_COMPLETE response
5674 */
5675static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, uint32_t *p,
5676 struct nfs41_reclaim_complete_res *res)
5677{
5678 struct xdr_stream xdr;
5679 struct compound_hdr hdr;
5680 int status;
5681
5682 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5683 status = decode_compound_hdr(&xdr, &hdr);
5684 if (!status)
5685 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5686 if (!status)
5687 status = decode_reclaim_complete(&xdr, (void *)NULL);
5688 return status;
5689}
99fe60d0
BH
5690#endif /* CONFIG_NFS_V4_1 */
5691
babddc72 5692__be32 *nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, int plus)
1da177e4
LT
5693{
5694 uint32_t bitmap[2] = {0};
5695 uint32_t len;
babddc72
BS
5696 __be32 *p = xdr_inline_decode(xdr, 4);
5697 if (unlikely(!p))
5698 goto out_overflow;
5699 if (!ntohl(*p++)) {
5700 p = xdr_inline_decode(xdr, 4);
5701 if (unlikely(!p))
5702 goto out_overflow;
5703 if (!ntohl(*p++))
1da177e4
LT
5704 return ERR_PTR(-EAGAIN);
5705 entry->eof = 1;
5706 return ERR_PTR(-EBADCOOKIE);
5707 }
5708
babddc72
BS
5709 p = xdr_inline_decode(xdr, 12);
5710 if (unlikely(!p))
5711 goto out_overflow;
1da177e4
LT
5712 entry->prev_cookie = entry->cookie;
5713 p = xdr_decode_hyper(p, &entry->cookie);
5714 entry->len = ntohl(*p++);
babddc72
BS
5715
5716 p = xdr_inline_decode(xdr, entry->len + 4);
5717 if (unlikely(!p))
5718 goto out_overflow;
1da177e4
LT
5719 entry->name = (const char *) p;
5720 p += XDR_QUADLEN(entry->len);
5721
5722 /*
5723 * In case the server doesn't return an inode number,
5724 * we fake one here. (We don't use inode number 0,
5725 * since glibc seems to choke on it...)
5726 */
5727 entry->ino = 1;
5728
5729 len = ntohl(*p++); /* bitmap length */
5730 if (len-- > 0) {
babddc72
BS
5731 p = xdr_inline_decode(xdr, 4);
5732 if (unlikely(!p))
5733 goto out_overflow;
1da177e4
LT
5734 bitmap[0] = ntohl(*p++);
5735 if (len-- > 0) {
babddc72
BS
5736 p = xdr_inline_decode(xdr, 4);
5737 if (unlikely(!p))
5738 goto out_overflow;
1da177e4
LT
5739 bitmap[1] = ntohl(*p++);
5740 p += len;
5741 }
5742 }
babddc72
BS
5743 p = xdr_inline_decode(xdr, 4);
5744 if (unlikely(!p))
5745 goto out_overflow;
1da177e4
LT
5746 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
5747 if (len > 0) {
97d312d0
MN
5748 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
5749 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
5750 /* Ignore the return value of rdattr_error for now */
babddc72
BS
5751 p = xdr_inline_decode(xdr, 4);
5752 if (unlikely(!p))
5753 goto out_overflow;
97d312d0 5754 }
babddc72
BS
5755 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID) {
5756 p = xdr_inline_decode(xdr, 8);
5757 if (unlikely(!p))
5758 goto out_overflow;
1da177e4 5759 xdr_decode_hyper(p, &entry->ino);
babddc72
BS
5760 } else if (bitmap[0] == FATTR4_WORD0_FILEID) {
5761 p = xdr_inline_decode(xdr, 8);
5762 if (unlikely(!p))
5763 goto out_overflow;
1da177e4 5764 xdr_decode_hyper(p, &entry->ino);
babddc72 5765 }
1da177e4
LT
5766 }
5767
babddc72
BS
5768 p = xdr_inline_peek(xdr, 8);
5769 if (p != NULL)
5770 entry->eof = !p[0] && p[1];
5771 else
5772 entry->eof = 0;
5773
1da177e4 5774 return p;
babddc72
BS
5775
5776out_overflow:
5777 print_overflow_msg(__func__, xdr);
5778 return ERR_PTR(-EIO);
1da177e4
LT
5779}
5780
5781/*
5782 * We need to translate between nfs status return values and
5783 * the local errno values which may not be the same.
5784 */
5785static struct {
5786 int stat;
5787 int errno;
5788} nfs_errtbl[] = {
5789 { NFS4_OK, 0 },
856dff3d
BH
5790 { NFS4ERR_PERM, -EPERM },
5791 { NFS4ERR_NOENT, -ENOENT },
5792 { NFS4ERR_IO, -errno_NFSERR_IO},
5793 { NFS4ERR_NXIO, -ENXIO },
5794 { NFS4ERR_ACCESS, -EACCES },
5795 { NFS4ERR_EXIST, -EEXIST },
5796 { NFS4ERR_XDEV, -EXDEV },
5797 { NFS4ERR_NOTDIR, -ENOTDIR },
5798 { NFS4ERR_ISDIR, -EISDIR },
5799 { NFS4ERR_INVAL, -EINVAL },
5800 { NFS4ERR_FBIG, -EFBIG },
5801 { NFS4ERR_NOSPC, -ENOSPC },
5802 { NFS4ERR_ROFS, -EROFS },
5803 { NFS4ERR_MLINK, -EMLINK },
5804 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5805 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5806 { NFS4ERR_DQUOT, -EDQUOT },
5807 { NFS4ERR_STALE, -ESTALE },
5808 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5809 { NFS4ERR_BADOWNER, -EINVAL },
5810 { NFS4ERR_BADNAME, -EINVAL },
5811 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5812 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5813 { NFS4ERR_TOOSMALL, -ETOOSMALL },
fdcb4577 5814 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
856dff3d
BH
5815 { NFS4ERR_BADTYPE, -EBADTYPE },
5816 { NFS4ERR_LOCKED, -EAGAIN },
856dff3d
BH
5817 { NFS4ERR_SYMLINK, -ELOOP },
5818 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5819 { NFS4ERR_DEADLOCK, -EDEADLK },
5820 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
1da177e4
LT
5821 * to be handled by a
5822 * middle-layer.
5823 */
856dff3d 5824 { -1, -EIO }
1da177e4
LT
5825};
5826
5827/*
5828 * Convert an NFS error code to a local one.
5829 * This one is used jointly by NFSv2 and NFSv3.
5830 */
5831static int
0a8ea437 5832nfs4_stat_to_errno(int stat)
1da177e4
LT
5833{
5834 int i;
5835 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5836 if (nfs_errtbl[i].stat == stat)
5837 return nfs_errtbl[i].errno;
5838 }
5839 if (stat <= 10000 || stat > 10100) {
5840 /* The server is looney tunes. */
fdcb4577 5841 return -EREMOTEIO;
1da177e4
LT
5842 }
5843 /* If we cannot translate the error, the recovery routines should
5844 * handle it.
5845 * Note: remaining NFSv4 error codes have values > 10000, so should
5846 * not conflict with native Linux error codes.
5847 */
856dff3d 5848 return -stat;
1da177e4
LT
5849}
5850
1da177e4
LT
5851#define PROC(proc, argtype, restype) \
5852[NFSPROC4_CLNT_##proc] = { \
5853 .p_proc = NFSPROC4_COMPOUND, \
5854 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5855 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
2bea90d4
CL
5856 .p_arglen = NFS4_##argtype##_sz, \
5857 .p_replen = NFS4_##restype##_sz, \
cc0175c1
CL
5858 .p_statidx = NFSPROC4_CLNT_##proc, \
5859 .p_name = #proc, \
05d564fe 5860}
1da177e4
LT
5861
5862struct rpc_procinfo nfs4_procedures[] = {
5863 PROC(READ, enc_read, dec_read),
5864 PROC(WRITE, enc_write, dec_write),
5865 PROC(COMMIT, enc_commit, dec_commit),
5866 PROC(OPEN, enc_open, dec_open),
5867 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5868 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5869 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5870 PROC(CLOSE, enc_close, dec_close),
5871 PROC(SETATTR, enc_setattr, dec_setattr),
5872 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5873 PROC(RENEW, enc_renew, dec_renew),
5874 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5875 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5876 PROC(LOCK, enc_lock, dec_lock),
5877 PROC(LOCKT, enc_lockt, dec_lockt),
5878 PROC(LOCKU, enc_locku, dec_locku),
5879 PROC(ACCESS, enc_access, dec_access),
5880 PROC(GETATTR, enc_getattr, dec_getattr),
5881 PROC(LOOKUP, enc_lookup, dec_lookup),
5882 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5883 PROC(REMOVE, enc_remove, dec_remove),
5884 PROC(RENAME, enc_rename, dec_rename),
5885 PROC(LINK, enc_link, dec_link),
5886 PROC(SYMLINK, enc_symlink, dec_symlink),
5887 PROC(CREATE, enc_create, dec_create),
5888 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5889 PROC(STATFS, enc_statfs, dec_statfs),
5890 PROC(READLINK, enc_readlink, dec_readlink),
5891 PROC(READDIR, enc_readdir, dec_readdir),
5892 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5893 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
029d105e 5894 PROC(GETACL, enc_getacl, dec_getacl),
23ec6965 5895 PROC(SETACL, enc_setacl, dec_setacl),
683b57b4 5896 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
d3c7b7cc 5897 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
99fe60d0
BH
5898#if defined(CONFIG_NFS_V4_1)
5899 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
fc931582 5900 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
0f3e66c6 5901 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
fc01cea9 5902 PROC(SEQUENCE, enc_sequence, dec_sequence),
2050f0cc 5903 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
18019753 5904 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
99fe60d0 5905#endif /* CONFIG_NFS_V4_1 */
1da177e4
LT
5906};
5907
5908struct rpc_version nfs_version4 = {
5909 .number = 4,
e8c96f8c 5910 .nrprocs = ARRAY_SIZE(nfs4_procedures),
1da177e4
LT
5911 .procs = nfs4_procedures
5912};
5913
5914/*
5915 * Local variables:
5916 * c-basic-offset: 8
5917 * End:
5918 */
This page took 1.007137 seconds and 5 git commands to generate.