blob: 9a03b24ead5f5dd15c857dc17a7041aa3895d36d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * 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>
41#include <linux/slab.h>
42#include <linux/utsname.h>
43#include <linux/errno.h>
44#include <linux/string.h>
45#include <linux/in.h>
46#include <linux/pagemap.h>
47#include <linux/proc_fs.h>
48#include <linux/kdev_t.h>
49#include <linux/sunrpc/clnt.h>
50#include <linux/nfs.h>
51#include <linux/nfs4.h>
52#include <linux/nfs_fs.h>
53#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000054#include "nfs4_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#define NFSDBG_FACILITY NFSDBG_XDR
57
58/* Mapping from NFS error code to "errno" error code. */
59#define errno_NFSERR_IO EIO
60
David Howells0a8ea432006-08-22 20:06:08 -040061static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
64#ifdef DEBUG
65#define NFS4_MAXTAGLEN 20
66#else
67#define NFS4_MAXTAGLEN 0
68#endif
69
Andy Adamson6c0195a2008-12-23 16:06:15 -050070/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040071 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 */
Trond Myklebust9f958ab2007-07-02 13:58:33 -040073#define open_owner_id_maxsz (1 + 4)
74#define lock_owner_id_maxsz (1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040075#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78#define op_encode_hdr_maxsz (1)
79#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040080#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
85 (NFS4_FHSIZE >> 2))
86#define decode_putfh_maxsz (op_decode_hdr_maxsz)
87#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89#define encode_getfh_maxsz (op_encode_hdr_maxsz)
90#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000092#define nfs4_fattr_bitmap_maxsz 3
93#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040096#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +000098/* This is based on getfattr, which uses the most attributes: */
99#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000101#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400104#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
105 1 + 2 + 1 + \
106 nfs4_owner_maxsz + \
107 nfs4_group_maxsz + \
108 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#define encode_savefh_maxsz (op_encode_hdr_maxsz)
110#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400111#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200113#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116#define decode_renew_maxsz (op_decode_hdr_maxsz)
117#define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
121 1 /* sc_prog */ + \
122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
124 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#define decode_setclientid_maxsz \
126 (op_decode_hdr_maxsz + \
127 2 + \
128 1024) /* large value for CLID_INUSE */
129#define encode_setclientid_confirm_maxsz \
130 (op_encode_hdr_maxsz + \
131 3 + (NFS4_VERIFIER_SIZE >> 2))
132#define decode_setclientid_confirm_maxsz \
133 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400134#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400136#define encode_share_access_maxsz \
137 (2)
Trond Myklebust9104a552007-07-17 21:52:42 -0400138#define encode_createmode_maxsz (1 + encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400139#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141#define encode_open_maxsz (op_encode_hdr_maxsz + \
142 2 + encode_share_access_maxsz + 2 + \
143 open_owner_id_maxsz + \
144 encode_opentype_maxsz + \
145 encode_claim_null_maxsz)
146#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400147#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400148 decode_ace_maxsz)
149#define decode_change_info_maxsz (5)
150#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400151 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400155#define encode_open_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 encode_stateid_maxsz + 1)
158#define decode_open_confirm_maxsz \
159 (op_decode_hdr_maxsz + \
160 decode_stateid_maxsz)
161#define encode_open_downgrade_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1 + \
164 encode_share_access_maxsz)
165#define decode_open_downgrade_maxsz \
166 (op_decode_hdr_maxsz + \
167 decode_stateid_maxsz)
168#define encode_close_maxsz (op_encode_hdr_maxsz + \
169 1 + encode_stateid_maxsz)
170#define decode_close_maxsz (op_decode_hdr_maxsz + \
171 decode_stateid_maxsz)
172#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + \
174 encode_attrs_maxsz)
175#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
176 nfs4_fattr_bitmap_maxsz)
177#define encode_read_maxsz (op_encode_hdr_maxsz + \
178 encode_stateid_maxsz + 3)
179#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
180#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
181 2 + encode_verifier_maxsz + 5)
182#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
183 decode_verifier_maxsz)
184#define encode_readlink_maxsz (op_encode_hdr_maxsz)
185#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
186#define encode_write_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 4)
188#define decode_write_maxsz (op_decode_hdr_maxsz + \
189 2 + decode_verifier_maxsz)
190#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
191#define decode_commit_maxsz (op_decode_hdr_maxsz + \
192 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193#define encode_remove_maxsz (op_encode_hdr_maxsz + \
194 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400195#define decode_remove_maxsz (op_decode_hdr_maxsz + \
196 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#define encode_rename_maxsz (op_encode_hdr_maxsz + \
198 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400199#define decode_rename_maxsz (op_decode_hdr_maxsz + \
200 decode_change_info_maxsz + \
201 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#define encode_link_maxsz (op_encode_hdr_maxsz + \
203 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400204#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400205#define encode_lock_maxsz (op_encode_hdr_maxsz + \
206 7 + \
207 1 + encode_stateid_maxsz + 8)
208#define decode_lock_denied_maxsz \
209 (8 + decode_lockowner_maxsz)
210#define decode_lock_maxsz (op_decode_hdr_maxsz + \
211 decode_lock_denied_maxsz)
212#define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
213#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
215#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
216 encode_stateid_maxsz + \
217 4)
218#define decode_locku_maxsz (op_decode_hdr_maxsz + \
219 decode_stateid_maxsz)
220#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
221#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
223 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400224 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000225 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
227#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400228 1 + 2 + nfs4_name_maxsz + \
229 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400230#define decode_create_maxsz (op_decode_hdr_maxsz + \
231 decode_change_info_maxsz + \
232 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400233#define encode_statfs_maxsz (encode_getattr_maxsz)
234#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
236#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400237#define encode_getacl_maxsz (encode_getattr_maxsz)
238#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
239 nfs4_fattr_bitmap_maxsz + 1)
240#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
241 encode_stateid_maxsz + 3)
242#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400243#define encode_fs_locations_maxsz \
244 (encode_getattr_maxsz)
245#define decode_fs_locations_maxsz \
246 (0)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400247
248#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400249#define NFS4_MAX_MACHINE_NAME_LEN (64)
250
Benny Halevy99fe60d2009-04-01 09:22:29 -0400251#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
252 encode_verifier_maxsz + \
253 1 /* co_ownerid.len */ + \
254 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
255 1 /* flags */ + \
256 1 /* spa_how */ + \
257 0 /* SP4_NONE (for now) */ + \
258 1 /* zero implemetation id array */)
259#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
260 2 /* eir_clientid */ + \
261 1 /* eir_sequenceid */ + \
262 1 /* eir_flags */ + \
263 1 /* spr_how */ + \
264 0 /* SP4_NONE (for now) */ + \
265 2 /* eir_server_owner.so_minor_id */ + \
266 /* eir_server_owner.so_major_id<> */ \
267 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
268 /* eir_server_scope<> */ \
269 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
270 1 /* eir_server_impl_id array length */ + \
271 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400272#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
273#define decode_channel_attrs_maxsz (6 + \
274 1 /* ca_rdma_ird.len */ + \
275 1 /* ca_rdma_ird */)
276#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
277 2 /* csa_clientid */ + \
278 1 /* csa_sequence */ + \
279 1 /* csa_flags */ + \
280 encode_channel_attrs_maxsz + \
281 encode_channel_attrs_maxsz + \
282 1 /* csa_cb_program */ + \
283 1 /* csa_sec_parms.len (1) */ + \
284 1 /* cb_secflavor (AUTH_SYS) */ + \
285 1 /* stamp */ + \
286 1 /* machinename.len */ + \
287 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
288 1 /* uid */ + \
289 1 /* gid */ + \
290 1 /* gids.len (0) */)
291#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
292 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
293 1 /* csr_sequence */ + \
294 1 /* csr_flags */ + \
295 decode_channel_attrs_maxsz + \
296 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400297#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
298#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400299#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
300 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
301#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
302 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400303#else /* CONFIG_NFS_V4_1 */
304#define encode_sequence_maxsz 0
305#define decode_sequence_maxsz 0
306#endif /* CONFIG_NFS_V4_1 */
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
309#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
310#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400311 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400313 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400315 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400317 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400319 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400321 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400323 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400325 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400327 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400329 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400331 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400333 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400335 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400337 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400338 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400340 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400342 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400343 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400345 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400347 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400348 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400350 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400352 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400353 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400355 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400356 encode_putfh_maxsz + \
357 encode_savefh_maxsz + \
358 encode_open_maxsz + \
359 encode_getfh_maxsz + \
360 encode_getattr_maxsz + \
361 encode_restorefh_maxsz + \
362 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400364 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400365 decode_putfh_maxsz + \
366 decode_savefh_maxsz + \
367 decode_open_maxsz + \
368 decode_getfh_maxsz + \
369 decode_getattr_maxsz + \
370 decode_restorefh_maxsz + \
371 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400372#define NFS4_enc_open_confirm_sz \
373 (compound_encode_hdr_maxsz + \
374 encode_putfh_maxsz + \
375 encode_open_confirm_maxsz)
376#define NFS4_dec_open_confirm_sz \
377 (compound_decode_hdr_maxsz + \
378 decode_putfh_maxsz + \
379 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400381 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400383 encode_open_maxsz + \
384 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400386 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400388 decode_open_maxsz + \
389 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#define NFS4_enc_open_downgrade_sz \
391 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400392 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400393 encode_putfh_maxsz + \
394 encode_open_downgrade_maxsz + \
395 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396#define NFS4_dec_open_downgrade_sz \
397 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400398 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400399 decode_putfh_maxsz + \
400 decode_open_downgrade_maxsz + \
401 decode_getattr_maxsz)
402#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400403 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400404 encode_putfh_maxsz + \
405 encode_close_maxsz + \
406 encode_getattr_maxsz)
407#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400409 decode_putfh_maxsz + \
410 decode_close_maxsz + \
411 decode_getattr_maxsz)
412#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400413 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 encode_putfh_maxsz + \
415 encode_setattr_maxsz + \
416 encode_getattr_maxsz)
417#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400418 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 decode_putfh_maxsz + \
420 decode_setattr_maxsz + \
421 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400423 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 encode_putfh_maxsz + \
425 encode_fsinfo_maxsz)
426#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 decode_putfh_maxsz + \
429 decode_fsinfo_maxsz)
430#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
431 encode_renew_maxsz)
432#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
433 decode_renew_maxsz)
434#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
435 encode_setclientid_maxsz)
436#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
437 decode_setclientid_maxsz)
438#define NFS4_enc_setclientid_confirm_sz \
439 (compound_encode_hdr_maxsz + \
440 encode_setclientid_confirm_maxsz + \
441 encode_putrootfh_maxsz + \
442 encode_fsinfo_maxsz)
443#define NFS4_dec_setclientid_confirm_sz \
444 (compound_decode_hdr_maxsz + \
445 decode_setclientid_confirm_maxsz + \
446 decode_putrootfh_maxsz + \
447 decode_fsinfo_maxsz)
448#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400449 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400451 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400453 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400455 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400457 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400459 encode_lockt_maxsz)
460#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400461 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400462 decode_putfh_maxsz + \
463 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400465 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400467 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400471 decode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400473 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400475 encode_access_maxsz + \
476 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400478 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400480 decode_access_maxsz + \
481 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400483 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 encode_putfh_maxsz + \
485 encode_getattr_maxsz)
486#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400487 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 decode_putfh_maxsz + \
489 decode_getattr_maxsz)
490#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400491 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 encode_putfh_maxsz + \
493 encode_lookup_maxsz + \
494 encode_getattr_maxsz + \
495 encode_getfh_maxsz)
496#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400497 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400499 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 decode_getattr_maxsz + \
501 decode_getfh_maxsz)
502#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400503 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 encode_putrootfh_maxsz + \
505 encode_getattr_maxsz + \
506 encode_getfh_maxsz)
507#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400508 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 decode_putrootfh_maxsz + \
510 decode_getattr_maxsz + \
511 decode_getfh_maxsz)
512#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400513 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400515 encode_remove_maxsz + \
516 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400518 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400520 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400521 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400523 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 encode_putfh_maxsz + \
525 encode_savefh_maxsz + \
526 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400527 encode_rename_maxsz + \
528 encode_getattr_maxsz + \
529 encode_restorefh_maxsz + \
530 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400532 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 decode_putfh_maxsz + \
534 decode_savefh_maxsz + \
535 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400536 decode_rename_maxsz + \
537 decode_getattr_maxsz + \
538 decode_restorefh_maxsz + \
539 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400541 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 encode_putfh_maxsz + \
543 encode_savefh_maxsz + \
544 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400545 encode_link_maxsz + \
546 decode_getattr_maxsz + \
547 encode_restorefh_maxsz + \
548 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400550 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 decode_putfh_maxsz + \
552 decode_savefh_maxsz + \
553 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400554 decode_link_maxsz + \
555 decode_getattr_maxsz + \
556 decode_restorefh_maxsz + \
557 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400559 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 encode_putfh_maxsz + \
561 encode_symlink_maxsz + \
562 encode_getattr_maxsz + \
563 encode_getfh_maxsz)
564#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400565 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 decode_putfh_maxsz + \
567 decode_symlink_maxsz + \
568 decode_getattr_maxsz + \
569 decode_getfh_maxsz)
570#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400571 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400573 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400575 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400577 encode_restorefh_maxsz + \
578 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400582 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400584 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400586 decode_restorefh_maxsz + \
587 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400589 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 encode_putfh_maxsz + \
591 encode_getattr_maxsz)
592#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400593 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 decode_putfh_maxsz + \
595 decode_getattr_maxsz)
596#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400597 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400599 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400603 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400605 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800606 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 encode_getattr_maxsz)
608#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400609 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800610 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 decode_getattr_maxsz)
612#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400613 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100615 encode_delegreturn_maxsz + \
616 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400618 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100619 decode_delegreturn_maxsz + \
620 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000621#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000623 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400624 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000625#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400626 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000627 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400628 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000629#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400630 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000631 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400632 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000633#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400634 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000635 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400636 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400637#define NFS4_enc_fs_locations_sz \
638 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400639 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400640 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400641 encode_lookup_maxsz + \
642 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400643#define NFS4_dec_fs_locations_sz \
644 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400645 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400646 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400647 decode_lookup_maxsz + \
648 decode_fs_locations_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400649#if defined(CONFIG_NFS_V4_1)
650#define NFS4_enc_exchange_id_sz \
651 (compound_encode_hdr_maxsz + \
652 encode_exchange_id_maxsz)
653#define NFS4_dec_exchange_id_sz \
654 (compound_decode_hdr_maxsz + \
655 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400656#define NFS4_enc_create_session_sz \
657 (compound_encode_hdr_maxsz + \
658 encode_create_session_maxsz)
659#define NFS4_dec_create_session_sz \
660 (compound_decode_hdr_maxsz + \
661 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400662#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
663 encode_destroy_session_maxsz)
664#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
665 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400666#define NFS4_enc_sequence_sz \
667 (compound_decode_hdr_maxsz + \
668 encode_sequence_maxsz)
669#define NFS4_dec_sequence_sz \
670 (compound_decode_hdr_maxsz + \
671 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400672#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
673 encode_sequence_maxsz + \
674 encode_putrootfh_maxsz + \
675 encode_fsinfo_maxsz)
676#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
677 decode_sequence_maxsz + \
678 decode_putrootfh_maxsz + \
679 decode_fsinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400680#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Trond Myklebustbca79472009-03-11 14:10:26 -0400682static const umode_t nfs_type2fmt[] = {
683 [NF4BAD] = 0,
684 [NF4REG] = S_IFREG,
685 [NF4DIR] = S_IFDIR,
686 [NF4BLK] = S_IFBLK,
687 [NF4CHR] = S_IFCHR,
688 [NF4LNK] = S_IFLNK,
689 [NF4SOCK] = S_IFSOCK,
690 [NF4FIFO] = S_IFIFO,
691 [NF4ATTRDIR] = 0,
692 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693};
694
695struct compound_hdr {
696 int32_t status;
697 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500698 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 uint32_t taglen;
700 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400701 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400702 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703};
704
705/*
706 * START OF "GENERIC" ENCODE ROUTINES.
707 * These may look a little ugly since they are imported from a "generic"
708 * set of XDR encode/decode routines which are intended to be shared by
709 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
710 *
711 * If the pain of reading these is too great, it should be a straightforward
712 * task to translate them into Linux-specific versions which are more
713 * consistent with the style used in NFSv2/v3...
714 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715#define WRITE64(n) do { \
716 *p++ = htonl((uint32_t)((n) >> 32)); \
717 *p++ = htonl((uint32_t)(n)); \
718} while (0)
719#define WRITEMEM(ptr,nbytes) do { \
720 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
721} while (0)
722
723#define RESERVE_SPACE(nbytes) do { \
724 p = xdr_reserve_space(xdr, nbytes); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 BUG_ON(!p); \
726} while (0)
727
728static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
729{
Al Viro8687b632006-10-19 23:28:48 -0700730 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
732 p = xdr_reserve_space(xdr, 4 + len);
733 BUG_ON(p == NULL);
734 xdr_encode_opaque(p, str, len);
735}
736
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400737static void encode_compound_hdr(struct xdr_stream *xdr,
738 struct rpc_rqst *req,
739 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740{
Al Viro8687b632006-10-19 23:28:48 -0700741 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400742 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
743
744 /* initialize running count of expected bytes in reply.
745 * NOTE: the replied tag SHOULD be the same is the one sent,
746 * but this is not required as a MUST for the server to do so. */
747 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
749 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
750 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
751 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
Benny Halevye75bc1c2009-08-14 17:18:54 +0300752 *p++ = cpu_to_be32(hdr->taglen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 WRITEMEM(hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300754 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500755 hdr->nops_p = p;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300756 *p++ = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500757}
758
759static void encode_nops(struct compound_hdr *hdr)
760{
Andy Adamsonfc931582009-04-01 09:22:31 -0400761 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500762 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763}
764
765static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
766{
Al Viro8687b632006-10-19 23:28:48 -0700767 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
770 BUG_ON(p == NULL);
771 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
772}
773
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500774static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775{
776 char owner_name[IDMAP_NAMESZ];
777 char owner_group[IDMAP_NAMESZ];
778 int owner_namelen = 0;
779 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700780 __be32 *p;
781 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 int len;
783 uint32_t bmval0 = 0;
784 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
786 /*
787 * We reserve enough space to write the entire attribute buffer at once.
788 * In the worst-case, this would be
789 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
790 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000791 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 */
793 len = 16;
794
795 /* Sigh */
796 if (iap->ia_valid & ATTR_SIZE)
797 len += 8;
798 if (iap->ia_valid & ATTR_MODE)
799 len += 4;
800 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400801 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400803 dprintk("nfs: couldn't resolve uid %d to string\n",
804 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 /* XXX */
806 strcpy(owner_name, "nobody");
807 owner_namelen = sizeof("nobody") - 1;
808 /* goto out; */
809 }
810 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
811 }
812 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400813 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400815 dprintk("nfs: couldn't resolve gid %d to string\n",
816 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 strcpy(owner_group, "nobody");
818 owner_grouplen = sizeof("nobody") - 1;
819 /* goto out; */
820 }
821 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
822 }
823 if (iap->ia_valid & ATTR_ATIME_SET)
824 len += 16;
825 else if (iap->ia_valid & ATTR_ATIME)
826 len += 4;
827 if (iap->ia_valid & ATTR_MTIME_SET)
828 len += 16;
829 else if (iap->ia_valid & ATTR_MTIME)
830 len += 4;
831 RESERVE_SPACE(len);
832
833 /*
834 * We write the bitmap length now, but leave the bitmap and the attribute
835 * buffer length to be backfilled at the end of this routine.
836 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300837 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 q = p;
839 p += 3;
840
841 if (iap->ia_valid & ATTR_SIZE) {
842 bmval0 |= FATTR4_WORD0_SIZE;
843 WRITE64(iap->ia_size);
844 }
845 if (iap->ia_valid & ATTR_MODE) {
846 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300847 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 }
849 if (iap->ia_valid & ATTR_UID) {
850 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300851 *p++ = cpu_to_be32(owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 WRITEMEM(owner_name, owner_namelen);
853 }
854 if (iap->ia_valid & ATTR_GID) {
855 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300856 *p++ = cpu_to_be32(owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 WRITEMEM(owner_group, owner_grouplen);
858 }
859 if (iap->ia_valid & ATTR_ATIME_SET) {
860 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300861 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
862 *p++ = cpu_to_be32(0);
863 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
864 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 }
866 else if (iap->ia_valid & ATTR_ATIME) {
867 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300868 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 }
870 if (iap->ia_valid & ATTR_MTIME_SET) {
871 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300872 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
873 *p++ = cpu_to_be32(0);
874 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
875 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 }
877 else if (iap->ia_valid & ATTR_MTIME) {
878 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300879 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 /*
883 * Now we backfill the bitmap and the attribute buffer length.
884 */
885 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400886 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 len, ((char *)p - (char *)q) + 4);
888 BUG();
889 }
890 len = (char *)p - (char *)q - 12;
891 *q++ = htonl(bmval0);
892 *q++ = htonl(bmval1);
893 *q++ = htonl(len);
894
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896}
897
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500898static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899{
Al Viro8687b632006-10-19 23:28:48 -0700900 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
902 RESERVE_SPACE(8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300903 *p++ = cpu_to_be32(OP_ACCESS);
904 *p++ = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500905 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400906 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907}
908
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500909static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910{
Al Viro8687b632006-10-19 23:28:48 -0700911 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400913 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300914 *p++ = cpu_to_be32(OP_CLOSE);
915 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400916 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500917 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400918 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919}
920
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500921static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922{
Al Viro8687b632006-10-19 23:28:48 -0700923 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500924
Andy Adamson05d564f2008-12-23 16:06:15 -0500925 RESERVE_SPACE(16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300926 *p++ = cpu_to_be32(OP_COMMIT);
Andy Adamson05d564f2008-12-23 16:06:15 -0500927 WRITE64(args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300928 *p++ = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500929 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400930 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931}
932
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500933static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
Al Viro8687b632006-10-19 23:28:48 -0700935 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500936
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 RESERVE_SPACE(8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300938 *p++ = cpu_to_be32(OP_CREATE);
939 *p++ = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 switch (create->ftype) {
942 case NF4LNK:
Chuck Lever94a6d752006-08-22 20:06:23 -0400943 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300944 *p++ = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -0400945 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 break;
947
948 case NF4BLK: case NF4CHR:
949 RESERVE_SPACE(8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300950 *p++ = cpu_to_be32(create->u.device.specdata1);
951 *p++ = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 break;
953
954 default:
955 break;
956 }
957
958 RESERVE_SPACE(4 + create->name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300959 *p++ = cpu_to_be32(create->name->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 WRITEMEM(create->name->name, create->name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500961 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400962 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500964 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965}
966
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500967static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968{
Andy Adamson05d564f2008-12-23 16:06:15 -0500969 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
Andy Adamson05d564f2008-12-23 16:06:15 -0500971 RESERVE_SPACE(12);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300972 *p++ = cpu_to_be32(OP_GETATTR);
973 *p++ = cpu_to_be32(1);
974 *p++ = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500975 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400976 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977}
978
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500979static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980{
Andy Adamson05d564f2008-12-23 16:06:15 -0500981 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
Andy Adamson05d564f2008-12-23 16:06:15 -0500983 RESERVE_SPACE(16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300984 *p++ = cpu_to_be32(OP_GETATTR);
985 *p++ = cpu_to_be32(2);
986 *p++ = cpu_to_be32(bm0);
987 *p++ = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -0500988 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400989 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990}
991
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500992static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500994 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
995 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996}
997
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500998static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001000 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1001 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002}
1003
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001004static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001005{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001006 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1007 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001008}
1009
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001010static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011{
Al Viro8687b632006-10-19 23:28:48 -07001012 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
1014 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001015 *p++ = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001016 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001017 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018}
1019
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001020static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021{
Al Viro8687b632006-10-19 23:28:48 -07001022 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
1024 RESERVE_SPACE(8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001025 *p++ = cpu_to_be32(OP_LINK);
1026 *p++ = cpu_to_be32(name->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001028 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001029 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030}
1031
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001032static inline int nfs4_lock_type(struct file_lock *fl, int block)
1033{
1034 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1035 return block ? NFS4_READW_LT : NFS4_READ_LT;
1036 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1037}
1038
1039static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1040{
1041 if (fl->fl_end == OFFSET_MAX)
1042 return ~(uint64_t)0;
1043 return fl->fl_end - fl->fl_start + 1;
1044}
1045
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046/*
1047 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1048 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1049 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001050static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051{
Al Viro8687b632006-10-19 23:28:48 -07001052 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
1054 RESERVE_SPACE(32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001055 *p++ = cpu_to_be32(OP_LOCK);
1056 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1057 *p++ = cpu_to_be32(args->reclaim);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001058 WRITE64(args->fl->fl_start);
1059 WRITE64(nfs4_lock_length(args->fl));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001060 *p++ = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001061 if (args->new_lock_owner){
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001062 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001063 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001064 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001065 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001066 WRITE64(args->lock_owner.clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001067 *p++ = cpu_to_be32(16);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001068 WRITEMEM("lock id:", 8);
1069 WRITE64(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 }
1071 else {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001072 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
1073 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001074 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 }
Andy Adamsond0179312008-12-23 16:06:17 -05001076 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001077 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078}
1079
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001080static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081{
Al Viro8687b632006-10-19 23:28:48 -07001082 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001084 RESERVE_SPACE(52);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001085 *p++ = cpu_to_be32(OP_LOCKT);
1086 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001087 WRITE64(args->fl->fl_start);
1088 WRITE64(nfs4_lock_length(args->fl));
1089 WRITE64(args->lock_owner.clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001090 *p++ = cpu_to_be32(16);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001091 WRITEMEM("lock id:", 8);
1092 WRITE64(args->lock_owner.id);
Andy Adamsond0179312008-12-23 16:06:17 -05001093 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001094 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095}
1096
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001097static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098{
Al Viro8687b632006-10-19 23:28:48 -07001099 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001101 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001102 *p++ = cpu_to_be32(OP_LOCKU);
1103 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1104 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001105 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001106 WRITE64(args->fl->fl_start);
1107 WRITE64(nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001108 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001109 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110}
1111
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001112static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113{
1114 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001115 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
1117 RESERVE_SPACE(8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001118 *p++ = cpu_to_be32(OP_LOOKUP);
1119 *p++ = cpu_to_be32(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 WRITEMEM(name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001121 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001122 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123}
1124
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001125static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126{
Al Viro8687b632006-10-19 23:28:48 -07001127 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
1129 RESERVE_SPACE(8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001130 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001131 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001132 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001133 break;
1134 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001135 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001136 break;
1137 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001138 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001139 break;
1140 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001141 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 }
Benny Halevye75bc1c2009-08-14 17:18:54 +03001143 *p++ = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144}
1145
1146static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1147{
Al Viro8687b632006-10-19 23:28:48 -07001148 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 /*
1150 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1151 * owner 4 = 32
1152 */
1153 RESERVE_SPACE(8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001154 *p++ = cpu_to_be32(OP_OPEN);
1155 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001156 encode_share_access(xdr, arg->fmode);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001157 RESERVE_SPACE(28);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 WRITE64(arg->clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001159 *p++ = cpu_to_be32(16);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001160 WRITEMEM("open id:", 8);
1161 WRITE64(arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162}
1163
1164static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1165{
Al Viro8687b632006-10-19 23:28:48 -07001166 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
1168 RESERVE_SPACE(4);
1169 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001170 case 0:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001171 *p++ = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001172 encode_attrs(xdr, arg->u.attrs, arg->server);
1173 break;
1174 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001175 *p++ = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001176 encode_nfs4_verifier(xdr, &arg->u.verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 }
1178}
1179
1180static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1181{
Al Viro8687b632006-10-19 23:28:48 -07001182 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
1184 RESERVE_SPACE(4);
1185 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001186 case 0:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001187 *p++ = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001188 break;
1189 default:
1190 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001191 *p++ = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001192 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 }
1194}
1195
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001196static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197{
Al Viro8687b632006-10-19 23:28:48 -07001198 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
1200 RESERVE_SPACE(4);
1201 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001202 case 0:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001203 *p++ = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001204 break;
1205 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001206 *p++ = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001207 break;
1208 case FMODE_WRITE|FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001209 *p++ = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001210 break;
1211 default:
1212 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 }
1214}
1215
1216static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1217{
Al Viro8687b632006-10-19 23:28:48 -07001218 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
1220 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001221 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 encode_string(xdr, name->len, name->name);
1223}
1224
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001225static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226{
Al Viro8687b632006-10-19 23:28:48 -07001227 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
1229 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001230 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 encode_delegation_type(xdr, type);
1232}
1233
1234static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1235{
Al Viro8687b632006-10-19 23:28:48 -07001236 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001238 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001239 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001240 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 encode_string(xdr, name->len, name->name);
1242}
1243
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001244static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245{
1246 encode_openhdr(xdr, arg);
1247 encode_opentype(xdr, arg);
1248 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001249 case NFS4_OPEN_CLAIM_NULL:
1250 encode_claim_null(xdr, arg->name);
1251 break;
1252 case NFS4_OPEN_CLAIM_PREVIOUS:
1253 encode_claim_previous(xdr, arg->u.delegation_type);
1254 break;
1255 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1256 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1257 break;
1258 default:
1259 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 }
Andy Adamsond0179312008-12-23 16:06:17 -05001261 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001262 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263}
1264
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001265static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266{
Al Viro8687b632006-10-19 23:28:48 -07001267 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001269 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001270 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001271 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001272 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001273 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001274 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275}
1276
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001277static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278{
Al Viro8687b632006-10-19 23:28:48 -07001279 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001281 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001282 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001283 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001284 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001285 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001286 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001287 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288}
1289
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001290static void
Andy Adamsond0179312008-12-23 16:06:17 -05001291encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
1293 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001294 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
1296 RESERVE_SPACE(8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001297 *p++ = cpu_to_be32(OP_PUTFH);
1298 *p++ = cpu_to_be32(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 WRITEMEM(fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001300 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001301 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302}
1303
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001304static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305{
Andy Adamson05d564f2008-12-23 16:06:15 -05001306 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001307
Andy Adamson05d564f2008-12-23 16:06:15 -05001308 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001309 *p++ = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001310 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001311 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312}
1313
1314static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1315{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001317 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001319 RESERVE_SPACE(NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 if (ctx->state != NULL) {
1321 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001322 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 } else
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001324 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325}
1326
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001327static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328{
Al Viro8687b632006-10-19 23:28:48 -07001329 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
1331 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001332 *p++ = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
1334 encode_stateid(xdr, args->context);
1335
1336 RESERVE_SPACE(12);
1337 WRITE64(args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001338 *p++ = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001339 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001340 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341}
1342
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001343static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344{
Manoj Naik97d312d2005-06-22 17:16:39 +00001345 uint32_t attrs[2] = {
1346 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1347 FATTR4_WORD1_MOUNTED_ON_FILEID,
1348 };
Al Viro8687b632006-10-19 23:28:48 -07001349 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001351 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001352 *p++ = cpu_to_be32(OP_READDIR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 WRITE64(readdir->cookie);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001354 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001355 *p++ = cpu_to_be32(readdir->count >> 1); /* We're not doing readdirplus */
1356 *p++ = cpu_to_be32(readdir->count);
1357 *p++ = cpu_to_be32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001358 /* Switch to mounted_on_fileid if the server supports it */
1359 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1360 attrs[0] &= ~FATTR4_WORD0_FILEID;
1361 else
1362 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001363 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1364 *p++ = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001365 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001366 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001367 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1368 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001369 (unsigned long long)readdir->cookie,
1370 ((u32 *)readdir->verifier.data)[0],
1371 ((u32 *)readdir->verifier.data)[1],
1372 attrs[0] & readdir->bitmask[0],
1373 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374}
1375
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001376static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377{
Al Viro8687b632006-10-19 23:28:48 -07001378 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
1380 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001381 *p++ = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001382 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001383 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384}
1385
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001386static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387{
Al Viro8687b632006-10-19 23:28:48 -07001388 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
1390 RESERVE_SPACE(8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001391 *p++ = cpu_to_be32(OP_REMOVE);
1392 *p++ = cpu_to_be32(name->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001394 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001395 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396}
1397
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001398static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399{
Al Viro8687b632006-10-19 23:28:48 -07001400 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
1402 RESERVE_SPACE(8 + oldname->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001403 *p++ = cpu_to_be32(OP_RENAME);
1404 *p++ = cpu_to_be32(oldname->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 WRITEMEM(oldname->name, oldname->len);
Andy Adamson6c0195a2008-12-23 16:06:15 -05001406
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 RESERVE_SPACE(4 + newname->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001408 *p++ = cpu_to_be32(newname->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 WRITEMEM(newname->name, newname->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001410 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001411 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412}
1413
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001414static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415{
Al Viro8687b632006-10-19 23:28:48 -07001416 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
1418 RESERVE_SPACE(12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001419 *p++ = cpu_to_be32(OP_RENEW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 WRITE64(client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001421 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001422 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423}
1424
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001425static void
Andy Adamsond0179312008-12-23 16:06:17 -05001426encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001427{
Al Viro8687b632006-10-19 23:28:48 -07001428 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001429
1430 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001431 *p++ = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001432 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001433 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001434}
1435
1436static int
Andy Adamsond0179312008-12-23 16:06:17 -05001437encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001438{
Al Viro8687b632006-10-19 23:28:48 -07001439 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001440
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001441 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001442 *p++ = cpu_to_be32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001443 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001444 RESERVE_SPACE(2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001445 *p++ = cpu_to_be32(1);
1446 *p++ = cpu_to_be32(FATTR4_WORD0_ACL);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001447 if (arg->acl_len % 4)
1448 return -EINVAL;
1449 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001450 *p++ = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001451 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001452 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001453 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001454 return 0;
1455}
1456
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001457static void
Andy Adamsond0179312008-12-23 16:06:17 -05001458encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459{
Al Viro8687b632006-10-19 23:28:48 -07001460 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
1462 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001463 *p++ = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001464 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001465 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466}
1467
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001468static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469{
Al Viro8687b632006-10-19 23:28:48 -07001470 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001471
Andy Adamson05d564f2008-12-23 16:06:15 -05001472 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001473 *p++ = cpu_to_be32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001474 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001475 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001476 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001477 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478}
1479
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001480static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481{
Al Viro8687b632006-10-19 23:28:48 -07001482 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001484 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001485 *p++ = cpu_to_be32(OP_SETCLIENTID);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001486 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
1488 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1489 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001490 *p++ = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1492 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1493 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001494 *p++ = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001495 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001496 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497}
1498
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001499static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500{
Andy Adamson05d564f2008-12-23 16:06:15 -05001501 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Andy Adamson05d564f2008-12-23 16:06:15 -05001503 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001504 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Andy Adamson05d564f2008-12-23 16:06:15 -05001505 WRITE64(client_state->cl_clientid);
1506 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001507 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001508 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509}
1510
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001511static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512{
Al Viro8687b632006-10-19 23:28:48 -07001513 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
1515 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001516 *p++ = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
1518 encode_stateid(xdr, args->context);
1519
1520 RESERVE_SPACE(16);
1521 WRITE64(args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001522 *p++ = cpu_to_be32(args->stable);
1523 *p++ = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524
1525 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001526 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001527 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528}
1529
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001530static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531{
Al Viro8687b632006-10-19 23:28:48 -07001532 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001534 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Benny Halevye75bc1c2009-08-14 17:18:54 +03001536 *p++ = cpu_to_be32(OP_DELEGRETURN);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001537 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001538 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001539 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001541
Benny Halevy99fe60d2009-04-01 09:22:29 -04001542#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001543/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001544static void encode_exchange_id(struct xdr_stream *xdr,
1545 struct nfs41_exchange_id_args *args,
1546 struct compound_hdr *hdr)
1547{
1548 __be32 *p;
1549
1550 RESERVE_SPACE(4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001551 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001552 WRITEMEM(args->verifier->data, sizeof(args->verifier->data));
1553
1554 encode_string(xdr, args->id_len, args->id);
1555
1556 RESERVE_SPACE(12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001557 *p++ = cpu_to_be32(args->flags);
1558 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
1559 *p++ = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001560 hdr->nops++;
1561 hdr->replen += decode_exchange_id_maxsz;
1562}
Andy Adamsonfc931582009-04-01 09:22:31 -04001563
1564static void encode_create_session(struct xdr_stream *xdr,
1565 struct nfs41_create_session_args *args,
1566 struct compound_hdr *hdr)
1567{
1568 __be32 *p;
1569 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1570 uint32_t len;
1571 struct nfs_client *clp = args->client;
1572
1573 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001574 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamsonfc931582009-04-01 09:22:31 -04001575
1576 RESERVE_SPACE(8);
1577 WRITE64(clp->cl_ex_clid);
1578
1579 RESERVE_SPACE(8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001580 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1581 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001582
1583 RESERVE_SPACE(2*28); /* 2 channel_attrs */
1584 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001585 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1586 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1587 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1588 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1589 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1590 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1591 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001592
1593 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001594 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1595 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1596 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1597 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1598 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1599 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1600 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001601
1602 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001603 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Andy Adamsonfc931582009-04-01 09:22:31 -04001604
1605 RESERVE_SPACE(4); /* # of security flavors */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001606 *p++ = cpu_to_be32(1);
Andy Adamsonfc931582009-04-01 09:22:31 -04001607
1608 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001609 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001610
1611 /* authsys_parms rfc1831 */
1612 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001613 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Andy Adamsonfc931582009-04-01 09:22:31 -04001614 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1615 clp->cl_ipaddr);
1616 RESERVE_SPACE(16 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001617 *p++ = cpu_to_be32(len);
Andy Adamsonfc931582009-04-01 09:22:31 -04001618 WRITEMEM(machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001619 *p++ = cpu_to_be32(0); /* UID */
1620 *p++ = cpu_to_be32(0); /* GID */
1621 *p++ = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001622 hdr->nops++;
1623 hdr->replen += decode_create_session_maxsz;
1624}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001625
1626static void encode_destroy_session(struct xdr_stream *xdr,
1627 struct nfs4_session *session,
1628 struct compound_hdr *hdr)
1629{
1630 __be32 *p;
1631 RESERVE_SPACE(4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001632 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001633 WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1634 hdr->nops++;
1635 hdr->replen += decode_destroy_session_maxsz;
1636}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001637#endif /* CONFIG_NFS_V4_1 */
1638
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001639static void encode_sequence(struct xdr_stream *xdr,
1640 const struct nfs4_sequence_args *args,
1641 struct compound_hdr *hdr)
1642{
1643#if defined(CONFIG_NFS_V4_1)
1644 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001645 struct nfs4_slot_table *tp;
1646 struct nfs4_slot *slot;
1647 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001648
1649 if (!session)
1650 return;
1651
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001652 tp = &session->fc_slot_table;
1653
1654 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1655 slot = tp->slots + args->sa_slotid;
1656
1657 RESERVE_SPACE(4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001658 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001659
1660 /*
1661 * Sessionid + seqid + slotid + max slotid + cache_this
1662 */
1663 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1664 "max_slotid=%d cache_this=%d\n",
1665 __func__,
1666 ((u32 *)session->sess_id.data)[0],
1667 ((u32 *)session->sess_id.data)[1],
1668 ((u32 *)session->sess_id.data)[2],
1669 ((u32 *)session->sess_id.data)[3],
1670 slot->seq_nr, args->sa_slotid,
1671 tp->highest_used_slotid, args->sa_cache_this);
1672 RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 16);
1673 WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001674 *p++ = cpu_to_be32(slot->seq_nr);
1675 *p++ = cpu_to_be32(args->sa_slotid);
1676 *p++ = cpu_to_be32(tp->highest_used_slotid);
1677 *p++ = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001678 hdr->nops++;
1679 hdr->replen += decode_sequence_maxsz;
1680#endif /* CONFIG_NFS_V4_1 */
1681}
1682
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683/*
1684 * END OF "GENERIC" ENCODE ROUTINES.
1685 */
1686
Benny Halevy66cc0422009-04-01 09:22:10 -04001687static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1688{
1689#if defined(CONFIG_NFS_V4_1)
1690 if (args->sa_session)
1691 return args->sa_session->clp->cl_minorversion;
1692#endif /* CONFIG_NFS_V4_1 */
1693 return 0;
1694}
1695
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696/*
1697 * Encode an ACCESS request
1698 */
Al Viro8687b632006-10-19 23:28:48 -07001699static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700{
1701 struct xdr_stream xdr;
1702 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001703 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
1706 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001707 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001708 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001709 encode_putfh(&xdr, args->fh, &hdr);
1710 encode_access(&xdr, args->access, &hdr);
1711 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001712 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001713 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714}
1715
1716/*
1717 * Encode LOOKUP request
1718 */
Al Viro8687b632006-10-19 23:28:48 -07001719static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720{
1721 struct xdr_stream xdr;
1722 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001723 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
1726 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001727 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001728 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001729 encode_putfh(&xdr, args->dir_fh, &hdr);
1730 encode_lookup(&xdr, args->name, &hdr);
1731 encode_getfh(&xdr, &hdr);
1732 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001733 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001734 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735}
1736
1737/*
1738 * Encode LOOKUP_ROOT request
1739 */
Al Viro8687b632006-10-19 23:28:48 -07001740static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741{
1742 struct xdr_stream xdr;
1743 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001744 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746
1747 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001748 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001749 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001750 encode_putrootfh(&xdr, &hdr);
1751 encode_getfh(&xdr, &hdr);
1752 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001753 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001754 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755}
1756
1757/*
1758 * Encode REMOVE request
1759 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001760static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761{
1762 struct xdr_stream xdr;
1763 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001764 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
1767 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001768 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001769 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001770 encode_putfh(&xdr, args->fh, &hdr);
1771 encode_remove(&xdr, &args->name, &hdr);
1772 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001773 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001774 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775}
1776
1777/*
1778 * Encode RENAME request
1779 */
Al Viro8687b632006-10-19 23:28:48 -07001780static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781{
1782 struct xdr_stream xdr;
1783 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001784 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786
1787 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001788 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001789 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001790 encode_putfh(&xdr, args->old_dir, &hdr);
1791 encode_savefh(&xdr, &hdr);
1792 encode_putfh(&xdr, args->new_dir, &hdr);
1793 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1794 encode_getfattr(&xdr, args->bitmask, &hdr);
1795 encode_restorefh(&xdr, &hdr);
1796 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001797 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001798 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799}
1800
1801/*
1802 * Encode LINK request
1803 */
Al Viro8687b632006-10-19 23:28:48 -07001804static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805{
1806 struct xdr_stream xdr;
1807 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001808 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
1811 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001812 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001813 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001814 encode_putfh(&xdr, args->fh, &hdr);
1815 encode_savefh(&xdr, &hdr);
1816 encode_putfh(&xdr, args->dir_fh, &hdr);
1817 encode_link(&xdr, args->name, &hdr);
1818 encode_getfattr(&xdr, args->bitmask, &hdr);
1819 encode_restorefh(&xdr, &hdr);
1820 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001821 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001822 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823}
1824
1825/*
1826 * Encode CREATE request
1827 */
Al Viro8687b632006-10-19 23:28:48 -07001828static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829{
1830 struct xdr_stream xdr;
1831 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001832 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
1835 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001836 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001837 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001838 encode_putfh(&xdr, args->dir_fh, &hdr);
1839 encode_savefh(&xdr, &hdr);
1840 encode_create(&xdr, args, &hdr);
1841 encode_getfh(&xdr, &hdr);
1842 encode_getfattr(&xdr, args->bitmask, &hdr);
1843 encode_restorefh(&xdr, &hdr);
1844 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001845 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001846 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847}
1848
1849/*
1850 * Encode SYMLINK request
1851 */
Al Viro8687b632006-10-19 23:28:48 -07001852static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853{
1854 return nfs4_xdr_enc_create(req, p, args);
1855}
1856
1857/*
1858 * Encode GETATTR request
1859 */
Al Viro8687b632006-10-19 23:28:48 -07001860static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861{
1862 struct xdr_stream xdr;
1863 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001864 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866
1867 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001868 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001869 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001870 encode_putfh(&xdr, args->fh, &hdr);
1871 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001872 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001873 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874}
1875
1876/*
1877 * Encode a CLOSE request
1878 */
Al Viro8687b632006-10-19 23:28:48 -07001879static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880{
Andy Adamson05d564f2008-12-23 16:06:15 -05001881 struct xdr_stream xdr;
1882 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001883 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001884 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
Andy Adamson05d564f2008-12-23 16:06:15 -05001886 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001887 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001888 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001889 encode_putfh(&xdr, args->fh, &hdr);
1890 encode_close(&xdr, args, &hdr);
1891 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001892 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001893 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894}
1895
1896/*
1897 * Encode an OPEN request
1898 */
Al Viro8687b632006-10-19 23:28:48 -07001899static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900{
1901 struct xdr_stream xdr;
1902 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001903 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905
1906 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001907 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001908 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001909 encode_putfh(&xdr, args->fh, &hdr);
1910 encode_savefh(&xdr, &hdr);
1911 encode_open(&xdr, args, &hdr);
1912 encode_getfh(&xdr, &hdr);
1913 encode_getfattr(&xdr, args->bitmask, &hdr);
1914 encode_restorefh(&xdr, &hdr);
1915 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001916 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001917 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918}
1919
1920/*
1921 * Encode an OPEN_CONFIRM request
1922 */
Al Viro8687b632006-10-19 23:28:48 -07001923static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924{
1925 struct xdr_stream xdr;
1926 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001927 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929
1930 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001931 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001932 encode_putfh(&xdr, args->fh, &hdr);
1933 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001934 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001935 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936}
1937
1938/*
1939 * Encode an OPEN request with no attributes.
1940 */
Al Viro8687b632006-10-19 23:28:48 -07001941static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942{
1943 struct xdr_stream xdr;
1944 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001945 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947
1948 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001949 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001950 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001951 encode_putfh(&xdr, args->fh, &hdr);
1952 encode_open(&xdr, args, &hdr);
1953 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001954 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001955 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956}
1957
1958/*
1959 * Encode an OPEN_DOWNGRADE request
1960 */
Al Viro8687b632006-10-19 23:28:48 -07001961static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962{
1963 struct xdr_stream xdr;
1964 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001965 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
1968 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001969 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001970 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001971 encode_putfh(&xdr, args->fh, &hdr);
1972 encode_open_downgrade(&xdr, args, &hdr);
1973 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001974 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001975 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976}
1977
1978/*
1979 * Encode a LOCK request
1980 */
Al Viro8687b632006-10-19 23:28:48 -07001981static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982{
1983 struct xdr_stream xdr;
1984 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001985 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987
1988 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001989 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001990 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001991 encode_putfh(&xdr, args->fh, &hdr);
1992 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001993 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001994 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995}
1996
1997/*
1998 * Encode a LOCKT request
1999 */
Al Viro8687b632006-10-19 23:28:48 -07002000static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001{
2002 struct xdr_stream xdr;
2003 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002004 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
2007 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002008 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002009 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002010 encode_putfh(&xdr, args->fh, &hdr);
2011 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002012 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002013 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014}
2015
2016/*
2017 * Encode a LOCKU request
2018 */
Al Viro8687b632006-10-19 23:28:48 -07002019static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020{
2021 struct xdr_stream xdr;
2022 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002023 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025
2026 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002027 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002028 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002029 encode_putfh(&xdr, args->fh, &hdr);
2030 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002031 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002032 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033}
2034
2035/*
2036 * Encode a READLINK request
2037 */
Al Viro8687b632006-10-19 23:28:48 -07002038static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039{
2040 struct xdr_stream xdr;
2041 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002042 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044
2045 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002046 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002047 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002048 encode_putfh(&xdr, args->fh, &hdr);
2049 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002050
Benny Halevy28f56692009-04-01 09:22:09 -04002051 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002052 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002053 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002054 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055}
2056
2057/*
2058 * Encode a READDIR request
2059 */
Al Viro8687b632006-10-19 23:28:48 -07002060static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061{
2062 struct xdr_stream xdr;
2063 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002064 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066
2067 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002068 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002069 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002070 encode_putfh(&xdr, args->fh, &hdr);
2071 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002072
Benny Halevy28f56692009-04-01 09:22:09 -04002073 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002074 args->pgbase, args->count);
2075 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002076 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002077 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002078 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002079 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080}
2081
2082/*
2083 * Encode a READ request
2084 */
Al Viro8687b632006-10-19 23:28:48 -07002085static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 struct xdr_stream xdr;
2088 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002089 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
2092 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002093 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002094 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002095 encode_putfh(&xdr, args->fh, &hdr);
2096 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
Benny Halevy28f56692009-04-01 09:22:09 -04002098 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002100 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002101 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002102 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103}
2104
2105/*
2106 * Encode an SETATTR request
2107 */
Al Viro8687b632006-10-19 23:28:48 -07002108static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109{
Andy Adamson05d564f2008-12-23 16:06:15 -05002110 struct xdr_stream xdr;
2111 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002112 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002113 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114
Andy Adamson05d564f2008-12-23 16:06:15 -05002115 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002116 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002117 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002118 encode_putfh(&xdr, args->fh, &hdr);
2119 encode_setattr(&xdr, args, args->server, &hdr);
2120 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002121 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002122 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123}
2124
2125/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002126 * Encode a GETACL request
2127 */
2128static int
Al Viro8687b632006-10-19 23:28:48 -07002129nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002130 struct nfs_getaclargs *args)
2131{
2132 struct xdr_stream xdr;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002133 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002134 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002135 };
Benny Halevy28f56692009-04-01 09:22:09 -04002136 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002137
2138 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002139 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002140 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002141 encode_putfh(&xdr, args->fh, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002142 replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002143 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2144
Benny Halevy28f56692009-04-01 09:22:09 -04002145 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002146 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002147 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002148 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002149}
2150
2151/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 * Encode a WRITE request
2153 */
Al Viro8687b632006-10-19 23:28:48 -07002154static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155{
2156 struct xdr_stream xdr;
2157 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002158 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
2161 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002162 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002163 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002164 encode_putfh(&xdr, args->fh, &hdr);
2165 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002166 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002167 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002168 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002169 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170}
2171
2172/*
2173 * a COMMIT request
2174 */
Al Viro8687b632006-10-19 23:28:48 -07002175static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176{
2177 struct xdr_stream xdr;
2178 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002179 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
2182 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002183 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002184 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002185 encode_putfh(&xdr, args->fh, &hdr);
2186 encode_commit(&xdr, args, &hdr);
2187 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002188 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002189 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190}
2191
2192/*
2193 * FSINFO request
2194 */
Al Viro8687b632006-10-19 23:28:48 -07002195static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196{
2197 struct xdr_stream xdr;
2198 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002199 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
2202 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002203 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002204 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002205 encode_putfh(&xdr, args->fh, &hdr);
2206 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002207 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002208 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209}
2210
2211/*
2212 * a PATHCONF request
2213 */
Al Viro8687b632006-10-19 23:28:48 -07002214static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 struct xdr_stream xdr;
2217 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002218 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
2221 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002222 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002223 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002224 encode_putfh(&xdr, args->fh, &hdr);
2225 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2226 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002227 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002228 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229}
2230
2231/*
2232 * a STATFS request
2233 */
Al Viro8687b632006-10-19 23:28:48 -07002234static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 struct xdr_stream xdr;
2237 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002238 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
2241 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002242 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002243 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002244 encode_putfh(&xdr, args->fh, &hdr);
2245 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2246 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002247 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002248 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249}
2250
2251/*
2252 * GETATTR_BITMAP request
2253 */
Benny Halevy43652ad2009-04-01 09:21:54 -04002254static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2255 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
2257 struct xdr_stream xdr;
2258 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002259 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
2262 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002263 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002264 encode_sequence(&xdr, &args->seq_args, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04002265 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002266 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2267 FATTR4_WORD0_LINK_SUPPORT|
2268 FATTR4_WORD0_SYMLINK_SUPPORT|
2269 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002270 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002271 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272}
2273
2274/*
2275 * a RENEW request
2276 */
Al Viro8687b632006-10-19 23:28:48 -07002277static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278{
2279 struct xdr_stream xdr;
2280 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002281 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 };
2283
2284 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002285 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002286 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002287 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002288 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289}
2290
2291/*
2292 * a SETCLIENTID request
2293 */
Al Viro8687b632006-10-19 23:28:48 -07002294static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295{
2296 struct xdr_stream xdr;
2297 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002298 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 };
2300
2301 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002302 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002303 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002304 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002305 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306}
2307
2308/*
2309 * a SETCLIENTID_CONFIRM request
2310 */
Al Viro8687b632006-10-19 23:28:48 -07002311static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312{
2313 struct xdr_stream xdr;
2314 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002315 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 };
2317 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318
2319 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002320 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002321 encode_setclientid_confirm(&xdr, clp, &hdr);
2322 encode_putrootfh(&xdr, &hdr);
2323 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002324 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002325 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326}
2327
2328/*
2329 * DELEGRETURN request
2330 */
Al Viro8687b632006-10-19 23:28:48 -07002331static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332{
2333 struct xdr_stream xdr;
2334 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002335 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
2338 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002339 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002340 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002341 encode_putfh(&xdr, args->fhandle, &hdr);
2342 encode_delegreturn(&xdr, args->stateid, &hdr);
2343 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002344 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002345 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346}
2347
2348/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002349 * Encode FS_LOCATIONS request
2350 */
Al Viro8687b632006-10-19 23:28:48 -07002351static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002352{
2353 struct xdr_stream xdr;
2354 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002355 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002356 };
Benny Halevy28f56692009-04-01 09:22:09 -04002357 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002358
2359 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002360 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002361 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002362 encode_putfh(&xdr, args->dir_fh, &hdr);
2363 encode_lookup(&xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002364 replen = hdr.replen; /* get the attribute into args->page */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002365 encode_fs_locations(&xdr, args->bitmask, &hdr);
2366
Benny Halevy28f56692009-04-01 09:22:09 -04002367 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002368 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002369 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002370 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002371}
2372
Benny Halevy99fe60d2009-04-01 09:22:29 -04002373#if defined(CONFIG_NFS_V4_1)
2374/*
2375 * EXCHANGE_ID request
2376 */
2377static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2378 struct nfs41_exchange_id_args *args)
2379{
2380 struct xdr_stream xdr;
2381 struct compound_hdr hdr = {
2382 .minorversion = args->client->cl_minorversion,
2383 };
2384
2385 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2386 encode_compound_hdr(&xdr, req, &hdr);
2387 encode_exchange_id(&xdr, args, &hdr);
2388 encode_nops(&hdr);
2389 return 0;
2390}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002391
2392/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002393 * a CREATE_SESSION request
2394 */
2395static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2396 struct nfs41_create_session_args *args)
2397{
2398 struct xdr_stream xdr;
2399 struct compound_hdr hdr = {
2400 .minorversion = args->client->cl_minorversion,
2401 };
2402
2403 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2404 encode_compound_hdr(&xdr, req, &hdr);
2405 encode_create_session(&xdr, args, &hdr);
2406 encode_nops(&hdr);
2407 return 0;
2408}
2409
2410/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002411 * a DESTROY_SESSION request
2412 */
2413static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2414 struct nfs4_session *session)
2415{
2416 struct xdr_stream xdr;
2417 struct compound_hdr hdr = {
2418 .minorversion = session->clp->cl_minorversion,
2419 };
2420
2421 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2422 encode_compound_hdr(&xdr, req, &hdr);
2423 encode_destroy_session(&xdr, session, &hdr);
2424 encode_nops(&hdr);
2425 return 0;
2426}
2427
2428/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002429 * a SEQUENCE request
2430 */
2431static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p,
2432 struct nfs4_sequence_args *args)
2433{
2434 struct xdr_stream xdr;
2435 struct compound_hdr hdr = {
2436 .minorversion = nfs4_xdr_minorversion(args),
2437 };
2438
2439 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2440 encode_compound_hdr(&xdr, req, &hdr);
2441 encode_sequence(&xdr, args, &hdr);
2442 encode_nops(&hdr);
2443 return 0;
2444}
2445
2446/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002447 * a GET_LEASE_TIME request
2448 */
2449static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2450 struct nfs4_get_lease_time_args *args)
2451{
2452 struct xdr_stream xdr;
2453 struct compound_hdr hdr = {
2454 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2455 };
2456 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2457
2458 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2459 encode_compound_hdr(&xdr, req, &hdr);
2460 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2461 encode_putrootfh(&xdr, &hdr);
2462 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2463 encode_nops(&hdr);
2464 return 0;
2465}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002466#endif /* CONFIG_NFS_V4_1 */
2467
Trond Myklebust683b57b2006-06-09 09:34:22 -04002468/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 * START OF "GENERIC" DECODE ROUTINES.
2470 * These may look a little ugly since they are imported from a "generic"
2471 * set of XDR encode/decode routines which are intended to be shared by
2472 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2473 *
2474 * If the pain of reading these is too great, it should be a straightforward
2475 * task to translate them into Linux-specific versions which are more
2476 * consistent with the style used in NFSv2/v3...
2477 */
2478#define READ32(x) (x) = ntohl(*p++)
2479#define READ64(x) do { \
2480 (x) = (u64)ntohl(*p++) << 32; \
2481 (x) |= ntohl(*p++); \
2482} while (0)
2483#define READTIME(x) do { \
2484 p++; \
2485 (x.tv_sec) = ntohl(*p++); \
2486 (x.tv_nsec) = ntohl(*p++); \
2487} while (0)
2488#define COPYMEM(x,nbytes) do { \
2489 memcpy((x), p, nbytes); \
2490 p += XDR_QUADLEN(nbytes); \
2491} while (0)
2492
2493#define READ_BUF(nbytes) do { \
2494 p = xdr_inline_decode(xdr, nbytes); \
Chuck Levere4cc6ee2007-05-08 18:23:28 -04002495 if (unlikely(!p)) { \
Chuck Leverfe82a182007-09-11 18:01:10 -04002496 dprintk("nfs: %s: prematurely hit end of receive" \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002497 " buffer\n", __func__); \
Chuck Leverfe82a182007-09-11 18:01:10 -04002498 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002499 __func__, xdr->p, nbytes, xdr->end); \
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 return -EIO; \
2501 } \
2502} while (0)
2503
Trond Myklebust683b57b2006-06-09 09:34:22 -04002504static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505{
Al Viro8687b632006-10-19 23:28:48 -07002506 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507
2508 READ_BUF(4);
2509 READ32(*len);
2510 READ_BUF(*len);
2511 *string = (char *)p;
2512 return 0;
2513}
2514
2515static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2516{
Al Viro8687b632006-10-19 23:28:48 -07002517 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
2519 READ_BUF(8);
2520 READ32(hdr->status);
2521 READ32(hdr->taglen);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002522
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 READ_BUF(hdr->taglen + 4);
2524 hdr->tag = (char *)p;
2525 p += XDR_QUADLEN(hdr->taglen);
2526 READ32(hdr->nops);
Benny Halevyaadf6152008-12-23 16:06:13 -05002527 if (unlikely(hdr->nops < 1))
2528 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 return 0;
2530}
2531
2532static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2533{
Al Viro8687b632006-10-19 23:28:48 -07002534 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 uint32_t opnum;
2536 int32_t nfserr;
2537
2538 READ_BUF(8);
2539 READ32(opnum);
2540 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002541 dprintk("nfs: Server returned operation"
2542 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 opnum, expected);
2544 return -EIO;
2545 }
2546 READ32(nfserr);
2547 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002548 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 return 0;
2550}
2551
2552/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002553static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554{
Al Viro8687b632006-10-19 23:28:48 -07002555 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002556 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 char *str;
2558
2559 READ_BUF(12);
2560 return decode_opaque_inline(xdr, &strlen, &str);
2561}
2562
2563static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2564{
Al Viro8687b632006-10-19 23:28:48 -07002565 uint32_t bmlen;
2566 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567
2568 READ_BUF(4);
2569 READ32(bmlen);
2570
2571 bitmap[0] = bitmap[1] = 0;
2572 READ_BUF((bmlen << 2));
2573 if (bmlen > 0) {
2574 READ32(bitmap[0]);
2575 if (bmlen > 1)
2576 READ32(bitmap[1]);
2577 }
2578 return 0;
2579}
2580
Al Viro8687b632006-10-19 23:28:48 -07002581static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582{
Al Viro8687b632006-10-19 23:28:48 -07002583 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584
2585 READ_BUF(4);
2586 READ32(*attrlen);
2587 *savep = xdr->p;
2588 return 0;
2589}
2590
2591static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2592{
2593 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2594 decode_attr_bitmap(xdr, bitmask);
2595 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2596 } else
2597 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002598 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 return 0;
2600}
2601
2602static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2603{
Al Viro8687b632006-10-19 23:28:48 -07002604 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002605 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606
2607 *type = 0;
2608 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2609 return -EIO;
2610 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2611 READ_BUF(4);
2612 READ32(*type);
2613 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002614 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 return -EIO;
2616 }
2617 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002618 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002620 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002621 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622}
2623
2624static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2625{
Al Viro8687b632006-10-19 23:28:48 -07002626 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002627 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628
2629 *change = 0;
2630 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2631 return -EIO;
2632 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2633 READ_BUF(8);
2634 READ64(*change);
2635 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002636 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002638 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002640 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641}
2642
2643static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2644{
Al Viro8687b632006-10-19 23:28:48 -07002645 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002646 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
2648 *size = 0;
2649 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2650 return -EIO;
2651 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2652 READ_BUF(8);
2653 READ64(*size);
2654 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002655 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002657 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002658 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659}
2660
2661static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2662{
Al Viro8687b632006-10-19 23:28:48 -07002663 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
2665 *res = 0;
2666 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2667 return -EIO;
2668 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2669 READ_BUF(4);
2670 READ32(*res);
2671 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2672 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002673 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 return 0;
2675}
2676
2677static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2678{
Al Viro8687b632006-10-19 23:28:48 -07002679 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680
2681 *res = 0;
2682 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2683 return -EIO;
2684 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2685 READ_BUF(4);
2686 READ32(*res);
2687 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2688 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002689 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 return 0;
2691}
2692
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002693static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694{
Al Viro8687b632006-10-19 23:28:48 -07002695 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002696 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697
2698 fsid->major = 0;
2699 fsid->minor = 0;
2700 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2701 return -EIO;
2702 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2703 READ_BUF(16);
2704 READ64(fsid->major);
2705 READ64(fsid->minor);
2706 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002707 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002709 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 (unsigned long long)fsid->major,
2711 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002712 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713}
2714
2715static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2716{
Al Viro8687b632006-10-19 23:28:48 -07002717 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718
2719 *res = 60;
2720 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2721 return -EIO;
2722 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2723 READ_BUF(4);
2724 READ32(*res);
2725 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2726 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002727 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 return 0;
2729}
2730
2731static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2732{
Al Viro8687b632006-10-19 23:28:48 -07002733 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734
2735 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2736 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2737 return -EIO;
2738 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2739 READ_BUF(4);
2740 READ32(*res);
2741 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2742 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002743 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 return 0;
2745}
2746
2747static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2748{
Al Viro8687b632006-10-19 23:28:48 -07002749 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002750 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751
2752 *fileid = 0;
2753 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2754 return -EIO;
2755 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2756 READ_BUF(8);
2757 READ64(*fileid);
2758 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002759 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002761 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002762 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763}
2764
Manoj Naik99baf622006-06-09 09:34:24 -04002765static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2766{
Al Viro8687b632006-10-19 23:28:48 -07002767 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002768 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002769
2770 *fileid = 0;
2771 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2772 return -EIO;
2773 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2774 READ_BUF(8);
2775 READ64(*fileid);
2776 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002777 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002778 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002779 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002780 return ret;
Manoj Naik99baf622006-06-09 09:34:24 -04002781}
2782
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2784{
Al Viro8687b632006-10-19 23:28:48 -07002785 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 int status = 0;
2787
2788 *res = 0;
2789 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2790 return -EIO;
2791 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2792 READ_BUF(8);
2793 READ64(*res);
2794 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2795 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002796 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 return status;
2798}
2799
2800static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2801{
Al Viro8687b632006-10-19 23:28:48 -07002802 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 int status = 0;
2804
2805 *res = 0;
2806 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2807 return -EIO;
2808 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2809 READ_BUF(8);
2810 READ64(*res);
2811 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2812 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002813 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 return status;
2815}
2816
2817static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2818{
Al Viro8687b632006-10-19 23:28:48 -07002819 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 int status = 0;
2821
2822 *res = 0;
2823 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2824 return -EIO;
2825 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2826 READ_BUF(8);
2827 READ64(*res);
2828 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2829 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002830 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 return status;
2832}
2833
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002834static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2835{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002836 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002837 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002838 int status = 0;
2839
2840 READ_BUF(4);
2841 READ32(n);
Andy Adamson33a43f22006-06-09 09:34:30 -04002842 if (n == 0)
2843 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002844 dprintk("path ");
2845 path->ncomponents = 0;
2846 while (path->ncomponents < n) {
2847 struct nfs4_string *component = &path->components[path->ncomponents];
2848 status = decode_opaque_inline(xdr, &component->len, &component->data);
2849 if (unlikely(status != 0))
2850 goto out_eio;
2851 if (path->ncomponents != n)
2852 dprintk("/");
2853 dprintk("%s", component->data);
2854 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2855 path->ncomponents++;
2856 else {
2857 dprintk("cannot parse %d components in path\n", n);
2858 goto out_eio;
2859 }
2860 }
2861out:
2862 dprintk("\n");
2863 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002864root_path:
2865/* a root pathname is sent as a zero component4 */
2866 path->ncomponents = 1;
2867 path->components[0].len=0;
2868 path->components[0].data=NULL;
2869 dprintk("path /\n");
2870 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002871out_eio:
2872 dprintk(" status %d", status);
2873 status = -EIO;
2874 goto out;
2875}
2876
2877static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002878{
2879 int n;
Al Viro8687b632006-10-19 23:28:48 -07002880 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002881 int status = -EIO;
2882
2883 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2884 goto out;
2885 status = 0;
2886 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2887 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002888 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002889 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002890 if (unlikely(status != 0))
2891 goto out;
2892 READ_BUF(4);
2893 READ32(n);
2894 if (n <= 0)
2895 goto out_eio;
2896 res->nlocations = 0;
2897 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002898 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002899 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04002900
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002901 READ_BUF(4);
2902 READ32(m);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002903
2904 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002905 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002906 while (loc->nservers < m) {
2907 struct nfs4_string *server = &loc->servers[loc->nservers];
2908 status = decode_opaque_inline(xdr, &server->len, &server->data);
2909 if (unlikely(status != 0))
2910 goto out_eio;
2911 dprintk("%s ", server->data);
2912 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2913 loc->nservers++;
2914 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002915 unsigned int i;
2916 dprintk("%s: using first %u of %u servers "
2917 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002918 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04002919 NFS4_FS_LOCATION_MAXSERVERS,
2920 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002921 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002922 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002923 char *data;
2924 status = decode_opaque_inline(xdr, &len, &data);
2925 if (unlikely(status != 0))
2926 goto out_eio;
2927 }
2928 }
2929 }
2930 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002931 if (unlikely(status != 0))
2932 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002933 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002934 res->nlocations++;
2935 }
Trond Myklebust409924e2009-03-11 14:10:27 -04002936 if (res->nlocations != 0)
2937 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002938out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002939 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002940 return status;
2941out_eio:
2942 status = -EIO;
2943 goto out;
2944}
2945
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2947{
Al Viro8687b632006-10-19 23:28:48 -07002948 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 int status = 0;
2950
2951 *res = 0;
2952 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2953 return -EIO;
2954 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2955 READ_BUF(8);
2956 READ64(*res);
2957 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2958 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002959 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 return status;
2961}
2962
2963static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2964{
Al Viro8687b632006-10-19 23:28:48 -07002965 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 int status = 0;
2967
2968 *maxlink = 1;
2969 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2970 return -EIO;
2971 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2972 READ_BUF(4);
2973 READ32(*maxlink);
2974 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2975 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002976 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 return status;
2978}
2979
2980static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2981{
Al Viro8687b632006-10-19 23:28:48 -07002982 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 int status = 0;
2984
2985 *maxname = 1024;
2986 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2987 return -EIO;
2988 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2989 READ_BUF(4);
2990 READ32(*maxname);
2991 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2992 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002993 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 return status;
2995}
2996
2997static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2998{
Al Viro8687b632006-10-19 23:28:48 -07002999 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 int status = 0;
3001
3002 *res = 1024;
3003 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3004 return -EIO;
3005 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3006 uint64_t maxread;
3007 READ_BUF(8);
3008 READ64(maxread);
3009 if (maxread > 0x7FFFFFFF)
3010 maxread = 0x7FFFFFFF;
3011 *res = (uint32_t)maxread;
3012 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3013 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003014 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 return status;
3016}
3017
3018static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3019{
Al Viro8687b632006-10-19 23:28:48 -07003020 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 int status = 0;
3022
3023 *res = 1024;
3024 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3025 return -EIO;
3026 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3027 uint64_t maxwrite;
3028 READ_BUF(8);
3029 READ64(maxwrite);
3030 if (maxwrite > 0x7FFFFFFF)
3031 maxwrite = 0x7FFFFFFF;
3032 *res = (uint32_t)maxwrite;
3033 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3034 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003035 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 return status;
3037}
3038
Trond Myklebustbca79472009-03-11 14:10:26 -04003039static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040{
Trond Myklebustbca79472009-03-11 14:10:26 -04003041 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003042 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003043 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044
3045 *mode = 0;
3046 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3047 return -EIO;
3048 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3049 READ_BUF(4);
Trond Myklebustbca79472009-03-11 14:10:26 -04003050 READ32(tmp);
3051 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003053 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003055 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003056 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057}
3058
3059static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3060{
Al Viro8687b632006-10-19 23:28:48 -07003061 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003062 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063
3064 *nlink = 1;
3065 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3066 return -EIO;
3067 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3068 READ_BUF(4);
3069 READ32(*nlink);
3070 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003071 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003073 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003074 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075}
3076
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003077static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078{
Al Viro8687b632006-10-19 23:28:48 -07003079 uint32_t len;
3080 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003081 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082
3083 *uid = -2;
3084 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3085 return -EIO;
3086 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3087 READ_BUF(4);
3088 READ32(len);
3089 READ_BUF(len);
3090 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003091 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3092 ret = NFS_ATTR_FATTR_OWNER;
3093 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003095 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003097 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003098 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3100 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003101 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003102 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103}
3104
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003105static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106{
Al Viro8687b632006-10-19 23:28:48 -07003107 uint32_t len;
3108 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003109 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110
3111 *gid = -2;
3112 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3113 return -EIO;
3114 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3115 READ_BUF(4);
3116 READ32(len);
3117 READ_BUF(len);
3118 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003119 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3120 ret = NFS_ATTR_FATTR_GROUP;
3121 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003123 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003125 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003126 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3128 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003129 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003130 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131}
3132
3133static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3134{
Al Viro8687b632006-10-19 23:28:48 -07003135 uint32_t major = 0, minor = 0;
3136 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003137 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138
3139 *rdev = MKDEV(0,0);
3140 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3141 return -EIO;
3142 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3143 dev_t tmp;
3144
3145 READ_BUF(8);
3146 READ32(major);
3147 READ32(minor);
3148 tmp = MKDEV(major, minor);
3149 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3150 *rdev = tmp;
3151 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003152 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003154 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003155 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156}
3157
3158static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3159{
Al Viro8687b632006-10-19 23:28:48 -07003160 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 int status = 0;
3162
3163 *res = 0;
3164 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3165 return -EIO;
3166 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3167 READ_BUF(8);
3168 READ64(*res);
3169 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3170 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003171 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 return status;
3173}
3174
3175static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3176{
Al Viro8687b632006-10-19 23:28:48 -07003177 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 int status = 0;
3179
3180 *res = 0;
3181 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3182 return -EIO;
3183 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3184 READ_BUF(8);
3185 READ64(*res);
3186 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3187 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003188 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 return status;
3190}
3191
3192static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3193{
Al Viro8687b632006-10-19 23:28:48 -07003194 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 int status = 0;
3196
3197 *res = 0;
3198 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3199 return -EIO;
3200 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3201 READ_BUF(8);
3202 READ64(*res);
3203 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3204 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003205 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 return status;
3207}
3208
3209static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3210{
Al Viro8687b632006-10-19 23:28:48 -07003211 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003212 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213
3214 *used = 0;
3215 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3216 return -EIO;
3217 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3218 READ_BUF(8);
3219 READ64(*used);
3220 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003221 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003223 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003225 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226}
3227
3228static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3229{
Al Viro8687b632006-10-19 23:28:48 -07003230 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 uint64_t sec;
3232 uint32_t nsec;
3233
3234 READ_BUF(12);
3235 READ64(sec);
3236 READ32(nsec);
3237 time->tv_sec = (time_t)sec;
3238 time->tv_nsec = (long)nsec;
3239 return 0;
3240}
3241
3242static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3243{
3244 int status = 0;
3245
3246 time->tv_sec = 0;
3247 time->tv_nsec = 0;
3248 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3249 return -EIO;
3250 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3251 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003252 if (status == 0)
3253 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3255 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003256 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 return status;
3258}
3259
3260static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3261{
3262 int status = 0;
3263
3264 time->tv_sec = 0;
3265 time->tv_nsec = 0;
3266 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3267 return -EIO;
3268 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3269 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003270 if (status == 0)
3271 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3273 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003274 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 return status;
3276}
3277
3278static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3279{
3280 int status = 0;
3281
3282 time->tv_sec = 0;
3283 time->tv_nsec = 0;
3284 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3285 return -EIO;
3286 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3287 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003288 if (status == 0)
3289 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3291 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003292 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 return status;
3294}
3295
Al Viro8687b632006-10-19 23:28:48 -07003296static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297{
3298 unsigned int attrwords = XDR_QUADLEN(attrlen);
3299 unsigned int nwords = xdr->p - savep;
3300
3301 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003302 dprintk("%s: server returned incorrect attribute length: "
3303 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003304 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 attrwords << 2,
3306 (attrwords < nwords) ? '<' : '>',
3307 nwords << 2);
3308 return -EIO;
3309 }
3310 return 0;
3311}
3312
3313static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3314{
Al Viro8687b632006-10-19 23:28:48 -07003315 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316
3317 READ_BUF(20);
3318 READ32(cinfo->atomic);
3319 READ64(cinfo->before);
3320 READ64(cinfo->after);
3321 return 0;
3322}
3323
3324static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3325{
Al Viro8687b632006-10-19 23:28:48 -07003326 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 uint32_t supp, acc;
3328 int status;
3329
3330 status = decode_op_hdr(xdr, OP_ACCESS);
3331 if (status)
3332 return status;
3333 READ_BUF(8);
3334 READ32(supp);
3335 READ32(acc);
3336 access->supported = supp;
3337 access->access = acc;
3338 return 0;
3339}
3340
3341static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3342{
Al Viro8687b632006-10-19 23:28:48 -07003343 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 int status;
3345
3346 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003347 if (status != -EIO)
3348 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 if (status)
3350 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003351 READ_BUF(NFS4_STATEID_SIZE);
3352 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 return 0;
3354}
3355
3356static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3357{
Al Viro8687b632006-10-19 23:28:48 -07003358 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 int status;
3360
3361 status = decode_op_hdr(xdr, OP_COMMIT);
3362 if (status)
3363 return status;
3364 READ_BUF(8);
3365 COPYMEM(res->verf->verifier, 8);
3366 return 0;
3367}
3368
3369static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3370{
Al Viro8687b632006-10-19 23:28:48 -07003371 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 uint32_t bmlen;
3373 int status;
3374
3375 status = decode_op_hdr(xdr, OP_CREATE);
3376 if (status)
3377 return status;
3378 if ((status = decode_change_info(xdr, cinfo)))
3379 return status;
3380 READ_BUF(4);
3381 READ32(bmlen);
3382 READ_BUF(bmlen << 2);
3383 return 0;
3384}
3385
3386static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3387{
Al Viro8687b632006-10-19 23:28:48 -07003388 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003389 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 int status;
3391
3392 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3393 goto xdr_error;
3394 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3395 goto xdr_error;
3396 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3397 goto xdr_error;
3398 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3399 goto xdr_error;
3400 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3401 goto xdr_error;
3402 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3403 goto xdr_error;
3404 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3405 goto xdr_error;
3406 status = verify_attr_len(xdr, savep, attrlen);
3407xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003408 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 return status;
3410}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003411
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3413{
Al Viro8687b632006-10-19 23:28:48 -07003414 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003415 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003417
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3419 goto xdr_error;
3420 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3421 goto xdr_error;
3422 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3423 goto xdr_error;
3424
3425 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3426 goto xdr_error;
3427 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3428 goto xdr_error;
3429 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3430 goto xdr_error;
3431 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3432 goto xdr_error;
3433 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3434 goto xdr_error;
3435 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3436 goto xdr_error;
3437
3438 status = verify_attr_len(xdr, savep, attrlen);
3439xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003440 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 return status;
3442}
3443
3444static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3445{
Al Viro8687b632006-10-19 23:28:48 -07003446 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003447 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003449
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3451 goto xdr_error;
3452 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3453 goto xdr_error;
3454 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3455 goto xdr_error;
3456
3457 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3458 goto xdr_error;
3459 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3460 goto xdr_error;
3461
3462 status = verify_attr_len(xdr, savep, attrlen);
3463xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003464 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465 return status;
3466}
3467
3468static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3469{
Al Viro8687b632006-10-19 23:28:48 -07003470 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471 uint32_t attrlen,
3472 bitmap[2] = {0},
3473 type;
Trond Myklebustbca79472009-03-11 14:10:26 -04003474 int status;
3475 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003476 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003478 status = decode_op_hdr(xdr, OP_GETATTR);
3479 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 goto xdr_error;
3481
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003482 status = decode_attr_bitmap(xdr, bitmap);
3483 if (status < 0)
3484 goto xdr_error;
3485
3486 status = decode_attr_length(xdr, &attrlen, &savep);
3487 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 goto xdr_error;
3489
3490
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003491 status = decode_attr_type(xdr, bitmap, &type);
3492 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003494 fattr->mode = 0;
3495 if (status != 0) {
3496 fattr->mode |= nfs_type2fmt[type];
3497 fattr->valid |= status;
3498 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003500 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3501 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003503 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003504
3505 status = decode_attr_size(xdr, bitmap, &fattr->size);
3506 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003508 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003509
3510 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3511 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003513 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003514
3515 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3516 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003518 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003519
3520 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003521 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003522 fattr));
3523 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003524 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003525 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003526
3527 status = decode_attr_mode(xdr, bitmap, &fmode);
3528 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003530 if (status != 0) {
3531 fattr->mode |= fmode;
3532 fattr->valid |= status;
3533 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003534
3535 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3536 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003538 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003539
3540 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
3541 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003543 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003544
3545 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
3546 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003548 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003549
3550 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3551 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003553 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003554
3555 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3556 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003558 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003559
3560 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3561 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003563 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003564
3565 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3566 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003568 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003569
3570 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3571 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003573 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003574
3575 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3576 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003577 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003578 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003579 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003580 fattr->valid |= status;
3581 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003582
3583 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003585 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586 return status;
3587}
3588
3589
3590static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3591{
Al Viro8687b632006-10-19 23:28:48 -07003592 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 uint32_t attrlen, bitmap[2];
3594 int status;
3595
3596 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3597 goto xdr_error;
3598 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3599 goto xdr_error;
3600 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3601 goto xdr_error;
3602
3603 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3604
3605 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3606 goto xdr_error;
3607 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3608 goto xdr_error;
3609 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3610 goto xdr_error;
3611 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3612 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3613 goto xdr_error;
3614 fsinfo->wtpref = fsinfo->wtmax;
3615
3616 status = verify_attr_len(xdr, savep, attrlen);
3617xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003618 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619 return status;
3620}
3621
3622static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3623{
Al Viro8687b632006-10-19 23:28:48 -07003624 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 uint32_t len;
3626 int status;
3627
Trond Myklebust99367812007-07-17 21:52:41 -04003628 /* Zero handle first to allow comparisons */
3629 memset(fh, 0, sizeof(*fh));
3630
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 status = decode_op_hdr(xdr, OP_GETFH);
3632 if (status)
3633 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634
3635 READ_BUF(4);
3636 READ32(len);
3637 if (len > NFS4_FHSIZE)
3638 return -EIO;
3639 fh->size = len;
3640 READ_BUF(len);
3641 COPYMEM(fh->data, len);
3642 return 0;
3643}
3644
3645static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3646{
3647 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003648
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649 status = decode_op_hdr(xdr, OP_LINK);
3650 if (status)
3651 return status;
3652 return decode_change_info(xdr, cinfo);
3653}
3654
3655/*
3656 * We create the owner, so we know a proper owner.id length is 4.
3657 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003658static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003660 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003661 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003662 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663
3664 READ_BUF(32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003665 READ64(offset);
3666 READ64(length);
3667 READ32(type);
3668 if (fl != NULL) {
3669 fl->fl_start = (loff_t)offset;
3670 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3671 if (length == ~(uint64_t)0)
3672 fl->fl_end = OFFSET_MAX;
3673 fl->fl_type = F_WRLCK;
3674 if (type & 1)
3675 fl->fl_type = F_RDLCK;
3676 fl->fl_pid = 0;
3677 }
3678 READ64(clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679 READ32(namelen);
3680 READ_BUF(namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 return -NFS4ERR_DENIED;
3682}
3683
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003684static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685{
Al Viro8687b632006-10-19 23:28:48 -07003686 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687 int status;
3688
3689 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003690 if (status == -EIO)
3691 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003693 READ_BUF(NFS4_STATEID_SIZE);
3694 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003696 status = decode_lock_denied(xdr, NULL);
3697 if (res->open_seqid != NULL)
3698 nfs_increment_open_seqid(status, res->open_seqid);
3699 nfs_increment_lock_seqid(status, res->lock_seqid);
3700out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 return status;
3702}
3703
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003704static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705{
3706 int status;
3707 status = decode_op_hdr(xdr, OP_LOCKT);
3708 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003709 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 return status;
3711}
3712
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003713static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714{
Al Viro8687b632006-10-19 23:28:48 -07003715 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 int status;
3717
3718 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003719 if (status != -EIO)
3720 nfs_increment_lock_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003722 READ_BUF(NFS4_STATEID_SIZE);
3723 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 }
3725 return status;
3726}
3727
3728static int decode_lookup(struct xdr_stream *xdr)
3729{
3730 return decode_op_hdr(xdr, OP_LOOKUP);
3731}
3732
3733/* This is too sick! */
3734static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3735{
Andy Adamson05d564f2008-12-23 16:06:15 -05003736 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 uint32_t limit_type, nblocks, blocksize;
3738
3739 READ_BUF(12);
3740 READ32(limit_type);
3741 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003742 case 1:
3743 READ64(*maxsize);
3744 break;
3745 case 2:
3746 READ32(nblocks);
3747 READ32(blocksize);
3748 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 }
3750 return 0;
3751}
3752
3753static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3754{
Andy Adamson05d564f2008-12-23 16:06:15 -05003755 __be32 *p;
3756 uint32_t delegation_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757
3758 READ_BUF(4);
3759 READ32(delegation_type);
3760 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3761 res->delegation_type = 0;
3762 return 0;
3763 }
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003764 READ_BUF(NFS4_STATEID_SIZE+4);
3765 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 READ32(res->do_recall);
Andy Adamson05d564f2008-12-23 16:06:15 -05003767
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003769 case NFS4_OPEN_DELEGATE_READ:
3770 res->delegation_type = FMODE_READ;
3771 break;
3772 case NFS4_OPEN_DELEGATE_WRITE:
3773 res->delegation_type = FMODE_WRITE|FMODE_READ;
3774 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 return -EIO;
3776 }
David Howells7539bba2006-08-22 20:06:09 -04003777 return decode_ace(xdr, NULL, res->server->nfs_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778}
3779
3780static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3781{
Andy Adamson05d564f2008-12-23 16:06:15 -05003782 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003783 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05003784 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785
Andy Adamson05d564f2008-12-23 16:06:15 -05003786 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003787 if (status != -EIO)
3788 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003789 if (status)
3790 return status;
3791 READ_BUF(NFS4_STATEID_SIZE);
3792 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793
Andy Adamson05d564f2008-12-23 16:06:15 -05003794 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795
Andy Adamson05d564f2008-12-23 16:06:15 -05003796 READ_BUF(8);
3797 READ32(res->rflags);
3798 READ32(bmlen);
3799 if (bmlen > 10)
3800 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801
Andy Adamson05d564f2008-12-23 16:06:15 -05003802 READ_BUF(bmlen << 2);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003803 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3804 for (i = 0; i < savewords; ++i)
3805 READ32(res->attrset[i]);
3806 for (; i < NFS4_BITMAP_SIZE; i++)
3807 res->attrset[i] = 0;
3808
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 return decode_delegation(xdr, res);
3810xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003811 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812 return -EIO;
3813}
3814
3815static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3816{
Andy Adamson05d564f2008-12-23 16:06:15 -05003817 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818 int status;
3819
Andy Adamson05d564f2008-12-23 16:06:15 -05003820 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003821 if (status != -EIO)
3822 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003823 if (status)
3824 return status;
3825 READ_BUF(NFS4_STATEID_SIZE);
3826 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3827 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828}
3829
3830static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3831{
Al Viro8687b632006-10-19 23:28:48 -07003832 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 int status;
3834
3835 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003836 if (status != -EIO)
3837 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 if (status)
3839 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003840 READ_BUF(NFS4_STATEID_SIZE);
3841 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842 return 0;
3843}
3844
3845static int decode_putfh(struct xdr_stream *xdr)
3846{
3847 return decode_op_hdr(xdr, OP_PUTFH);
3848}
3849
3850static int decode_putrootfh(struct xdr_stream *xdr)
3851{
3852 return decode_op_hdr(xdr, OP_PUTROOTFH);
3853}
3854
3855static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3856{
3857 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07003858 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 uint32_t count, eof, recvd, hdrlen;
3860 int status;
3861
3862 status = decode_op_hdr(xdr, OP_READ);
3863 if (status)
3864 return status;
3865 READ_BUF(8);
3866 READ32(eof);
3867 READ32(count);
3868 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3869 recvd = req->rq_rcv_buf.len - hdrlen;
3870 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003871 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 "count %u > recvd %u\n", count, recvd);
3873 count = recvd;
3874 eof = 0;
3875 }
3876 xdr_read_pages(xdr, count);
3877 res->eof = eof;
3878 res->count = count;
3879 return 0;
3880}
3881
3882static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3883{
3884 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3885 struct page *page = *rcvbuf->pages;
3886 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003887 size_t hdrlen;
3888 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07003889 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003890 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04003891 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892
3893 status = decode_op_hdr(xdr, OP_READDIR);
3894 if (status)
3895 return status;
3896 READ_BUF(8);
3897 COPYMEM(readdir->verifier.data, 8);
Fred Isaman44109242008-04-02 15:21:15 +03003898 dprintk("%s: verifier = %08x:%08x\n",
3899 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00003900 ((u32 *)readdir->verifier.data)[0],
3901 ((u32 *)readdir->verifier.data)[1]);
3902
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903
3904 hdrlen = (char *) p - (char *) iov->iov_base;
3905 recvd = rcvbuf->len - hdrlen;
3906 if (pglen > recvd)
3907 pglen = recvd;
3908 xdr_read_pages(xdr, pglen);
3909
3910 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07003911 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04003912 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003914
3915 /* Make sure the packet actually has a value_follows and EOF entry */
3916 if ((entry + 1) > end)
3917 goto short_pkt;
3918
3919 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003920 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04003921 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003923 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924 p += 2; /* cookie */
3925 len = ntohl(*p++); /* filename length */
3926 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003927 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3928 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 goto err_unmap;
3930 }
David Howellse8896492006-08-24 15:44:19 -04003931 xlen = XDR_QUADLEN(len);
3932 if (end - p < xlen + 1)
3933 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003934 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04003935 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04003937 if (end - p < len + 1)
3938 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04003941 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04003943 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 entry = p;
3945 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003946 /*
3947 * Apparently some server sends responses that are a valid size, but
3948 * contain no entries, and have value_follows==0 and EOF==0. For
3949 * those, just set the EOF marker.
3950 */
3951 if (!nr && entry[1] == 0) {
3952 dprintk("NFS: readdir reply truncated!\n");
3953 entry[1] = 1;
3954 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05003955out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956 kunmap_atomic(kaddr, KM_USER0);
3957 return 0;
3958short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003959 /*
3960 * When we get a short packet there are 2 possibilities. We can
3961 * return an error, or fix up the response to look like a valid
3962 * response and return what we have so far. If there are no
3963 * entries and the packet was short, then return -EIO. If there
3964 * are valid entries in the response, return them and pretend that
3965 * the call was successful, but incomplete. The caller can retry the
3966 * readdir starting at the last cookie.
3967 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07003968 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003970 if (nr)
3971 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972err_unmap:
3973 kunmap_atomic(kaddr, KM_USER0);
3974 return -errno_NFSERR_IO;
3975}
3976
3977static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3978{
3979 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3980 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003981 size_t hdrlen;
3982 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07003983 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 char *kaddr;
3985 int status;
3986
3987 status = decode_op_hdr(xdr, OP_READLINK);
3988 if (status)
3989 return status;
3990
3991 /* Convert length of symlink */
3992 READ_BUF(4);
3993 READ32(len);
3994 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003995 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 return -ENAMETOOLONG;
3997 }
3998 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3999 recvd = req->rq_rcv_buf.len - hdrlen;
4000 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004001 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 "count %u > recvd %u\n", len, recvd);
4003 return -EIO;
4004 }
4005 xdr_read_pages(xdr, len);
4006 /*
4007 * The XDR encode routine has set things up so that
4008 * the link text will be copied directly into the
4009 * buffer. We just have to do overflow-checking,
4010 * and and null-terminate the text (the VFS expects
4011 * null-termination).
4012 */
4013 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
4014 kaddr[len+rcvbuf->page_base] = '\0';
4015 kunmap_atomic(kaddr, KM_USER0);
4016 return 0;
4017}
4018
4019static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4020{
4021 int status;
4022
4023 status = decode_op_hdr(xdr, OP_REMOVE);
4024 if (status)
4025 goto out;
4026 status = decode_change_info(xdr, cinfo);
4027out:
4028 return status;
4029}
4030
4031static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4032 struct nfs4_change_info *new_cinfo)
4033{
4034 int status;
4035
4036 status = decode_op_hdr(xdr, OP_RENAME);
4037 if (status)
4038 goto out;
4039 if ((status = decode_change_info(xdr, old_cinfo)))
4040 goto out;
4041 status = decode_change_info(xdr, new_cinfo);
4042out:
4043 return status;
4044}
4045
4046static int decode_renew(struct xdr_stream *xdr)
4047{
4048 return decode_op_hdr(xdr, OP_RENEW);
4049}
4050
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004051static int
4052decode_restorefh(struct xdr_stream *xdr)
4053{
4054 return decode_op_hdr(xdr, OP_RESTOREFH);
4055}
4056
J. Bruce Fields029d1052005-06-22 17:16:22 +00004057static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4058 size_t *acl_len)
4059{
Al Viro8687b632006-10-19 23:28:48 -07004060 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004061 uint32_t attrlen,
4062 bitmap[2] = {0};
4063 struct kvec *iov = req->rq_rcv_buf.head;
4064 int status;
4065
4066 *acl_len = 0;
4067 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4068 goto out;
4069 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4070 goto out;
4071 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4072 goto out;
4073
4074 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4075 return -EIO;
4076 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004077 size_t hdrlen;
4078 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004079
4080 /* We ignore &savep and don't do consistency checks on
4081 * the attr length. Let userspace figure it out.... */
4082 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4083 recvd = req->rq_rcv_buf.len - hdrlen;
4084 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004085 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004086 " acl reply: attrlen %u > recvd %u\n",
4087 attrlen, recvd);
4088 return -EINVAL;
4089 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004090 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004091 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004092 } else
4093 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004094
4095out:
4096 return status;
4097}
4098
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099static int
4100decode_savefh(struct xdr_stream *xdr)
4101{
4102 return decode_op_hdr(xdr, OP_SAVEFH);
4103}
4104
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004105static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106{
Al Viro8687b632006-10-19 23:28:48 -07004107 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004108 uint32_t bmlen;
4109 int status;
4110
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111 status = decode_op_hdr(xdr, OP_SETATTR);
4112 if (status)
4113 return status;
4114 READ_BUF(4);
4115 READ32(bmlen);
4116 READ_BUF(bmlen << 2);
4117 return 0;
4118}
4119
David Howellsadfa6f92006-08-22 20:06:08 -04004120static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121{
Al Viro8687b632006-10-19 23:28:48 -07004122 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123 uint32_t opnum;
4124 int32_t nfserr;
4125
4126 READ_BUF(8);
4127 READ32(opnum);
4128 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004129 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004130 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 return -EIO;
4132 }
4133 READ32(nfserr);
4134 if (nfserr == NFS_OK) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04004135 READ_BUF(8 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 READ64(clp->cl_clientid);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04004137 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 } else if (nfserr == NFSERR_CLID_INUSE) {
4139 uint32_t len;
4140
4141 /* skip netid string */
4142 READ_BUF(4);
4143 READ32(len);
4144 READ_BUF(len);
4145
4146 /* skip uaddr string */
4147 READ_BUF(4);
4148 READ32(len);
4149 READ_BUF(len);
4150 return -NFSERR_CLID_INUSE;
4151 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004152 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153
4154 return 0;
4155}
4156
4157static int decode_setclientid_confirm(struct xdr_stream *xdr)
4158{
4159 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4160}
4161
4162static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4163{
Al Viro8687b632006-10-19 23:28:48 -07004164 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004165 int status;
4166
4167 status = decode_op_hdr(xdr, OP_WRITE);
4168 if (status)
4169 return status;
4170
4171 READ_BUF(16);
4172 READ32(res->count);
4173 READ32(res->verf->committed);
4174 COPYMEM(res->verf->verifier, 8);
4175 return 0;
4176}
4177
4178static int decode_delegreturn(struct xdr_stream *xdr)
4179{
4180 return decode_op_hdr(xdr, OP_DELEGRETURN);
4181}
4182
Benny Halevy99fe60d2009-04-01 09:22:29 -04004183#if defined(CONFIG_NFS_V4_1)
4184static int decode_exchange_id(struct xdr_stream *xdr,
4185 struct nfs41_exchange_id_res *res)
4186{
4187 __be32 *p;
4188 uint32_t dummy;
4189 int status;
4190 struct nfs_client *clp = res->client;
4191
4192 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4193 if (status)
4194 return status;
4195
4196 READ_BUF(8);
4197 READ64(clp->cl_ex_clid);
4198 READ_BUF(12);
4199 READ32(clp->cl_seqid);
4200 READ32(clp->cl_exchange_flags);
4201
4202 /* We ask for SP4_NONE */
4203 READ32(dummy);
4204 if (dummy != SP4_NONE)
4205 return -EIO;
4206
4207 /* Throw away minor_id */
4208 READ_BUF(8);
4209
4210 /* Throw away Major id */
4211 READ_BUF(4);
4212 READ32(dummy);
4213 READ_BUF(dummy);
4214
4215 /* Throw away server_scope */
4216 READ_BUF(4);
4217 READ32(dummy);
4218 READ_BUF(dummy);
4219
4220 /* Throw away Implementation id array */
4221 READ_BUF(4);
4222 READ32(dummy);
4223 READ_BUF(dummy);
4224
4225 return 0;
4226}
Andy Adamsonfc931582009-04-01 09:22:31 -04004227
4228static int decode_chan_attrs(struct xdr_stream *xdr,
4229 struct nfs4_channel_attrs *attrs)
4230{
4231 __be32 *p;
4232 u32 nr_attrs;
4233
4234 READ_BUF(28);
4235 READ32(attrs->headerpadsz);
4236 READ32(attrs->max_rqst_sz);
4237 READ32(attrs->max_resp_sz);
4238 READ32(attrs->max_resp_sz_cached);
4239 READ32(attrs->max_ops);
4240 READ32(attrs->max_reqs);
4241 READ32(nr_attrs);
4242 if (unlikely(nr_attrs > 1)) {
4243 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4244 __func__, nr_attrs);
4245 return -EINVAL;
4246 }
4247 if (nr_attrs == 1)
4248 READ_BUF(4); /* skip rdma_attrs */
4249 return 0;
4250}
4251
4252static int decode_create_session(struct xdr_stream *xdr,
4253 struct nfs41_create_session_res *res)
4254{
4255 __be32 *p;
4256 int status;
4257 struct nfs_client *clp = res->client;
4258 struct nfs4_session *session = clp->cl_session;
4259
4260 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
4261
4262 if (status)
4263 return status;
4264
4265 /* sessionid */
4266 READ_BUF(NFS4_MAX_SESSIONID_LEN);
4267 COPYMEM(&session->sess_id, NFS4_MAX_SESSIONID_LEN);
4268
4269 /* seqid, flags */
4270 READ_BUF(8);
4271 READ32(clp->cl_seqid);
4272 READ32(session->flags);
4273
4274 /* Channel attributes */
4275 status = decode_chan_attrs(xdr, &session->fc_attrs);
4276 if (!status)
4277 status = decode_chan_attrs(xdr, &session->bc_attrs);
4278 return status;
4279}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004280
4281static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4282{
4283 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4284}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004285#endif /* CONFIG_NFS_V4_1 */
4286
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004287static int decode_sequence(struct xdr_stream *xdr,
4288 struct nfs4_sequence_res *res,
4289 struct rpc_rqst *rqstp)
4290{
4291#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004292 struct nfs4_slot *slot;
4293 struct nfs4_sessionid id;
4294 u32 dummy;
4295 int status;
4296 __be32 *p;
4297
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004298 if (!res->sr_session)
4299 return 0;
4300
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004301 status = decode_op_hdr(xdr, OP_SEQUENCE);
4302 if (status)
4303 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004304
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004305 /*
4306 * If the server returns different values for sessionID, slotID or
4307 * sequence number, the server is looney tunes.
4308 */
4309 status = -ESERVERFAULT;
4310
4311 slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid];
4312 READ_BUF(NFS4_MAX_SESSIONID_LEN + 20);
4313 COPYMEM(id.data, NFS4_MAX_SESSIONID_LEN);
4314 if (memcmp(id.data, res->sr_session->sess_id.data,
4315 NFS4_MAX_SESSIONID_LEN)) {
4316 dprintk("%s Invalid session id\n", __func__);
4317 goto out_err;
4318 }
4319 /* seqid */
4320 READ32(dummy);
4321 if (dummy != slot->seq_nr) {
4322 dprintk("%s Invalid sequence number\n", __func__);
4323 goto out_err;
4324 }
4325 /* slot id */
4326 READ32(dummy);
4327 if (dummy != res->sr_slotid) {
4328 dprintk("%s Invalid slot id\n", __func__);
4329 goto out_err;
4330 }
4331 /* highest slot id - currently not processed */
4332 READ32(dummy);
4333 /* target highest slot id - currently not processed */
4334 READ32(dummy);
4335 /* result flags - currently not processed */
4336 READ32(dummy);
4337 status = 0;
4338out_err:
4339 res->sr_status = status;
4340 return status;
4341#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004342 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004343#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004344}
4345
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346/*
Benny Halevy49c25592008-12-23 16:06:16 -05004347 * END OF "GENERIC" DECODE ROUTINES.
4348 */
4349
4350/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351 * Decode OPEN_DOWNGRADE response
4352 */
Al Viro8687b632006-10-19 23:28:48 -07004353static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354{
Andy Adamson05d564f2008-12-23 16:06:15 -05004355 struct xdr_stream xdr;
4356 struct compound_hdr hdr;
4357 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358
Andy Adamson05d564f2008-12-23 16:06:15 -05004359 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4360 status = decode_compound_hdr(&xdr, &hdr);
4361 if (status)
4362 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004363 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4364 if (status)
4365 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004366 status = decode_putfh(&xdr);
4367 if (status)
4368 goto out;
4369 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004370 if (status != 0)
4371 goto out;
4372 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004374 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004375}
4376
4377/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378 * Decode ACCESS response
4379 */
Al Viro8687b632006-10-19 23:28:48 -07004380static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004381{
4382 struct xdr_stream xdr;
4383 struct compound_hdr hdr;
4384 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004385
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004387 status = decode_compound_hdr(&xdr, &hdr);
4388 if (status)
4389 goto out;
4390 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4391 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04004393 status = decode_putfh(&xdr);
4394 if (status != 0)
4395 goto out;
4396 status = decode_access(&xdr, res);
4397 if (status != 0)
4398 goto out;
4399 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400out:
4401 return status;
4402}
4403
4404/*
4405 * Decode LOOKUP response
4406 */
Al Viro8687b632006-10-19 23:28:48 -07004407static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408{
4409 struct xdr_stream xdr;
4410 struct compound_hdr hdr;
4411 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004412
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004414 status = decode_compound_hdr(&xdr, &hdr);
4415 if (status)
4416 goto out;
4417 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4418 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419 goto out;
4420 if ((status = decode_putfh(&xdr)) != 0)
4421 goto out;
4422 if ((status = decode_lookup(&xdr)) != 0)
4423 goto out;
4424 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4425 goto out;
4426 status = decode_getfattr(&xdr, res->fattr, res->server);
4427out:
4428 return status;
4429}
4430
4431/*
4432 * Decode LOOKUP_ROOT response
4433 */
Al Viro8687b632006-10-19 23:28:48 -07004434static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435{
4436 struct xdr_stream xdr;
4437 struct compound_hdr hdr;
4438 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004439
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004441 status = decode_compound_hdr(&xdr, &hdr);
4442 if (status)
4443 goto out;
4444 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4445 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004446 goto out;
4447 if ((status = decode_putrootfh(&xdr)) != 0)
4448 goto out;
4449 if ((status = decode_getfh(&xdr, res->fh)) == 0)
4450 status = decode_getfattr(&xdr, res->fattr, res->server);
4451out:
4452 return status;
4453}
4454
4455/*
4456 * Decode REMOVE response
4457 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004458static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459{
4460 struct xdr_stream xdr;
4461 struct compound_hdr hdr;
4462 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004463
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004465 status = decode_compound_hdr(&xdr, &hdr);
4466 if (status)
4467 goto out;
4468 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4469 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04004471 if ((status = decode_putfh(&xdr)) != 0)
4472 goto out;
4473 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4474 goto out;
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004475 decode_getfattr(&xdr, &res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476out:
4477 return status;
4478}
4479
4480/*
4481 * Decode RENAME response
4482 */
Al Viro8687b632006-10-19 23:28:48 -07004483static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004484{
4485 struct xdr_stream xdr;
4486 struct compound_hdr hdr;
4487 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004488
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004490 status = decode_compound_hdr(&xdr, &hdr);
4491 if (status)
4492 goto out;
4493 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4494 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495 goto out;
4496 if ((status = decode_putfh(&xdr)) != 0)
4497 goto out;
4498 if ((status = decode_savefh(&xdr)) != 0)
4499 goto out;
4500 if ((status = decode_putfh(&xdr)) != 0)
4501 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004502 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4503 goto out;
4504 /* Current FH is target directory */
4505 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
4506 goto out;
4507 if ((status = decode_restorefh(&xdr)) != 0)
4508 goto out;
4509 decode_getfattr(&xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510out:
4511 return status;
4512}
4513
4514/*
4515 * Decode LINK response
4516 */
Al Viro8687b632006-10-19 23:28:48 -07004517static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004518{
4519 struct xdr_stream xdr;
4520 struct compound_hdr hdr;
4521 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004522
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004524 status = decode_compound_hdr(&xdr, &hdr);
4525 if (status)
4526 goto out;
4527 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4528 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529 goto out;
4530 if ((status = decode_putfh(&xdr)) != 0)
4531 goto out;
4532 if ((status = decode_savefh(&xdr)) != 0)
4533 goto out;
4534 if ((status = decode_putfh(&xdr)) != 0)
4535 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004536 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4537 goto out;
4538 /*
4539 * Note order: OP_LINK leaves the directory as the current
4540 * filehandle.
4541 */
4542 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
4543 goto out;
4544 if ((status = decode_restorefh(&xdr)) != 0)
4545 goto out;
4546 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547out:
4548 return status;
4549}
4550
4551/*
4552 * Decode CREATE response
4553 */
Al Viro8687b632006-10-19 23:28:48 -07004554static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004555{
4556 struct xdr_stream xdr;
4557 struct compound_hdr hdr;
4558 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004559
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004561 status = decode_compound_hdr(&xdr, &hdr);
4562 if (status)
4563 goto out;
4564 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4565 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566 goto out;
4567 if ((status = decode_putfh(&xdr)) != 0)
4568 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004569 if ((status = decode_savefh(&xdr)) != 0)
4570 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004571 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4572 goto out;
4573 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4574 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004575 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
4576 goto out;
4577 if ((status = decode_restorefh(&xdr)) != 0)
4578 goto out;
4579 decode_getfattr(&xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580out:
4581 return status;
4582}
4583
4584/*
4585 * Decode SYMLINK response
4586 */
Al Viro8687b632006-10-19 23:28:48 -07004587static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004588{
4589 return nfs4_xdr_dec_create(rqstp, p, res);
4590}
4591
4592/*
4593 * Decode GETATTR response
4594 */
Al Viro8687b632006-10-19 23:28:48 -07004595static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596{
4597 struct xdr_stream xdr;
4598 struct compound_hdr hdr;
4599 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004600
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4602 status = decode_compound_hdr(&xdr, &hdr);
4603 if (status)
4604 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004605 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4606 if (status)
4607 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 status = decode_putfh(&xdr);
4609 if (status)
4610 goto out;
4611 status = decode_getfattr(&xdr, res->fattr, res->server);
4612out:
4613 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004614}
4615
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004616/*
4617 * Encode an SETACL request
4618 */
4619static int
Al Viro8687b632006-10-19 23:28:48 -07004620nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004621{
Andy Adamson05d564f2008-12-23 16:06:15 -05004622 struct xdr_stream xdr;
4623 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04004624 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05004625 };
4626 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004627
Andy Adamson05d564f2008-12-23 16:06:15 -05004628 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04004629 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004630 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05004631 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004632 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004633 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004634 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004635}
Andy Adamson05d564f2008-12-23 16:06:15 -05004636
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004637/*
4638 * Decode SETACL response
4639 */
4640static int
Benny Halevy73c403a2009-04-01 09:22:01 -04004641nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4642 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004643{
4644 struct xdr_stream xdr;
4645 struct compound_hdr hdr;
4646 int status;
4647
4648 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4649 status = decode_compound_hdr(&xdr, &hdr);
4650 if (status)
4651 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004652 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4653 if (status)
4654 goto out;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004655 status = decode_putfh(&xdr);
4656 if (status)
4657 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004658 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004659out:
4660 return status;
4661}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662
4663/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00004664 * Decode GETACL response
4665 */
4666static int
Benny Halevy663c79b2009-04-01 09:21:59 -04004667nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4668 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004669{
4670 struct xdr_stream xdr;
4671 struct compound_hdr hdr;
4672 int status;
4673
4674 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4675 status = decode_compound_hdr(&xdr, &hdr);
4676 if (status)
4677 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004678 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4679 if (status)
4680 goto out;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004681 status = decode_putfh(&xdr);
4682 if (status)
4683 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04004684 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004685
4686out:
4687 return status;
4688}
4689
4690/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691 * Decode CLOSE response
4692 */
Al Viro8687b632006-10-19 23:28:48 -07004693static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004694{
Andy Adamson05d564f2008-12-23 16:06:15 -05004695 struct xdr_stream xdr;
4696 struct compound_hdr hdr;
4697 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698
Andy Adamson05d564f2008-12-23 16:06:15 -05004699 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4700 status = decode_compound_hdr(&xdr, &hdr);
4701 if (status)
4702 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004703 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4704 if (status)
4705 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004706 status = decode_putfh(&xdr);
4707 if (status)
4708 goto out;
4709 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004710 if (status != 0)
4711 goto out;
4712 /*
4713 * Note: Server may do delete on close for this file
4714 * in which case the getattr call will fail with
4715 * an ESTALE error. Shouldn't be a problem,
4716 * though, since fattr->valid will remain unset.
4717 */
4718 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004720 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721}
4722
4723/*
4724 * Decode OPEN response
4725 */
Al Viro8687b632006-10-19 23:28:48 -07004726static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004727{
Andy Adamson05d564f2008-12-23 16:06:15 -05004728 struct xdr_stream xdr;
4729 struct compound_hdr hdr;
4730 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731
Andy Adamson05d564f2008-12-23 16:06:15 -05004732 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4733 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004734 if (status)
4735 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004736 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4737 if (status)
4738 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004739 status = decode_putfh(&xdr);
4740 if (status)
4741 goto out;
4742 status = decode_savefh(&xdr);
4743 if (status)
4744 goto out;
4745 status = decode_open(&xdr, res);
4746 if (status)
4747 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04004748 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004750 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4751 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04004752 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004753 goto out;
4754 decode_getfattr(&xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004756 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757}
4758
4759/*
4760 * Decode OPEN_CONFIRM response
4761 */
Al Viro8687b632006-10-19 23:28:48 -07004762static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004763{
Andy Adamson05d564f2008-12-23 16:06:15 -05004764 struct xdr_stream xdr;
4765 struct compound_hdr hdr;
4766 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767
Andy Adamson05d564f2008-12-23 16:06:15 -05004768 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4769 status = decode_compound_hdr(&xdr, &hdr);
4770 if (status)
4771 goto out;
4772 status = decode_putfh(&xdr);
4773 if (status)
4774 goto out;
4775 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004776out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004777 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778}
4779
4780/*
4781 * Decode OPEN response
4782 */
Al Viro8687b632006-10-19 23:28:48 -07004783static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784{
Andy Adamson05d564f2008-12-23 16:06:15 -05004785 struct xdr_stream xdr;
4786 struct compound_hdr hdr;
4787 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788
Andy Adamson05d564f2008-12-23 16:06:15 -05004789 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4790 status = decode_compound_hdr(&xdr, &hdr);
4791 if (status)
4792 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004793 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4794 if (status)
4795 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004796 status = decode_putfh(&xdr);
4797 if (status)
4798 goto out;
4799 status = decode_open(&xdr, res);
4800 if (status)
4801 goto out;
Trond Myklebust864472e2006-01-03 09:55:15 +01004802 decode_getfattr(&xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004804 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004805}
4806
4807/*
4808 * Decode SETATTR response
4809 */
Al Viro8687b632006-10-19 23:28:48 -07004810static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811{
Andy Adamson05d564f2008-12-23 16:06:15 -05004812 struct xdr_stream xdr;
4813 struct compound_hdr hdr;
4814 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815
Andy Adamson05d564f2008-12-23 16:06:15 -05004816 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4817 status = decode_compound_hdr(&xdr, &hdr);
4818 if (status)
4819 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004820 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4821 if (status)
4822 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004823 status = decode_putfh(&xdr);
4824 if (status)
4825 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004826 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004827 if (status)
4828 goto out;
Trond Myklebust78f945f2009-03-11 14:10:23 -04004829 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004831 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832}
4833
4834/*
4835 * Decode LOCK response
4836 */
Al Viro8687b632006-10-19 23:28:48 -07004837static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838{
4839 struct xdr_stream xdr;
4840 struct compound_hdr hdr;
4841 int status;
4842
4843 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4844 status = decode_compound_hdr(&xdr, &hdr);
4845 if (status)
4846 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004847 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4848 if (status)
4849 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850 status = decode_putfh(&xdr);
4851 if (status)
4852 goto out;
4853 status = decode_lock(&xdr, res);
4854out:
4855 return status;
4856}
4857
4858/*
4859 * Decode LOCKT response
4860 */
Al Viro8687b632006-10-19 23:28:48 -07004861static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862{
4863 struct xdr_stream xdr;
4864 struct compound_hdr hdr;
4865 int status;
4866
4867 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4868 status = decode_compound_hdr(&xdr, &hdr);
4869 if (status)
4870 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004871 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4872 if (status)
4873 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874 status = decode_putfh(&xdr);
4875 if (status)
4876 goto out;
4877 status = decode_lockt(&xdr, res);
4878out:
4879 return status;
4880}
4881
4882/*
4883 * Decode LOCKU response
4884 */
Al Viro8687b632006-10-19 23:28:48 -07004885static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886{
4887 struct xdr_stream xdr;
4888 struct compound_hdr hdr;
4889 int status;
4890
4891 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4892 status = decode_compound_hdr(&xdr, &hdr);
4893 if (status)
4894 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004895 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4896 if (status)
4897 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 status = decode_putfh(&xdr);
4899 if (status)
4900 goto out;
4901 status = decode_locku(&xdr, res);
4902out:
4903 return status;
4904}
4905
4906/*
4907 * Decode READLINK response
4908 */
Benny Halevyf50c7002009-04-01 09:21:55 -04004909static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4910 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004911{
4912 struct xdr_stream xdr;
4913 struct compound_hdr hdr;
4914 int status;
4915
4916 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4917 status = decode_compound_hdr(&xdr, &hdr);
4918 if (status)
4919 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004920 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4921 if (status)
4922 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004923 status = decode_putfh(&xdr);
4924 if (status)
4925 goto out;
4926 status = decode_readlink(&xdr, rqstp);
4927out:
4928 return status;
4929}
4930
4931/*
4932 * Decode READDIR response
4933 */
Al Viro8687b632006-10-19 23:28:48 -07004934static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935{
4936 struct xdr_stream xdr;
4937 struct compound_hdr hdr;
4938 int status;
4939
4940 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4941 status = decode_compound_hdr(&xdr, &hdr);
4942 if (status)
4943 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004944 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4945 if (status)
4946 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947 status = decode_putfh(&xdr);
4948 if (status)
4949 goto out;
4950 status = decode_readdir(&xdr, rqstp, res);
4951out:
4952 return status;
4953}
4954
4955/*
4956 * Decode Read response
4957 */
Al Viro8687b632006-10-19 23:28:48 -07004958static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004959{
4960 struct xdr_stream xdr;
4961 struct compound_hdr hdr;
4962 int status;
4963
4964 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4965 status = decode_compound_hdr(&xdr, &hdr);
4966 if (status)
4967 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004968 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4969 if (status)
4970 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971 status = decode_putfh(&xdr);
4972 if (status)
4973 goto out;
4974 status = decode_read(&xdr, rqstp, res);
4975 if (!status)
4976 status = res->count;
4977out:
4978 return status;
4979}
4980
4981/*
4982 * Decode WRITE response
4983 */
Al Viro8687b632006-10-19 23:28:48 -07004984static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985{
4986 struct xdr_stream xdr;
4987 struct compound_hdr hdr;
4988 int status;
4989
4990 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4991 status = decode_compound_hdr(&xdr, &hdr);
4992 if (status)
4993 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004994 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4995 if (status)
4996 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004997 status = decode_putfh(&xdr);
4998 if (status)
4999 goto out;
5000 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005001 if (status)
5002 goto out;
5003 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005004 if (!status)
5005 status = res->count;
5006out:
5007 return status;
5008}
5009
5010/*
5011 * Decode COMMIT response
5012 */
Al Viro8687b632006-10-19 23:28:48 -07005013static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005014{
5015 struct xdr_stream xdr;
5016 struct compound_hdr hdr;
5017 int status;
5018
5019 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5020 status = decode_compound_hdr(&xdr, &hdr);
5021 if (status)
5022 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005023 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5024 if (status)
5025 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026 status = decode_putfh(&xdr);
5027 if (status)
5028 goto out;
5029 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005030 if (status)
5031 goto out;
5032 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005033out:
5034 return status;
5035}
5036
5037/*
5038 * FSINFO request
5039 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04005040static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
5041 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005042{
5043 struct xdr_stream xdr;
5044 struct compound_hdr hdr;
5045 int status;
5046
5047 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5048 status = decode_compound_hdr(&xdr, &hdr);
5049 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005050 status = decode_sequence(&xdr, &res->seq_res, req);
5051 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005052 status = decode_putfh(&xdr);
5053 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04005054 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005055 return status;
5056}
5057
5058/*
5059 * PATHCONF request
5060 */
Benny Halevyd45b2982009-04-01 09:21:58 -04005061static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
5062 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005063{
5064 struct xdr_stream xdr;
5065 struct compound_hdr hdr;
5066 int status;
5067
5068 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5069 status = decode_compound_hdr(&xdr, &hdr);
5070 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005071 status = decode_sequence(&xdr, &res->seq_res, req);
5072 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073 status = decode_putfh(&xdr);
5074 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04005075 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005076 return status;
5077}
5078
5079/*
5080 * STATFS request
5081 */
Benny Halevy24ad1482009-04-01 09:21:56 -04005082static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
5083 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084{
5085 struct xdr_stream xdr;
5086 struct compound_hdr hdr;
5087 int status;
5088
5089 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5090 status = decode_compound_hdr(&xdr, &hdr);
5091 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005092 status = decode_sequence(&xdr, &res->seq_res, req);
5093 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005094 status = decode_putfh(&xdr);
5095 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04005096 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005097 return status;
5098}
5099
5100/*
5101 * GETATTR_BITMAP request
5102 */
Al Viro8687b632006-10-19 23:28:48 -07005103static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104{
5105 struct xdr_stream xdr;
5106 struct compound_hdr hdr;
5107 int status;
5108
5109 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005110 status = decode_compound_hdr(&xdr, &hdr);
5111 if (status)
5112 goto out;
5113 status = decode_sequence(&xdr, &res->seq_res, req);
5114 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115 goto out;
5116 if ((status = decode_putfh(&xdr)) != 0)
5117 goto out;
5118 status = decode_server_caps(&xdr, res);
5119out:
5120 return status;
5121}
5122
5123/*
5124 * Decode RENEW response
5125 */
Al Viro8687b632006-10-19 23:28:48 -07005126static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127{
5128 struct xdr_stream xdr;
5129 struct compound_hdr hdr;
5130 int status;
5131
5132 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5133 status = decode_compound_hdr(&xdr, &hdr);
5134 if (!status)
5135 status = decode_renew(&xdr);
5136 return status;
5137}
5138
5139/*
5140 * a SETCLIENTID request
5141 */
Al Viro8687b632006-10-19 23:28:48 -07005142static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04005143 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144{
5145 struct xdr_stream xdr;
5146 struct compound_hdr hdr;
5147 int status;
5148
5149 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5150 status = decode_compound_hdr(&xdr, &hdr);
5151 if (!status)
5152 status = decode_setclientid(&xdr, clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153 return status;
5154}
5155
5156/*
5157 * a SETCLIENTID_CONFIRM request
5158 */
Al Viro8687b632006-10-19 23:28:48 -07005159static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005160{
5161 struct xdr_stream xdr;
5162 struct compound_hdr hdr;
5163 int status;
5164
5165 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5166 status = decode_compound_hdr(&xdr, &hdr);
5167 if (!status)
5168 status = decode_setclientid_confirm(&xdr);
5169 if (!status)
5170 status = decode_putrootfh(&xdr);
5171 if (!status)
5172 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173 return status;
5174}
5175
5176/*
5177 * DELEGRETURN request
5178 */
Al Viro8687b632006-10-19 23:28:48 -07005179static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005180{
5181 struct xdr_stream xdr;
5182 struct compound_hdr hdr;
5183 int status;
5184
5185 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5186 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005187 if (status)
5188 goto out;
5189 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5190 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005191 goto out;
5192 status = decode_putfh(&xdr);
5193 if (status != 0)
5194 goto out;
5195 status = decode_delegreturn(&xdr);
5196 decode_getfattr(&xdr, res->fattr, res->server);
5197out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005198 return status;
5199}
5200
Trond Myklebust683b57b2006-06-09 09:34:22 -04005201/*
5202 * FS_LOCATIONS request
5203 */
Benny Halevy22958462009-04-01 09:22:02 -04005204static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
5205 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005206{
5207 struct xdr_stream xdr;
5208 struct compound_hdr hdr;
5209 int status;
5210
5211 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5212 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005213 if (status)
5214 goto out;
5215 status = decode_sequence(&xdr, &res->seq_res, req);
5216 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005217 goto out;
5218 if ((status = decode_putfh(&xdr)) != 0)
5219 goto out;
5220 if ((status = decode_lookup(&xdr)) != 0)
5221 goto out;
5222 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04005223 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
5224 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04005225out:
5226 return status;
5227}
5228
Benny Halevy99fe60d2009-04-01 09:22:29 -04005229#if defined(CONFIG_NFS_V4_1)
5230/*
5231 * EXCHANGE_ID request
5232 */
5233static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
5234 void *res)
5235{
5236 struct xdr_stream xdr;
5237 struct compound_hdr hdr;
5238 int status;
5239
5240 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5241 status = decode_compound_hdr(&xdr, &hdr);
5242 if (!status)
5243 status = decode_exchange_id(&xdr, res);
5244 return status;
5245}
Andy Adamson2050f0c2009-04-01 09:22:30 -04005246
5247/*
Andy Adamsonfc931582009-04-01 09:22:31 -04005248 * a CREATE_SESSION request
5249 */
5250static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
5251 struct nfs41_create_session_res *res)
5252{
5253 struct xdr_stream xdr;
5254 struct compound_hdr hdr;
5255 int status;
5256
5257 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5258 status = decode_compound_hdr(&xdr, &hdr);
5259 if (!status)
5260 status = decode_create_session(&xdr, res);
5261 return status;
5262}
5263
5264/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005265 * a DESTROY_SESSION request
5266 */
5267static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
5268 void *dummy)
5269{
5270 struct xdr_stream xdr;
5271 struct compound_hdr hdr;
5272 int status;
5273
5274 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5275 status = decode_compound_hdr(&xdr, &hdr);
5276 if (!status)
5277 status = decode_destroy_session(&xdr, dummy);
5278 return status;
5279}
5280
5281/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005282 * a SEQUENCE request
5283 */
5284static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p,
5285 struct nfs4_sequence_res *res)
5286{
5287 struct xdr_stream xdr;
5288 struct compound_hdr hdr;
5289 int status;
5290
5291 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5292 status = decode_compound_hdr(&xdr, &hdr);
5293 if (!status)
5294 status = decode_sequence(&xdr, res, rqstp);
5295 return status;
5296}
5297
5298/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04005299 * a GET_LEASE_TIME request
5300 */
5301static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
5302 struct nfs4_get_lease_time_res *res)
5303{
5304 struct xdr_stream xdr;
5305 struct compound_hdr hdr;
5306 int status;
5307
5308 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5309 status = decode_compound_hdr(&xdr, &hdr);
5310 if (!status)
5311 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
5312 if (!status)
5313 status = decode_putrootfh(&xdr);
5314 if (!status)
5315 status = decode_fsinfo(&xdr, res->lr_fsinfo);
5316 return status;
5317}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005318#endif /* CONFIG_NFS_V4_1 */
5319
Al Viro0dbb4c62006-10-19 23:28:49 -07005320__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005321{
5322 uint32_t bitmap[2] = {0};
5323 uint32_t len;
5324
5325 if (!*p++) {
5326 if (!*p)
5327 return ERR_PTR(-EAGAIN);
5328 entry->eof = 1;
5329 return ERR_PTR(-EBADCOOKIE);
5330 }
5331
5332 entry->prev_cookie = entry->cookie;
5333 p = xdr_decode_hyper(p, &entry->cookie);
5334 entry->len = ntohl(*p++);
5335 entry->name = (const char *) p;
5336 p += XDR_QUADLEN(entry->len);
5337
5338 /*
5339 * In case the server doesn't return an inode number,
5340 * we fake one here. (We don't use inode number 0,
5341 * since glibc seems to choke on it...)
5342 */
5343 entry->ino = 1;
5344
5345 len = ntohl(*p++); /* bitmap length */
5346 if (len-- > 0) {
5347 bitmap[0] = ntohl(*p++);
5348 if (len-- > 0) {
5349 bitmap[1] = ntohl(*p++);
5350 p += len;
5351 }
5352 }
5353 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
5354 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00005355 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
5356 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
5357 /* Ignore the return value of rdattr_error for now */
5358 p++;
5359 len--;
5360 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005361 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
5362 xdr_decode_hyper(p, &entry->ino);
5363 else if (bitmap[0] == FATTR4_WORD0_FILEID)
5364 xdr_decode_hyper(p, &entry->ino);
5365 p += len;
5366 }
5367
5368 entry->eof = !p[0] && p[1];
5369 return p;
5370}
5371
5372/*
5373 * We need to translate between nfs status return values and
5374 * the local errno values which may not be the same.
5375 */
5376static struct {
5377 int stat;
5378 int errno;
5379} nfs_errtbl[] = {
5380 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03005381 { NFS4ERR_PERM, -EPERM },
5382 { NFS4ERR_NOENT, -ENOENT },
5383 { NFS4ERR_IO, -errno_NFSERR_IO},
5384 { NFS4ERR_NXIO, -ENXIO },
5385 { NFS4ERR_ACCESS, -EACCES },
5386 { NFS4ERR_EXIST, -EEXIST },
5387 { NFS4ERR_XDEV, -EXDEV },
5388 { NFS4ERR_NOTDIR, -ENOTDIR },
5389 { NFS4ERR_ISDIR, -EISDIR },
5390 { NFS4ERR_INVAL, -EINVAL },
5391 { NFS4ERR_FBIG, -EFBIG },
5392 { NFS4ERR_NOSPC, -ENOSPC },
5393 { NFS4ERR_ROFS, -EROFS },
5394 { NFS4ERR_MLINK, -EMLINK },
5395 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5396 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5397 { NFS4ERR_DQUOT, -EDQUOT },
5398 { NFS4ERR_STALE, -ESTALE },
5399 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5400 { NFS4ERR_BADOWNER, -EINVAL },
5401 { NFS4ERR_BADNAME, -EINVAL },
5402 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5403 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5404 { NFS4ERR_TOOSMALL, -ETOOSMALL },
5405 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
5406 { NFS4ERR_BADTYPE, -EBADTYPE },
5407 { NFS4ERR_LOCKED, -EAGAIN },
5408 { NFS4ERR_RESOURCE, -EREMOTEIO },
5409 { NFS4ERR_SYMLINK, -ELOOP },
5410 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5411 { NFS4ERR_DEADLOCK, -EDEADLK },
5412 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005413 * to be handled by a
5414 * middle-layer.
5415 */
Benny Halevy856dff32008-03-31 17:39:06 +03005416 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005417};
5418
5419/*
5420 * Convert an NFS error code to a local one.
5421 * This one is used jointly by NFSv2 and NFSv3.
5422 */
5423static int
David Howells0a8ea432006-08-22 20:06:08 -04005424nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005425{
5426 int i;
5427 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5428 if (nfs_errtbl[i].stat == stat)
5429 return nfs_errtbl[i].errno;
5430 }
5431 if (stat <= 10000 || stat > 10100) {
5432 /* The server is looney tunes. */
Benny Halevy856dff32008-03-31 17:39:06 +03005433 return -ESERVERFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005434 }
5435 /* If we cannot translate the error, the recovery routines should
5436 * handle it.
5437 * Note: remaining NFSv4 error codes have values > 10000, so should
5438 * not conflict with native Linux error codes.
5439 */
Benny Halevy856dff32008-03-31 17:39:06 +03005440 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005441}
5442
Linus Torvalds1da177e2005-04-16 15:20:36 -07005443#define PROC(proc, argtype, restype) \
5444[NFSPROC4_CLNT_##proc] = { \
5445 .p_proc = NFSPROC4_COMPOUND, \
5446 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5447 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04005448 .p_arglen = NFS4_##argtype##_sz, \
5449 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05005450 .p_statidx = NFSPROC4_CLNT_##proc, \
5451 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05005452}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005453
5454struct rpc_procinfo nfs4_procedures[] = {
5455 PROC(READ, enc_read, dec_read),
5456 PROC(WRITE, enc_write, dec_write),
5457 PROC(COMMIT, enc_commit, dec_commit),
5458 PROC(OPEN, enc_open, dec_open),
5459 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5460 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5461 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5462 PROC(CLOSE, enc_close, dec_close),
5463 PROC(SETATTR, enc_setattr, dec_setattr),
5464 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5465 PROC(RENEW, enc_renew, dec_renew),
5466 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5467 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5468 PROC(LOCK, enc_lock, dec_lock),
5469 PROC(LOCKT, enc_lockt, dec_lockt),
5470 PROC(LOCKU, enc_locku, dec_locku),
5471 PROC(ACCESS, enc_access, dec_access),
5472 PROC(GETATTR, enc_getattr, dec_getattr),
5473 PROC(LOOKUP, enc_lookup, dec_lookup),
5474 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5475 PROC(REMOVE, enc_remove, dec_remove),
5476 PROC(RENAME, enc_rename, dec_rename),
5477 PROC(LINK, enc_link, dec_link),
5478 PROC(SYMLINK, enc_symlink, dec_symlink),
5479 PROC(CREATE, enc_create, dec_create),
5480 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5481 PROC(STATFS, enc_statfs, dec_statfs),
5482 PROC(READLINK, enc_readlink, dec_readlink),
5483 PROC(READDIR, enc_readdir, dec_readdir),
5484 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5485 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00005486 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005487 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04005488 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005489#if defined(CONFIG_NFS_V4_1)
5490 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
Andy Adamsonfc931582009-04-01 09:22:31 -04005491 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005492 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005493 PROC(SEQUENCE, enc_sequence, dec_sequence),
Andy Adamson2050f0c2009-04-01 09:22:30 -04005494 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005495#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005496};
5497
5498struct rpc_version nfs_version4 = {
5499 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08005500 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005501 .procs = nfs4_procedures
5502};
5503
5504/*
5505 * Local variables:
5506 * c-basic-offset: 8
5507 * End:
5508 */