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