blob: a81e49648ccbe7918a5b880af1f333a54c51291b [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 Adamson9b7b9fc2009-04-01 09:22:11 -0400299#define encode_sequence_maxsz 0 /* stub */
300#define decode_sequence_maxsz 0 /* stub */
301#else /* CONFIG_NFS_V4_1 */
302#define encode_sequence_maxsz 0
303#define decode_sequence_maxsz 0
304#endif /* CONFIG_NFS_V4_1 */
305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
307#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
308#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400309 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400311 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400313 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400315 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400317 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400319 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400321 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400323 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400325 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400327 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400329 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400331 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400333 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400335 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400336 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400338 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400340 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400341 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400343 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400345 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400346 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400348 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400350 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400351 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400353 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400354 encode_putfh_maxsz + \
355 encode_savefh_maxsz + \
356 encode_open_maxsz + \
357 encode_getfh_maxsz + \
358 encode_getattr_maxsz + \
359 encode_restorefh_maxsz + \
360 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400362 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400363 decode_putfh_maxsz + \
364 decode_savefh_maxsz + \
365 decode_open_maxsz + \
366 decode_getfh_maxsz + \
367 decode_getattr_maxsz + \
368 decode_restorefh_maxsz + \
369 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400370#define NFS4_enc_open_confirm_sz \
371 (compound_encode_hdr_maxsz + \
372 encode_putfh_maxsz + \
373 encode_open_confirm_maxsz)
374#define NFS4_dec_open_confirm_sz \
375 (compound_decode_hdr_maxsz + \
376 decode_putfh_maxsz + \
377 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400379 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400381 encode_open_maxsz + \
382 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400384 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400386 decode_open_maxsz + \
387 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388#define NFS4_enc_open_downgrade_sz \
389 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400390 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400391 encode_putfh_maxsz + \
392 encode_open_downgrade_maxsz + \
393 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394#define NFS4_dec_open_downgrade_sz \
395 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400396 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400397 decode_putfh_maxsz + \
398 decode_open_downgrade_maxsz + \
399 decode_getattr_maxsz)
400#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400401 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400402 encode_putfh_maxsz + \
403 encode_close_maxsz + \
404 encode_getattr_maxsz)
405#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400406 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400407 decode_putfh_maxsz + \
408 decode_close_maxsz + \
409 decode_getattr_maxsz)
410#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400411 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400412 encode_putfh_maxsz + \
413 encode_setattr_maxsz + \
414 encode_getattr_maxsz)
415#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400416 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400417 decode_putfh_maxsz + \
418 decode_setattr_maxsz + \
419 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400421 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 encode_putfh_maxsz + \
423 encode_fsinfo_maxsz)
424#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400425 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 decode_putfh_maxsz + \
427 decode_fsinfo_maxsz)
428#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
429 encode_renew_maxsz)
430#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
431 decode_renew_maxsz)
432#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
433 encode_setclientid_maxsz)
434#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
435 decode_setclientid_maxsz)
436#define NFS4_enc_setclientid_confirm_sz \
437 (compound_encode_hdr_maxsz + \
438 encode_setclientid_confirm_maxsz + \
439 encode_putrootfh_maxsz + \
440 encode_fsinfo_maxsz)
441#define NFS4_dec_setclientid_confirm_sz \
442 (compound_decode_hdr_maxsz + \
443 decode_setclientid_confirm_maxsz + \
444 decode_putrootfh_maxsz + \
445 decode_fsinfo_maxsz)
446#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400447 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400449 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400451 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400453 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400455 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400457 encode_lockt_maxsz)
458#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400459 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400460 decode_putfh_maxsz + \
461 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400465 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400467 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400469 decode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400471 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400473 encode_access_maxsz + \
474 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400476 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400478 decode_access_maxsz + \
479 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400481 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 encode_putfh_maxsz + \
483 encode_getattr_maxsz)
484#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 decode_putfh_maxsz + \
487 decode_getattr_maxsz)
488#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400489 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 encode_putfh_maxsz + \
491 encode_lookup_maxsz + \
492 encode_getattr_maxsz + \
493 encode_getfh_maxsz)
494#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400495 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400497 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 decode_getattr_maxsz + \
499 decode_getfh_maxsz)
500#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400501 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 encode_putrootfh_maxsz + \
503 encode_getattr_maxsz + \
504 encode_getfh_maxsz)
505#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400506 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 decode_putrootfh_maxsz + \
508 decode_getattr_maxsz + \
509 decode_getfh_maxsz)
510#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400511 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400513 encode_remove_maxsz + \
514 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400516 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400518 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400519 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400521 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 encode_putfh_maxsz + \
523 encode_savefh_maxsz + \
524 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400525 encode_rename_maxsz + \
526 encode_getattr_maxsz + \
527 encode_restorefh_maxsz + \
528 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 decode_putfh_maxsz + \
532 decode_savefh_maxsz + \
533 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400534 decode_rename_maxsz + \
535 decode_getattr_maxsz + \
536 decode_restorefh_maxsz + \
537 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400539 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 encode_putfh_maxsz + \
541 encode_savefh_maxsz + \
542 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400543 encode_link_maxsz + \
544 decode_getattr_maxsz + \
545 encode_restorefh_maxsz + \
546 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400548 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 decode_putfh_maxsz + \
550 decode_savefh_maxsz + \
551 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400552 decode_link_maxsz + \
553 decode_getattr_maxsz + \
554 decode_restorefh_maxsz + \
555 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400557 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 encode_putfh_maxsz + \
559 encode_symlink_maxsz + \
560 encode_getattr_maxsz + \
561 encode_getfh_maxsz)
562#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400563 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 decode_putfh_maxsz + \
565 decode_symlink_maxsz + \
566 decode_getattr_maxsz + \
567 decode_getfh_maxsz)
568#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400569 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400571 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400573 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400575 encode_restorefh_maxsz + \
576 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400578 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400580 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400582 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400584 decode_restorefh_maxsz + \
585 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400587 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 encode_putfh_maxsz + \
589 encode_getattr_maxsz)
590#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400591 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 decode_putfh_maxsz + \
593 decode_getattr_maxsz)
594#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400595 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400597 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400599 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400601 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400603 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800604 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 encode_getattr_maxsz)
606#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400607 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800608 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 decode_getattr_maxsz)
610#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400611 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100613 encode_delegreturn_maxsz + \
614 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400616 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100617 decode_delegreturn_maxsz + \
618 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000619#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400620 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000621 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400622 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000623#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400624 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000625 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400626 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000627#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400628 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000629 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400630 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000631#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400632 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000633 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400634 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400635#define NFS4_enc_fs_locations_sz \
636 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400637 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400638 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400639 encode_lookup_maxsz + \
640 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400641#define NFS4_dec_fs_locations_sz \
642 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400643 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400644 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400645 decode_lookup_maxsz + \
646 decode_fs_locations_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400647#if defined(CONFIG_NFS_V4_1)
648#define NFS4_enc_exchange_id_sz \
649 (compound_encode_hdr_maxsz + \
650 encode_exchange_id_maxsz)
651#define NFS4_dec_exchange_id_sz \
652 (compound_decode_hdr_maxsz + \
653 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400654#define NFS4_enc_create_session_sz \
655 (compound_encode_hdr_maxsz + \
656 encode_create_session_maxsz)
657#define NFS4_dec_create_session_sz \
658 (compound_decode_hdr_maxsz + \
659 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400660#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
661 encode_destroy_session_maxsz)
662#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
663 decode_destroy_session_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400664#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
665 encode_sequence_maxsz + \
666 encode_putrootfh_maxsz + \
667 encode_fsinfo_maxsz)
668#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
669 decode_sequence_maxsz + \
670 decode_putrootfh_maxsz + \
671 decode_fsinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400672#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Trond Myklebustbca79472009-03-11 14:10:26 -0400674static const umode_t nfs_type2fmt[] = {
675 [NF4BAD] = 0,
676 [NF4REG] = S_IFREG,
677 [NF4DIR] = S_IFDIR,
678 [NF4BLK] = S_IFBLK,
679 [NF4CHR] = S_IFCHR,
680 [NF4LNK] = S_IFLNK,
681 [NF4SOCK] = S_IFSOCK,
682 [NF4FIFO] = S_IFIFO,
683 [NF4ATTRDIR] = 0,
684 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685};
686
687struct compound_hdr {
688 int32_t status;
689 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500690 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 uint32_t taglen;
692 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400693 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400694 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695};
696
697/*
698 * START OF "GENERIC" ENCODE ROUTINES.
699 * These may look a little ugly since they are imported from a "generic"
700 * set of XDR encode/decode routines which are intended to be shared by
701 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
702 *
703 * If the pain of reading these is too great, it should be a straightforward
704 * task to translate them into Linux-specific versions which are more
705 * consistent with the style used in NFSv2/v3...
706 */
707#define WRITE32(n) *p++ = htonl(n)
708#define WRITE64(n) do { \
709 *p++ = htonl((uint32_t)((n) >> 32)); \
710 *p++ = htonl((uint32_t)(n)); \
711} while (0)
712#define WRITEMEM(ptr,nbytes) do { \
713 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
714} while (0)
715
716#define RESERVE_SPACE(nbytes) do { \
717 p = xdr_reserve_space(xdr, nbytes); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 BUG_ON(!p); \
719} while (0)
720
721static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
722{
Al Viro8687b632006-10-19 23:28:48 -0700723 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
725 p = xdr_reserve_space(xdr, 4 + len);
726 BUG_ON(p == NULL);
727 xdr_encode_opaque(p, str, len);
728}
729
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400730static void encode_compound_hdr(struct xdr_stream *xdr,
731 struct rpc_rqst *req,
732 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
Al Viro8687b632006-10-19 23:28:48 -0700734 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400735 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
736
737 /* initialize running count of expected bytes in reply.
738 * NOTE: the replied tag SHOULD be the same is the one sent,
739 * but this is not required as a MUST for the server to do so. */
740 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
743 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
744 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
745 WRITE32(hdr->taglen);
746 WRITEMEM(hdr->tag, hdr->taglen);
Benny Halevy66cc0422009-04-01 09:22:10 -0400747 WRITE32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500748 hdr->nops_p = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 WRITE32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500750}
751
752static void encode_nops(struct compound_hdr *hdr)
753{
Andy Adamsonfc931582009-04-01 09:22:31 -0400754 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500755 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756}
757
758static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
759{
Al Viro8687b632006-10-19 23:28:48 -0700760 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
763 BUG_ON(p == NULL);
764 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
765}
766
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500767static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
769 char owner_name[IDMAP_NAMESZ];
770 char owner_group[IDMAP_NAMESZ];
771 int owner_namelen = 0;
772 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700773 __be32 *p;
774 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 int len;
776 uint32_t bmval0 = 0;
777 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779 /*
780 * We reserve enough space to write the entire attribute buffer at once.
781 * In the worst-case, this would be
782 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
783 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000784 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 */
786 len = 16;
787
788 /* Sigh */
789 if (iap->ia_valid & ATTR_SIZE)
790 len += 8;
791 if (iap->ia_valid & ATTR_MODE)
792 len += 4;
793 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400794 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400796 dprintk("nfs: couldn't resolve uid %d to string\n",
797 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 /* XXX */
799 strcpy(owner_name, "nobody");
800 owner_namelen = sizeof("nobody") - 1;
801 /* goto out; */
802 }
803 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
804 }
805 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400806 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400808 dprintk("nfs: couldn't resolve gid %d to string\n",
809 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 strcpy(owner_group, "nobody");
811 owner_grouplen = sizeof("nobody") - 1;
812 /* goto out; */
813 }
814 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
815 }
816 if (iap->ia_valid & ATTR_ATIME_SET)
817 len += 16;
818 else if (iap->ia_valid & ATTR_ATIME)
819 len += 4;
820 if (iap->ia_valid & ATTR_MTIME_SET)
821 len += 16;
822 else if (iap->ia_valid & ATTR_MTIME)
823 len += 4;
824 RESERVE_SPACE(len);
825
826 /*
827 * We write the bitmap length now, but leave the bitmap and the attribute
828 * buffer length to be backfilled at the end of this routine.
829 */
830 WRITE32(2);
831 q = p;
832 p += 3;
833
834 if (iap->ia_valid & ATTR_SIZE) {
835 bmval0 |= FATTR4_WORD0_SIZE;
836 WRITE64(iap->ia_size);
837 }
838 if (iap->ia_valid & ATTR_MODE) {
839 bmval1 |= FATTR4_WORD1_MODE;
Trond Myklebustcf3fff52006-01-03 09:55:53 +0100840 WRITE32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 }
842 if (iap->ia_valid & ATTR_UID) {
843 bmval1 |= FATTR4_WORD1_OWNER;
844 WRITE32(owner_namelen);
845 WRITEMEM(owner_name, owner_namelen);
846 }
847 if (iap->ia_valid & ATTR_GID) {
848 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
849 WRITE32(owner_grouplen);
850 WRITEMEM(owner_group, owner_grouplen);
851 }
852 if (iap->ia_valid & ATTR_ATIME_SET) {
853 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
854 WRITE32(NFS4_SET_TO_CLIENT_TIME);
855 WRITE32(0);
856 WRITE32(iap->ia_mtime.tv_sec);
857 WRITE32(iap->ia_mtime.tv_nsec);
858 }
859 else if (iap->ia_valid & ATTR_ATIME) {
860 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
861 WRITE32(NFS4_SET_TO_SERVER_TIME);
862 }
863 if (iap->ia_valid & ATTR_MTIME_SET) {
864 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
865 WRITE32(NFS4_SET_TO_CLIENT_TIME);
866 WRITE32(0);
867 WRITE32(iap->ia_mtime.tv_sec);
868 WRITE32(iap->ia_mtime.tv_nsec);
869 }
870 else if (iap->ia_valid & ATTR_MTIME) {
871 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
872 WRITE32(NFS4_SET_TO_SERVER_TIME);
873 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500874
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 /*
876 * Now we backfill the bitmap and the attribute buffer length.
877 */
878 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400879 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 len, ((char *)p - (char *)q) + 4);
881 BUG();
882 }
883 len = (char *)p - (char *)q - 12;
884 *q++ = htonl(bmval0);
885 *q++ = htonl(bmval1);
886 *q++ = htonl(len);
887
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889}
890
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500891static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892{
Al Viro8687b632006-10-19 23:28:48 -0700893 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
895 RESERVE_SPACE(8);
896 WRITE32(OP_ACCESS);
897 WRITE32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500898 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400899 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900}
901
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500902static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903{
Al Viro8687b632006-10-19 23:28:48 -0700904 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400906 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 WRITE32(OP_CLOSE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700908 WRITE32(arg->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400909 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500910 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400911 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912}
913
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500914static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
Al Viro8687b632006-10-19 23:28:48 -0700916 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500917
Andy Adamson05d564f2008-12-23 16:06:15 -0500918 RESERVE_SPACE(16);
919 WRITE32(OP_COMMIT);
920 WRITE64(args->offset);
921 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500922 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400923 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924}
925
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500926static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927{
Al Viro8687b632006-10-19 23:28:48 -0700928 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 RESERVE_SPACE(8);
931 WRITE32(OP_CREATE);
932 WRITE32(create->ftype);
933
934 switch (create->ftype) {
935 case NF4LNK:
Chuck Lever94a6d752006-08-22 20:06:23 -0400936 RESERVE_SPACE(4);
937 WRITE32(create->u.symlink.len);
938 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 break;
940
941 case NF4BLK: case NF4CHR:
942 RESERVE_SPACE(8);
943 WRITE32(create->u.device.specdata1);
944 WRITE32(create->u.device.specdata2);
945 break;
946
947 default:
948 break;
949 }
950
951 RESERVE_SPACE(4 + create->name->len);
952 WRITE32(create->name->len);
953 WRITEMEM(create->name->name, create->name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500954 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400955 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500957 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958}
959
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500960static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961{
Andy Adamson05d564f2008-12-23 16:06:15 -0500962 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
Andy Adamson05d564f2008-12-23 16:06:15 -0500964 RESERVE_SPACE(12);
965 WRITE32(OP_GETATTR);
966 WRITE32(1);
967 WRITE32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500968 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400969 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970}
971
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500972static 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 -0700973{
Andy Adamson05d564f2008-12-23 16:06:15 -0500974 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
Andy Adamson05d564f2008-12-23 16:06:15 -0500976 RESERVE_SPACE(16);
977 WRITE32(OP_GETATTR);
978 WRITE32(2);
979 WRITE32(bm0);
980 WRITE32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -0500981 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400982 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983}
984
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500985static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500987 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
988 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500991static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500993 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
994 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995}
996
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500997static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -0400998{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500999 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1000 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001001}
1002
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001003static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004{
Al Viro8687b632006-10-19 23:28:48 -07001005 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
1007 RESERVE_SPACE(4);
1008 WRITE32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001009 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001010 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011}
1012
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001013static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014{
Al Viro8687b632006-10-19 23:28:48 -07001015 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
1017 RESERVE_SPACE(8 + name->len);
1018 WRITE32(OP_LINK);
1019 WRITE32(name->len);
1020 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001021 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001022 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023}
1024
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001025static inline int nfs4_lock_type(struct file_lock *fl, int block)
1026{
1027 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1028 return block ? NFS4_READW_LT : NFS4_READ_LT;
1029 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1030}
1031
1032static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1033{
1034 if (fl->fl_end == OFFSET_MAX)
1035 return ~(uint64_t)0;
1036 return fl->fl_end - fl->fl_start + 1;
1037}
1038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039/*
1040 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1041 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1042 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001043static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044{
Al Viro8687b632006-10-19 23:28:48 -07001045 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
1047 RESERVE_SPACE(32);
1048 WRITE32(OP_LOCK);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001049 WRITE32(nfs4_lock_type(args->fl, args->block));
1050 WRITE32(args->reclaim);
1051 WRITE64(args->fl->fl_start);
1052 WRITE64(nfs4_lock_length(args->fl));
1053 WRITE32(args->new_lock_owner);
1054 if (args->new_lock_owner){
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001055 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001056 WRITE32(args->open_seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001057 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001058 WRITE32(args->lock_seqid->sequence->counter);
1059 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001060 WRITE32(16);
1061 WRITEMEM("lock id:", 8);
1062 WRITE64(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 }
1064 else {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001065 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
1066 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001067 WRITE32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
Andy Adamsond0179312008-12-23 16:06:17 -05001069 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001070 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001073static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074{
Al Viro8687b632006-10-19 23:28:48 -07001075 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001077 RESERVE_SPACE(52);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 WRITE32(OP_LOCKT);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001079 WRITE32(nfs4_lock_type(args->fl, 0));
1080 WRITE64(args->fl->fl_start);
1081 WRITE64(nfs4_lock_length(args->fl));
1082 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001083 WRITE32(16);
1084 WRITEMEM("lock id:", 8);
1085 WRITE64(args->lock_owner.id);
Andy Adamsond0179312008-12-23 16:06:17 -05001086 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001087 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001090static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
Al Viro8687b632006-10-19 23:28:48 -07001092 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001094 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 WRITE32(OP_LOCKU);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001096 WRITE32(nfs4_lock_type(args->fl, 0));
1097 WRITE32(args->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001098 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001099 WRITE64(args->fl->fl_start);
1100 WRITE64(nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001101 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001102 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103}
1104
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001105static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106{
1107 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001108 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
1110 RESERVE_SPACE(8 + len);
1111 WRITE32(OP_LOOKUP);
1112 WRITE32(len);
1113 WRITEMEM(name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001114 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001115 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001118static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
Al Viro8687b632006-10-19 23:28:48 -07001120 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
1122 RESERVE_SPACE(8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001123 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001124 case FMODE_READ:
1125 WRITE32(NFS4_SHARE_ACCESS_READ);
1126 break;
1127 case FMODE_WRITE:
1128 WRITE32(NFS4_SHARE_ACCESS_WRITE);
1129 break;
1130 case FMODE_READ|FMODE_WRITE:
1131 WRITE32(NFS4_SHARE_ACCESS_BOTH);
1132 break;
1133 default:
1134 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 }
1136 WRITE32(0); /* for linux, share_deny = 0 always */
1137}
1138
1139static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1140{
Al Viro8687b632006-10-19 23:28:48 -07001141 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 /*
1143 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1144 * owner 4 = 32
1145 */
1146 RESERVE_SPACE(8);
1147 WRITE32(OP_OPEN);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001148 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001149 encode_share_access(xdr, arg->fmode);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001150 RESERVE_SPACE(28);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 WRITE64(arg->clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001152 WRITE32(16);
1153 WRITEMEM("open id:", 8);
1154 WRITE64(arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155}
1156
1157static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1158{
Al Viro8687b632006-10-19 23:28:48 -07001159 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
1161 RESERVE_SPACE(4);
1162 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001163 case 0:
1164 WRITE32(NFS4_CREATE_UNCHECKED);
1165 encode_attrs(xdr, arg->u.attrs, arg->server);
1166 break;
1167 default:
1168 WRITE32(NFS4_CREATE_EXCLUSIVE);
1169 encode_nfs4_verifier(xdr, &arg->u.verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 }
1171}
1172
1173static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1174{
Al Viro8687b632006-10-19 23:28:48 -07001175 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
1177 RESERVE_SPACE(4);
1178 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001179 case 0:
1180 WRITE32(NFS4_OPEN_NOCREATE);
1181 break;
1182 default:
1183 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1184 WRITE32(NFS4_OPEN_CREATE);
1185 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 }
1187}
1188
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001189static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190{
Al Viro8687b632006-10-19 23:28:48 -07001191 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
1193 RESERVE_SPACE(4);
1194 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001195 case 0:
1196 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1197 break;
1198 case FMODE_READ:
1199 WRITE32(NFS4_OPEN_DELEGATE_READ);
1200 break;
1201 case FMODE_WRITE|FMODE_READ:
1202 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1203 break;
1204 default:
1205 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 }
1207}
1208
1209static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1210{
Al Viro8687b632006-10-19 23:28:48 -07001211 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
1213 RESERVE_SPACE(4);
1214 WRITE32(NFS4_OPEN_CLAIM_NULL);
1215 encode_string(xdr, name->len, name->name);
1216}
1217
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001218static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219{
Al Viro8687b632006-10-19 23:28:48 -07001220 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
1222 RESERVE_SPACE(4);
1223 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1224 encode_delegation_type(xdr, type);
1225}
1226
1227static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1228{
Al Viro8687b632006-10-19 23:28:48 -07001229 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001231 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001233 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 encode_string(xdr, name->len, name->name);
1235}
1236
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001237static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238{
1239 encode_openhdr(xdr, arg);
1240 encode_opentype(xdr, arg);
1241 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001242 case NFS4_OPEN_CLAIM_NULL:
1243 encode_claim_null(xdr, arg->name);
1244 break;
1245 case NFS4_OPEN_CLAIM_PREVIOUS:
1246 encode_claim_previous(xdr, arg->u.delegation_type);
1247 break;
1248 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1249 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1250 break;
1251 default:
1252 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 }
Andy Adamsond0179312008-12-23 16:06:17 -05001254 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001255 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256}
1257
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001258static 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 -07001259{
Al Viro8687b632006-10-19 23:28:48 -07001260 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001262 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 WRITE32(OP_OPEN_CONFIRM);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001264 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001265 WRITE32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001266 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001267 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268}
1269
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001270static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271{
Al Viro8687b632006-10-19 23:28:48 -07001272 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001274 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 WRITE32(OP_OPEN_DOWNGRADE);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001276 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001277 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001278 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001279 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001280 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281}
1282
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001283static void
Andy Adamsond0179312008-12-23 16:06:17 -05001284encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285{
1286 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001287 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
1289 RESERVE_SPACE(8 + len);
1290 WRITE32(OP_PUTFH);
1291 WRITE32(len);
1292 WRITEMEM(fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001293 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001294 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295}
1296
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001297static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298{
Andy Adamson05d564f2008-12-23 16:06:15 -05001299 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001300
Andy Adamson05d564f2008-12-23 16:06:15 -05001301 RESERVE_SPACE(4);
1302 WRITE32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001303 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001304 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305}
1306
1307static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1308{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001310 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001312 RESERVE_SPACE(NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 if (ctx->state != NULL) {
1314 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001315 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 } else
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001317 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318}
1319
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001320static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321{
Al Viro8687b632006-10-19 23:28:48 -07001322 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
1324 RESERVE_SPACE(4);
1325 WRITE32(OP_READ);
1326
1327 encode_stateid(xdr, args->context);
1328
1329 RESERVE_SPACE(12);
1330 WRITE64(args->offset);
1331 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001332 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001333 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334}
1335
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001336static 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 -07001337{
Manoj Naik97d312d2005-06-22 17:16:39 +00001338 uint32_t attrs[2] = {
1339 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1340 FATTR4_WORD1_MOUNTED_ON_FILEID,
1341 };
Al Viro8687b632006-10-19 23:28:48 -07001342 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001344 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 WRITE32(OP_READDIR);
1346 WRITE64(readdir->cookie);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001347 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1349 WRITE32(readdir->count);
1350 WRITE32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001351 /* Switch to mounted_on_fileid if the server supports it */
1352 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1353 attrs[0] &= ~FATTR4_WORD0_FILEID;
1354 else
1355 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1356 WRITE32(attrs[0] & readdir->bitmask[0]);
1357 WRITE32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001358 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001359 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001360 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1361 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001362 (unsigned long long)readdir->cookie,
1363 ((u32 *)readdir->verifier.data)[0],
1364 ((u32 *)readdir->verifier.data)[1],
1365 attrs[0] & readdir->bitmask[0],
1366 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367}
1368
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001369static 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 -07001370{
Al Viro8687b632006-10-19 23:28:48 -07001371 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372
1373 RESERVE_SPACE(4);
1374 WRITE32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001375 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001376 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377}
1378
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001379static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380{
Al Viro8687b632006-10-19 23:28:48 -07001381 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
1383 RESERVE_SPACE(8 + name->len);
1384 WRITE32(OP_REMOVE);
1385 WRITE32(name->len);
1386 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001387 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001388 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389}
1390
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001391static 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 -07001392{
Al Viro8687b632006-10-19 23:28:48 -07001393 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
1395 RESERVE_SPACE(8 + oldname->len);
1396 WRITE32(OP_RENAME);
1397 WRITE32(oldname->len);
1398 WRITEMEM(oldname->name, oldname->len);
Andy Adamson6c0195a2008-12-23 16:06:15 -05001399
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 RESERVE_SPACE(4 + newname->len);
1401 WRITE32(newname->len);
1402 WRITEMEM(newname->name, newname->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001403 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001404 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405}
1406
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001407static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408{
Al Viro8687b632006-10-19 23:28:48 -07001409 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
1411 RESERVE_SPACE(12);
1412 WRITE32(OP_RENEW);
1413 WRITE64(client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001414 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001415 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416}
1417
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001418static void
Andy Adamsond0179312008-12-23 16:06:17 -05001419encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001420{
Al Viro8687b632006-10-19 23:28:48 -07001421 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001422
1423 RESERVE_SPACE(4);
1424 WRITE32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001425 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001426 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001427}
1428
1429static int
Andy Adamsond0179312008-12-23 16:06:17 -05001430encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001431{
Al Viro8687b632006-10-19 23:28:48 -07001432 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001433
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001434 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001435 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001436 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001437 RESERVE_SPACE(2*4);
1438 WRITE32(1);
1439 WRITE32(FATTR4_WORD0_ACL);
1440 if (arg->acl_len % 4)
1441 return -EINVAL;
1442 RESERVE_SPACE(4);
1443 WRITE32(arg->acl_len);
1444 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001445 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001446 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001447 return 0;
1448}
1449
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001450static void
Andy Adamsond0179312008-12-23 16:06:17 -05001451encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452{
Al Viro8687b632006-10-19 23:28:48 -07001453 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
1455 RESERVE_SPACE(4);
1456 WRITE32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001457 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001458 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459}
1460
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001461static 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 -07001462{
Al Viro8687b632006-10-19 23:28:48 -07001463 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001464
Andy Adamson05d564f2008-12-23 16:06:15 -05001465 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1466 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001467 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001468 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001469 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001470 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471}
1472
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001473static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474{
Al Viro8687b632006-10-19 23:28:48 -07001475 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001477 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 WRITE32(OP_SETCLIENTID);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001479 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
1481 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1482 RESERVE_SPACE(4);
1483 WRITE32(setclientid->sc_prog);
1484 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1485 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1486 RESERVE_SPACE(4);
1487 WRITE32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001488 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001489 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490}
1491
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001492static 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 -07001493{
Andy Adamson05d564f2008-12-23 16:06:15 -05001494 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
Andy Adamson05d564f2008-12-23 16:06:15 -05001496 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1497 WRITE32(OP_SETCLIENTID_CONFIRM);
1498 WRITE64(client_state->cl_clientid);
1499 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001500 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001501 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502}
1503
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001504static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505{
Al Viro8687b632006-10-19 23:28:48 -07001506 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
1508 RESERVE_SPACE(4);
1509 WRITE32(OP_WRITE);
1510
1511 encode_stateid(xdr, args->context);
1512
1513 RESERVE_SPACE(16);
1514 WRITE64(args->offset);
1515 WRITE32(args->stable);
1516 WRITE32(args->count);
1517
1518 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001519 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001520 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521}
1522
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001523static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524{
Al Viro8687b632006-10-19 23:28:48 -07001525 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001527 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
1529 WRITE32(OP_DELEGRETURN);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001530 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001531 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001532 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001534
Benny Halevy99fe60d2009-04-01 09:22:29 -04001535#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001536/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001537static void encode_exchange_id(struct xdr_stream *xdr,
1538 struct nfs41_exchange_id_args *args,
1539 struct compound_hdr *hdr)
1540{
1541 __be32 *p;
1542
1543 RESERVE_SPACE(4 + sizeof(args->verifier->data));
1544 WRITE32(OP_EXCHANGE_ID);
1545 WRITEMEM(args->verifier->data, sizeof(args->verifier->data));
1546
1547 encode_string(xdr, args->id_len, args->id);
1548
1549 RESERVE_SPACE(12);
1550 WRITE32(args->flags);
1551 WRITE32(0); /* zero length state_protect4_a */
1552 WRITE32(0); /* zero length implementation id array */
1553 hdr->nops++;
1554 hdr->replen += decode_exchange_id_maxsz;
1555}
Andy Adamsonfc931582009-04-01 09:22:31 -04001556
1557static void encode_create_session(struct xdr_stream *xdr,
1558 struct nfs41_create_session_args *args,
1559 struct compound_hdr *hdr)
1560{
1561 __be32 *p;
1562 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1563 uint32_t len;
1564 struct nfs_client *clp = args->client;
1565
1566 RESERVE_SPACE(4);
1567 WRITE32(OP_CREATE_SESSION);
1568
1569 RESERVE_SPACE(8);
1570 WRITE64(clp->cl_ex_clid);
1571
1572 RESERVE_SPACE(8);
1573 WRITE32(clp->cl_seqid); /*Sequence id */
1574 WRITE32(args->flags); /*flags */
1575
1576 RESERVE_SPACE(2*28); /* 2 channel_attrs */
1577 /* Fore Channel */
1578 WRITE32(args->fc_attrs.headerpadsz); /* header padding size */
1579 WRITE32(args->fc_attrs.max_rqst_sz); /* max req size */
1580 WRITE32(args->fc_attrs.max_resp_sz); /* max resp size */
1581 WRITE32(args->fc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1582 WRITE32(args->fc_attrs.max_ops); /* max operations */
1583 WRITE32(args->fc_attrs.max_reqs); /* max requests */
1584 WRITE32(0); /* rdmachannel_attrs */
1585
1586 /* Back Channel */
1587 WRITE32(args->fc_attrs.headerpadsz); /* header padding size */
1588 WRITE32(args->bc_attrs.max_rqst_sz); /* max req size */
1589 WRITE32(args->bc_attrs.max_resp_sz); /* max resp size */
1590 WRITE32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1591 WRITE32(args->bc_attrs.max_ops); /* max operations */
1592 WRITE32(args->bc_attrs.max_reqs); /* max requests */
1593 WRITE32(0); /* rdmachannel_attrs */
1594
1595 RESERVE_SPACE(4);
1596 WRITE32(args->cb_program); /* cb_program */
1597
1598 RESERVE_SPACE(4); /* # of security flavors */
1599 WRITE32(1);
1600
1601 RESERVE_SPACE(4);
1602 WRITE32(RPC_AUTH_UNIX); /* auth_sys */
1603
1604 /* authsys_parms rfc1831 */
1605 RESERVE_SPACE(4);
1606 WRITE32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
1607 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1608 clp->cl_ipaddr);
1609 RESERVE_SPACE(16 + len);
1610 WRITE32(len);
1611 WRITEMEM(machine_name, len);
1612 WRITE32(0); /* UID */
1613 WRITE32(0); /* GID */
1614 WRITE32(0); /* No more gids */
1615 hdr->nops++;
1616 hdr->replen += decode_create_session_maxsz;
1617}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001618
1619static void encode_destroy_session(struct xdr_stream *xdr,
1620 struct nfs4_session *session,
1621 struct compound_hdr *hdr)
1622{
1623 __be32 *p;
1624 RESERVE_SPACE(4 + NFS4_MAX_SESSIONID_LEN);
1625 WRITE32(OP_DESTROY_SESSION);
1626 WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1627 hdr->nops++;
1628 hdr->replen += decode_destroy_session_maxsz;
1629}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001630#endif /* CONFIG_NFS_V4_1 */
1631
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001632static void encode_sequence(struct xdr_stream *xdr,
1633 const struct nfs4_sequence_args *args,
1634 struct compound_hdr *hdr)
1635{
1636#if defined(CONFIG_NFS_V4_1)
1637 struct nfs4_session *session = args->sa_session;
1638
1639 if (!session)
1640 return;
1641
1642 /* stub */
1643 hdr->nops++;
1644 hdr->replen += decode_sequence_maxsz;
1645#endif /* CONFIG_NFS_V4_1 */
1646}
1647
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648/*
1649 * END OF "GENERIC" ENCODE ROUTINES.
1650 */
1651
Benny Halevy66cc0422009-04-01 09:22:10 -04001652static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1653{
1654#if defined(CONFIG_NFS_V4_1)
1655 if (args->sa_session)
1656 return args->sa_session->clp->cl_minorversion;
1657#endif /* CONFIG_NFS_V4_1 */
1658 return 0;
1659}
1660
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661/*
1662 * Encode an ACCESS request
1663 */
Al Viro8687b632006-10-19 23:28:48 -07001664static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665{
1666 struct xdr_stream xdr;
1667 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001668 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
1671 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001672 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001673 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001674 encode_putfh(&xdr, args->fh, &hdr);
1675 encode_access(&xdr, args->access, &hdr);
1676 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001677 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001678 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679}
1680
1681/*
1682 * Encode LOOKUP request
1683 */
Al Viro8687b632006-10-19 23:28:48 -07001684static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685{
1686 struct xdr_stream xdr;
1687 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001688 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690
1691 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001692 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001693 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001694 encode_putfh(&xdr, args->dir_fh, &hdr);
1695 encode_lookup(&xdr, args->name, &hdr);
1696 encode_getfh(&xdr, &hdr);
1697 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001698 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001699 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700}
1701
1702/*
1703 * Encode LOOKUP_ROOT request
1704 */
Al Viro8687b632006-10-19 23:28:48 -07001705static 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 -07001706{
1707 struct xdr_stream xdr;
1708 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001709 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
1712 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001713 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001714 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001715 encode_putrootfh(&xdr, &hdr);
1716 encode_getfh(&xdr, &hdr);
1717 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001718 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001719 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720}
1721
1722/*
1723 * Encode REMOVE request
1724 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001725static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726{
1727 struct xdr_stream xdr;
1728 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001729 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
1732 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001733 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001734 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001735 encode_putfh(&xdr, args->fh, &hdr);
1736 encode_remove(&xdr, &args->name, &hdr);
1737 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001738 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001739 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740}
1741
1742/*
1743 * Encode RENAME request
1744 */
Al Viro8687b632006-10-19 23:28:48 -07001745static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746{
1747 struct xdr_stream xdr;
1748 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001749 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
1752 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001753 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001754 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001755 encode_putfh(&xdr, args->old_dir, &hdr);
1756 encode_savefh(&xdr, &hdr);
1757 encode_putfh(&xdr, args->new_dir, &hdr);
1758 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1759 encode_getfattr(&xdr, args->bitmask, &hdr);
1760 encode_restorefh(&xdr, &hdr);
1761 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001762 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001763 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764}
1765
1766/*
1767 * Encode LINK request
1768 */
Al Viro8687b632006-10-19 23:28:48 -07001769static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770{
1771 struct xdr_stream xdr;
1772 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001773 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775
1776 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001777 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001778 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001779 encode_putfh(&xdr, args->fh, &hdr);
1780 encode_savefh(&xdr, &hdr);
1781 encode_putfh(&xdr, args->dir_fh, &hdr);
1782 encode_link(&xdr, args->name, &hdr);
1783 encode_getfattr(&xdr, args->bitmask, &hdr);
1784 encode_restorefh(&xdr, &hdr);
1785 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001786 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001787 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788}
1789
1790/*
1791 * Encode CREATE request
1792 */
Al Viro8687b632006-10-19 23:28:48 -07001793static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794{
1795 struct xdr_stream xdr;
1796 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001797 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799
1800 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001801 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001802 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001803 encode_putfh(&xdr, args->dir_fh, &hdr);
1804 encode_savefh(&xdr, &hdr);
1805 encode_create(&xdr, args, &hdr);
1806 encode_getfh(&xdr, &hdr);
1807 encode_getfattr(&xdr, args->bitmask, &hdr);
1808 encode_restorefh(&xdr, &hdr);
1809 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001810 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001811 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812}
1813
1814/*
1815 * Encode SYMLINK request
1816 */
Al Viro8687b632006-10-19 23:28:48 -07001817static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818{
1819 return nfs4_xdr_enc_create(req, p, args);
1820}
1821
1822/*
1823 * Encode GETATTR request
1824 */
Al Viro8687b632006-10-19 23:28:48 -07001825static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826{
1827 struct xdr_stream xdr;
1828 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001829 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
1832 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001833 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001834 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001835 encode_putfh(&xdr, args->fh, &hdr);
1836 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001837 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001838 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839}
1840
1841/*
1842 * Encode a CLOSE request
1843 */
Al Viro8687b632006-10-19 23:28:48 -07001844static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845{
Andy Adamson05d564f2008-12-23 16:06:15 -05001846 struct xdr_stream xdr;
1847 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001848 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001849 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850
Andy Adamson05d564f2008-12-23 16:06:15 -05001851 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001852 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001853 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001854 encode_putfh(&xdr, args->fh, &hdr);
1855 encode_close(&xdr, args, &hdr);
1856 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001857 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001858 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859}
1860
1861/*
1862 * Encode an OPEN request
1863 */
Al Viro8687b632006-10-19 23:28:48 -07001864static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865{
1866 struct xdr_stream xdr;
1867 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001868 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
1871 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001872 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001873 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001874 encode_putfh(&xdr, args->fh, &hdr);
1875 encode_savefh(&xdr, &hdr);
1876 encode_open(&xdr, args, &hdr);
1877 encode_getfh(&xdr, &hdr);
1878 encode_getfattr(&xdr, args->bitmask, &hdr);
1879 encode_restorefh(&xdr, &hdr);
1880 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001881 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001882 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883}
1884
1885/*
1886 * Encode an OPEN_CONFIRM request
1887 */
Al Viro8687b632006-10-19 23:28:48 -07001888static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889{
1890 struct xdr_stream xdr;
1891 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001892 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894
1895 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001896 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001897 encode_putfh(&xdr, args->fh, &hdr);
1898 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001899 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001900 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901}
1902
1903/*
1904 * Encode an OPEN request with no attributes.
1905 */
Al Viro8687b632006-10-19 23:28:48 -07001906static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907{
1908 struct xdr_stream xdr;
1909 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001910 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
1913 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001914 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001915 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001916 encode_putfh(&xdr, args->fh, &hdr);
1917 encode_open(&xdr, args, &hdr);
1918 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001919 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001920 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921}
1922
1923/*
1924 * Encode an OPEN_DOWNGRADE request
1925 */
Al Viro8687b632006-10-19 23:28:48 -07001926static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927{
1928 struct xdr_stream xdr;
1929 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001930 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
1933 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001934 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001935 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001936 encode_putfh(&xdr, args->fh, &hdr);
1937 encode_open_downgrade(&xdr, args, &hdr);
1938 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001939 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001940 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941}
1942
1943/*
1944 * Encode a LOCK request
1945 */
Al Viro8687b632006-10-19 23:28:48 -07001946static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947{
1948 struct xdr_stream xdr;
1949 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001950 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952
1953 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001954 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001955 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001956 encode_putfh(&xdr, args->fh, &hdr);
1957 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001958 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001959 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960}
1961
1962/*
1963 * Encode a LOCKT request
1964 */
Al Viro8687b632006-10-19 23:28:48 -07001965static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966{
1967 struct xdr_stream xdr;
1968 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001969 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971
1972 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001973 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001974 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001975 encode_putfh(&xdr, args->fh, &hdr);
1976 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001977 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001978 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979}
1980
1981/*
1982 * Encode a LOCKU request
1983 */
Al Viro8687b632006-10-19 23:28:48 -07001984static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985{
1986 struct xdr_stream xdr;
1987 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001988 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
1991 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001992 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001993 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001994 encode_putfh(&xdr, args->fh, &hdr);
1995 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001996 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001997 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998}
1999
2000/*
2001 * Encode a READLINK request
2002 */
Al Viro8687b632006-10-19 23:28:48 -07002003static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004{
2005 struct xdr_stream xdr;
2006 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002007 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009
2010 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002011 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002012 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002013 encode_putfh(&xdr, args->fh, &hdr);
2014 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002015
Benny Halevy28f56692009-04-01 09:22:09 -04002016 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002017 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002018 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002019 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020}
2021
2022/*
2023 * Encode a READDIR request
2024 */
Al Viro8687b632006-10-19 23:28:48 -07002025static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026{
2027 struct xdr_stream xdr;
2028 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002029 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
2032 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002033 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002034 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002035 encode_putfh(&xdr, args->fh, &hdr);
2036 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002037
Benny Halevy28f56692009-04-01 09:22:09 -04002038 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002039 args->pgbase, args->count);
2040 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002041 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002042 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002043 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002044 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045}
2046
2047/*
2048 * Encode a READ request
2049 */
Al Viro8687b632006-10-19 23:28:48 -07002050static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 struct xdr_stream xdr;
2053 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002054 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056
2057 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002058 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002059 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002060 encode_putfh(&xdr, args->fh, &hdr);
2061 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
Benny Halevy28f56692009-04-01 09:22:09 -04002063 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002065 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002066 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002067 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068}
2069
2070/*
2071 * Encode an SETATTR request
2072 */
Al Viro8687b632006-10-19 23:28:48 -07002073static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074{
Andy Adamson05d564f2008-12-23 16:06:15 -05002075 struct xdr_stream xdr;
2076 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002077 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002078 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079
Andy Adamson05d564f2008-12-23 16:06:15 -05002080 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002081 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002082 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002083 encode_putfh(&xdr, args->fh, &hdr);
2084 encode_setattr(&xdr, args, args->server, &hdr);
2085 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002086 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002087 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088}
2089
2090/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002091 * Encode a GETACL request
2092 */
2093static int
Al Viro8687b632006-10-19 23:28:48 -07002094nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002095 struct nfs_getaclargs *args)
2096{
2097 struct xdr_stream xdr;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002098 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002099 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002100 };
Benny Halevy28f56692009-04-01 09:22:09 -04002101 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002102
2103 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002104 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002105 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002106 encode_putfh(&xdr, args->fh, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002107 replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002108 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2109
Benny Halevy28f56692009-04-01 09:22:09 -04002110 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002111 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002112 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002113 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002114}
2115
2116/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 * Encode a WRITE request
2118 */
Al Viro8687b632006-10-19 23:28:48 -07002119static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120{
2121 struct xdr_stream xdr;
2122 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002123 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125
2126 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002127 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002128 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002129 encode_putfh(&xdr, args->fh, &hdr);
2130 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002131 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002132 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002133 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002134 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135}
2136
2137/*
2138 * a COMMIT request
2139 */
Al Viro8687b632006-10-19 23:28:48 -07002140static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141{
2142 struct xdr_stream xdr;
2143 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002144 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146
2147 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002148 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002149 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002150 encode_putfh(&xdr, args->fh, &hdr);
2151 encode_commit(&xdr, args, &hdr);
2152 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002153 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002154 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155}
2156
2157/*
2158 * FSINFO request
2159 */
Al Viro8687b632006-10-19 23:28:48 -07002160static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161{
2162 struct xdr_stream xdr;
2163 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002164 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
2167 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002168 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002169 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002170 encode_putfh(&xdr, args->fh, &hdr);
2171 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002172 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002173 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174}
2175
2176/*
2177 * a PATHCONF request
2178 */
Al Viro8687b632006-10-19 23:28:48 -07002179static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 struct xdr_stream xdr;
2182 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002183 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185
2186 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002187 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002188 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002189 encode_putfh(&xdr, args->fh, &hdr);
2190 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2191 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002192 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002193 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194}
2195
2196/*
2197 * a STATFS request
2198 */
Al Viro8687b632006-10-19 23:28:48 -07002199static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 struct xdr_stream xdr;
2202 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002203 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205
2206 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002207 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002208 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002209 encode_putfh(&xdr, args->fh, &hdr);
2210 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2211 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002212 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002213 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214}
2215
2216/*
2217 * GETATTR_BITMAP request
2218 */
Benny Halevy43652ad2009-04-01 09:21:54 -04002219static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2220 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221{
2222 struct xdr_stream xdr;
2223 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002224 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
2227 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002228 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002229 encode_sequence(&xdr, &args->seq_args, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04002230 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002231 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2232 FATTR4_WORD0_LINK_SUPPORT|
2233 FATTR4_WORD0_SYMLINK_SUPPORT|
2234 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002235 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002236 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237}
2238
2239/*
2240 * a RENEW request
2241 */
Al Viro8687b632006-10-19 23:28:48 -07002242static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243{
2244 struct xdr_stream xdr;
2245 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002246 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 };
2248
2249 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002250 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002251 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002252 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002253 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254}
2255
2256/*
2257 * a SETCLIENTID request
2258 */
Al Viro8687b632006-10-19 23:28:48 -07002259static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260{
2261 struct xdr_stream xdr;
2262 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002263 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 };
2265
2266 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002267 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002268 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002269 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002270 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271}
2272
2273/*
2274 * a SETCLIENTID_CONFIRM request
2275 */
Al Viro8687b632006-10-19 23:28:48 -07002276static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277{
2278 struct xdr_stream xdr;
2279 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002280 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 };
2282 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283
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_setclientid_confirm(&xdr, clp, &hdr);
2287 encode_putrootfh(&xdr, &hdr);
2288 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002289 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002290 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291}
2292
2293/*
2294 * DELEGRETURN request
2295 */
Al Viro8687b632006-10-19 23:28:48 -07002296static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297{
2298 struct xdr_stream xdr;
2299 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002300 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302
2303 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002304 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002305 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002306 encode_putfh(&xdr, args->fhandle, &hdr);
2307 encode_delegreturn(&xdr, args->stateid, &hdr);
2308 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002309 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002310 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311}
2312
2313/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002314 * Encode FS_LOCATIONS request
2315 */
Al Viro8687b632006-10-19 23:28:48 -07002316static 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 -04002317{
2318 struct xdr_stream xdr;
2319 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002320 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002321 };
Benny Halevy28f56692009-04-01 09:22:09 -04002322 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002323
2324 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002325 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002326 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002327 encode_putfh(&xdr, args->dir_fh, &hdr);
2328 encode_lookup(&xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002329 replen = hdr.replen; /* get the attribute into args->page */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002330 encode_fs_locations(&xdr, args->bitmask, &hdr);
2331
Benny Halevy28f56692009-04-01 09:22:09 -04002332 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002333 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002334 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002335 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002336}
2337
Benny Halevy99fe60d2009-04-01 09:22:29 -04002338#if defined(CONFIG_NFS_V4_1)
2339/*
2340 * EXCHANGE_ID request
2341 */
2342static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2343 struct nfs41_exchange_id_args *args)
2344{
2345 struct xdr_stream xdr;
2346 struct compound_hdr hdr = {
2347 .minorversion = args->client->cl_minorversion,
2348 };
2349
2350 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2351 encode_compound_hdr(&xdr, req, &hdr);
2352 encode_exchange_id(&xdr, args, &hdr);
2353 encode_nops(&hdr);
2354 return 0;
2355}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002356
2357/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002358 * a CREATE_SESSION request
2359 */
2360static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2361 struct nfs41_create_session_args *args)
2362{
2363 struct xdr_stream xdr;
2364 struct compound_hdr hdr = {
2365 .minorversion = args->client->cl_minorversion,
2366 };
2367
2368 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2369 encode_compound_hdr(&xdr, req, &hdr);
2370 encode_create_session(&xdr, args, &hdr);
2371 encode_nops(&hdr);
2372 return 0;
2373}
2374
2375/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002376 * a DESTROY_SESSION request
2377 */
2378static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2379 struct nfs4_session *session)
2380{
2381 struct xdr_stream xdr;
2382 struct compound_hdr hdr = {
2383 .minorversion = session->clp->cl_minorversion,
2384 };
2385
2386 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2387 encode_compound_hdr(&xdr, req, &hdr);
2388 encode_destroy_session(&xdr, session, &hdr);
2389 encode_nops(&hdr);
2390 return 0;
2391}
2392
2393/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002394 * a GET_LEASE_TIME request
2395 */
2396static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2397 struct nfs4_get_lease_time_args *args)
2398{
2399 struct xdr_stream xdr;
2400 struct compound_hdr hdr = {
2401 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2402 };
2403 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2404
2405 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2406 encode_compound_hdr(&xdr, req, &hdr);
2407 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2408 encode_putrootfh(&xdr, &hdr);
2409 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2410 encode_nops(&hdr);
2411 return 0;
2412}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002413#endif /* CONFIG_NFS_V4_1 */
2414
Trond Myklebust683b57b2006-06-09 09:34:22 -04002415/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 * START OF "GENERIC" DECODE ROUTINES.
2417 * These may look a little ugly since they are imported from a "generic"
2418 * set of XDR encode/decode routines which are intended to be shared by
2419 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2420 *
2421 * If the pain of reading these is too great, it should be a straightforward
2422 * task to translate them into Linux-specific versions which are more
2423 * consistent with the style used in NFSv2/v3...
2424 */
2425#define READ32(x) (x) = ntohl(*p++)
2426#define READ64(x) do { \
2427 (x) = (u64)ntohl(*p++) << 32; \
2428 (x) |= ntohl(*p++); \
2429} while (0)
2430#define READTIME(x) do { \
2431 p++; \
2432 (x.tv_sec) = ntohl(*p++); \
2433 (x.tv_nsec) = ntohl(*p++); \
2434} while (0)
2435#define COPYMEM(x,nbytes) do { \
2436 memcpy((x), p, nbytes); \
2437 p += XDR_QUADLEN(nbytes); \
2438} while (0)
2439
2440#define READ_BUF(nbytes) do { \
2441 p = xdr_inline_decode(xdr, nbytes); \
Chuck Levere4cc6ee2007-05-08 18:23:28 -04002442 if (unlikely(!p)) { \
Chuck Leverfe82a182007-09-11 18:01:10 -04002443 dprintk("nfs: %s: prematurely hit end of receive" \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002444 " buffer\n", __func__); \
Chuck Leverfe82a182007-09-11 18:01:10 -04002445 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002446 __func__, xdr->p, nbytes, xdr->end); \
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 return -EIO; \
2448 } \
2449} while (0)
2450
Trond Myklebust683b57b2006-06-09 09:34:22 -04002451static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452{
Al Viro8687b632006-10-19 23:28:48 -07002453 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454
2455 READ_BUF(4);
2456 READ32(*len);
2457 READ_BUF(*len);
2458 *string = (char *)p;
2459 return 0;
2460}
2461
2462static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2463{
Al Viro8687b632006-10-19 23:28:48 -07002464 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465
2466 READ_BUF(8);
2467 READ32(hdr->status);
2468 READ32(hdr->taglen);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002469
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 READ_BUF(hdr->taglen + 4);
2471 hdr->tag = (char *)p;
2472 p += XDR_QUADLEN(hdr->taglen);
2473 READ32(hdr->nops);
Benny Halevyaadf6152008-12-23 16:06:13 -05002474 if (unlikely(hdr->nops < 1))
2475 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 return 0;
2477}
2478
2479static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2480{
Al Viro8687b632006-10-19 23:28:48 -07002481 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 uint32_t opnum;
2483 int32_t nfserr;
2484
2485 READ_BUF(8);
2486 READ32(opnum);
2487 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002488 dprintk("nfs: Server returned operation"
2489 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 opnum, expected);
2491 return -EIO;
2492 }
2493 READ32(nfserr);
2494 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002495 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 return 0;
2497}
2498
2499/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002500static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501{
Al Viro8687b632006-10-19 23:28:48 -07002502 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002503 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 char *str;
2505
2506 READ_BUF(12);
2507 return decode_opaque_inline(xdr, &strlen, &str);
2508}
2509
2510static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2511{
Al Viro8687b632006-10-19 23:28:48 -07002512 uint32_t bmlen;
2513 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514
2515 READ_BUF(4);
2516 READ32(bmlen);
2517
2518 bitmap[0] = bitmap[1] = 0;
2519 READ_BUF((bmlen << 2));
2520 if (bmlen > 0) {
2521 READ32(bitmap[0]);
2522 if (bmlen > 1)
2523 READ32(bitmap[1]);
2524 }
2525 return 0;
2526}
2527
Al Viro8687b632006-10-19 23:28:48 -07002528static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529{
Al Viro8687b632006-10-19 23:28:48 -07002530 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
2532 READ_BUF(4);
2533 READ32(*attrlen);
2534 *savep = xdr->p;
2535 return 0;
2536}
2537
2538static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2539{
2540 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2541 decode_attr_bitmap(xdr, bitmask);
2542 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2543 } else
2544 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002545 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 return 0;
2547}
2548
2549static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2550{
Al Viro8687b632006-10-19 23:28:48 -07002551 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002552 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553
2554 *type = 0;
2555 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2556 return -EIO;
2557 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2558 READ_BUF(4);
2559 READ32(*type);
2560 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002561 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 return -EIO;
2563 }
2564 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002565 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002567 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002568 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569}
2570
2571static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2572{
Al Viro8687b632006-10-19 23:28:48 -07002573 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002574 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575
2576 *change = 0;
2577 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2578 return -EIO;
2579 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2580 READ_BUF(8);
2581 READ64(*change);
2582 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002583 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002585 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002587 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588}
2589
2590static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2591{
Al Viro8687b632006-10-19 23:28:48 -07002592 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002593 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594
2595 *size = 0;
2596 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2597 return -EIO;
2598 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2599 READ_BUF(8);
2600 READ64(*size);
2601 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002602 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002604 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002605 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606}
2607
2608static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2609{
Al Viro8687b632006-10-19 23:28:48 -07002610 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611
2612 *res = 0;
2613 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2614 return -EIO;
2615 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2616 READ_BUF(4);
2617 READ32(*res);
2618 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2619 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002620 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 return 0;
2622}
2623
2624static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2625{
Al Viro8687b632006-10-19 23:28:48 -07002626 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627
2628 *res = 0;
2629 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2630 return -EIO;
2631 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2632 READ_BUF(4);
2633 READ32(*res);
2634 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2635 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002636 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 return 0;
2638}
2639
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002640static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641{
Al Viro8687b632006-10-19 23:28:48 -07002642 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002643 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
2645 fsid->major = 0;
2646 fsid->minor = 0;
2647 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2648 return -EIO;
2649 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2650 READ_BUF(16);
2651 READ64(fsid->major);
2652 READ64(fsid->minor);
2653 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002654 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002656 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 (unsigned long long)fsid->major,
2658 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002659 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660}
2661
2662static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2663{
Al Viro8687b632006-10-19 23:28:48 -07002664 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665
2666 *res = 60;
2667 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2668 return -EIO;
2669 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2670 READ_BUF(4);
2671 READ32(*res);
2672 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2673 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002674 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 return 0;
2676}
2677
2678static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2679{
Al Viro8687b632006-10-19 23:28:48 -07002680 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681
2682 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2683 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2684 return -EIO;
2685 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2686 READ_BUF(4);
2687 READ32(*res);
2688 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2689 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002690 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 return 0;
2692}
2693
2694static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2695{
Al Viro8687b632006-10-19 23:28:48 -07002696 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002697 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
2699 *fileid = 0;
2700 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2701 return -EIO;
2702 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2703 READ_BUF(8);
2704 READ64(*fileid);
2705 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002706 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002708 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002709 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710}
2711
Manoj Naik99baf622006-06-09 09:34:24 -04002712static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2713{
Al Viro8687b632006-10-19 23:28:48 -07002714 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002715 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002716
2717 *fileid = 0;
2718 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2719 return -EIO;
2720 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2721 READ_BUF(8);
2722 READ64(*fileid);
2723 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002724 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002725 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002726 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002727 return ret;
Manoj Naik99baf622006-06-09 09:34:24 -04002728}
2729
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2731{
Al Viro8687b632006-10-19 23:28:48 -07002732 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 int status = 0;
2734
2735 *res = 0;
2736 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2737 return -EIO;
2738 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2739 READ_BUF(8);
2740 READ64(*res);
2741 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2742 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002743 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 return status;
2745}
2746
2747static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2748{
Al Viro8687b632006-10-19 23:28:48 -07002749 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 int status = 0;
2751
2752 *res = 0;
2753 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2754 return -EIO;
2755 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2756 READ_BUF(8);
2757 READ64(*res);
2758 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2759 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002760 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 return status;
2762}
2763
2764static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2765{
Al Viro8687b632006-10-19 23:28:48 -07002766 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 int status = 0;
2768
2769 *res = 0;
2770 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2771 return -EIO;
2772 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2773 READ_BUF(8);
2774 READ64(*res);
2775 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2776 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002777 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 return status;
2779}
2780
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002781static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2782{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002783 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002784 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002785 int status = 0;
2786
2787 READ_BUF(4);
2788 READ32(n);
Andy Adamson33a43f22006-06-09 09:34:30 -04002789 if (n == 0)
2790 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002791 dprintk("path ");
2792 path->ncomponents = 0;
2793 while (path->ncomponents < n) {
2794 struct nfs4_string *component = &path->components[path->ncomponents];
2795 status = decode_opaque_inline(xdr, &component->len, &component->data);
2796 if (unlikely(status != 0))
2797 goto out_eio;
2798 if (path->ncomponents != n)
2799 dprintk("/");
2800 dprintk("%s", component->data);
2801 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2802 path->ncomponents++;
2803 else {
2804 dprintk("cannot parse %d components in path\n", n);
2805 goto out_eio;
2806 }
2807 }
2808out:
2809 dprintk("\n");
2810 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002811root_path:
2812/* a root pathname is sent as a zero component4 */
2813 path->ncomponents = 1;
2814 path->components[0].len=0;
2815 path->components[0].data=NULL;
2816 dprintk("path /\n");
2817 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002818out_eio:
2819 dprintk(" status %d", status);
2820 status = -EIO;
2821 goto out;
2822}
2823
2824static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002825{
2826 int n;
Al Viro8687b632006-10-19 23:28:48 -07002827 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002828 int status = -EIO;
2829
2830 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2831 goto out;
2832 status = 0;
2833 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2834 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002835 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002836 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002837 if (unlikely(status != 0))
2838 goto out;
2839 READ_BUF(4);
2840 READ32(n);
2841 if (n <= 0)
2842 goto out_eio;
2843 res->nlocations = 0;
2844 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002845 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002846 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04002847
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002848 READ_BUF(4);
2849 READ32(m);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002850
2851 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002852 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002853 while (loc->nservers < m) {
2854 struct nfs4_string *server = &loc->servers[loc->nservers];
2855 status = decode_opaque_inline(xdr, &server->len, &server->data);
2856 if (unlikely(status != 0))
2857 goto out_eio;
2858 dprintk("%s ", server->data);
2859 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2860 loc->nservers++;
2861 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002862 unsigned int i;
2863 dprintk("%s: using first %u of %u servers "
2864 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002865 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04002866 NFS4_FS_LOCATION_MAXSERVERS,
2867 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002868 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002869 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002870 char *data;
2871 status = decode_opaque_inline(xdr, &len, &data);
2872 if (unlikely(status != 0))
2873 goto out_eio;
2874 }
2875 }
2876 }
2877 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002878 if (unlikely(status != 0))
2879 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002880 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002881 res->nlocations++;
2882 }
Trond Myklebust409924e2009-03-11 14:10:27 -04002883 if (res->nlocations != 0)
2884 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002885out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002886 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002887 return status;
2888out_eio:
2889 status = -EIO;
2890 goto out;
2891}
2892
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2894{
Al Viro8687b632006-10-19 23:28:48 -07002895 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 int status = 0;
2897
2898 *res = 0;
2899 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2900 return -EIO;
2901 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2902 READ_BUF(8);
2903 READ64(*res);
2904 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2905 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002906 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 return status;
2908}
2909
2910static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2911{
Al Viro8687b632006-10-19 23:28:48 -07002912 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 int status = 0;
2914
2915 *maxlink = 1;
2916 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2917 return -EIO;
2918 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2919 READ_BUF(4);
2920 READ32(*maxlink);
2921 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2922 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002923 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 return status;
2925}
2926
2927static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2928{
Al Viro8687b632006-10-19 23:28:48 -07002929 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 int status = 0;
2931
2932 *maxname = 1024;
2933 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2934 return -EIO;
2935 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2936 READ_BUF(4);
2937 READ32(*maxname);
2938 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2939 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002940 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 return status;
2942}
2943
2944static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2945{
Al Viro8687b632006-10-19 23:28:48 -07002946 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 int status = 0;
2948
2949 *res = 1024;
2950 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2951 return -EIO;
2952 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2953 uint64_t maxread;
2954 READ_BUF(8);
2955 READ64(maxread);
2956 if (maxread > 0x7FFFFFFF)
2957 maxread = 0x7FFFFFFF;
2958 *res = (uint32_t)maxread;
2959 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2960 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002961 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 return status;
2963}
2964
2965static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2966{
Al Viro8687b632006-10-19 23:28:48 -07002967 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 int status = 0;
2969
2970 *res = 1024;
2971 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2972 return -EIO;
2973 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2974 uint64_t maxwrite;
2975 READ_BUF(8);
2976 READ64(maxwrite);
2977 if (maxwrite > 0x7FFFFFFF)
2978 maxwrite = 0x7FFFFFFF;
2979 *res = (uint32_t)maxwrite;
2980 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2981 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002982 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 return status;
2984}
2985
Trond Myklebustbca79472009-03-11 14:10:26 -04002986static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987{
Trond Myklebustbca79472009-03-11 14:10:26 -04002988 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07002989 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002990 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991
2992 *mode = 0;
2993 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2994 return -EIO;
2995 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2996 READ_BUF(4);
Trond Myklebustbca79472009-03-11 14:10:26 -04002997 READ32(tmp);
2998 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003000 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003002 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003003 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004}
3005
3006static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3007{
Al Viro8687b632006-10-19 23:28:48 -07003008 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003009 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010
3011 *nlink = 1;
3012 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3013 return -EIO;
3014 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3015 READ_BUF(4);
3016 READ32(*nlink);
3017 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003018 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003020 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003021 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022}
3023
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003024static 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 -07003025{
Al Viro8687b632006-10-19 23:28:48 -07003026 uint32_t len;
3027 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003028 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029
3030 *uid = -2;
3031 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3032 return -EIO;
3033 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3034 READ_BUF(4);
3035 READ32(len);
3036 READ_BUF(len);
3037 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003038 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3039 ret = NFS_ATTR_FATTR_OWNER;
3040 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003042 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003044 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003045 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3047 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003048 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003049 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050}
3051
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003052static 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 -07003053{
Al Viro8687b632006-10-19 23:28:48 -07003054 uint32_t len;
3055 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003056 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057
3058 *gid = -2;
3059 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3060 return -EIO;
3061 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3062 READ_BUF(4);
3063 READ32(len);
3064 READ_BUF(len);
3065 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003066 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3067 ret = NFS_ATTR_FATTR_GROUP;
3068 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003070 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003072 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003073 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3075 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003076 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003077 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078}
3079
3080static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3081{
Al Viro8687b632006-10-19 23:28:48 -07003082 uint32_t major = 0, minor = 0;
3083 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003084 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085
3086 *rdev = MKDEV(0,0);
3087 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3088 return -EIO;
3089 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3090 dev_t tmp;
3091
3092 READ_BUF(8);
3093 READ32(major);
3094 READ32(minor);
3095 tmp = MKDEV(major, minor);
3096 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3097 *rdev = tmp;
3098 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003099 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003101 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003102 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103}
3104
3105static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3106{
Al Viro8687b632006-10-19 23:28:48 -07003107 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 int status = 0;
3109
3110 *res = 0;
3111 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3112 return -EIO;
3113 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3114 READ_BUF(8);
3115 READ64(*res);
3116 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3117 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003118 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 return status;
3120}
3121
3122static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3123{
Al Viro8687b632006-10-19 23:28:48 -07003124 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125 int status = 0;
3126
3127 *res = 0;
3128 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3129 return -EIO;
3130 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3131 READ_BUF(8);
3132 READ64(*res);
3133 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3134 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003135 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 return status;
3137}
3138
3139static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3140{
Al Viro8687b632006-10-19 23:28:48 -07003141 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 int status = 0;
3143
3144 *res = 0;
3145 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3146 return -EIO;
3147 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3148 READ_BUF(8);
3149 READ64(*res);
3150 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3151 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003152 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 return status;
3154}
3155
3156static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3157{
Al Viro8687b632006-10-19 23:28:48 -07003158 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003159 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160
3161 *used = 0;
3162 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3163 return -EIO;
3164 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3165 READ_BUF(8);
3166 READ64(*used);
3167 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003168 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003170 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003172 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173}
3174
3175static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3176{
Al Viro8687b632006-10-19 23:28:48 -07003177 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 uint64_t sec;
3179 uint32_t nsec;
3180
3181 READ_BUF(12);
3182 READ64(sec);
3183 READ32(nsec);
3184 time->tv_sec = (time_t)sec;
3185 time->tv_nsec = (long)nsec;
3186 return 0;
3187}
3188
3189static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3190{
3191 int status = 0;
3192
3193 time->tv_sec = 0;
3194 time->tv_nsec = 0;
3195 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3196 return -EIO;
3197 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3198 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003199 if (status == 0)
3200 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3202 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003203 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 return status;
3205}
3206
3207static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3208{
3209 int status = 0;
3210
3211 time->tv_sec = 0;
3212 time->tv_nsec = 0;
3213 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3214 return -EIO;
3215 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3216 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003217 if (status == 0)
3218 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3220 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003221 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 return status;
3223}
3224
3225static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3226{
3227 int status = 0;
3228
3229 time->tv_sec = 0;
3230 time->tv_nsec = 0;
3231 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3232 return -EIO;
3233 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3234 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003235 if (status == 0)
3236 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3238 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003239 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240 return status;
3241}
3242
Al Viro8687b632006-10-19 23:28:48 -07003243static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244{
3245 unsigned int attrwords = XDR_QUADLEN(attrlen);
3246 unsigned int nwords = xdr->p - savep;
3247
3248 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003249 dprintk("%s: server returned incorrect attribute length: "
3250 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003251 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252 attrwords << 2,
3253 (attrwords < nwords) ? '<' : '>',
3254 nwords << 2);
3255 return -EIO;
3256 }
3257 return 0;
3258}
3259
3260static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3261{
Al Viro8687b632006-10-19 23:28:48 -07003262 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263
3264 READ_BUF(20);
3265 READ32(cinfo->atomic);
3266 READ64(cinfo->before);
3267 READ64(cinfo->after);
3268 return 0;
3269}
3270
3271static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3272{
Al Viro8687b632006-10-19 23:28:48 -07003273 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 uint32_t supp, acc;
3275 int status;
3276
3277 status = decode_op_hdr(xdr, OP_ACCESS);
3278 if (status)
3279 return status;
3280 READ_BUF(8);
3281 READ32(supp);
3282 READ32(acc);
3283 access->supported = supp;
3284 access->access = acc;
3285 return 0;
3286}
3287
3288static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3289{
Al Viro8687b632006-10-19 23:28:48 -07003290 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 int status;
3292
3293 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003294 if (status != -EIO)
3295 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 if (status)
3297 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003298 READ_BUF(NFS4_STATEID_SIZE);
3299 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 return 0;
3301}
3302
3303static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3304{
Al Viro8687b632006-10-19 23:28:48 -07003305 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 int status;
3307
3308 status = decode_op_hdr(xdr, OP_COMMIT);
3309 if (status)
3310 return status;
3311 READ_BUF(8);
3312 COPYMEM(res->verf->verifier, 8);
3313 return 0;
3314}
3315
3316static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3317{
Al Viro8687b632006-10-19 23:28:48 -07003318 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 uint32_t bmlen;
3320 int status;
3321
3322 status = decode_op_hdr(xdr, OP_CREATE);
3323 if (status)
3324 return status;
3325 if ((status = decode_change_info(xdr, cinfo)))
3326 return status;
3327 READ_BUF(4);
3328 READ32(bmlen);
3329 READ_BUF(bmlen << 2);
3330 return 0;
3331}
3332
3333static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3334{
Al Viro8687b632006-10-19 23:28:48 -07003335 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003336 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 int status;
3338
3339 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3340 goto xdr_error;
3341 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3342 goto xdr_error;
3343 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3344 goto xdr_error;
3345 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3346 goto xdr_error;
3347 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3348 goto xdr_error;
3349 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3350 goto xdr_error;
3351 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3352 goto xdr_error;
3353 status = verify_attr_len(xdr, savep, attrlen);
3354xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003355 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 return status;
3357}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003358
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3360{
Al Viro8687b632006-10-19 23:28:48 -07003361 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003362 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003364
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3366 goto xdr_error;
3367 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3368 goto xdr_error;
3369 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3370 goto xdr_error;
3371
3372 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3373 goto xdr_error;
3374 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3375 goto xdr_error;
3376 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3377 goto xdr_error;
3378 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3379 goto xdr_error;
3380 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3381 goto xdr_error;
3382 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3383 goto xdr_error;
3384
3385 status = verify_attr_len(xdr, savep, attrlen);
3386xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003387 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 return status;
3389}
3390
3391static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3392{
Al Viro8687b632006-10-19 23:28:48 -07003393 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003394 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003396
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3398 goto xdr_error;
3399 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3400 goto xdr_error;
3401 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3402 goto xdr_error;
3403
3404 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3405 goto xdr_error;
3406 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3407 goto xdr_error;
3408
3409 status = verify_attr_len(xdr, savep, attrlen);
3410xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003411 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 return status;
3413}
3414
3415static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3416{
Al Viro8687b632006-10-19 23:28:48 -07003417 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 uint32_t attrlen,
3419 bitmap[2] = {0},
3420 type;
Trond Myklebustbca79472009-03-11 14:10:26 -04003421 int status;
3422 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003423 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003425 status = decode_op_hdr(xdr, OP_GETATTR);
3426 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 goto xdr_error;
3428
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003429 status = decode_attr_bitmap(xdr, bitmap);
3430 if (status < 0)
3431 goto xdr_error;
3432
3433 status = decode_attr_length(xdr, &attrlen, &savep);
3434 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 goto xdr_error;
3436
3437
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003438 status = decode_attr_type(xdr, bitmap, &type);
3439 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003441 fattr->mode = 0;
3442 if (status != 0) {
3443 fattr->mode |= nfs_type2fmt[type];
3444 fattr->valid |= status;
3445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003447 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3448 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003450 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003451
3452 status = decode_attr_size(xdr, bitmap, &fattr->size);
3453 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003455 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003456
3457 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3458 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003460 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003461
3462 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3463 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003465 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003466
3467 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003468 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003469 fattr));
3470 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003471 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003472 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003473
3474 status = decode_attr_mode(xdr, bitmap, &fmode);
3475 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003477 if (status != 0) {
3478 fattr->mode |= fmode;
3479 fattr->valid |= status;
3480 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003481
3482 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3483 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003485 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003486
3487 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
3488 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003490 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003491
3492 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
3493 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003495 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003496
3497 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3498 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003500 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003501
3502 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3503 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003505 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003506
3507 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3508 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003510 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003511
3512 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3513 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003515 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003516
3517 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3518 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003520 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003521
3522 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3523 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003524 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003525 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003526 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003527 fattr->valid |= status;
3528 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003529
3530 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003532 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 return status;
3534}
3535
3536
3537static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3538{
Al Viro8687b632006-10-19 23:28:48 -07003539 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 uint32_t attrlen, bitmap[2];
3541 int status;
3542
3543 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3544 goto xdr_error;
3545 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3546 goto xdr_error;
3547 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3548 goto xdr_error;
3549
3550 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3551
3552 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3553 goto xdr_error;
3554 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3555 goto xdr_error;
3556 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3557 goto xdr_error;
3558 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3559 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3560 goto xdr_error;
3561 fsinfo->wtpref = fsinfo->wtmax;
3562
3563 status = verify_attr_len(xdr, savep, attrlen);
3564xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003565 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566 return status;
3567}
3568
3569static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3570{
Al Viro8687b632006-10-19 23:28:48 -07003571 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 uint32_t len;
3573 int status;
3574
Trond Myklebust99367812007-07-17 21:52:41 -04003575 /* Zero handle first to allow comparisons */
3576 memset(fh, 0, sizeof(*fh));
3577
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 status = decode_op_hdr(xdr, OP_GETFH);
3579 if (status)
3580 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581
3582 READ_BUF(4);
3583 READ32(len);
3584 if (len > NFS4_FHSIZE)
3585 return -EIO;
3586 fh->size = len;
3587 READ_BUF(len);
3588 COPYMEM(fh->data, len);
3589 return 0;
3590}
3591
3592static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3593{
3594 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003595
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596 status = decode_op_hdr(xdr, OP_LINK);
3597 if (status)
3598 return status;
3599 return decode_change_info(xdr, cinfo);
3600}
3601
3602/*
3603 * We create the owner, so we know a proper owner.id length is 4.
3604 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003605static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003607 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003608 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003609 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610
3611 READ_BUF(32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003612 READ64(offset);
3613 READ64(length);
3614 READ32(type);
3615 if (fl != NULL) {
3616 fl->fl_start = (loff_t)offset;
3617 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3618 if (length == ~(uint64_t)0)
3619 fl->fl_end = OFFSET_MAX;
3620 fl->fl_type = F_WRLCK;
3621 if (type & 1)
3622 fl->fl_type = F_RDLCK;
3623 fl->fl_pid = 0;
3624 }
3625 READ64(clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 READ32(namelen);
3627 READ_BUF(namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 return -NFS4ERR_DENIED;
3629}
3630
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003631static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632{
Al Viro8687b632006-10-19 23:28:48 -07003633 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 int status;
3635
3636 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003637 if (status == -EIO)
3638 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003640 READ_BUF(NFS4_STATEID_SIZE);
3641 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003643 status = decode_lock_denied(xdr, NULL);
3644 if (res->open_seqid != NULL)
3645 nfs_increment_open_seqid(status, res->open_seqid);
3646 nfs_increment_lock_seqid(status, res->lock_seqid);
3647out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 return status;
3649}
3650
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003651static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652{
3653 int status;
3654 status = decode_op_hdr(xdr, OP_LOCKT);
3655 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003656 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 return status;
3658}
3659
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003660static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661{
Al Viro8687b632006-10-19 23:28:48 -07003662 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663 int status;
3664
3665 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003666 if (status != -EIO)
3667 nfs_increment_lock_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003669 READ_BUF(NFS4_STATEID_SIZE);
3670 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671 }
3672 return status;
3673}
3674
3675static int decode_lookup(struct xdr_stream *xdr)
3676{
3677 return decode_op_hdr(xdr, OP_LOOKUP);
3678}
3679
3680/* This is too sick! */
3681static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3682{
Andy Adamson05d564f2008-12-23 16:06:15 -05003683 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 uint32_t limit_type, nblocks, blocksize;
3685
3686 READ_BUF(12);
3687 READ32(limit_type);
3688 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003689 case 1:
3690 READ64(*maxsize);
3691 break;
3692 case 2:
3693 READ32(nblocks);
3694 READ32(blocksize);
3695 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 }
3697 return 0;
3698}
3699
3700static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3701{
Andy Adamson05d564f2008-12-23 16:06:15 -05003702 __be32 *p;
3703 uint32_t delegation_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704
3705 READ_BUF(4);
3706 READ32(delegation_type);
3707 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3708 res->delegation_type = 0;
3709 return 0;
3710 }
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003711 READ_BUF(NFS4_STATEID_SIZE+4);
3712 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 READ32(res->do_recall);
Andy Adamson05d564f2008-12-23 16:06:15 -05003714
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003716 case NFS4_OPEN_DELEGATE_READ:
3717 res->delegation_type = FMODE_READ;
3718 break;
3719 case NFS4_OPEN_DELEGATE_WRITE:
3720 res->delegation_type = FMODE_WRITE|FMODE_READ;
3721 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 return -EIO;
3723 }
David Howells7539bba2006-08-22 20:06:09 -04003724 return decode_ace(xdr, NULL, res->server->nfs_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725}
3726
3727static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3728{
Andy Adamson05d564f2008-12-23 16:06:15 -05003729 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003730 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05003731 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732
Andy Adamson05d564f2008-12-23 16:06:15 -05003733 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003734 if (status != -EIO)
3735 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003736 if (status)
3737 return status;
3738 READ_BUF(NFS4_STATEID_SIZE);
3739 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740
Andy Adamson05d564f2008-12-23 16:06:15 -05003741 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742
Andy Adamson05d564f2008-12-23 16:06:15 -05003743 READ_BUF(8);
3744 READ32(res->rflags);
3745 READ32(bmlen);
3746 if (bmlen > 10)
3747 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748
Andy Adamson05d564f2008-12-23 16:06:15 -05003749 READ_BUF(bmlen << 2);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003750 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3751 for (i = 0; i < savewords; ++i)
3752 READ32(res->attrset[i]);
3753 for (; i < NFS4_BITMAP_SIZE; i++)
3754 res->attrset[i] = 0;
3755
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 return decode_delegation(xdr, res);
3757xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003758 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759 return -EIO;
3760}
3761
3762static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3763{
Andy Adamson05d564f2008-12-23 16:06:15 -05003764 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 int status;
3766
Andy Adamson05d564f2008-12-23 16:06:15 -05003767 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003768 if (status != -EIO)
3769 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003770 if (status)
3771 return status;
3772 READ_BUF(NFS4_STATEID_SIZE);
3773 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3774 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775}
3776
3777static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3778{
Al Viro8687b632006-10-19 23:28:48 -07003779 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780 int status;
3781
3782 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003783 if (status != -EIO)
3784 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 if (status)
3786 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003787 READ_BUF(NFS4_STATEID_SIZE);
3788 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 return 0;
3790}
3791
3792static int decode_putfh(struct xdr_stream *xdr)
3793{
3794 return decode_op_hdr(xdr, OP_PUTFH);
3795}
3796
3797static int decode_putrootfh(struct xdr_stream *xdr)
3798{
3799 return decode_op_hdr(xdr, OP_PUTROOTFH);
3800}
3801
3802static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3803{
3804 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07003805 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 uint32_t count, eof, recvd, hdrlen;
3807 int status;
3808
3809 status = decode_op_hdr(xdr, OP_READ);
3810 if (status)
3811 return status;
3812 READ_BUF(8);
3813 READ32(eof);
3814 READ32(count);
3815 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3816 recvd = req->rq_rcv_buf.len - hdrlen;
3817 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003818 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 "count %u > recvd %u\n", count, recvd);
3820 count = recvd;
3821 eof = 0;
3822 }
3823 xdr_read_pages(xdr, count);
3824 res->eof = eof;
3825 res->count = count;
3826 return 0;
3827}
3828
3829static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3830{
3831 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3832 struct page *page = *rcvbuf->pages;
3833 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003834 size_t hdrlen;
3835 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07003836 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003837 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04003838 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839
3840 status = decode_op_hdr(xdr, OP_READDIR);
3841 if (status)
3842 return status;
3843 READ_BUF(8);
3844 COPYMEM(readdir->verifier.data, 8);
Fred Isaman44109242008-04-02 15:21:15 +03003845 dprintk("%s: verifier = %08x:%08x\n",
3846 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00003847 ((u32 *)readdir->verifier.data)[0],
3848 ((u32 *)readdir->verifier.data)[1]);
3849
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850
3851 hdrlen = (char *) p - (char *) iov->iov_base;
3852 recvd = rcvbuf->len - hdrlen;
3853 if (pglen > recvd)
3854 pglen = recvd;
3855 xdr_read_pages(xdr, pglen);
3856
3857 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07003858 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04003859 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003861
3862 /* Make sure the packet actually has a value_follows and EOF entry */
3863 if ((entry + 1) > end)
3864 goto short_pkt;
3865
3866 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003867 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04003868 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003870 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 p += 2; /* cookie */
3872 len = ntohl(*p++); /* filename length */
3873 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003874 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3875 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 goto err_unmap;
3877 }
David Howellse8896492006-08-24 15:44:19 -04003878 xlen = XDR_QUADLEN(len);
3879 if (end - p < xlen + 1)
3880 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003881 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04003882 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04003884 if (end - p < len + 1)
3885 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04003888 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04003890 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891 entry = p;
3892 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003893 /*
3894 * Apparently some server sends responses that are a valid size, but
3895 * contain no entries, and have value_follows==0 and EOF==0. For
3896 * those, just set the EOF marker.
3897 */
3898 if (!nr && entry[1] == 0) {
3899 dprintk("NFS: readdir reply truncated!\n");
3900 entry[1] = 1;
3901 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05003902out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 kunmap_atomic(kaddr, KM_USER0);
3904 return 0;
3905short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003906 /*
3907 * When we get a short packet there are 2 possibilities. We can
3908 * return an error, or fix up the response to look like a valid
3909 * response and return what we have so far. If there are no
3910 * entries and the packet was short, then return -EIO. If there
3911 * are valid entries in the response, return them and pretend that
3912 * the call was successful, but incomplete. The caller can retry the
3913 * readdir starting at the last cookie.
3914 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07003915 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003917 if (nr)
3918 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919err_unmap:
3920 kunmap_atomic(kaddr, KM_USER0);
3921 return -errno_NFSERR_IO;
3922}
3923
3924static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3925{
3926 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3927 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003928 size_t hdrlen;
3929 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07003930 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931 char *kaddr;
3932 int status;
3933
3934 status = decode_op_hdr(xdr, OP_READLINK);
3935 if (status)
3936 return status;
3937
3938 /* Convert length of symlink */
3939 READ_BUF(4);
3940 READ32(len);
3941 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003942 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 return -ENAMETOOLONG;
3944 }
3945 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3946 recvd = req->rq_rcv_buf.len - hdrlen;
3947 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003948 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 "count %u > recvd %u\n", len, recvd);
3950 return -EIO;
3951 }
3952 xdr_read_pages(xdr, len);
3953 /*
3954 * The XDR encode routine has set things up so that
3955 * the link text will be copied directly into the
3956 * buffer. We just have to do overflow-checking,
3957 * and and null-terminate the text (the VFS expects
3958 * null-termination).
3959 */
3960 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3961 kaddr[len+rcvbuf->page_base] = '\0';
3962 kunmap_atomic(kaddr, KM_USER0);
3963 return 0;
3964}
3965
3966static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3967{
3968 int status;
3969
3970 status = decode_op_hdr(xdr, OP_REMOVE);
3971 if (status)
3972 goto out;
3973 status = decode_change_info(xdr, cinfo);
3974out:
3975 return status;
3976}
3977
3978static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3979 struct nfs4_change_info *new_cinfo)
3980{
3981 int status;
3982
3983 status = decode_op_hdr(xdr, OP_RENAME);
3984 if (status)
3985 goto out;
3986 if ((status = decode_change_info(xdr, old_cinfo)))
3987 goto out;
3988 status = decode_change_info(xdr, new_cinfo);
3989out:
3990 return status;
3991}
3992
3993static int decode_renew(struct xdr_stream *xdr)
3994{
3995 return decode_op_hdr(xdr, OP_RENEW);
3996}
3997
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003998static int
3999decode_restorefh(struct xdr_stream *xdr)
4000{
4001 return decode_op_hdr(xdr, OP_RESTOREFH);
4002}
4003
J. Bruce Fields029d1052005-06-22 17:16:22 +00004004static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4005 size_t *acl_len)
4006{
Al Viro8687b632006-10-19 23:28:48 -07004007 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004008 uint32_t attrlen,
4009 bitmap[2] = {0};
4010 struct kvec *iov = req->rq_rcv_buf.head;
4011 int status;
4012
4013 *acl_len = 0;
4014 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4015 goto out;
4016 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4017 goto out;
4018 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4019 goto out;
4020
4021 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4022 return -EIO;
4023 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004024 size_t hdrlen;
4025 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004026
4027 /* We ignore &savep and don't do consistency checks on
4028 * the attr length. Let userspace figure it out.... */
4029 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4030 recvd = req->rq_rcv_buf.len - hdrlen;
4031 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004032 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004033 " acl reply: attrlen %u > recvd %u\n",
4034 attrlen, recvd);
4035 return -EINVAL;
4036 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004037 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004038 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004039 } else
4040 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004041
4042out:
4043 return status;
4044}
4045
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046static int
4047decode_savefh(struct xdr_stream *xdr)
4048{
4049 return decode_op_hdr(xdr, OP_SAVEFH);
4050}
4051
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004052static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053{
Al Viro8687b632006-10-19 23:28:48 -07004054 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055 uint32_t bmlen;
4056 int status;
4057
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 status = decode_op_hdr(xdr, OP_SETATTR);
4059 if (status)
4060 return status;
4061 READ_BUF(4);
4062 READ32(bmlen);
4063 READ_BUF(bmlen << 2);
4064 return 0;
4065}
4066
David Howellsadfa6f92006-08-22 20:06:08 -04004067static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068{
Al Viro8687b632006-10-19 23:28:48 -07004069 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 uint32_t opnum;
4071 int32_t nfserr;
4072
4073 READ_BUF(8);
4074 READ32(opnum);
4075 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004076 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004077 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078 return -EIO;
4079 }
4080 READ32(nfserr);
4081 if (nfserr == NFS_OK) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04004082 READ_BUF(8 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083 READ64(clp->cl_clientid);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04004084 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 } else if (nfserr == NFSERR_CLID_INUSE) {
4086 uint32_t len;
4087
4088 /* skip netid string */
4089 READ_BUF(4);
4090 READ32(len);
4091 READ_BUF(len);
4092
4093 /* skip uaddr string */
4094 READ_BUF(4);
4095 READ32(len);
4096 READ_BUF(len);
4097 return -NFSERR_CLID_INUSE;
4098 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004099 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100
4101 return 0;
4102}
4103
4104static int decode_setclientid_confirm(struct xdr_stream *xdr)
4105{
4106 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4107}
4108
4109static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4110{
Al Viro8687b632006-10-19 23:28:48 -07004111 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 int status;
4113
4114 status = decode_op_hdr(xdr, OP_WRITE);
4115 if (status)
4116 return status;
4117
4118 READ_BUF(16);
4119 READ32(res->count);
4120 READ32(res->verf->committed);
4121 COPYMEM(res->verf->verifier, 8);
4122 return 0;
4123}
4124
4125static int decode_delegreturn(struct xdr_stream *xdr)
4126{
4127 return decode_op_hdr(xdr, OP_DELEGRETURN);
4128}
4129
Benny Halevy99fe60d2009-04-01 09:22:29 -04004130#if defined(CONFIG_NFS_V4_1)
4131static int decode_exchange_id(struct xdr_stream *xdr,
4132 struct nfs41_exchange_id_res *res)
4133{
4134 __be32 *p;
4135 uint32_t dummy;
4136 int status;
4137 struct nfs_client *clp = res->client;
4138
4139 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4140 if (status)
4141 return status;
4142
4143 READ_BUF(8);
4144 READ64(clp->cl_ex_clid);
4145 READ_BUF(12);
4146 READ32(clp->cl_seqid);
4147 READ32(clp->cl_exchange_flags);
4148
4149 /* We ask for SP4_NONE */
4150 READ32(dummy);
4151 if (dummy != SP4_NONE)
4152 return -EIO;
4153
4154 /* Throw away minor_id */
4155 READ_BUF(8);
4156
4157 /* Throw away Major id */
4158 READ_BUF(4);
4159 READ32(dummy);
4160 READ_BUF(dummy);
4161
4162 /* Throw away server_scope */
4163 READ_BUF(4);
4164 READ32(dummy);
4165 READ_BUF(dummy);
4166
4167 /* Throw away Implementation id array */
4168 READ_BUF(4);
4169 READ32(dummy);
4170 READ_BUF(dummy);
4171
4172 return 0;
4173}
Andy Adamsonfc931582009-04-01 09:22:31 -04004174
4175static int decode_chan_attrs(struct xdr_stream *xdr,
4176 struct nfs4_channel_attrs *attrs)
4177{
4178 __be32 *p;
4179 u32 nr_attrs;
4180
4181 READ_BUF(28);
4182 READ32(attrs->headerpadsz);
4183 READ32(attrs->max_rqst_sz);
4184 READ32(attrs->max_resp_sz);
4185 READ32(attrs->max_resp_sz_cached);
4186 READ32(attrs->max_ops);
4187 READ32(attrs->max_reqs);
4188 READ32(nr_attrs);
4189 if (unlikely(nr_attrs > 1)) {
4190 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4191 __func__, nr_attrs);
4192 return -EINVAL;
4193 }
4194 if (nr_attrs == 1)
4195 READ_BUF(4); /* skip rdma_attrs */
4196 return 0;
4197}
4198
4199static int decode_create_session(struct xdr_stream *xdr,
4200 struct nfs41_create_session_res *res)
4201{
4202 __be32 *p;
4203 int status;
4204 struct nfs_client *clp = res->client;
4205 struct nfs4_session *session = clp->cl_session;
4206
4207 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
4208
4209 if (status)
4210 return status;
4211
4212 /* sessionid */
4213 READ_BUF(NFS4_MAX_SESSIONID_LEN);
4214 COPYMEM(&session->sess_id, NFS4_MAX_SESSIONID_LEN);
4215
4216 /* seqid, flags */
4217 READ_BUF(8);
4218 READ32(clp->cl_seqid);
4219 READ32(session->flags);
4220
4221 /* Channel attributes */
4222 status = decode_chan_attrs(xdr, &session->fc_attrs);
4223 if (!status)
4224 status = decode_chan_attrs(xdr, &session->bc_attrs);
4225 return status;
4226}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004227
4228static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4229{
4230 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4231}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004232#endif /* CONFIG_NFS_V4_1 */
4233
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004234static int decode_sequence(struct xdr_stream *xdr,
4235 struct nfs4_sequence_res *res,
4236 struct rpc_rqst *rqstp)
4237{
4238#if defined(CONFIG_NFS_V4_1)
4239 if (!res->sr_session)
4240 return 0;
4241
4242 /* stub */
4243#endif /* CONFIG_NFS_V4_1 */
4244
4245 return 0;
4246}
4247
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248/*
Benny Halevy49c25592008-12-23 16:06:16 -05004249 * END OF "GENERIC" DECODE ROUTINES.
4250 */
4251
4252/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253 * Decode OPEN_DOWNGRADE response
4254 */
Al Viro8687b632006-10-19 23:28:48 -07004255static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256{
Andy Adamson05d564f2008-12-23 16:06:15 -05004257 struct xdr_stream xdr;
4258 struct compound_hdr hdr;
4259 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260
Andy Adamson05d564f2008-12-23 16:06:15 -05004261 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4262 status = decode_compound_hdr(&xdr, &hdr);
4263 if (status)
4264 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004265 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4266 if (status)
4267 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004268 status = decode_putfh(&xdr);
4269 if (status)
4270 goto out;
4271 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004272 if (status != 0)
4273 goto out;
4274 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004276 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277}
4278
4279/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004280 * Decode ACCESS response
4281 */
Al Viro8687b632006-10-19 23:28:48 -07004282static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283{
4284 struct xdr_stream xdr;
4285 struct compound_hdr hdr;
4286 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004287
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004289 status = decode_compound_hdr(&xdr, &hdr);
4290 if (status)
4291 goto out;
4292 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4293 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04004295 status = decode_putfh(&xdr);
4296 if (status != 0)
4297 goto out;
4298 status = decode_access(&xdr, res);
4299 if (status != 0)
4300 goto out;
4301 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302out:
4303 return status;
4304}
4305
4306/*
4307 * Decode LOOKUP response
4308 */
Al Viro8687b632006-10-19 23:28:48 -07004309static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310{
4311 struct xdr_stream xdr;
4312 struct compound_hdr hdr;
4313 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004314
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004316 status = decode_compound_hdr(&xdr, &hdr);
4317 if (status)
4318 goto out;
4319 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4320 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321 goto out;
4322 if ((status = decode_putfh(&xdr)) != 0)
4323 goto out;
4324 if ((status = decode_lookup(&xdr)) != 0)
4325 goto out;
4326 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4327 goto out;
4328 status = decode_getfattr(&xdr, res->fattr, res->server);
4329out:
4330 return status;
4331}
4332
4333/*
4334 * Decode LOOKUP_ROOT response
4335 */
Al Viro8687b632006-10-19 23:28:48 -07004336static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337{
4338 struct xdr_stream xdr;
4339 struct compound_hdr hdr;
4340 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004341
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004343 status = decode_compound_hdr(&xdr, &hdr);
4344 if (status)
4345 goto out;
4346 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4347 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348 goto out;
4349 if ((status = decode_putrootfh(&xdr)) != 0)
4350 goto out;
4351 if ((status = decode_getfh(&xdr, res->fh)) == 0)
4352 status = decode_getfattr(&xdr, res->fattr, res->server);
4353out:
4354 return status;
4355}
4356
4357/*
4358 * Decode REMOVE response
4359 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004360static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361{
4362 struct xdr_stream xdr;
4363 struct compound_hdr hdr;
4364 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004365
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004367 status = decode_compound_hdr(&xdr, &hdr);
4368 if (status)
4369 goto out;
4370 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4371 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004372 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04004373 if ((status = decode_putfh(&xdr)) != 0)
4374 goto out;
4375 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4376 goto out;
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004377 decode_getfattr(&xdr, &res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378out:
4379 return status;
4380}
4381
4382/*
4383 * Decode RENAME response
4384 */
Al Viro8687b632006-10-19 23:28:48 -07004385static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386{
4387 struct xdr_stream xdr;
4388 struct compound_hdr hdr;
4389 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004390
Linus Torvalds1da177e2005-04-16 15:20:36 -07004391 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004392 status = decode_compound_hdr(&xdr, &hdr);
4393 if (status)
4394 goto out;
4395 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4396 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397 goto out;
4398 if ((status = decode_putfh(&xdr)) != 0)
4399 goto out;
4400 if ((status = decode_savefh(&xdr)) != 0)
4401 goto out;
4402 if ((status = decode_putfh(&xdr)) != 0)
4403 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004404 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4405 goto out;
4406 /* Current FH is target directory */
4407 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
4408 goto out;
4409 if ((status = decode_restorefh(&xdr)) != 0)
4410 goto out;
4411 decode_getfattr(&xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004412out:
4413 return status;
4414}
4415
4416/*
4417 * Decode LINK response
4418 */
Al Viro8687b632006-10-19 23:28:48 -07004419static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420{
4421 struct xdr_stream xdr;
4422 struct compound_hdr hdr;
4423 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004424
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004426 status = decode_compound_hdr(&xdr, &hdr);
4427 if (status)
4428 goto out;
4429 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4430 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431 goto out;
4432 if ((status = decode_putfh(&xdr)) != 0)
4433 goto out;
4434 if ((status = decode_savefh(&xdr)) != 0)
4435 goto out;
4436 if ((status = decode_putfh(&xdr)) != 0)
4437 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004438 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4439 goto out;
4440 /*
4441 * Note order: OP_LINK leaves the directory as the current
4442 * filehandle.
4443 */
4444 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
4445 goto out;
4446 if ((status = decode_restorefh(&xdr)) != 0)
4447 goto out;
4448 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449out:
4450 return status;
4451}
4452
4453/*
4454 * Decode CREATE response
4455 */
Al Viro8687b632006-10-19 23:28:48 -07004456static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004457{
4458 struct xdr_stream xdr;
4459 struct compound_hdr hdr;
4460 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004461
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004463 status = decode_compound_hdr(&xdr, &hdr);
4464 if (status)
4465 goto out;
4466 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4467 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 goto out;
4469 if ((status = decode_putfh(&xdr)) != 0)
4470 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004471 if ((status = decode_savefh(&xdr)) != 0)
4472 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4474 goto out;
4475 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4476 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004477 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
4478 goto out;
4479 if ((status = decode_restorefh(&xdr)) != 0)
4480 goto out;
4481 decode_getfattr(&xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482out:
4483 return status;
4484}
4485
4486/*
4487 * Decode SYMLINK response
4488 */
Al Viro8687b632006-10-19 23:28:48 -07004489static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490{
4491 return nfs4_xdr_dec_create(rqstp, p, res);
4492}
4493
4494/*
4495 * Decode GETATTR response
4496 */
Al Viro8687b632006-10-19 23:28:48 -07004497static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004498{
4499 struct xdr_stream xdr;
4500 struct compound_hdr hdr;
4501 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004502
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4504 status = decode_compound_hdr(&xdr, &hdr);
4505 if (status)
4506 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004507 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4508 if (status)
4509 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510 status = decode_putfh(&xdr);
4511 if (status)
4512 goto out;
4513 status = decode_getfattr(&xdr, res->fattr, res->server);
4514out:
4515 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516}
4517
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004518/*
4519 * Encode an SETACL request
4520 */
4521static int
Al Viro8687b632006-10-19 23:28:48 -07004522nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004523{
Andy Adamson05d564f2008-12-23 16:06:15 -05004524 struct xdr_stream xdr;
4525 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04004526 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05004527 };
4528 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004529
Andy Adamson05d564f2008-12-23 16:06:15 -05004530 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04004531 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004532 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05004533 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004534 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004535 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004536 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004537}
Andy Adamson05d564f2008-12-23 16:06:15 -05004538
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004539/*
4540 * Decode SETACL response
4541 */
4542static int
Benny Halevy73c403a2009-04-01 09:22:01 -04004543nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4544 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004545{
4546 struct xdr_stream xdr;
4547 struct compound_hdr hdr;
4548 int status;
4549
4550 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4551 status = decode_compound_hdr(&xdr, &hdr);
4552 if (status)
4553 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004554 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4555 if (status)
4556 goto out;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004557 status = decode_putfh(&xdr);
4558 if (status)
4559 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004560 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004561out:
4562 return status;
4563}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004564
4565/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00004566 * Decode GETACL response
4567 */
4568static int
Benny Halevy663c79b2009-04-01 09:21:59 -04004569nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4570 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004571{
4572 struct xdr_stream xdr;
4573 struct compound_hdr hdr;
4574 int status;
4575
4576 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4577 status = decode_compound_hdr(&xdr, &hdr);
4578 if (status)
4579 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004580 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4581 if (status)
4582 goto out;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004583 status = decode_putfh(&xdr);
4584 if (status)
4585 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04004586 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004587
4588out:
4589 return status;
4590}
4591
4592/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593 * Decode CLOSE response
4594 */
Al Viro8687b632006-10-19 23:28:48 -07004595static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596{
Andy Adamson05d564f2008-12-23 16:06:15 -05004597 struct xdr_stream xdr;
4598 struct compound_hdr hdr;
4599 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600
Andy Adamson05d564f2008-12-23 16:06:15 -05004601 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;
Andy Adamson05d564f2008-12-23 16:06:15 -05004608 status = decode_putfh(&xdr);
4609 if (status)
4610 goto out;
4611 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004612 if (status != 0)
4613 goto out;
4614 /*
4615 * Note: Server may do delete on close for this file
4616 * in which case the getattr call will fail with
4617 * an ESTALE error. Shouldn't be a problem,
4618 * though, since fattr->valid will remain unset.
4619 */
4620 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004622 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623}
4624
4625/*
4626 * Decode OPEN response
4627 */
Al Viro8687b632006-10-19 23:28:48 -07004628static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629{
Andy Adamson05d564f2008-12-23 16:06:15 -05004630 struct xdr_stream xdr;
4631 struct compound_hdr hdr;
4632 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633
Andy Adamson05d564f2008-12-23 16:06:15 -05004634 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4635 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004636 if (status)
4637 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004638 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4639 if (status)
4640 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004641 status = decode_putfh(&xdr);
4642 if (status)
4643 goto out;
4644 status = decode_savefh(&xdr);
4645 if (status)
4646 goto out;
4647 status = decode_open(&xdr, res);
4648 if (status)
4649 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04004650 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004652 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4653 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04004654 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004655 goto out;
4656 decode_getfattr(&xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004658 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659}
4660
4661/*
4662 * Decode OPEN_CONFIRM response
4663 */
Al Viro8687b632006-10-19 23:28:48 -07004664static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665{
Andy Adamson05d564f2008-12-23 16:06:15 -05004666 struct xdr_stream xdr;
4667 struct compound_hdr hdr;
4668 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669
Andy Adamson05d564f2008-12-23 16:06:15 -05004670 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4671 status = decode_compound_hdr(&xdr, &hdr);
4672 if (status)
4673 goto out;
4674 status = decode_putfh(&xdr);
4675 if (status)
4676 goto out;
4677 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004679 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004680}
4681
4682/*
4683 * Decode OPEN response
4684 */
Al Viro8687b632006-10-19 23:28:48 -07004685static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686{
Andy Adamson05d564f2008-12-23 16:06:15 -05004687 struct xdr_stream xdr;
4688 struct compound_hdr hdr;
4689 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004690
Andy Adamson05d564f2008-12-23 16:06:15 -05004691 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4692 status = decode_compound_hdr(&xdr, &hdr);
4693 if (status)
4694 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004695 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4696 if (status)
4697 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004698 status = decode_putfh(&xdr);
4699 if (status)
4700 goto out;
4701 status = decode_open(&xdr, res);
4702 if (status)
4703 goto out;
Trond Myklebust864472e2006-01-03 09:55:15 +01004704 decode_getfattr(&xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004705out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004706 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004707}
4708
4709/*
4710 * Decode SETATTR response
4711 */
Al Viro8687b632006-10-19 23:28:48 -07004712static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004713{
Andy Adamson05d564f2008-12-23 16:06:15 -05004714 struct xdr_stream xdr;
4715 struct compound_hdr hdr;
4716 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004717
Andy Adamson05d564f2008-12-23 16:06:15 -05004718 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4719 status = decode_compound_hdr(&xdr, &hdr);
4720 if (status)
4721 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004722 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4723 if (status)
4724 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004725 status = decode_putfh(&xdr);
4726 if (status)
4727 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004728 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004729 if (status)
4730 goto out;
Trond Myklebust78f945f2009-03-11 14:10:23 -04004731 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004733 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004734}
4735
4736/*
4737 * Decode LOCK response
4738 */
Al Viro8687b632006-10-19 23:28:48 -07004739static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740{
4741 struct xdr_stream xdr;
4742 struct compound_hdr hdr;
4743 int status;
4744
4745 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4746 status = decode_compound_hdr(&xdr, &hdr);
4747 if (status)
4748 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004749 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4750 if (status)
4751 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752 status = decode_putfh(&xdr);
4753 if (status)
4754 goto out;
4755 status = decode_lock(&xdr, res);
4756out:
4757 return status;
4758}
4759
4760/*
4761 * Decode LOCKT response
4762 */
Al Viro8687b632006-10-19 23:28:48 -07004763static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764{
4765 struct xdr_stream xdr;
4766 struct compound_hdr hdr;
4767 int status;
4768
4769 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4770 status = decode_compound_hdr(&xdr, &hdr);
4771 if (status)
4772 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004773 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4774 if (status)
4775 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004776 status = decode_putfh(&xdr);
4777 if (status)
4778 goto out;
4779 status = decode_lockt(&xdr, res);
4780out:
4781 return status;
4782}
4783
4784/*
4785 * Decode LOCKU response
4786 */
Al Viro8687b632006-10-19 23:28:48 -07004787static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788{
4789 struct xdr_stream xdr;
4790 struct compound_hdr hdr;
4791 int status;
4792
4793 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4794 status = decode_compound_hdr(&xdr, &hdr);
4795 if (status)
4796 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004797 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4798 if (status)
4799 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800 status = decode_putfh(&xdr);
4801 if (status)
4802 goto out;
4803 status = decode_locku(&xdr, res);
4804out:
4805 return status;
4806}
4807
4808/*
4809 * Decode READLINK response
4810 */
Benny Halevyf50c7002009-04-01 09:21:55 -04004811static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4812 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813{
4814 struct xdr_stream xdr;
4815 struct compound_hdr hdr;
4816 int status;
4817
4818 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4819 status = decode_compound_hdr(&xdr, &hdr);
4820 if (status)
4821 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004822 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4823 if (status)
4824 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825 status = decode_putfh(&xdr);
4826 if (status)
4827 goto out;
4828 status = decode_readlink(&xdr, rqstp);
4829out:
4830 return status;
4831}
4832
4833/*
4834 * Decode READDIR response
4835 */
Al Viro8687b632006-10-19 23:28:48 -07004836static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837{
4838 struct xdr_stream xdr;
4839 struct compound_hdr hdr;
4840 int status;
4841
4842 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4843 status = decode_compound_hdr(&xdr, &hdr);
4844 if (status)
4845 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004846 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4847 if (status)
4848 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849 status = decode_putfh(&xdr);
4850 if (status)
4851 goto out;
4852 status = decode_readdir(&xdr, rqstp, res);
4853out:
4854 return status;
4855}
4856
4857/*
4858 * Decode Read response
4859 */
Al Viro8687b632006-10-19 23:28:48 -07004860static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861{
4862 struct xdr_stream xdr;
4863 struct compound_hdr hdr;
4864 int status;
4865
4866 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4867 status = decode_compound_hdr(&xdr, &hdr);
4868 if (status)
4869 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004870 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4871 if (status)
4872 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873 status = decode_putfh(&xdr);
4874 if (status)
4875 goto out;
4876 status = decode_read(&xdr, rqstp, res);
4877 if (!status)
4878 status = res->count;
4879out:
4880 return status;
4881}
4882
4883/*
4884 * Decode WRITE response
4885 */
Al Viro8687b632006-10-19 23:28:48 -07004886static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887{
4888 struct xdr_stream xdr;
4889 struct compound_hdr hdr;
4890 int status;
4891
4892 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4893 status = decode_compound_hdr(&xdr, &hdr);
4894 if (status)
4895 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004896 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4897 if (status)
4898 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899 status = decode_putfh(&xdr);
4900 if (status)
4901 goto out;
4902 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004903 if (status)
4904 goto out;
4905 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906 if (!status)
4907 status = res->count;
4908out:
4909 return status;
4910}
4911
4912/*
4913 * Decode COMMIT response
4914 */
Al Viro8687b632006-10-19 23:28:48 -07004915static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916{
4917 struct xdr_stream xdr;
4918 struct compound_hdr hdr;
4919 int status;
4920
4921 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4922 status = decode_compound_hdr(&xdr, &hdr);
4923 if (status)
4924 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004925 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4926 if (status)
4927 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928 status = decode_putfh(&xdr);
4929 if (status)
4930 goto out;
4931 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004932 if (status)
4933 goto out;
4934 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935out:
4936 return status;
4937}
4938
4939/*
4940 * FSINFO request
4941 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04004942static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
4943 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944{
4945 struct xdr_stream xdr;
4946 struct compound_hdr hdr;
4947 int status;
4948
4949 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4950 status = decode_compound_hdr(&xdr, &hdr);
4951 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004952 status = decode_sequence(&xdr, &res->seq_res, req);
4953 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 status = decode_putfh(&xdr);
4955 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04004956 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957 return status;
4958}
4959
4960/*
4961 * PATHCONF request
4962 */
Benny Halevyd45b2982009-04-01 09:21:58 -04004963static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
4964 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965{
4966 struct xdr_stream xdr;
4967 struct compound_hdr hdr;
4968 int status;
4969
4970 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4971 status = decode_compound_hdr(&xdr, &hdr);
4972 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004973 status = decode_sequence(&xdr, &res->seq_res, req);
4974 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975 status = decode_putfh(&xdr);
4976 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04004977 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004978 return status;
4979}
4980
4981/*
4982 * STATFS request
4983 */
Benny Halevy24ad1482009-04-01 09:21:56 -04004984static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
4985 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986{
4987 struct xdr_stream xdr;
4988 struct compound_hdr hdr;
4989 int status;
4990
4991 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4992 status = decode_compound_hdr(&xdr, &hdr);
4993 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004994 status = decode_sequence(&xdr, &res->seq_res, req);
4995 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996 status = decode_putfh(&xdr);
4997 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04004998 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999 return status;
5000}
5001
5002/*
5003 * GETATTR_BITMAP request
5004 */
Al Viro8687b632006-10-19 23:28:48 -07005005static 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 -07005006{
5007 struct xdr_stream xdr;
5008 struct compound_hdr hdr;
5009 int status;
5010
5011 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005012 status = decode_compound_hdr(&xdr, &hdr);
5013 if (status)
5014 goto out;
5015 status = decode_sequence(&xdr, &res->seq_res, req);
5016 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005017 goto out;
5018 if ((status = decode_putfh(&xdr)) != 0)
5019 goto out;
5020 status = decode_server_caps(&xdr, res);
5021out:
5022 return status;
5023}
5024
5025/*
5026 * Decode RENEW response
5027 */
Al Viro8687b632006-10-19 23:28:48 -07005028static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029{
5030 struct xdr_stream xdr;
5031 struct compound_hdr hdr;
5032 int status;
5033
5034 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5035 status = decode_compound_hdr(&xdr, &hdr);
5036 if (!status)
5037 status = decode_renew(&xdr);
5038 return status;
5039}
5040
5041/*
5042 * a SETCLIENTID request
5043 */
Al Viro8687b632006-10-19 23:28:48 -07005044static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04005045 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046{
5047 struct xdr_stream xdr;
5048 struct compound_hdr hdr;
5049 int status;
5050
5051 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5052 status = decode_compound_hdr(&xdr, &hdr);
5053 if (!status)
5054 status = decode_setclientid(&xdr, clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005055 return status;
5056}
5057
5058/*
5059 * a SETCLIENTID_CONFIRM request
5060 */
Al Viro8687b632006-10-19 23:28:48 -07005061static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005062{
5063 struct xdr_stream xdr;
5064 struct compound_hdr hdr;
5065 int status;
5066
5067 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5068 status = decode_compound_hdr(&xdr, &hdr);
5069 if (!status)
5070 status = decode_setclientid_confirm(&xdr);
5071 if (!status)
5072 status = decode_putrootfh(&xdr);
5073 if (!status)
5074 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005075 return status;
5076}
5077
5078/*
5079 * DELEGRETURN request
5080 */
Al Viro8687b632006-10-19 23:28:48 -07005081static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082{
5083 struct xdr_stream xdr;
5084 struct compound_hdr hdr;
5085 int status;
5086
5087 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5088 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005089 if (status)
5090 goto out;
5091 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5092 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005093 goto out;
5094 status = decode_putfh(&xdr);
5095 if (status != 0)
5096 goto out;
5097 status = decode_delegreturn(&xdr);
5098 decode_getfattr(&xdr, res->fattr, res->server);
5099out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005100 return status;
5101}
5102
Trond Myklebust683b57b2006-06-09 09:34:22 -04005103/*
5104 * FS_LOCATIONS request
5105 */
Benny Halevy22958462009-04-01 09:22:02 -04005106static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
5107 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005108{
5109 struct xdr_stream xdr;
5110 struct compound_hdr hdr;
5111 int status;
5112
5113 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5114 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005115 if (status)
5116 goto out;
5117 status = decode_sequence(&xdr, &res->seq_res, req);
5118 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005119 goto out;
5120 if ((status = decode_putfh(&xdr)) != 0)
5121 goto out;
5122 if ((status = decode_lookup(&xdr)) != 0)
5123 goto out;
5124 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04005125 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
5126 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04005127out:
5128 return status;
5129}
5130
Benny Halevy99fe60d2009-04-01 09:22:29 -04005131#if defined(CONFIG_NFS_V4_1)
5132/*
5133 * EXCHANGE_ID request
5134 */
5135static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
5136 void *res)
5137{
5138 struct xdr_stream xdr;
5139 struct compound_hdr hdr;
5140 int status;
5141
5142 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5143 status = decode_compound_hdr(&xdr, &hdr);
5144 if (!status)
5145 status = decode_exchange_id(&xdr, res);
5146 return status;
5147}
Andy Adamson2050f0c2009-04-01 09:22:30 -04005148
5149/*
Andy Adamsonfc931582009-04-01 09:22:31 -04005150 * a CREATE_SESSION request
5151 */
5152static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
5153 struct nfs41_create_session_res *res)
5154{
5155 struct xdr_stream xdr;
5156 struct compound_hdr hdr;
5157 int status;
5158
5159 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5160 status = decode_compound_hdr(&xdr, &hdr);
5161 if (!status)
5162 status = decode_create_session(&xdr, res);
5163 return status;
5164}
5165
5166/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005167 * a DESTROY_SESSION request
5168 */
5169static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
5170 void *dummy)
5171{
5172 struct xdr_stream xdr;
5173 struct compound_hdr hdr;
5174 int status;
5175
5176 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5177 status = decode_compound_hdr(&xdr, &hdr);
5178 if (!status)
5179 status = decode_destroy_session(&xdr, dummy);
5180 return status;
5181}
5182
5183/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04005184 * a GET_LEASE_TIME request
5185 */
5186static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
5187 struct nfs4_get_lease_time_res *res)
5188{
5189 struct xdr_stream xdr;
5190 struct compound_hdr hdr;
5191 int status;
5192
5193 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5194 status = decode_compound_hdr(&xdr, &hdr);
5195 if (!status)
5196 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
5197 if (!status)
5198 status = decode_putrootfh(&xdr);
5199 if (!status)
5200 status = decode_fsinfo(&xdr, res->lr_fsinfo);
5201 return status;
5202}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005203#endif /* CONFIG_NFS_V4_1 */
5204
Al Viro0dbb4c62006-10-19 23:28:49 -07005205__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005206{
5207 uint32_t bitmap[2] = {0};
5208 uint32_t len;
5209
5210 if (!*p++) {
5211 if (!*p)
5212 return ERR_PTR(-EAGAIN);
5213 entry->eof = 1;
5214 return ERR_PTR(-EBADCOOKIE);
5215 }
5216
5217 entry->prev_cookie = entry->cookie;
5218 p = xdr_decode_hyper(p, &entry->cookie);
5219 entry->len = ntohl(*p++);
5220 entry->name = (const char *) p;
5221 p += XDR_QUADLEN(entry->len);
5222
5223 /*
5224 * In case the server doesn't return an inode number,
5225 * we fake one here. (We don't use inode number 0,
5226 * since glibc seems to choke on it...)
5227 */
5228 entry->ino = 1;
5229
5230 len = ntohl(*p++); /* bitmap length */
5231 if (len-- > 0) {
5232 bitmap[0] = ntohl(*p++);
5233 if (len-- > 0) {
5234 bitmap[1] = ntohl(*p++);
5235 p += len;
5236 }
5237 }
5238 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
5239 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00005240 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
5241 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
5242 /* Ignore the return value of rdattr_error for now */
5243 p++;
5244 len--;
5245 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005246 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
5247 xdr_decode_hyper(p, &entry->ino);
5248 else if (bitmap[0] == FATTR4_WORD0_FILEID)
5249 xdr_decode_hyper(p, &entry->ino);
5250 p += len;
5251 }
5252
5253 entry->eof = !p[0] && p[1];
5254 return p;
5255}
5256
5257/*
5258 * We need to translate between nfs status return values and
5259 * the local errno values which may not be the same.
5260 */
5261static struct {
5262 int stat;
5263 int errno;
5264} nfs_errtbl[] = {
5265 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03005266 { NFS4ERR_PERM, -EPERM },
5267 { NFS4ERR_NOENT, -ENOENT },
5268 { NFS4ERR_IO, -errno_NFSERR_IO},
5269 { NFS4ERR_NXIO, -ENXIO },
5270 { NFS4ERR_ACCESS, -EACCES },
5271 { NFS4ERR_EXIST, -EEXIST },
5272 { NFS4ERR_XDEV, -EXDEV },
5273 { NFS4ERR_NOTDIR, -ENOTDIR },
5274 { NFS4ERR_ISDIR, -EISDIR },
5275 { NFS4ERR_INVAL, -EINVAL },
5276 { NFS4ERR_FBIG, -EFBIG },
5277 { NFS4ERR_NOSPC, -ENOSPC },
5278 { NFS4ERR_ROFS, -EROFS },
5279 { NFS4ERR_MLINK, -EMLINK },
5280 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5281 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5282 { NFS4ERR_DQUOT, -EDQUOT },
5283 { NFS4ERR_STALE, -ESTALE },
5284 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5285 { NFS4ERR_BADOWNER, -EINVAL },
5286 { NFS4ERR_BADNAME, -EINVAL },
5287 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5288 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5289 { NFS4ERR_TOOSMALL, -ETOOSMALL },
5290 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
5291 { NFS4ERR_BADTYPE, -EBADTYPE },
5292 { NFS4ERR_LOCKED, -EAGAIN },
5293 { NFS4ERR_RESOURCE, -EREMOTEIO },
5294 { NFS4ERR_SYMLINK, -ELOOP },
5295 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5296 { NFS4ERR_DEADLOCK, -EDEADLK },
5297 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005298 * to be handled by a
5299 * middle-layer.
5300 */
Benny Halevy856dff32008-03-31 17:39:06 +03005301 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302};
5303
5304/*
5305 * Convert an NFS error code to a local one.
5306 * This one is used jointly by NFSv2 and NFSv3.
5307 */
5308static int
David Howells0a8ea432006-08-22 20:06:08 -04005309nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005310{
5311 int i;
5312 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5313 if (nfs_errtbl[i].stat == stat)
5314 return nfs_errtbl[i].errno;
5315 }
5316 if (stat <= 10000 || stat > 10100) {
5317 /* The server is looney tunes. */
Benny Halevy856dff32008-03-31 17:39:06 +03005318 return -ESERVERFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319 }
5320 /* If we cannot translate the error, the recovery routines should
5321 * handle it.
5322 * Note: remaining NFSv4 error codes have values > 10000, so should
5323 * not conflict with native Linux error codes.
5324 */
Benny Halevy856dff32008-03-31 17:39:06 +03005325 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005326}
5327
Linus Torvalds1da177e2005-04-16 15:20:36 -07005328#define PROC(proc, argtype, restype) \
5329[NFSPROC4_CLNT_##proc] = { \
5330 .p_proc = NFSPROC4_COMPOUND, \
5331 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5332 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04005333 .p_arglen = NFS4_##argtype##_sz, \
5334 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05005335 .p_statidx = NFSPROC4_CLNT_##proc, \
5336 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05005337}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005338
5339struct rpc_procinfo nfs4_procedures[] = {
5340 PROC(READ, enc_read, dec_read),
5341 PROC(WRITE, enc_write, dec_write),
5342 PROC(COMMIT, enc_commit, dec_commit),
5343 PROC(OPEN, enc_open, dec_open),
5344 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5345 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5346 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5347 PROC(CLOSE, enc_close, dec_close),
5348 PROC(SETATTR, enc_setattr, dec_setattr),
5349 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5350 PROC(RENEW, enc_renew, dec_renew),
5351 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5352 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5353 PROC(LOCK, enc_lock, dec_lock),
5354 PROC(LOCKT, enc_lockt, dec_lockt),
5355 PROC(LOCKU, enc_locku, dec_locku),
5356 PROC(ACCESS, enc_access, dec_access),
5357 PROC(GETATTR, enc_getattr, dec_getattr),
5358 PROC(LOOKUP, enc_lookup, dec_lookup),
5359 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5360 PROC(REMOVE, enc_remove, dec_remove),
5361 PROC(RENAME, enc_rename, dec_rename),
5362 PROC(LINK, enc_link, dec_link),
5363 PROC(SYMLINK, enc_symlink, dec_symlink),
5364 PROC(CREATE, enc_create, dec_create),
5365 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5366 PROC(STATFS, enc_statfs, dec_statfs),
5367 PROC(READLINK, enc_readlink, dec_readlink),
5368 PROC(READDIR, enc_readdir, dec_readdir),
5369 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5370 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00005371 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005372 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04005373 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005374#if defined(CONFIG_NFS_V4_1)
5375 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
Andy Adamsonfc931582009-04-01 09:22:31 -04005376 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005377 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
Andy Adamson2050f0c2009-04-01 09:22:30 -04005378 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005379#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005380};
5381
5382struct rpc_version nfs_version4 = {
5383 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08005384 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005385 .procs = nfs4_procedures
5386};
5387
5388/*
5389 * Local variables:
5390 * c-basic-offset: 8
5391 * End:
5392 */