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