blob: a6b00e84bd1a1c38dac2a6d2990837fa9e9b3067 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
47#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050048#include <linux/sunrpc/msg_prot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/nfs.h>
50#include <linux/nfs4.h>
51#include <linux/nfs_fs.h>
52#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000053#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050054#include "internal.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)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500138#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_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 Myklebustdaccbde2010-06-25 18:11:43 -0400205#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400206#define encode_lock_maxsz (op_encode_hdr_maxsz + \
207 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400208 1 + encode_stateid_maxsz + 1 + \
209 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400210#define decode_lock_denied_maxsz \
211 (8 + decode_lockowner_maxsz)
212#define decode_lock_maxsz (op_decode_hdr_maxsz + \
213 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400214#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
215 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400216#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
217 decode_lock_denied_maxsz)
218#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
219 encode_stateid_maxsz + \
220 4)
221#define decode_locku_maxsz (op_decode_hdr_maxsz + \
222 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400223#define encode_release_lockowner_maxsz \
224 (op_encode_hdr_maxsz + \
225 encode_lockowner_maxsz)
226#define decode_release_lockowner_maxsz \
227 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400228#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
229#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
231 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400232 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000233 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
235#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400236 1 + 2 + nfs4_name_maxsz + \
237 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400238#define decode_create_maxsz (op_decode_hdr_maxsz + \
239 decode_change_info_maxsz + \
240 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400241#define encode_statfs_maxsz (encode_getattr_maxsz)
242#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
244#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400245#define encode_getacl_maxsz (encode_getattr_maxsz)
246#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
247 nfs4_fattr_bitmap_maxsz + 1)
248#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
249 encode_stateid_maxsz + 3)
250#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400251#define encode_fs_locations_maxsz \
252 (encode_getattr_maxsz)
253#define decode_fs_locations_maxsz \
254 (0)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400255
256#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400257#define NFS4_MAX_MACHINE_NAME_LEN (64)
258
Benny Halevy99fe60d2009-04-01 09:22:29 -0400259#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
260 encode_verifier_maxsz + \
261 1 /* co_ownerid.len */ + \
262 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
263 1 /* flags */ + \
264 1 /* spa_how */ + \
265 0 /* SP4_NONE (for now) */ + \
266 1 /* zero implemetation id array */)
267#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
268 2 /* eir_clientid */ + \
269 1 /* eir_sequenceid */ + \
270 1 /* eir_flags */ + \
271 1 /* spr_how */ + \
272 0 /* SP4_NONE (for now) */ + \
273 2 /* eir_server_owner.so_minor_id */ + \
274 /* eir_server_owner.so_major_id<> */ \
275 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
276 /* eir_server_scope<> */ \
277 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
278 1 /* eir_server_impl_id array length */ + \
279 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400280#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
281#define decode_channel_attrs_maxsz (6 + \
282 1 /* ca_rdma_ird.len */ + \
283 1 /* ca_rdma_ird */)
284#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
285 2 /* csa_clientid */ + \
286 1 /* csa_sequence */ + \
287 1 /* csa_flags */ + \
288 encode_channel_attrs_maxsz + \
289 encode_channel_attrs_maxsz + \
290 1 /* csa_cb_program */ + \
291 1 /* csa_sec_parms.len (1) */ + \
292 1 /* cb_secflavor (AUTH_SYS) */ + \
293 1 /* stamp */ + \
294 1 /* machinename.len */ + \
295 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
296 1 /* uid */ + \
297 1 /* gid */ + \
298 1 /* gids.len (0) */)
299#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
300 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
301 1 /* csr_sequence */ + \
302 1 /* csr_flags */ + \
303 decode_channel_attrs_maxsz + \
304 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400305#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
306#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400307#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
308 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
309#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
310 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500311#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
312#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400313#else /* CONFIG_NFS_V4_1 */
314#define encode_sequence_maxsz 0
315#define decode_sequence_maxsz 0
316#endif /* CONFIG_NFS_V4_1 */
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
319#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
320#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400321 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400323 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400325 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400327 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400329 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400331 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400333 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400335 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400337 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400339 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400341 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400343 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400345 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400347 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400348 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400350 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400352 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400353 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400355 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400357 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400358 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400360 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400362 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400363 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400365 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400366 encode_putfh_maxsz + \
367 encode_savefh_maxsz + \
368 encode_open_maxsz + \
369 encode_getfh_maxsz + \
370 encode_getattr_maxsz + \
371 encode_restorefh_maxsz + \
372 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400374 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400375 decode_putfh_maxsz + \
376 decode_savefh_maxsz + \
377 decode_open_maxsz + \
378 decode_getfh_maxsz + \
379 decode_getattr_maxsz + \
380 decode_restorefh_maxsz + \
381 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400382#define NFS4_enc_open_confirm_sz \
383 (compound_encode_hdr_maxsz + \
384 encode_putfh_maxsz + \
385 encode_open_confirm_maxsz)
386#define NFS4_dec_open_confirm_sz \
387 (compound_decode_hdr_maxsz + \
388 decode_putfh_maxsz + \
389 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400391 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400393 encode_open_maxsz + \
394 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400396 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400398 decode_open_maxsz + \
399 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400#define NFS4_enc_open_downgrade_sz \
401 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400402 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400403 encode_putfh_maxsz + \
404 encode_open_downgrade_maxsz + \
405 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406#define NFS4_dec_open_downgrade_sz \
407 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400409 decode_putfh_maxsz + \
410 decode_open_downgrade_maxsz + \
411 decode_getattr_maxsz)
412#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400413 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 encode_putfh_maxsz + \
415 encode_close_maxsz + \
416 encode_getattr_maxsz)
417#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400418 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 decode_putfh_maxsz + \
420 decode_close_maxsz + \
421 decode_getattr_maxsz)
422#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400423 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 encode_putfh_maxsz + \
425 encode_setattr_maxsz + \
426 encode_getattr_maxsz)
427#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400428 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400429 decode_putfh_maxsz + \
430 decode_setattr_maxsz + \
431 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400433 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 encode_putfh_maxsz + \
435 encode_fsinfo_maxsz)
436#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 decode_putfh_maxsz + \
439 decode_fsinfo_maxsz)
440#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
441 encode_renew_maxsz)
442#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
443 decode_renew_maxsz)
444#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
445 encode_setclientid_maxsz)
446#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
447 decode_setclientid_maxsz)
448#define NFS4_enc_setclientid_confirm_sz \
449 (compound_encode_hdr_maxsz + \
450 encode_setclientid_confirm_maxsz + \
451 encode_putrootfh_maxsz + \
452 encode_fsinfo_maxsz)
453#define NFS4_dec_setclientid_confirm_sz \
454 (compound_decode_hdr_maxsz + \
455 decode_setclientid_confirm_maxsz + \
456 decode_putrootfh_maxsz + \
457 decode_fsinfo_maxsz)
458#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400459 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400461 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400465 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400467 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400469 encode_lockt_maxsz)
470#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400471 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400472 decode_putfh_maxsz + \
473 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400475 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400477 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400479 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400481 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400482#define NFS4_enc_release_lockowner_sz \
483 (compound_encode_hdr_maxsz + \
484 encode_lockowner_maxsz)
485#define NFS4_dec_release_lockowner_sz \
486 (compound_decode_hdr_maxsz + \
487 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488#define NFS4_enc_access_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 + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400491 encode_access_maxsz + \
492 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400494 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400496 decode_access_maxsz + \
497 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400499 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 encode_putfh_maxsz + \
501 encode_getattr_maxsz)
502#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400503 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 decode_putfh_maxsz + \
505 decode_getattr_maxsz)
506#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400507 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 encode_putfh_maxsz + \
509 encode_lookup_maxsz + \
510 encode_getattr_maxsz + \
511 encode_getfh_maxsz)
512#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400513 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400515 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 decode_getattr_maxsz + \
517 decode_getfh_maxsz)
518#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400519 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 encode_putrootfh_maxsz + \
521 encode_getattr_maxsz + \
522 encode_getfh_maxsz)
523#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400524 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 decode_putrootfh_maxsz + \
526 decode_getattr_maxsz + \
527 decode_getfh_maxsz)
528#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400529 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400531 encode_remove_maxsz + \
532 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400536 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400537 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538#define NFS4_enc_rename_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 Myklebust6caf2c82005-10-27 22:12:43 -0400543 encode_rename_maxsz + \
544 encode_getattr_maxsz + \
545 encode_restorefh_maxsz + \
546 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547#define NFS4_dec_rename_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 Myklebust6caf2c82005-10-27 22:12:43 -0400552 decode_rename_maxsz + \
553 decode_getattr_maxsz + \
554 decode_restorefh_maxsz + \
555 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556#define NFS4_enc_link_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_savefh_maxsz + \
560 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400561 encode_link_maxsz + \
562 decode_getattr_maxsz + \
563 encode_restorefh_maxsz + \
564 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 decode_putfh_maxsz + \
568 decode_savefh_maxsz + \
569 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400570 decode_link_maxsz + \
571 decode_getattr_maxsz + \
572 decode_restorefh_maxsz + \
573 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400575 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 encode_putfh_maxsz + \
577 encode_symlink_maxsz + \
578 encode_getattr_maxsz + \
579 encode_getfh_maxsz)
580#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400581 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 decode_putfh_maxsz + \
583 decode_symlink_maxsz + \
584 decode_getattr_maxsz + \
585 decode_getfh_maxsz)
586#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400587 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400589 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400591 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400593 encode_restorefh_maxsz + \
594 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400598 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400600 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400602 decode_restorefh_maxsz + \
603 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400605 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 encode_putfh_maxsz + \
607 encode_getattr_maxsz)
608#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400609 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 decode_putfh_maxsz + \
611 decode_getattr_maxsz)
612#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400613 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400615 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400617 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400619 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400621 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800622 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 encode_getattr_maxsz)
624#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400625 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800626 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 decode_getattr_maxsz)
628#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400629 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100631 encode_delegreturn_maxsz + \
632 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400634 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100635 decode_delegreturn_maxsz + \
636 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000637#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400638 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000639 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400640 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000641#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000643 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400644 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000645#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400646 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000647 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400648 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000649#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000651 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400652 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400653#define NFS4_enc_fs_locations_sz \
654 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400655 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400656 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400657 encode_lookup_maxsz + \
658 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400659#define NFS4_dec_fs_locations_sz \
660 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400661 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400662 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400663 decode_lookup_maxsz + \
664 decode_fs_locations_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400665#if defined(CONFIG_NFS_V4_1)
666#define NFS4_enc_exchange_id_sz \
667 (compound_encode_hdr_maxsz + \
668 encode_exchange_id_maxsz)
669#define NFS4_dec_exchange_id_sz \
670 (compound_decode_hdr_maxsz + \
671 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400672#define NFS4_enc_create_session_sz \
673 (compound_encode_hdr_maxsz + \
674 encode_create_session_maxsz)
675#define NFS4_dec_create_session_sz \
676 (compound_decode_hdr_maxsz + \
677 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400678#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
679 encode_destroy_session_maxsz)
680#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
681 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400682#define NFS4_enc_sequence_sz \
683 (compound_decode_hdr_maxsz + \
684 encode_sequence_maxsz)
685#define NFS4_dec_sequence_sz \
686 (compound_decode_hdr_maxsz + \
687 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400688#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
689 encode_sequence_maxsz + \
690 encode_putrootfh_maxsz + \
691 encode_fsinfo_maxsz)
692#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
693 decode_sequence_maxsz + \
694 decode_putrootfh_maxsz + \
695 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500696#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
697 encode_sequence_maxsz + \
698 encode_reclaim_complete_maxsz)
699#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
700 decode_sequence_maxsz + \
701 decode_reclaim_complete_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500702
703const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
704 compound_encode_hdr_maxsz +
705 encode_sequence_maxsz +
706 encode_putfh_maxsz +
707 encode_getattr_maxsz) *
708 XDR_UNIT);
709
710const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
711 compound_decode_hdr_maxsz +
712 decode_sequence_maxsz +
713 decode_putfh_maxsz) *
714 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400715#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Trond Myklebustbca79472009-03-11 14:10:26 -0400717static const umode_t nfs_type2fmt[] = {
718 [NF4BAD] = 0,
719 [NF4REG] = S_IFREG,
720 [NF4DIR] = S_IFDIR,
721 [NF4BLK] = S_IFBLK,
722 [NF4CHR] = S_IFCHR,
723 [NF4LNK] = S_IFLNK,
724 [NF4SOCK] = S_IFSOCK,
725 [NF4FIFO] = S_IFIFO,
726 [NF4ATTRDIR] = 0,
727 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728};
729
730struct compound_hdr {
731 int32_t status;
732 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500733 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 uint32_t taglen;
735 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400736 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400737 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738};
739
Benny Halevy13c65ce2009-08-14 17:19:25 +0300740static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
741{
742 __be32 *p = xdr_reserve_space(xdr, nbytes);
743 BUG_ON(!p);
744 return p;
745}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
748{
Al Viro8687b632006-10-19 23:28:48 -0700749 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
751 p = xdr_reserve_space(xdr, 4 + len);
752 BUG_ON(p == NULL);
753 xdr_encode_opaque(p, str, len);
754}
755
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400756static void encode_compound_hdr(struct xdr_stream *xdr,
757 struct rpc_rqst *req,
758 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759{
Al Viro8687b632006-10-19 23:28:48 -0700760 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400761 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400762
763 /* initialize running count of expected bytes in reply.
764 * NOTE: the replied tag SHOULD be the same is the one sent,
765 * but this is not required as a MUST for the server to do so. */
766 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
768 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
769 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300770 p = reserve_space(xdr, 4 + hdr->taglen + 8);
771 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300772 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500773 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300774 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500775}
776
777static void encode_nops(struct compound_hdr *hdr)
778{
Andy Adamsonfc931582009-04-01 09:22:31 -0400779 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500780 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781}
782
783static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
784{
Al Viro8687b632006-10-19 23:28:48 -0700785 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
788 BUG_ON(p == NULL);
789 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
790}
791
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500792static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793{
794 char owner_name[IDMAP_NAMESZ];
795 char owner_group[IDMAP_NAMESZ];
796 int owner_namelen = 0;
797 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700798 __be32 *p;
799 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 int len;
801 uint32_t bmval0 = 0;
802 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
804 /*
805 * We reserve enough space to write the entire attribute buffer at once.
806 * In the worst-case, this would be
807 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
808 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000809 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 */
811 len = 16;
812
813 /* Sigh */
814 if (iap->ia_valid & ATTR_SIZE)
815 len += 8;
816 if (iap->ia_valid & ATTR_MODE)
817 len += 4;
818 if (iap->ia_valid & ATTR_UID) {
Bryan Schumaker955a8572010-09-29 15:41:49 -0400819 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400821 dprintk("nfs: couldn't resolve uid %d to string\n",
822 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 /* XXX */
824 strcpy(owner_name, "nobody");
825 owner_namelen = sizeof("nobody") - 1;
826 /* goto out; */
827 }
828 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
829 }
830 if (iap->ia_valid & ATTR_GID) {
Bryan Schumaker955a8572010-09-29 15:41:49 -0400831 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400833 dprintk("nfs: couldn't resolve gid %d to string\n",
834 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 strcpy(owner_group, "nobody");
836 owner_grouplen = sizeof("nobody") - 1;
837 /* goto out; */
838 }
839 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
840 }
841 if (iap->ia_valid & ATTR_ATIME_SET)
842 len += 16;
843 else if (iap->ia_valid & ATTR_ATIME)
844 len += 4;
845 if (iap->ia_valid & ATTR_MTIME_SET)
846 len += 16;
847 else if (iap->ia_valid & ATTR_MTIME)
848 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300849 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 /*
852 * We write the bitmap length now, but leave the bitmap and the attribute
853 * buffer length to be backfilled at the end of this routine.
854 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300855 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 q = p;
857 p += 3;
858
859 if (iap->ia_valid & ATTR_SIZE) {
860 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300861 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 }
863 if (iap->ia_valid & ATTR_MODE) {
864 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300865 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 }
867 if (iap->ia_valid & ATTR_UID) {
868 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300869 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 }
871 if (iap->ia_valid & ATTR_GID) {
872 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300873 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 }
875 if (iap->ia_valid & ATTR_ATIME_SET) {
876 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300877 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
878 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -0400879 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
880 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 }
882 else if (iap->ia_valid & ATTR_ATIME) {
883 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300884 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 }
886 if (iap->ia_valid & ATTR_MTIME_SET) {
887 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300888 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
889 *p++ = cpu_to_be32(0);
890 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
891 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 }
893 else if (iap->ia_valid & ATTR_MTIME) {
894 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300895 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 /*
899 * Now we backfill the bitmap and the attribute buffer length.
900 */
901 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400902 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 len, ((char *)p - (char *)q) + 4);
904 BUG();
905 }
906 len = (char *)p - (char *)q - 12;
907 *q++ = htonl(bmval0);
908 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300909 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912}
913
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500914static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
Al Viro8687b632006-10-19 23:28:48 -0700916 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Benny Halevy13c65ce2009-08-14 17:19:25 +0300918 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300919 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +0300920 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500921 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400922 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923}
924
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500925static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926{
Al Viro8687b632006-10-19 23:28:48 -0700927 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Benny Halevy13c65ce2009-08-14 17:19:25 +0300929 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300930 *p++ = cpu_to_be32(OP_CLOSE);
931 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +0300932 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500933 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400934 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935}
936
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500937static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938{
Al Viro8687b632006-10-19 23:28:48 -0700939 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500940
Benny Halevy13c65ce2009-08-14 17:19:25 +0300941 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300942 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +0300943 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +0300944 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500945 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400946 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947}
948
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500949static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950{
Al Viro8687b632006-10-19 23:28:48 -0700951 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500952
Benny Halevy13c65ce2009-08-14 17:19:25 +0300953 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300954 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +0300955 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
957 switch (create->ftype) {
958 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300959 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +0300960 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -0400961 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 break;
963
964 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300965 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300966 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +0300967 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 break;
969
970 default:
971 break;
972 }
973
Benny Halevy811652b2009-08-14 17:19:34 +0300974 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -0500975 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400976 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500978 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979}
980
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500981static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982{
Andy Adamson05d564f2008-12-23 16:06:15 -0500983 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
Benny Halevy13c65ce2009-08-14 17:19:25 +0300985 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300986 *p++ = cpu_to_be32(OP_GETATTR);
987 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +0300988 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500989 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400990 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991}
992
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500993static 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 -0700994{
Andy Adamson05d564f2008-12-23 16:06:15 -0500995 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
Benny Halevy13c65ce2009-08-14 17:19:25 +0300997 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300998 *p++ = cpu_to_be32(OP_GETATTR);
999 *p++ = cpu_to_be32(2);
1000 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001001 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001002 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001003 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004}
1005
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001006static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001008 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1009 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010}
1011
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001012static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001014 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1015 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016}
1017
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001018static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001019{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001020 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1021 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001022}
1023
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001024static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025{
Al Viro8687b632006-10-19 23:28:48 -07001026 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Benny Halevy13c65ce2009-08-14 17:19:25 +03001028 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001029 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001030 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001031 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032}
1033
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001034static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035{
Al Viro8687b632006-10-19 23:28:48 -07001036 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037
Benny Halevy13c65ce2009-08-14 17:19:25 +03001038 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001039 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001040 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001041 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001042 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043}
1044
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001045static inline int nfs4_lock_type(struct file_lock *fl, int block)
1046{
1047 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1048 return block ? NFS4_READW_LT : NFS4_READ_LT;
1049 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1050}
1051
1052static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1053{
1054 if (fl->fl_end == OFFSET_MAX)
1055 return ~(uint64_t)0;
1056 return fl->fl_end - fl->fl_start + 1;
1057}
1058
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001059static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1060{
1061 __be32 *p;
1062
1063 p = reserve_space(xdr, 28);
1064 p = xdr_encode_hyper(p, lowner->clientid);
1065 *p++ = cpu_to_be32(16);
1066 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1067 xdr_encode_hyper(p, lowner->id);
1068}
1069
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070/*
1071 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1072 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1073 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001074static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075{
Al Viro8687b632006-10-19 23:28:48 -07001076 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Benny Halevy13c65ce2009-08-14 17:19:25 +03001078 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001079 *p++ = cpu_to_be32(OP_LOCK);
1080 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1081 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001082 p = xdr_encode_hyper(p, args->fl->fl_start);
1083 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001084 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001085 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001086 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001087 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001088 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001089 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001090 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 }
1092 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001093 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001094 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001095 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 }
Andy Adamsond0179312008-12-23 16:06:17 -05001097 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001098 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099}
1100
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001101static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102{
Al Viro8687b632006-10-19 23:28:48 -07001103 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001105 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001106 *p++ = cpu_to_be32(OP_LOCKT);
1107 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001108 p = xdr_encode_hyper(p, args->fl->fl_start);
1109 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001110 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001111 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001112 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113}
1114
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001115static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116{
Al Viro8687b632006-10-19 23:28:48 -07001117 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
Benny Halevy13c65ce2009-08-14 17:19:25 +03001119 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001120 *p++ = cpu_to_be32(OP_LOCKU);
1121 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1122 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001123 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001124 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001125 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001126 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001127 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128}
1129
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001130static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1131{
1132 __be32 *p;
1133
1134 p = reserve_space(xdr, 4);
1135 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1136 encode_lockowner(xdr, lowner);
1137 hdr->nops++;
1138 hdr->replen += decode_release_lockowner_maxsz;
1139}
1140
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001141static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
1143 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001144 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
Benny Halevy13c65ce2009-08-14 17:19:25 +03001146 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001147 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001148 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001149 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001150 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151}
1152
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001153static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154{
Al Viro8687b632006-10-19 23:28:48 -07001155 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Benny Halevy13c65ce2009-08-14 17:19:25 +03001157 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001158 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001159 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001160 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001161 break;
1162 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001163 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001164 break;
1165 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001166 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001167 break;
1168 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001169 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 }
Benny Halevy34558512009-08-14 17:19:30 +03001171 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172}
1173
1174static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1175{
Al Viro8687b632006-10-19 23:28:48 -07001176 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 /*
1178 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1179 * owner 4 = 32
1180 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001181 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001182 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001183 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001184 encode_share_access(xdr, arg->fmode);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001185 p = reserve_space(xdr, 28);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001186 p = xdr_encode_hyper(p, arg->clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001187 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001188 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001189 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190}
1191
1192static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1193{
Al Viro8687b632006-10-19 23:28:48 -07001194 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001195 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Benny Halevy13c65ce2009-08-14 17:19:25 +03001197 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001199 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001200 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001201 encode_attrs(xdr, arg->u.attrs, arg->server);
1202 break;
1203 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001204 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001205 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001206 if (nfs4_has_persistent_session(clp)) {
1207 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1208 encode_attrs(xdr, arg->u.attrs, arg->server);
1209 } else {
1210 struct iattr dummy;
1211
1212 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1213 encode_nfs4_verifier(xdr, &arg->u.verifier);
1214 dummy.ia_valid = 0;
1215 encode_attrs(xdr, &dummy, arg->server);
1216 }
1217 } else {
1218 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1219 encode_nfs4_verifier(xdr, &arg->u.verifier);
1220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 }
1222}
1223
1224static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1225{
Al Viro8687b632006-10-19 23:28:48 -07001226 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
Benny Halevy13c65ce2009-08-14 17:19:25 +03001228 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001230 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001231 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001232 break;
1233 default:
1234 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001235 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001236 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 }
1238}
1239
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001240static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241{
Al Viro8687b632006-10-19 23:28:48 -07001242 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
Benny Halevy13c65ce2009-08-14 17:19:25 +03001244 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001246 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001247 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001248 break;
1249 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001250 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001251 break;
1252 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001253 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001254 break;
1255 default:
1256 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 }
1258}
1259
1260static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1261{
Al Viro8687b632006-10-19 23:28:48 -07001262 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
Benny Halevy13c65ce2009-08-14 17:19:25 +03001264 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001265 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 encode_string(xdr, name->len, name->name);
1267}
1268
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001269static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270{
Al Viro8687b632006-10-19 23:28:48 -07001271 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
Benny Halevy13c65ce2009-08-14 17:19:25 +03001273 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001274 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 encode_delegation_type(xdr, type);
1276}
1277
1278static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1279{
Al Viro8687b632006-10-19 23:28:48 -07001280 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Benny Halevy13c65ce2009-08-14 17:19:25 +03001282 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001283 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001284 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 encode_string(xdr, name->len, name->name);
1286}
1287
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001288static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
1290 encode_openhdr(xdr, arg);
1291 encode_opentype(xdr, arg);
1292 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001293 case NFS4_OPEN_CLAIM_NULL:
1294 encode_claim_null(xdr, arg->name);
1295 break;
1296 case NFS4_OPEN_CLAIM_PREVIOUS:
1297 encode_claim_previous(xdr, arg->u.delegation_type);
1298 break;
1299 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1300 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1301 break;
1302 default:
1303 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 }
Andy Adamsond0179312008-12-23 16:06:17 -05001305 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001306 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307}
1308
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001309static 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 -07001310{
Al Viro8687b632006-10-19 23:28:48 -07001311 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
Benny Halevy13c65ce2009-08-14 17:19:25 +03001313 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001314 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001315 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001316 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001317 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001318 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319}
1320
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001321static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322{
Al Viro8687b632006-10-19 23:28:48 -07001323 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
Benny Halevy13c65ce2009-08-14 17:19:25 +03001325 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001326 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001327 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001328 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001329 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001330 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001331 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332}
1333
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001334static void
Andy Adamsond0179312008-12-23 16:06:17 -05001335encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336{
1337 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001338 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Benny Halevy13c65ce2009-08-14 17:19:25 +03001340 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001341 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001342 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001343 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001344 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345}
1346
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001347static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348{
Andy Adamson05d564f2008-12-23 16:06:15 -05001349 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001350
Benny Halevy13c65ce2009-08-14 17:19:25 +03001351 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001352 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001353 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001354 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355}
1356
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001357static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001360 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Benny Halevy13c65ce2009-08-14 17:19:25 +03001362 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001364 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Benny Halevy34558512009-08-14 17:19:30 +03001365 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 } else
Benny Halevy34558512009-08-14 17:19:30 +03001367 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368}
1369
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001370static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371{
Al Viro8687b632006-10-19 23:28:48 -07001372 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
Benny Halevy13c65ce2009-08-14 17:19:25 +03001374 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001375 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001377 encode_stateid(xdr, args->context, args->lock_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Benny Halevy13c65ce2009-08-14 17:19:25 +03001379 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001380 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001381 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001382 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001383 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384}
1385
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001386static 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 -07001387{
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001388 uint32_t attrs[2] = {0, 0};
Al Viro8687b632006-10-19 23:28:48 -07001389 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001391 if (readdir->plus) {
1392 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1393 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE;
1394 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1395 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1396 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1397 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1398 }
1399 attrs[0] |= FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID;
1400 attrs[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
1401
Benny Halevy13c65ce2009-08-14 17:19:25 +03001402 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001403 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001404 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001405 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001406 *p++ = cpu_to_be32(readdir->count >> 1); /* We're not doing readdirplus */
1407 *p++ = cpu_to_be32(readdir->count);
1408 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001409
1410 if (!readdir->plus) {
1411 /* Switch to mounted_on_fileid if the server supports it */
1412 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1413 attrs[0] &= ~FATTR4_WORD0_FILEID;
1414 else
1415 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1416 }
1417
Benny Halevye75bc1c2009-08-14 17:18:54 +03001418 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001419 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001420 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001421 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001422 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1423 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001424 (unsigned long long)readdir->cookie,
1425 ((u32 *)readdir->verifier.data)[0],
1426 ((u32 *)readdir->verifier.data)[1],
1427 attrs[0] & readdir->bitmask[0],
1428 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429}
1430
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001431static 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 -07001432{
Al Viro8687b632006-10-19 23:28:48 -07001433 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
Benny Halevy13c65ce2009-08-14 17:19:25 +03001435 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001436 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001437 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001438 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439}
1440
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001441static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442{
Al Viro8687b632006-10-19 23:28:48 -07001443 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
Benny Halevy13c65ce2009-08-14 17:19:25 +03001445 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001446 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001447 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001448 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001449 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450}
1451
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001452static 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 -07001453{
Al Viro8687b632006-10-19 23:28:48 -07001454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Benny Halevy811652b2009-08-14 17:19:34 +03001456 p = reserve_space(xdr, 4);
1457 *p = cpu_to_be32(OP_RENAME);
1458 encode_string(xdr, oldname->len, oldname->name);
1459 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001460 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001461 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462}
1463
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001464static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465{
Al Viro8687b632006-10-19 23:28:48 -07001466 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Benny Halevy13c65ce2009-08-14 17:19:25 +03001468 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001469 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001470 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001471 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001472 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473}
1474
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001475static void
Andy Adamsond0179312008-12-23 16:06:17 -05001476encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001477{
Al Viro8687b632006-10-19 23:28:48 -07001478 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001479
Benny Halevy13c65ce2009-08-14 17:19:25 +03001480 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001481 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001482 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001483 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001484}
1485
1486static int
Andy Adamsond0179312008-12-23 16:06:17 -05001487encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001488{
Al Viro8687b632006-10-19 23:28:48 -07001489 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001490
Benny Halevy13c65ce2009-08-14 17:19:25 +03001491 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001492 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001493 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001494 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001495 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001496 *p = cpu_to_be32(FATTR4_WORD0_ACL);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001497 if (arg->acl_len % 4)
1498 return -EINVAL;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001499 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001500 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001501 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001502 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001503 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001504 return 0;
1505}
1506
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001507static void
Andy Adamsond0179312008-12-23 16:06:17 -05001508encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509{
Al Viro8687b632006-10-19 23:28:48 -07001510 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
Benny Halevy13c65ce2009-08-14 17:19:25 +03001512 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001513 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001514 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001515 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516}
1517
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001518static 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 -07001519{
Al Viro8687b632006-10-19 23:28:48 -07001520 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001521
Benny Halevy13c65ce2009-08-14 17:19:25 +03001522 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001523 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001524 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001525 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001526 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001527 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528}
1529
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001530static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531{
Al Viro8687b632006-10-19 23:28:48 -07001532 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
Benny Halevy13c65ce2009-08-14 17:19:25 +03001534 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001535 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001536 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
1538 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001539 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001540 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1542 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001543 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001544 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001545 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001546 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547}
1548
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001549static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550{
Andy Adamson05d564f2008-12-23 16:06:15 -05001551 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Benny Halevy13c65ce2009-08-14 17:19:25 +03001553 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001554 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001555 p = xdr_encode_hyper(p, arg->clientid);
1556 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001557 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001558 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559}
1560
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001561static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562{
Al Viro8687b632006-10-19 23:28:48 -07001563 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
Benny Halevy13c65ce2009-08-14 17:19:25 +03001565 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001566 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001568 encode_stateid(xdr, args->context, args->lock_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
Benny Halevy13c65ce2009-08-14 17:19:25 +03001570 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001571 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001572 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001573 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
1575 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001576 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001577 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578}
1579
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001580static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581{
Al Viro8687b632006-10-19 23:28:48 -07001582 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
Benny Halevy13c65ce2009-08-14 17:19:25 +03001584 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
Benny Halevye75bc1c2009-08-14 17:18:54 +03001586 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001587 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001588 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001589 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001591
Benny Halevy99fe60d2009-04-01 09:22:29 -04001592#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001593/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001594static void encode_exchange_id(struct xdr_stream *xdr,
1595 struct nfs41_exchange_id_args *args,
1596 struct compound_hdr *hdr)
1597{
1598 __be32 *p;
1599
Benny Halevy13c65ce2009-08-14 17:19:25 +03001600 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001601 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001602 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001603
1604 encode_string(xdr, args->id_len, args->id);
1605
Benny Halevy13c65ce2009-08-14 17:19:25 +03001606 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001607 *p++ = cpu_to_be32(args->flags);
1608 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001609 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001610 hdr->nops++;
1611 hdr->replen += decode_exchange_id_maxsz;
1612}
Andy Adamsonfc931582009-04-01 09:22:31 -04001613
1614static void encode_create_session(struct xdr_stream *xdr,
1615 struct nfs41_create_session_args *args,
1616 struct compound_hdr *hdr)
1617{
1618 __be32 *p;
1619 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1620 uint32_t len;
1621 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001622 u32 max_resp_sz_cached;
1623
1624 /*
1625 * Assumes OPEN is the biggest non-idempotent compound.
1626 * 2 is the verifier.
1627 */
1628 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1629 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001630
Andy Adamsonfc931582009-04-01 09:22:31 -04001631 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1632 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001633
Benny Halevy13c65ce2009-08-14 17:19:25 +03001634 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001635 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001636 p = xdr_encode_hyper(p, clp->cl_ex_clid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001637 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1638 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001639
Andy Adamsonfc931582009-04-01 09:22:31 -04001640 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001641 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1642 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1643 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001644 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001645 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1646 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1647 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001648
1649 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001650 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1651 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1652 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1653 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1654 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1655 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1656 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001657
Benny Halevye75bc1c2009-08-14 17:18:54 +03001658 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001659 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001660 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001661
1662 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001663 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001664 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001665 *p++ = cpu_to_be32(0); /* UID */
1666 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001667 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001668 hdr->nops++;
1669 hdr->replen += decode_create_session_maxsz;
1670}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001671
1672static void encode_destroy_session(struct xdr_stream *xdr,
1673 struct nfs4_session *session,
1674 struct compound_hdr *hdr)
1675{
1676 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001677 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001678 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001679 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001680 hdr->nops++;
1681 hdr->replen += decode_destroy_session_maxsz;
1682}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001683
1684static void encode_reclaim_complete(struct xdr_stream *xdr,
1685 struct nfs41_reclaim_complete_args *args,
1686 struct compound_hdr *hdr)
1687{
1688 __be32 *p;
1689
1690 p = reserve_space(xdr, 8);
1691 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1692 *p++ = cpu_to_be32(args->one_fs);
1693 hdr->nops++;
1694 hdr->replen += decode_reclaim_complete_maxsz;
1695}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001696#endif /* CONFIG_NFS_V4_1 */
1697
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001698static void encode_sequence(struct xdr_stream *xdr,
1699 const struct nfs4_sequence_args *args,
1700 struct compound_hdr *hdr)
1701{
1702#if defined(CONFIG_NFS_V4_1)
1703 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001704 struct nfs4_slot_table *tp;
1705 struct nfs4_slot *slot;
1706 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001707
1708 if (!session)
1709 return;
1710
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001711 tp = &session->fc_slot_table;
1712
1713 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1714 slot = tp->slots + args->sa_slotid;
1715
Benny Halevy13c65ce2009-08-14 17:19:25 +03001716 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001717 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001718
1719 /*
1720 * Sessionid + seqid + slotid + max slotid + cache_this
1721 */
1722 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1723 "max_slotid=%d cache_this=%d\n",
1724 __func__,
1725 ((u32 *)session->sess_id.data)[0],
1726 ((u32 *)session->sess_id.data)[1],
1727 ((u32 *)session->sess_id.data)[2],
1728 ((u32 *)session->sess_id.data)[3],
1729 slot->seq_nr, args->sa_slotid,
1730 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001731 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001732 *p++ = cpu_to_be32(slot->seq_nr);
1733 *p++ = cpu_to_be32(args->sa_slotid);
1734 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001735 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001736 hdr->nops++;
1737 hdr->replen += decode_sequence_maxsz;
1738#endif /* CONFIG_NFS_V4_1 */
1739}
1740
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741/*
1742 * END OF "GENERIC" ENCODE ROUTINES.
1743 */
1744
Benny Halevy66cc0422009-04-01 09:22:10 -04001745static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1746{
1747#if defined(CONFIG_NFS_V4_1)
1748 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001749 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001750#endif /* CONFIG_NFS_V4_1 */
1751 return 0;
1752}
1753
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754/*
1755 * Encode an ACCESS request
1756 */
Al Viro8687b632006-10-19 23:28:48 -07001757static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758{
1759 struct xdr_stream xdr;
1760 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001761 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
1764 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001765 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001766 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001767 encode_putfh(&xdr, args->fh, &hdr);
1768 encode_access(&xdr, args->access, &hdr);
1769 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001770 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001771 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772}
1773
1774/*
1775 * Encode LOOKUP request
1776 */
Al Viro8687b632006-10-19 23:28:48 -07001777static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778{
1779 struct xdr_stream xdr;
1780 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001781 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
1784 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001785 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001786 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001787 encode_putfh(&xdr, args->dir_fh, &hdr);
1788 encode_lookup(&xdr, args->name, &hdr);
1789 encode_getfh(&xdr, &hdr);
1790 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001791 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001792 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793}
1794
1795/*
1796 * Encode LOOKUP_ROOT request
1797 */
Al Viro8687b632006-10-19 23:28:48 -07001798static 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 -07001799{
1800 struct xdr_stream xdr;
1801 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001802 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
1805 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001806 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001807 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001808 encode_putrootfh(&xdr, &hdr);
1809 encode_getfh(&xdr, &hdr);
1810 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001811 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001812 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813}
1814
1815/*
1816 * Encode REMOVE request
1817 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001818static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819{
1820 struct xdr_stream xdr;
1821 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001822 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824
1825 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001826 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001827 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001828 encode_putfh(&xdr, args->fh, &hdr);
1829 encode_remove(&xdr, &args->name, &hdr);
1830 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001831 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001832 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833}
1834
1835/*
1836 * Encode RENAME request
1837 */
Jeff Layton920769f2010-09-17 17:30:25 -04001838static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839{
1840 struct xdr_stream xdr;
1841 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001842 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
1845 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001846 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001847 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001848 encode_putfh(&xdr, args->old_dir, &hdr);
1849 encode_savefh(&xdr, &hdr);
1850 encode_putfh(&xdr, args->new_dir, &hdr);
1851 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1852 encode_getfattr(&xdr, args->bitmask, &hdr);
1853 encode_restorefh(&xdr, &hdr);
1854 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001855 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001856 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857}
1858
1859/*
1860 * Encode LINK request
1861 */
Al Viro8687b632006-10-19 23:28:48 -07001862static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863{
1864 struct xdr_stream xdr;
1865 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001866 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868
1869 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001870 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001871 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001872 encode_putfh(&xdr, args->fh, &hdr);
1873 encode_savefh(&xdr, &hdr);
1874 encode_putfh(&xdr, args->dir_fh, &hdr);
1875 encode_link(&xdr, args->name, &hdr);
1876 encode_getfattr(&xdr, args->bitmask, &hdr);
1877 encode_restorefh(&xdr, &hdr);
1878 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001879 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001880 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881}
1882
1883/*
1884 * Encode CREATE request
1885 */
Al Viro8687b632006-10-19 23:28:48 -07001886static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887{
1888 struct xdr_stream xdr;
1889 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001890 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892
1893 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001894 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001895 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001896 encode_putfh(&xdr, args->dir_fh, &hdr);
1897 encode_savefh(&xdr, &hdr);
1898 encode_create(&xdr, args, &hdr);
1899 encode_getfh(&xdr, &hdr);
1900 encode_getfattr(&xdr, args->bitmask, &hdr);
1901 encode_restorefh(&xdr, &hdr);
1902 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001903 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001904 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905}
1906
1907/*
1908 * Encode SYMLINK request
1909 */
Al Viro8687b632006-10-19 23:28:48 -07001910static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911{
1912 return nfs4_xdr_enc_create(req, p, args);
1913}
1914
1915/*
1916 * Encode GETATTR request
1917 */
Al Viro8687b632006-10-19 23:28:48 -07001918static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919{
1920 struct xdr_stream xdr;
1921 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001922 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924
1925 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001926 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001927 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001928 encode_putfh(&xdr, args->fh, &hdr);
1929 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001930 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001931 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932}
1933
1934/*
1935 * Encode a CLOSE request
1936 */
Al Viro8687b632006-10-19 23:28:48 -07001937static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938{
Andy Adamson05d564f2008-12-23 16:06:15 -05001939 struct xdr_stream xdr;
1940 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001941 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001942 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Andy Adamson05d564f2008-12-23 16:06:15 -05001944 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001945 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001946 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001947 encode_putfh(&xdr, args->fh, &hdr);
1948 encode_close(&xdr, args, &hdr);
1949 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001950 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001951 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952}
1953
1954/*
1955 * Encode an OPEN request
1956 */
Al Viro8687b632006-10-19 23:28:48 -07001957static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958{
1959 struct xdr_stream xdr;
1960 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001961 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
1964 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001965 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001966 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001967 encode_putfh(&xdr, args->fh, &hdr);
1968 encode_savefh(&xdr, &hdr);
1969 encode_open(&xdr, args, &hdr);
1970 encode_getfh(&xdr, &hdr);
1971 encode_getfattr(&xdr, args->bitmask, &hdr);
1972 encode_restorefh(&xdr, &hdr);
1973 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001974 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001975 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976}
1977
1978/*
1979 * Encode an OPEN_CONFIRM request
1980 */
Al Viro8687b632006-10-19 23:28:48 -07001981static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982{
1983 struct xdr_stream xdr;
1984 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001985 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987
1988 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001989 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001990 encode_putfh(&xdr, args->fh, &hdr);
1991 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001992 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001993 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994}
1995
1996/*
1997 * Encode an OPEN request with no attributes.
1998 */
Al Viro8687b632006-10-19 23:28:48 -07001999static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000{
2001 struct xdr_stream xdr;
2002 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002003 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
2006 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002007 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002008 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002009 encode_putfh(&xdr, args->fh, &hdr);
2010 encode_open(&xdr, args, &hdr);
2011 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002012 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002013 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014}
2015
2016/*
2017 * Encode an OPEN_DOWNGRADE request
2018 */
Al Viro8687b632006-10-19 23:28:48 -07002019static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020{
2021 struct xdr_stream xdr;
2022 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002023 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025
2026 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002027 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002028 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002029 encode_putfh(&xdr, args->fh, &hdr);
2030 encode_open_downgrade(&xdr, args, &hdr);
2031 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002032 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002033 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034}
2035
2036/*
2037 * Encode a LOCK request
2038 */
Al Viro8687b632006-10-19 23:28:48 -07002039static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040{
2041 struct xdr_stream xdr;
2042 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002043 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
2046 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002047 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002048 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002049 encode_putfh(&xdr, args->fh, &hdr);
2050 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002051 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002052 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053}
2054
2055/*
2056 * Encode a LOCKT request
2057 */
Al Viro8687b632006-10-19 23:28:48 -07002058static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059{
2060 struct xdr_stream xdr;
2061 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002062 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
2065 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002066 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002067 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002068 encode_putfh(&xdr, args->fh, &hdr);
2069 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002070 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002071 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072}
2073
2074/*
2075 * Encode a LOCKU request
2076 */
Al Viro8687b632006-10-19 23:28:48 -07002077static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078{
2079 struct xdr_stream xdr;
2080 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002081 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
2084 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002085 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002086 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002087 encode_putfh(&xdr, args->fh, &hdr);
2088 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002089 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002090 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091}
2092
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002093static int nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, __be32 *p, struct nfs_release_lockowner_args *args)
2094{
2095 struct xdr_stream xdr;
2096 struct compound_hdr hdr = {
2097 .minorversion = 0,
2098 };
2099
2100 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2101 encode_compound_hdr(&xdr, req, &hdr);
2102 encode_release_lockowner(&xdr, &args->lock_owner, &hdr);
2103 encode_nops(&hdr);
2104 return 0;
2105}
2106
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107/*
2108 * Encode a READLINK request
2109 */
Al Viro8687b632006-10-19 23:28:48 -07002110static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111{
2112 struct xdr_stream xdr;
2113 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002114 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
2117 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002118 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002119 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002120 encode_putfh(&xdr, args->fh, &hdr);
2121 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002122
Benny Halevy28f56692009-04-01 09:22:09 -04002123 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002124 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002125 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002126 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127}
2128
2129/*
2130 * Encode a READDIR request
2131 */
Al Viro8687b632006-10-19 23:28:48 -07002132static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
2134 struct xdr_stream xdr;
2135 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002136 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
2139 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002140 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002141 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002142 encode_putfh(&xdr, args->fh, &hdr);
2143 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002144
Benny Halevy28f56692009-04-01 09:22:09 -04002145 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002146 args->pgbase, args->count);
2147 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002148 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002149 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002150 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002151 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152}
2153
2154/*
2155 * Encode a READ request
2156 */
Al Viro8687b632006-10-19 23:28:48 -07002157static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 struct xdr_stream xdr;
2160 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002161 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
2164 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002165 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002166 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002167 encode_putfh(&xdr, args->fh, &hdr);
2168 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
Benny Halevy28f56692009-04-01 09:22:09 -04002170 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002172 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002173 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002174 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175}
2176
2177/*
2178 * Encode an SETATTR request
2179 */
Al Viro8687b632006-10-19 23:28:48 -07002180static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181{
Andy Adamson05d564f2008-12-23 16:06:15 -05002182 struct xdr_stream xdr;
2183 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002184 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002185 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186
Andy Adamson05d564f2008-12-23 16:06:15 -05002187 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002188 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002189 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002190 encode_putfh(&xdr, args->fh, &hdr);
2191 encode_setattr(&xdr, args, args->server, &hdr);
2192 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002193 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002194 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195}
2196
2197/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002198 * Encode a GETACL request
2199 */
2200static int
Al Viro8687b632006-10-19 23:28:48 -07002201nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002202 struct nfs_getaclargs *args)
2203{
2204 struct xdr_stream xdr;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002205 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002206 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002207 };
Benny Halevy28f56692009-04-01 09:22:09 -04002208 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002209
2210 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002211 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002212 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002213 encode_putfh(&xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002214 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002215 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2216
Benny Halevy28f56692009-04-01 09:22:09 -04002217 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002218 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002219 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002220 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002221}
2222
2223/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 * Encode a WRITE request
2225 */
Al Viro8687b632006-10-19 23:28:48 -07002226static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227{
2228 struct xdr_stream xdr;
2229 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002230 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
2233 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002234 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002235 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002236 encode_putfh(&xdr, args->fh, &hdr);
2237 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002238 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002239 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002240 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002241 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242}
2243
2244/*
2245 * a COMMIT request
2246 */
Al Viro8687b632006-10-19 23:28:48 -07002247static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248{
2249 struct xdr_stream xdr;
2250 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002251 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253
2254 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002255 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002256 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002257 encode_putfh(&xdr, args->fh, &hdr);
2258 encode_commit(&xdr, args, &hdr);
2259 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002260 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002261 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262}
2263
2264/*
2265 * FSINFO request
2266 */
Al Viro8687b632006-10-19 23:28:48 -07002267static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268{
2269 struct xdr_stream xdr;
2270 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002271 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273
2274 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002275 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002276 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002277 encode_putfh(&xdr, args->fh, &hdr);
2278 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002279 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002280 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281}
2282
2283/*
2284 * a PATHCONF request
2285 */
Al Viro8687b632006-10-19 23:28:48 -07002286static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 struct xdr_stream xdr;
2289 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002290 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
2293 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002294 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002295 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002296 encode_putfh(&xdr, args->fh, &hdr);
2297 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2298 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002299 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002300 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301}
2302
2303/*
2304 * a STATFS request
2305 */
Al Viro8687b632006-10-19 23:28:48 -07002306static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 struct xdr_stream xdr;
2309 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002310 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
2313 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002314 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002315 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002316 encode_putfh(&xdr, args->fh, &hdr);
2317 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2318 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002319 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002320 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321}
2322
2323/*
2324 * GETATTR_BITMAP request
2325 */
Benny Halevy43652ad2009-04-01 09:21:54 -04002326static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2327 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328{
2329 struct xdr_stream xdr;
2330 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002331 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
2334 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002335 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002336 encode_sequence(&xdr, &args->seq_args, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04002337 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002338 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2339 FATTR4_WORD0_LINK_SUPPORT|
2340 FATTR4_WORD0_SYMLINK_SUPPORT|
2341 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002342 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002343 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344}
2345
2346/*
2347 * a RENEW request
2348 */
Al Viro8687b632006-10-19 23:28:48 -07002349static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350{
2351 struct xdr_stream xdr;
2352 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002353 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 };
2355
2356 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002357 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002358 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002359 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002360 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361}
2362
2363/*
2364 * a SETCLIENTID request
2365 */
Al Viro8687b632006-10-19 23:28:48 -07002366static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367{
2368 struct xdr_stream xdr;
2369 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002370 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 };
2372
2373 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002374 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002375 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002376 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002377 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378}
2379
2380/*
2381 * a SETCLIENTID_CONFIRM request
2382 */
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04002383static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384{
2385 struct xdr_stream xdr;
2386 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002387 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 };
2389 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390
2391 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002392 encode_compound_hdr(&xdr, req, &hdr);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04002393 encode_setclientid_confirm(&xdr, arg, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002394 encode_putrootfh(&xdr, &hdr);
2395 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002396 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002397 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398}
2399
2400/*
2401 * DELEGRETURN request
2402 */
Al Viro8687b632006-10-19 23:28:48 -07002403static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404{
2405 struct xdr_stream xdr;
2406 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002407 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409
2410 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002411 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002412 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002413 encode_putfh(&xdr, args->fhandle, &hdr);
2414 encode_delegreturn(&xdr, args->stateid, &hdr);
2415 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002416 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002417 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418}
2419
2420/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002421 * Encode FS_LOCATIONS request
2422 */
Al Viro8687b632006-10-19 23:28:48 -07002423static 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 -04002424{
2425 struct xdr_stream xdr;
2426 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002427 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002428 };
Benny Halevy28f56692009-04-01 09:22:09 -04002429 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002430
2431 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002432 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002433 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002434 encode_putfh(&xdr, args->dir_fh, &hdr);
2435 encode_lookup(&xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002436 replen = hdr.replen; /* get the attribute into args->page */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002437 encode_fs_locations(&xdr, args->bitmask, &hdr);
2438
Benny Halevy28f56692009-04-01 09:22:09 -04002439 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002440 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002441 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002442 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002443}
2444
Benny Halevy99fe60d2009-04-01 09:22:29 -04002445#if defined(CONFIG_NFS_V4_1)
2446/*
2447 * EXCHANGE_ID request
2448 */
2449static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2450 struct nfs41_exchange_id_args *args)
2451{
2452 struct xdr_stream xdr;
2453 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002454 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002455 };
2456
2457 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2458 encode_compound_hdr(&xdr, req, &hdr);
2459 encode_exchange_id(&xdr, args, &hdr);
2460 encode_nops(&hdr);
2461 return 0;
2462}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002463
2464/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002465 * a CREATE_SESSION request
2466 */
2467static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2468 struct nfs41_create_session_args *args)
2469{
2470 struct xdr_stream xdr;
2471 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002472 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002473 };
2474
2475 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2476 encode_compound_hdr(&xdr, req, &hdr);
2477 encode_create_session(&xdr, args, &hdr);
2478 encode_nops(&hdr);
2479 return 0;
2480}
2481
2482/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002483 * a DESTROY_SESSION request
2484 */
2485static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2486 struct nfs4_session *session)
2487{
2488 struct xdr_stream xdr;
2489 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002490 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002491 };
2492
2493 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2494 encode_compound_hdr(&xdr, req, &hdr);
2495 encode_destroy_session(&xdr, session, &hdr);
2496 encode_nops(&hdr);
2497 return 0;
2498}
2499
2500/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002501 * a SEQUENCE request
2502 */
2503static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p,
2504 struct nfs4_sequence_args *args)
2505{
2506 struct xdr_stream xdr;
2507 struct compound_hdr hdr = {
2508 .minorversion = nfs4_xdr_minorversion(args),
2509 };
2510
2511 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2512 encode_compound_hdr(&xdr, req, &hdr);
2513 encode_sequence(&xdr, args, &hdr);
2514 encode_nops(&hdr);
2515 return 0;
2516}
2517
2518/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002519 * a GET_LEASE_TIME request
2520 */
2521static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2522 struct nfs4_get_lease_time_args *args)
2523{
2524 struct xdr_stream xdr;
2525 struct compound_hdr hdr = {
2526 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2527 };
2528 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2529
2530 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2531 encode_compound_hdr(&xdr, req, &hdr);
2532 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2533 encode_putrootfh(&xdr, &hdr);
2534 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2535 encode_nops(&hdr);
2536 return 0;
2537}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002538
2539/*
2540 * a RECLAIM_COMPLETE request
2541 */
2542static int nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, uint32_t *p,
2543 struct nfs41_reclaim_complete_args *args)
2544{
2545 struct xdr_stream xdr;
2546 struct compound_hdr hdr = {
2547 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2548 };
2549
2550 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2551 encode_compound_hdr(&xdr, req, &hdr);
2552 encode_sequence(&xdr, &args->seq_args, &hdr);
2553 encode_reclaim_complete(&xdr, args, &hdr);
2554 encode_nops(&hdr);
2555 return 0;
2556}
2557
Benny Halevy99fe60d2009-04-01 09:22:29 -04002558#endif /* CONFIG_NFS_V4_1 */
2559
Benny Halevy686841b2009-08-14 17:19:48 +03002560static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2561{
2562 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2563 "Remaining buffer length is %tu words.\n",
2564 func, xdr->end - xdr->p);
2565}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566
Trond Myklebust683b57b2006-06-09 09:34:22 -04002567static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568{
Al Viro8687b632006-10-19 23:28:48 -07002569 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570
Benny Halevyc0eae662009-08-14 17:20:14 +03002571 p = xdr_inline_decode(xdr, 4);
2572 if (unlikely(!p))
2573 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002574 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002575 p = xdr_inline_decode(xdr, *len);
2576 if (unlikely(!p))
2577 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 *string = (char *)p;
2579 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002580out_overflow:
2581 print_overflow_msg(__func__, xdr);
2582 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583}
2584
2585static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2586{
Al Viro8687b632006-10-19 23:28:48 -07002587 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588
Benny Halevyc0eae662009-08-14 17:20:14 +03002589 p = xdr_inline_decode(xdr, 8);
2590 if (unlikely(!p))
2591 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002592 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002593 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002594
Benny Halevyc0eae662009-08-14 17:20:14 +03002595 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2596 if (unlikely(!p))
2597 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 hdr->tag = (char *)p;
2599 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002600 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002601 if (unlikely(hdr->nops < 1))
2602 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002604out_overflow:
2605 print_overflow_msg(__func__, xdr);
2606 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607}
2608
2609static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2610{
Al Viro8687b632006-10-19 23:28:48 -07002611 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 uint32_t opnum;
2613 int32_t nfserr;
2614
Benny Halevyc0eae662009-08-14 17:20:14 +03002615 p = xdr_inline_decode(xdr, 8);
2616 if (unlikely(!p))
2617 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002618 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002620 dprintk("nfs: Server returned operation"
2621 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 opnum, expected);
2623 return -EIO;
2624 }
Benny Halevycccddf42009-08-14 17:20:19 +03002625 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002627 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002629out_overflow:
2630 print_overflow_msg(__func__, xdr);
2631 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632}
2633
2634/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002635static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636{
Al Viro8687b632006-10-19 23:28:48 -07002637 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002638 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 char *str;
2640
Benny Halevyc0eae662009-08-14 17:20:14 +03002641 p = xdr_inline_decode(xdr, 12);
2642 if (likely(p))
2643 return decode_opaque_inline(xdr, &strlen, &str);
2644 print_overflow_msg(__func__, xdr);
2645 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646}
2647
2648static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2649{
Al Viro8687b632006-10-19 23:28:48 -07002650 uint32_t bmlen;
2651 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652
Benny Halevyc0eae662009-08-14 17:20:14 +03002653 p = xdr_inline_decode(xdr, 4);
2654 if (unlikely(!p))
2655 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002656 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657
2658 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002659 p = xdr_inline_decode(xdr, (bmlen << 2));
2660 if (unlikely(!p))
2661 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002663 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002665 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 }
2667 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002668out_overflow:
2669 print_overflow_msg(__func__, xdr);
2670 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671}
2672
Al Viro8687b632006-10-19 23:28:48 -07002673static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674{
Al Viro8687b632006-10-19 23:28:48 -07002675 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676
Benny Halevyc0eae662009-08-14 17:20:14 +03002677 p = xdr_inline_decode(xdr, 4);
2678 if (unlikely(!p))
2679 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002680 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 *savep = xdr->p;
2682 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002683out_overflow:
2684 print_overflow_msg(__func__, xdr);
2685 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686}
2687
2688static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2689{
2690 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2691 decode_attr_bitmap(xdr, bitmask);
2692 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2693 } else
2694 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002695 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 return 0;
2697}
2698
2699static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2700{
Al Viro8687b632006-10-19 23:28:48 -07002701 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002702 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703
2704 *type = 0;
2705 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2706 return -EIO;
2707 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002708 p = xdr_inline_decode(xdr, 4);
2709 if (unlikely(!p))
2710 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002711 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002713 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 return -EIO;
2715 }
2716 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002717 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002719 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002720 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002721out_overflow:
2722 print_overflow_msg(__func__, xdr);
2723 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724}
2725
2726static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2727{
Al Viro8687b632006-10-19 23:28:48 -07002728 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002729 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730
2731 *change = 0;
2732 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2733 return -EIO;
2734 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002735 p = xdr_inline_decode(xdr, 8);
2736 if (unlikely(!p))
2737 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002738 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002740 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002742 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002744 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002745out_overflow:
2746 print_overflow_msg(__func__, xdr);
2747 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748}
2749
2750static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2751{
Al Viro8687b632006-10-19 23:28:48 -07002752 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002753 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754
2755 *size = 0;
2756 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2757 return -EIO;
2758 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002759 p = xdr_inline_decode(xdr, 8);
2760 if (unlikely(!p))
2761 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002762 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002764 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002766 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002767 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002768out_overflow:
2769 print_overflow_msg(__func__, xdr);
2770 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771}
2772
2773static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2774{
Al Viro8687b632006-10-19 23:28:48 -07002775 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776
2777 *res = 0;
2778 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2779 return -EIO;
2780 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002781 p = xdr_inline_decode(xdr, 4);
2782 if (unlikely(!p))
2783 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002784 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2786 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002787 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002789out_overflow:
2790 print_overflow_msg(__func__, xdr);
2791 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792}
2793
2794static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2795{
Al Viro8687b632006-10-19 23:28:48 -07002796 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797
2798 *res = 0;
2799 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2800 return -EIO;
2801 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002802 p = xdr_inline_decode(xdr, 4);
2803 if (unlikely(!p))
2804 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002805 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2807 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002808 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002810out_overflow:
2811 print_overflow_msg(__func__, xdr);
2812 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813}
2814
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002815static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816{
Al Viro8687b632006-10-19 23:28:48 -07002817 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002818 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819
2820 fsid->major = 0;
2821 fsid->minor = 0;
2822 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2823 return -EIO;
2824 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002825 p = xdr_inline_decode(xdr, 16);
2826 if (unlikely(!p))
2827 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03002828 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03002829 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002831 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002833 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 (unsigned long long)fsid->major,
2835 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002836 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002837out_overflow:
2838 print_overflow_msg(__func__, xdr);
2839 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840}
2841
2842static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2843{
Al Viro8687b632006-10-19 23:28:48 -07002844 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845
2846 *res = 60;
2847 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2848 return -EIO;
2849 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002850 p = xdr_inline_decode(xdr, 4);
2851 if (unlikely(!p))
2852 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002853 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2855 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002856 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002858out_overflow:
2859 print_overflow_msg(__func__, xdr);
2860 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861}
2862
Bryan Schumakerae42c702010-10-21 16:33:17 -04002863static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
2864{
2865 __be32 *p;
2866
2867 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
2868 return -EIO;
2869 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
2870 p = xdr_inline_decode(xdr, 4);
2871 if (unlikely(!p))
2872 goto out_overflow;
2873 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
2874 }
2875 return 0;
2876out_overflow:
2877 print_overflow_msg(__func__, xdr);
2878 return -EIO;
2879}
2880
2881static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
2882{
2883 __be32 *p;
2884 int len;
2885
Trond Myklebust7ad07352010-10-23 15:34:20 -04002886 if (fh != NULL)
2887 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04002888
2889 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
2890 return -EIO;
2891 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
2892 p = xdr_inline_decode(xdr, 4);
2893 if (unlikely(!p))
2894 goto out_overflow;
2895 len = be32_to_cpup(p);
2896 if (len > NFS4_FHSIZE)
2897 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04002898 p = xdr_inline_decode(xdr, len);
2899 if (unlikely(!p))
2900 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04002901 if (fh != NULL) {
2902 memcpy(fh->data, p, len);
2903 fh->size = len;
2904 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04002905 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
2906 }
2907 return 0;
2908out_overflow:
2909 print_overflow_msg(__func__, xdr);
2910 return -EIO;
2911}
2912
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2914{
Al Viro8687b632006-10-19 23:28:48 -07002915 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916
2917 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2918 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2919 return -EIO;
2920 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002921 p = xdr_inline_decode(xdr, 4);
2922 if (unlikely(!p))
2923 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002924 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2926 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002927 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002929out_overflow:
2930 print_overflow_msg(__func__, xdr);
2931 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932}
2933
2934static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2935{
Al Viro8687b632006-10-19 23:28:48 -07002936 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002937 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938
2939 *fileid = 0;
2940 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2941 return -EIO;
2942 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002943 p = xdr_inline_decode(xdr, 8);
2944 if (unlikely(!p))
2945 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002946 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002948 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002950 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002951 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002952out_overflow:
2953 print_overflow_msg(__func__, xdr);
2954 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955}
2956
Manoj Naik99baf622006-06-09 09:34:24 -04002957static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2958{
Al Viro8687b632006-10-19 23:28:48 -07002959 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002960 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002961
2962 *fileid = 0;
2963 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2964 return -EIO;
2965 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002966 p = xdr_inline_decode(xdr, 8);
2967 if (unlikely(!p))
2968 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002969 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04002970 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002971 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002972 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002973 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002974 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002975out_overflow:
2976 print_overflow_msg(__func__, xdr);
2977 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04002978}
2979
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2981{
Al Viro8687b632006-10-19 23:28:48 -07002982 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 int status = 0;
2984
2985 *res = 0;
2986 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2987 return -EIO;
2988 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002989 p = xdr_inline_decode(xdr, 8);
2990 if (unlikely(!p))
2991 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002992 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2994 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002995 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002997out_overflow:
2998 print_overflow_msg(__func__, xdr);
2999 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000}
3001
3002static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3003{
Al Viro8687b632006-10-19 23:28:48 -07003004 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 int status = 0;
3006
3007 *res = 0;
3008 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3009 return -EIO;
3010 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003011 p = xdr_inline_decode(xdr, 8);
3012 if (unlikely(!p))
3013 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003014 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3016 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003017 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003019out_overflow:
3020 print_overflow_msg(__func__, xdr);
3021 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022}
3023
3024static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3025{
Al Viro8687b632006-10-19 23:28:48 -07003026 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 int status = 0;
3028
3029 *res = 0;
3030 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3031 return -EIO;
3032 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003033 p = xdr_inline_decode(xdr, 8);
3034 if (unlikely(!p))
3035 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003036 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3038 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003039 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003041out_overflow:
3042 print_overflow_msg(__func__, xdr);
3043 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044}
3045
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003046static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3047{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003048 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003049 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003050 int status = 0;
3051
Benny Halevyc0eae662009-08-14 17:20:14 +03003052 p = xdr_inline_decode(xdr, 4);
3053 if (unlikely(!p))
3054 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003055 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003056 if (n == 0)
3057 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003058 dprintk("path ");
3059 path->ncomponents = 0;
3060 while (path->ncomponents < n) {
3061 struct nfs4_string *component = &path->components[path->ncomponents];
3062 status = decode_opaque_inline(xdr, &component->len, &component->data);
3063 if (unlikely(status != 0))
3064 goto out_eio;
3065 if (path->ncomponents != n)
3066 dprintk("/");
3067 dprintk("%s", component->data);
3068 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3069 path->ncomponents++;
3070 else {
3071 dprintk("cannot parse %d components in path\n", n);
3072 goto out_eio;
3073 }
3074 }
3075out:
3076 dprintk("\n");
3077 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003078root_path:
3079/* a root pathname is sent as a zero component4 */
3080 path->ncomponents = 1;
3081 path->components[0].len=0;
3082 path->components[0].data=NULL;
3083 dprintk("path /\n");
3084 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003085out_eio:
3086 dprintk(" status %d", status);
3087 status = -EIO;
3088 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003089out_overflow:
3090 print_overflow_msg(__func__, xdr);
3091 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003092}
3093
3094static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003095{
3096 int n;
Al Viro8687b632006-10-19 23:28:48 -07003097 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003098 int status = -EIO;
3099
3100 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3101 goto out;
3102 status = 0;
3103 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3104 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003105 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003106 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003107 if (unlikely(status != 0))
3108 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003109 p = xdr_inline_decode(xdr, 4);
3110 if (unlikely(!p))
3111 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003112 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003113 if (n <= 0)
3114 goto out_eio;
3115 res->nlocations = 0;
3116 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003117 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003118 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003119
Benny Halevyc0eae662009-08-14 17:20:14 +03003120 p = xdr_inline_decode(xdr, 4);
3121 if (unlikely(!p))
3122 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003123 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003124
3125 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003126 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003127 while (loc->nservers < m) {
3128 struct nfs4_string *server = &loc->servers[loc->nservers];
3129 status = decode_opaque_inline(xdr, &server->len, &server->data);
3130 if (unlikely(status != 0))
3131 goto out_eio;
3132 dprintk("%s ", server->data);
3133 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3134 loc->nservers++;
3135 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003136 unsigned int i;
3137 dprintk("%s: using first %u of %u servers "
3138 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003139 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003140 NFS4_FS_LOCATION_MAXSERVERS,
3141 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003142 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003143 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003144 char *data;
3145 status = decode_opaque_inline(xdr, &len, &data);
3146 if (unlikely(status != 0))
3147 goto out_eio;
3148 }
3149 }
3150 }
3151 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003152 if (unlikely(status != 0))
3153 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003154 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003155 res->nlocations++;
3156 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003157 if (res->nlocations != 0)
3158 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003159out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003160 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003161 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003162out_overflow:
3163 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003164out_eio:
3165 status = -EIO;
3166 goto out;
3167}
3168
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3170{
Al Viro8687b632006-10-19 23:28:48 -07003171 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 int status = 0;
3173
3174 *res = 0;
3175 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3176 return -EIO;
3177 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003178 p = xdr_inline_decode(xdr, 8);
3179 if (unlikely(!p))
3180 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003181 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3183 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003184 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003186out_overflow:
3187 print_overflow_msg(__func__, xdr);
3188 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189}
3190
3191static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3192{
Al Viro8687b632006-10-19 23:28:48 -07003193 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 int status = 0;
3195
3196 *maxlink = 1;
3197 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3198 return -EIO;
3199 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003200 p = xdr_inline_decode(xdr, 4);
3201 if (unlikely(!p))
3202 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003203 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3205 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003206 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003208out_overflow:
3209 print_overflow_msg(__func__, xdr);
3210 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211}
3212
3213static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3214{
Al Viro8687b632006-10-19 23:28:48 -07003215 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 int status = 0;
3217
3218 *maxname = 1024;
3219 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3220 return -EIO;
3221 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003222 p = xdr_inline_decode(xdr, 4);
3223 if (unlikely(!p))
3224 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003225 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3227 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003228 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003230out_overflow:
3231 print_overflow_msg(__func__, xdr);
3232 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233}
3234
3235static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3236{
Al Viro8687b632006-10-19 23:28:48 -07003237 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 int status = 0;
3239
3240 *res = 1024;
3241 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3242 return -EIO;
3243 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3244 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003245 p = xdr_inline_decode(xdr, 8);
3246 if (unlikely(!p))
3247 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003248 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 if (maxread > 0x7FFFFFFF)
3250 maxread = 0x7FFFFFFF;
3251 *res = (uint32_t)maxread;
3252 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3253 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003254 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003256out_overflow:
3257 print_overflow_msg(__func__, xdr);
3258 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259}
3260
3261static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3262{
Al Viro8687b632006-10-19 23:28:48 -07003263 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 int status = 0;
3265
3266 *res = 1024;
3267 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3268 return -EIO;
3269 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3270 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003271 p = xdr_inline_decode(xdr, 8);
3272 if (unlikely(!p))
3273 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003274 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 if (maxwrite > 0x7FFFFFFF)
3276 maxwrite = 0x7FFFFFFF;
3277 *res = (uint32_t)maxwrite;
3278 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3279 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003280 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003282out_overflow:
3283 print_overflow_msg(__func__, xdr);
3284 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285}
3286
Trond Myklebustbca79472009-03-11 14:10:26 -04003287static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288{
Trond Myklebustbca79472009-03-11 14:10:26 -04003289 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003290 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003291 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292
3293 *mode = 0;
3294 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3295 return -EIO;
3296 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003297 p = xdr_inline_decode(xdr, 4);
3298 if (unlikely(!p))
3299 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003300 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003301 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003303 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003305 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003306 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003307out_overflow:
3308 print_overflow_msg(__func__, xdr);
3309 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310}
3311
3312static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3313{
Al Viro8687b632006-10-19 23:28:48 -07003314 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003315 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316
3317 *nlink = 1;
3318 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3319 return -EIO;
3320 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003321 p = xdr_inline_decode(xdr, 4);
3322 if (unlikely(!p))
3323 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003324 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003326 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003328 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003329 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003330out_overflow:
3331 print_overflow_msg(__func__, xdr);
3332 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333}
3334
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003335static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3336 struct nfs_client *clp, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337{
Al Viro8687b632006-10-19 23:28:48 -07003338 uint32_t len;
3339 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003340 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341
3342 *uid = -2;
3343 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3344 return -EIO;
3345 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003346 p = xdr_inline_decode(xdr, 4);
3347 if (unlikely(!p))
3348 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003349 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003350 p = xdr_inline_decode(xdr, len);
3351 if (unlikely(!p))
3352 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003353 if (!may_sleep) {
3354 /* do nothing */
3355 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003356 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3357 ret = NFS_ATTR_FATTR_OWNER;
3358 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003360 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003362 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003363 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3365 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003366 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003367 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003368out_overflow:
3369 print_overflow_msg(__func__, xdr);
3370 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371}
3372
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003373static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3374 struct nfs_client *clp, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375{
Al Viro8687b632006-10-19 23:28:48 -07003376 uint32_t len;
3377 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003378 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379
3380 *gid = -2;
3381 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3382 return -EIO;
3383 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003384 p = xdr_inline_decode(xdr, 4);
3385 if (unlikely(!p))
3386 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003387 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003388 p = xdr_inline_decode(xdr, len);
3389 if (unlikely(!p))
3390 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003391 if (!may_sleep) {
3392 /* do nothing */
3393 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003394 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3395 ret = NFS_ATTR_FATTR_GROUP;
3396 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003398 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003400 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003401 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3403 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003404 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003405 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003406out_overflow:
3407 print_overflow_msg(__func__, xdr);
3408 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409}
3410
3411static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3412{
Al Viro8687b632006-10-19 23:28:48 -07003413 uint32_t major = 0, minor = 0;
3414 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003415 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416
3417 *rdev = MKDEV(0,0);
3418 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3419 return -EIO;
3420 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3421 dev_t tmp;
3422
Benny Halevyc0eae662009-08-14 17:20:14 +03003423 p = xdr_inline_decode(xdr, 8);
3424 if (unlikely(!p))
3425 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003426 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003427 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 tmp = MKDEV(major, minor);
3429 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3430 *rdev = tmp;
3431 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003432 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003434 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003435 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003436out_overflow:
3437 print_overflow_msg(__func__, xdr);
3438 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439}
3440
3441static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3442{
Al Viro8687b632006-10-19 23:28:48 -07003443 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 int status = 0;
3445
3446 *res = 0;
3447 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3448 return -EIO;
3449 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003450 p = xdr_inline_decode(xdr, 8);
3451 if (unlikely(!p))
3452 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003453 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3455 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003456 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003458out_overflow:
3459 print_overflow_msg(__func__, xdr);
3460 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461}
3462
3463static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3464{
Al Viro8687b632006-10-19 23:28:48 -07003465 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466 int status = 0;
3467
3468 *res = 0;
3469 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3470 return -EIO;
3471 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003472 p = xdr_inline_decode(xdr, 8);
3473 if (unlikely(!p))
3474 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003475 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3477 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003478 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003480out_overflow:
3481 print_overflow_msg(__func__, xdr);
3482 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483}
3484
3485static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3486{
Al Viro8687b632006-10-19 23:28:48 -07003487 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 int status = 0;
3489
3490 *res = 0;
3491 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3492 return -EIO;
3493 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003494 p = xdr_inline_decode(xdr, 8);
3495 if (unlikely(!p))
3496 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003497 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3499 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003500 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003502out_overflow:
3503 print_overflow_msg(__func__, xdr);
3504 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505}
3506
3507static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3508{
Al Viro8687b632006-10-19 23:28:48 -07003509 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003510 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511
3512 *used = 0;
3513 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3514 return -EIO;
3515 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003516 p = xdr_inline_decode(xdr, 8);
3517 if (unlikely(!p))
3518 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003519 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003521 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003523 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003525 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003526out_overflow:
3527 print_overflow_msg(__func__, xdr);
3528 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529}
3530
3531static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3532{
Al Viro8687b632006-10-19 23:28:48 -07003533 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534 uint64_t sec;
3535 uint32_t nsec;
3536
Benny Halevyc0eae662009-08-14 17:20:14 +03003537 p = xdr_inline_decode(xdr, 12);
3538 if (unlikely(!p))
3539 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003540 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003541 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 time->tv_sec = (time_t)sec;
3543 time->tv_nsec = (long)nsec;
3544 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003545out_overflow:
3546 print_overflow_msg(__func__, xdr);
3547 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548}
3549
3550static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3551{
3552 int status = 0;
3553
3554 time->tv_sec = 0;
3555 time->tv_nsec = 0;
3556 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3557 return -EIO;
3558 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3559 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003560 if (status == 0)
3561 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3563 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003564 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565 return status;
3566}
3567
3568static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3569{
3570 int status = 0;
3571
3572 time->tv_sec = 0;
3573 time->tv_nsec = 0;
3574 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3575 return -EIO;
3576 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3577 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003578 if (status == 0)
3579 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3581 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003582 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583 return status;
3584}
3585
3586static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3587{
3588 int status = 0;
3589
3590 time->tv_sec = 0;
3591 time->tv_nsec = 0;
3592 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3593 return -EIO;
3594 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3595 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003596 if (status == 0)
3597 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3599 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003600 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 return status;
3602}
3603
Al Viro8687b632006-10-19 23:28:48 -07003604static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605{
3606 unsigned int attrwords = XDR_QUADLEN(attrlen);
3607 unsigned int nwords = xdr->p - savep;
3608
3609 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003610 dprintk("%s: server returned incorrect attribute length: "
3611 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003612 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 attrwords << 2,
3614 (attrwords < nwords) ? '<' : '>',
3615 nwords << 2);
3616 return -EIO;
3617 }
3618 return 0;
3619}
3620
3621static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3622{
Al Viro8687b632006-10-19 23:28:48 -07003623 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624
Benny Halevyc0eae662009-08-14 17:20:14 +03003625 p = xdr_inline_decode(xdr, 20);
3626 if (unlikely(!p))
3627 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003628 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003629 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003630 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003632out_overflow:
3633 print_overflow_msg(__func__, xdr);
3634 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635}
3636
3637static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3638{
Al Viro8687b632006-10-19 23:28:48 -07003639 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 uint32_t supp, acc;
3641 int status;
3642
3643 status = decode_op_hdr(xdr, OP_ACCESS);
3644 if (status)
3645 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003646 p = xdr_inline_decode(xdr, 8);
3647 if (unlikely(!p))
3648 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003649 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003650 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 access->supported = supp;
3652 access->access = acc;
3653 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003654out_overflow:
3655 print_overflow_msg(__func__, xdr);
3656 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657}
3658
Benny Halevy07d30432009-08-14 17:19:52 +03003659static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660{
Al Viro8687b632006-10-19 23:28:48 -07003661 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003662
3663 p = xdr_inline_decode(xdr, len);
3664 if (likely(p)) {
3665 memcpy(buf, p, len);
3666 return 0;
3667 }
3668 print_overflow_msg(__func__, xdr);
3669 return -EIO;
3670}
3671
3672static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3673{
3674 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675}
3676
3677static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3678{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679 int status;
3680
3681 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003682 if (status != -EIO)
3683 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003684 if (!status)
3685 status = decode_stateid(xdr, &res->stateid);
3686 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687}
3688
Benny Halevydb942bb2009-08-14 17:19:56 +03003689static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3690{
3691 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692}
3693
3694static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3695{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 int status;
3697
3698 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003699 if (!status)
3700 status = decode_verifier(xdr, res->verf->verifier);
3701 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702}
3703
3704static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3705{
Al Viro8687b632006-10-19 23:28:48 -07003706 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 uint32_t bmlen;
3708 int status;
3709
3710 status = decode_op_hdr(xdr, OP_CREATE);
3711 if (status)
3712 return status;
3713 if ((status = decode_change_info(xdr, cinfo)))
3714 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003715 p = xdr_inline_decode(xdr, 4);
3716 if (unlikely(!p))
3717 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003718 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003719 p = xdr_inline_decode(xdr, bmlen << 2);
3720 if (likely(p))
3721 return 0;
3722out_overflow:
3723 print_overflow_msg(__func__, xdr);
3724 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725}
3726
3727static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3728{
Al Viro8687b632006-10-19 23:28:48 -07003729 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003730 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 int status;
3732
3733 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3734 goto xdr_error;
3735 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3736 goto xdr_error;
3737 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3738 goto xdr_error;
3739 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3740 goto xdr_error;
3741 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3742 goto xdr_error;
3743 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3744 goto xdr_error;
3745 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3746 goto xdr_error;
3747 status = verify_attr_len(xdr, savep, attrlen);
3748xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003749 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750 return status;
3751}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003752
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3754{
Al Viro8687b632006-10-19 23:28:48 -07003755 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003756 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003758
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3760 goto xdr_error;
3761 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3762 goto xdr_error;
3763 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3764 goto xdr_error;
3765
3766 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3767 goto xdr_error;
3768 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3769 goto xdr_error;
3770 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3771 goto xdr_error;
3772 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3773 goto xdr_error;
3774 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3775 goto xdr_error;
3776 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3777 goto xdr_error;
3778
3779 status = verify_attr_len(xdr, savep, attrlen);
3780xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003781 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782 return status;
3783}
3784
3785static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3786{
Al Viro8687b632006-10-19 23:28:48 -07003787 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003788 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003790
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3792 goto xdr_error;
3793 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3794 goto xdr_error;
3795 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3796 goto xdr_error;
3797
3798 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3799 goto xdr_error;
3800 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3801 goto xdr_error;
3802
3803 status = verify_attr_len(xdr, savep, attrlen);
3804xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003805 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 return status;
3807}
3808
Bryan Schumakerae42c702010-10-21 16:33:17 -04003809static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
3810 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003811 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812{
Trond Myklebustbca79472009-03-11 14:10:26 -04003813 int status;
3814 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003815 uint64_t fileid;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003816 uint32_t type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003818 status = decode_attr_type(xdr, bitmap, &type);
3819 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003821 fattr->mode = 0;
3822 if (status != 0) {
3823 fattr->mode |= nfs_type2fmt[type];
3824 fattr->valid |= status;
3825 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003827 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3828 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003830 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003831
3832 status = decode_attr_size(xdr, bitmap, &fattr->size);
3833 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003835 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003836
3837 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3838 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003840 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003841
Bryan Schumakerae42c702010-10-21 16:33:17 -04003842 status = decode_attr_error(xdr, bitmap);
3843 if (status < 0)
3844 goto xdr_error;
3845
3846 status = decode_attr_filehandle(xdr, bitmap, fh);
3847 if (status < 0)
3848 goto xdr_error;
3849
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003850 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3851 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003853 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003854
3855 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003856 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003857 fattr));
3858 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003859 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003860 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003861
3862 status = decode_attr_mode(xdr, bitmap, &fmode);
3863 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003865 if (status != 0) {
3866 fattr->mode |= fmode;
3867 fattr->valid |= status;
3868 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003869
3870 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3871 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003873 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003874
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003875 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3876 &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003877 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003879 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003880
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003881 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3882 &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003883 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003885 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003886
3887 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3888 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003890 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003891
3892 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3893 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003895 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003896
3897 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3898 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003900 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003901
3902 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3903 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003905 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003906
3907 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3908 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003910 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003911
3912 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3913 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003914 goto xdr_error;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003915 if (status != 0) {
Manoj Naik99baf622006-06-09 09:34:24 -04003916 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003917 fattr->valid |= status;
3918 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003919
Bryan Schumakerae42c702010-10-21 16:33:17 -04003920xdr_error:
3921 dprintk("%s: xdr returned %d\n", __func__, -status);
3922 return status;
3923}
3924
3925static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3926 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
3927{
3928 __be32 *savep;
3929 uint32_t attrlen,
3930 bitmap[2] = {0};
3931 int status;
3932
3933 status = decode_op_hdr(xdr, OP_GETATTR);
3934 if (status < 0)
3935 goto xdr_error;
3936
3937 status = decode_attr_bitmap(xdr, bitmap);
3938 if (status < 0)
3939 goto xdr_error;
3940
3941 status = decode_attr_length(xdr, &attrlen, &savep);
3942 if (status < 0)
3943 goto xdr_error;
3944
3945 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
3946 if (status < 0)
3947 goto xdr_error;
3948
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003949 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003951 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 return status;
3953}
3954
Bryan Schumakerae42c702010-10-21 16:33:17 -04003955static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3956 const struct nfs_server *server, int may_sleep)
3957{
3958 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
3959}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960
3961static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3962{
Al Viro8687b632006-10-19 23:28:48 -07003963 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 uint32_t attrlen, bitmap[2];
3965 int status;
3966
3967 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3968 goto xdr_error;
3969 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3970 goto xdr_error;
3971 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3972 goto xdr_error;
3973
3974 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3975
3976 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3977 goto xdr_error;
3978 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3979 goto xdr_error;
3980 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3981 goto xdr_error;
3982 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3983 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3984 goto xdr_error;
3985 fsinfo->wtpref = fsinfo->wtmax;
3986
3987 status = verify_attr_len(xdr, savep, attrlen);
3988xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003989 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990 return status;
3991}
3992
3993static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3994{
Al Viro8687b632006-10-19 23:28:48 -07003995 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 uint32_t len;
3997 int status;
3998
Trond Myklebust99367812007-07-17 21:52:41 -04003999 /* Zero handle first to allow comparisons */
4000 memset(fh, 0, sizeof(*fh));
4001
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 status = decode_op_hdr(xdr, OP_GETFH);
4003 if (status)
4004 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005
Benny Halevyc0eae662009-08-14 17:20:14 +03004006 p = xdr_inline_decode(xdr, 4);
4007 if (unlikely(!p))
4008 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004009 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010 if (len > NFS4_FHSIZE)
4011 return -EIO;
4012 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004013 p = xdr_inline_decode(xdr, len);
4014 if (unlikely(!p))
4015 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004016 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004018out_overflow:
4019 print_overflow_msg(__func__, xdr);
4020 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021}
4022
4023static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4024{
4025 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004026
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027 status = decode_op_hdr(xdr, OP_LINK);
4028 if (status)
4029 return status;
4030 return decode_change_info(xdr, cinfo);
4031}
4032
4033/*
4034 * We create the owner, so we know a proper owner.id length is 4.
4035 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004036static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004038 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004039 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004040 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004042 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004043 if (unlikely(!p))
4044 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004045 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004046 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004047 type = be32_to_cpup(p++); /* 4 byte read */
4048 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004049 fl->fl_start = (loff_t)offset;
4050 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4051 if (length == ~(uint64_t)0)
4052 fl->fl_end = OFFSET_MAX;
4053 fl->fl_type = F_WRLCK;
4054 if (type & 1)
4055 fl->fl_type = F_RDLCK;
4056 fl->fl_pid = 0;
4057 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004058 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4059 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4060 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004061 if (likely(p))
4062 return -NFS4ERR_DENIED;
4063out_overflow:
4064 print_overflow_msg(__func__, xdr);
4065 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066}
4067
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004068static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 int status;
4071
4072 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004073 if (status == -EIO)
4074 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004076 status = decode_stateid(xdr, &res->stateid);
4077 if (unlikely(status))
4078 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004080 status = decode_lock_denied(xdr, NULL);
4081 if (res->open_seqid != NULL)
4082 nfs_increment_open_seqid(status, res->open_seqid);
4083 nfs_increment_lock_seqid(status, res->lock_seqid);
4084out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 return status;
4086}
4087
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004088static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089{
4090 int status;
4091 status = decode_op_hdr(xdr, OP_LOCKT);
4092 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004093 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094 return status;
4095}
4096
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004097static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099 int status;
4100
4101 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004102 if (status != -EIO)
4103 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004104 if (status == 0)
4105 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 return status;
4107}
4108
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004109static int decode_release_lockowner(struct xdr_stream *xdr)
4110{
4111 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4112}
4113
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114static int decode_lookup(struct xdr_stream *xdr)
4115{
4116 return decode_op_hdr(xdr, OP_LOOKUP);
4117}
4118
4119/* This is too sick! */
4120static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4121{
Andy Adamson05d564f2008-12-23 16:06:15 -05004122 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123 uint32_t limit_type, nblocks, blocksize;
4124
Benny Halevyc0eae662009-08-14 17:20:14 +03004125 p = xdr_inline_decode(xdr, 12);
4126 if (unlikely(!p))
4127 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004128 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004130 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004131 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004132 break;
4133 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004134 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004135 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004136 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 }
4138 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004139out_overflow:
4140 print_overflow_msg(__func__, xdr);
4141 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142}
4143
4144static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4145{
Andy Adamson05d564f2008-12-23 16:06:15 -05004146 __be32 *p;
4147 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004148 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149
Benny Halevyc0eae662009-08-14 17:20:14 +03004150 p = xdr_inline_decode(xdr, 4);
4151 if (unlikely(!p))
4152 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004153 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4155 res->delegation_type = 0;
4156 return 0;
4157 }
Benny Halevy07d30432009-08-14 17:19:52 +03004158 status = decode_stateid(xdr, &res->delegation);
4159 if (unlikely(status))
4160 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004161 p = xdr_inline_decode(xdr, 4);
4162 if (unlikely(!p))
4163 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004164 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004165
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004167 case NFS4_OPEN_DELEGATE_READ:
4168 res->delegation_type = FMODE_READ;
4169 break;
4170 case NFS4_OPEN_DELEGATE_WRITE:
4171 res->delegation_type = FMODE_WRITE|FMODE_READ;
4172 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173 return -EIO;
4174 }
David Howells7539bba2006-08-22 20:06:09 -04004175 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004176out_overflow:
4177 print_overflow_msg(__func__, xdr);
4178 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179}
4180
4181static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4182{
Andy Adamson05d564f2008-12-23 16:06:15 -05004183 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004184 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004185 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186
Andy Adamson05d564f2008-12-23 16:06:15 -05004187 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004188 if (status != -EIO)
4189 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004190 if (!status)
4191 status = decode_stateid(xdr, &res->stateid);
4192 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004193 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194
Andy Adamson05d564f2008-12-23 16:06:15 -05004195 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196
Benny Halevyc0eae662009-08-14 17:20:14 +03004197 p = xdr_inline_decode(xdr, 8);
4198 if (unlikely(!p))
4199 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004200 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004201 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004202 if (bmlen > 10)
4203 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204
Benny Halevyc0eae662009-08-14 17:20:14 +03004205 p = xdr_inline_decode(xdr, bmlen << 2);
4206 if (unlikely(!p))
4207 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004208 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4209 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004210 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004211 for (; i < NFS4_BITMAP_SIZE; i++)
4212 res->attrset[i] = 0;
4213
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214 return decode_delegation(xdr, res);
4215xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004216 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004218out_overflow:
4219 print_overflow_msg(__func__, xdr);
4220 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221}
4222
4223static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4224{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225 int status;
4226
Andy Adamson05d564f2008-12-23 16:06:15 -05004227 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004228 if (status != -EIO)
4229 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004230 if (!status)
4231 status = decode_stateid(xdr, &res->stateid);
4232 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233}
4234
4235static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4236{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004237 int status;
4238
4239 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004240 if (status != -EIO)
4241 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004242 if (!status)
4243 status = decode_stateid(xdr, &res->stateid);
4244 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245}
4246
4247static int decode_putfh(struct xdr_stream *xdr)
4248{
4249 return decode_op_hdr(xdr, OP_PUTFH);
4250}
4251
4252static int decode_putrootfh(struct xdr_stream *xdr)
4253{
4254 return decode_op_hdr(xdr, OP_PUTROOTFH);
4255}
4256
4257static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4258{
4259 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004260 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261 uint32_t count, eof, recvd, hdrlen;
4262 int status;
4263
4264 status = decode_op_hdr(xdr, OP_READ);
4265 if (status)
4266 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004267 p = xdr_inline_decode(xdr, 8);
4268 if (unlikely(!p))
4269 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004270 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004271 count = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
4273 recvd = req->rq_rcv_buf.len - hdrlen;
4274 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004275 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276 "count %u > recvd %u\n", count, recvd);
4277 count = recvd;
4278 eof = 0;
4279 }
4280 xdr_read_pages(xdr, count);
4281 res->eof = eof;
4282 res->count = count;
4283 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004284out_overflow:
4285 print_overflow_msg(__func__, xdr);
4286 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287}
4288
4289static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4290{
4291 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004293 size_t hdrlen;
4294 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004295 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296
4297 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004298 if (!status)
4299 status = decode_verifier(xdr, readdir->verifier.data);
4300 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004302 dprintk("%s: verifier = %08x:%08x\n",
4303 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004304 ((u32 *)readdir->verifier.data)[0],
4305 ((u32 *)readdir->verifier.data)[1]);
4306
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307
Benny Halevydb942bb2009-08-14 17:19:56 +03004308 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 recvd = rcvbuf->len - hdrlen;
4310 if (pglen > recvd)
4311 pglen = recvd;
4312 xdr_read_pages(xdr, pglen);
4313
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004314
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316}
4317
4318static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4319{
4320 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4321 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004322 size_t hdrlen;
4323 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004324 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325 int status;
4326
4327 status = decode_op_hdr(xdr, OP_READLINK);
4328 if (status)
4329 return status;
4330
4331 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004332 p = xdr_inline_decode(xdr, 4);
4333 if (unlikely(!p))
4334 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004335 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004337 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338 return -ENAMETOOLONG;
4339 }
4340 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4341 recvd = req->rq_rcv_buf.len - hdrlen;
4342 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004343 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004344 "count %u > recvd %u\n", len, recvd);
4345 return -EIO;
4346 }
4347 xdr_read_pages(xdr, len);
4348 /*
4349 * The XDR encode routine has set things up so that
4350 * the link text will be copied directly into the
4351 * buffer. We just have to do overflow-checking,
4352 * and and null-terminate the text (the VFS expects
4353 * null-termination).
4354 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004355 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004357out_overflow:
4358 print_overflow_msg(__func__, xdr);
4359 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360}
4361
4362static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4363{
4364 int status;
4365
4366 status = decode_op_hdr(xdr, OP_REMOVE);
4367 if (status)
4368 goto out;
4369 status = decode_change_info(xdr, cinfo);
4370out:
4371 return status;
4372}
4373
4374static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4375 struct nfs4_change_info *new_cinfo)
4376{
4377 int status;
4378
4379 status = decode_op_hdr(xdr, OP_RENAME);
4380 if (status)
4381 goto out;
4382 if ((status = decode_change_info(xdr, old_cinfo)))
4383 goto out;
4384 status = decode_change_info(xdr, new_cinfo);
4385out:
4386 return status;
4387}
4388
4389static int decode_renew(struct xdr_stream *xdr)
4390{
4391 return decode_op_hdr(xdr, OP_RENEW);
4392}
4393
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004394static int
4395decode_restorefh(struct xdr_stream *xdr)
4396{
4397 return decode_op_hdr(xdr, OP_RESTOREFH);
4398}
4399
J. Bruce Fields029d1052005-06-22 17:16:22 +00004400static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4401 size_t *acl_len)
4402{
Al Viro8687b632006-10-19 23:28:48 -07004403 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004404 uint32_t attrlen,
4405 bitmap[2] = {0};
4406 struct kvec *iov = req->rq_rcv_buf.head;
4407 int status;
4408
4409 *acl_len = 0;
4410 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4411 goto out;
4412 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4413 goto out;
4414 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4415 goto out;
4416
4417 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4418 return -EIO;
4419 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004420 size_t hdrlen;
4421 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004422
4423 /* We ignore &savep and don't do consistency checks on
4424 * the attr length. Let userspace figure it out.... */
4425 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4426 recvd = req->rq_rcv_buf.len - hdrlen;
4427 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004428 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004429 " acl reply: attrlen %u > recvd %u\n",
4430 attrlen, recvd);
4431 return -EINVAL;
4432 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004433 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004434 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004435 } else
4436 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004437
4438out:
4439 return status;
4440}
4441
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442static int
4443decode_savefh(struct xdr_stream *xdr)
4444{
4445 return decode_op_hdr(xdr, OP_SAVEFH);
4446}
4447
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004448static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449{
Al Viro8687b632006-10-19 23:28:48 -07004450 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004451 uint32_t bmlen;
4452 int status;
4453
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454 status = decode_op_hdr(xdr, OP_SETATTR);
4455 if (status)
4456 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004457 p = xdr_inline_decode(xdr, 4);
4458 if (unlikely(!p))
4459 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004460 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004461 p = xdr_inline_decode(xdr, bmlen << 2);
4462 if (likely(p))
4463 return 0;
4464out_overflow:
4465 print_overflow_msg(__func__, xdr);
4466 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467}
4468
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004469static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470{
Al Viro8687b632006-10-19 23:28:48 -07004471 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472 uint32_t opnum;
4473 int32_t nfserr;
4474
Benny Halevyc0eae662009-08-14 17:20:14 +03004475 p = xdr_inline_decode(xdr, 8);
4476 if (unlikely(!p))
4477 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004478 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004479 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004480 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004481 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482 return -EIO;
4483 }
Benny Halevycccddf42009-08-14 17:20:19 +03004484 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004485 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004486 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4487 if (unlikely(!p))
4488 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004489 p = xdr_decode_hyper(p, &res->clientid);
4490 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491 } else if (nfserr == NFSERR_CLID_INUSE) {
4492 uint32_t len;
4493
4494 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004495 p = xdr_inline_decode(xdr, 4);
4496 if (unlikely(!p))
4497 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004498 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004499 p = xdr_inline_decode(xdr, len);
4500 if (unlikely(!p))
4501 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502
4503 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004504 p = xdr_inline_decode(xdr, 4);
4505 if (unlikely(!p))
4506 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004507 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004508 p = xdr_inline_decode(xdr, len);
4509 if (unlikely(!p))
4510 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511 return -NFSERR_CLID_INUSE;
4512 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004513 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004514
4515 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004516out_overflow:
4517 print_overflow_msg(__func__, xdr);
4518 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519}
4520
4521static int decode_setclientid_confirm(struct xdr_stream *xdr)
4522{
4523 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4524}
4525
4526static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4527{
Al Viro8687b632006-10-19 23:28:48 -07004528 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529 int status;
4530
4531 status = decode_op_hdr(xdr, OP_WRITE);
4532 if (status)
4533 return status;
4534
Benny Halevyc0eae662009-08-14 17:20:14 +03004535 p = xdr_inline_decode(xdr, 16);
4536 if (unlikely(!p))
4537 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004538 res->count = be32_to_cpup(p++);
4539 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004540 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004541 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004542out_overflow:
4543 print_overflow_msg(__func__, xdr);
4544 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545}
4546
4547static int decode_delegreturn(struct xdr_stream *xdr)
4548{
4549 return decode_op_hdr(xdr, OP_DELEGRETURN);
4550}
4551
Benny Halevy99fe60d2009-04-01 09:22:29 -04004552#if defined(CONFIG_NFS_V4_1)
4553static int decode_exchange_id(struct xdr_stream *xdr,
4554 struct nfs41_exchange_id_res *res)
4555{
4556 __be32 *p;
4557 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004558 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004559 int status;
4560 struct nfs_client *clp = res->client;
4561
4562 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4563 if (status)
4564 return status;
4565
Benny Halevyc0eae662009-08-14 17:20:14 +03004566 p = xdr_inline_decode(xdr, 8);
4567 if (unlikely(!p))
4568 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004569 xdr_decode_hyper(p, &clp->cl_ex_clid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004570 p = xdr_inline_decode(xdr, 12);
4571 if (unlikely(!p))
4572 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004573 clp->cl_seqid = be32_to_cpup(p++);
4574 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004575
4576 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004577 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004578 if (dummy != SP4_NONE)
4579 return -EIO;
4580
4581 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004582 p = xdr_inline_decode(xdr, 8);
4583 if (unlikely(!p))
4584 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004585
4586 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004587 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4588 if (unlikely(status))
4589 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004590
4591 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004592 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4593 if (unlikely(status))
4594 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004595
4596 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004597 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4598 if (unlikely(status))
4599 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004600
4601 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004602out_overflow:
4603 print_overflow_msg(__func__, xdr);
4604 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004605}
Andy Adamsonfc931582009-04-01 09:22:31 -04004606
4607static int decode_chan_attrs(struct xdr_stream *xdr,
4608 struct nfs4_channel_attrs *attrs)
4609{
4610 __be32 *p;
4611 u32 nr_attrs;
4612
Benny Halevyc0eae662009-08-14 17:20:14 +03004613 p = xdr_inline_decode(xdr, 28);
4614 if (unlikely(!p))
4615 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004616 attrs->headerpadsz = be32_to_cpup(p++);
4617 attrs->max_rqst_sz = be32_to_cpup(p++);
4618 attrs->max_resp_sz = be32_to_cpup(p++);
4619 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4620 attrs->max_ops = be32_to_cpup(p++);
4621 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004622 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004623 if (unlikely(nr_attrs > 1)) {
4624 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4625 __func__, nr_attrs);
4626 return -EINVAL;
4627 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004628 if (nr_attrs == 1) {
4629 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4630 if (unlikely(!p))
4631 goto out_overflow;
4632 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004633 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004634out_overflow:
4635 print_overflow_msg(__func__, xdr);
4636 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004637}
4638
Benny Halevye78291e2009-08-14 17:20:00 +03004639static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4640{
4641 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004642}
4643
4644static int decode_create_session(struct xdr_stream *xdr,
4645 struct nfs41_create_session_res *res)
4646{
4647 __be32 *p;
4648 int status;
4649 struct nfs_client *clp = res->client;
4650 struct nfs4_session *session = clp->cl_session;
4651
4652 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004653 if (!status)
4654 status = decode_sessionid(xdr, &session->sess_id);
4655 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004656 return status;
4657
Andy Adamsonfc931582009-04-01 09:22:31 -04004658 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004659 p = xdr_inline_decode(xdr, 8);
4660 if (unlikely(!p))
4661 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004662 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004663 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004664
4665 /* Channel attributes */
4666 status = decode_chan_attrs(xdr, &session->fc_attrs);
4667 if (!status)
4668 status = decode_chan_attrs(xdr, &session->bc_attrs);
4669 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004670out_overflow:
4671 print_overflow_msg(__func__, xdr);
4672 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004673}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004674
4675static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4676{
4677 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4678}
Ricardo Labiaga180197532009-12-05 16:08:40 -05004679
4680static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
4681{
4682 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
4683}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004684#endif /* CONFIG_NFS_V4_1 */
4685
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004686static int decode_sequence(struct xdr_stream *xdr,
4687 struct nfs4_sequence_res *res,
4688 struct rpc_rqst *rqstp)
4689{
4690#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004691 struct nfs4_sessionid id;
4692 u32 dummy;
4693 int status;
4694 __be32 *p;
4695
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004696 if (!res->sr_session)
4697 return 0;
4698
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004699 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03004700 if (!status)
4701 status = decode_sessionid(xdr, &id);
4702 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004703 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004704
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004705 /*
4706 * If the server returns different values for sessionID, slotID or
4707 * sequence number, the server is looney tunes.
4708 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05004709 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004710
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004711 if (memcmp(id.data, res->sr_session->sess_id.data,
4712 NFS4_MAX_SESSIONID_LEN)) {
4713 dprintk("%s Invalid session id\n", __func__);
4714 goto out_err;
4715 }
Benny Halevye78291e2009-08-14 17:20:00 +03004716
Benny Halevyc0eae662009-08-14 17:20:14 +03004717 p = xdr_inline_decode(xdr, 20);
4718 if (unlikely(!p))
4719 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03004720
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004721 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03004722 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004723 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004724 dprintk("%s Invalid sequence number\n", __func__);
4725 goto out_err;
4726 }
4727 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03004728 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004729 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004730 dprintk("%s Invalid slot id\n", __func__);
4731 goto out_err;
4732 }
4733 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004734 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004735 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004736 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05004737 /* result flags */
4738 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004739 status = 0;
4740out_err:
4741 res->sr_status = status;
4742 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004743out_overflow:
4744 print_overflow_msg(__func__, xdr);
4745 status = -EIO;
4746 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004747#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004748 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004749#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004750}
4751
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752/*
Benny Halevy49c25592008-12-23 16:06:16 -05004753 * END OF "GENERIC" DECODE ROUTINES.
4754 */
4755
4756/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757 * Decode OPEN_DOWNGRADE response
4758 */
Al Viro8687b632006-10-19 23:28:48 -07004759static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760{
Andy Adamson05d564f2008-12-23 16:06:15 -05004761 struct xdr_stream xdr;
4762 struct compound_hdr hdr;
4763 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764
Andy Adamson05d564f2008-12-23 16:06:15 -05004765 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4766 status = decode_compound_hdr(&xdr, &hdr);
4767 if (status)
4768 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004769 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4770 if (status)
4771 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004772 status = decode_putfh(&xdr);
4773 if (status)
4774 goto out;
4775 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004776 if (status != 0)
4777 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004778 decode_getfattr(&xdr, res->fattr, res->server,
4779 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004781 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782}
4783
4784/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785 * Decode ACCESS response
4786 */
Al Viro8687b632006-10-19 23:28:48 -07004787static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788{
4789 struct xdr_stream xdr;
4790 struct compound_hdr hdr;
4791 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004792
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004794 status = decode_compound_hdr(&xdr, &hdr);
4795 if (status)
4796 goto out;
4797 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4798 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04004800 status = decode_putfh(&xdr);
4801 if (status != 0)
4802 goto out;
4803 status = decode_access(&xdr, res);
4804 if (status != 0)
4805 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004806 decode_getfattr(&xdr, res->fattr, res->server,
4807 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808out:
4809 return status;
4810}
4811
4812/*
4813 * Decode LOOKUP response
4814 */
Al Viro8687b632006-10-19 23:28:48 -07004815static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816{
4817 struct xdr_stream xdr;
4818 struct compound_hdr hdr;
4819 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004820
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004822 status = decode_compound_hdr(&xdr, &hdr);
4823 if (status)
4824 goto out;
4825 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4826 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827 goto out;
4828 if ((status = decode_putfh(&xdr)) != 0)
4829 goto out;
4830 if ((status = decode_lookup(&xdr)) != 0)
4831 goto out;
4832 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4833 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004834 status = decode_getfattr(&xdr, res->fattr, res->server
4835 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836out:
4837 return status;
4838}
4839
4840/*
4841 * Decode LOOKUP_ROOT response
4842 */
Al Viro8687b632006-10-19 23:28:48 -07004843static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844{
4845 struct xdr_stream xdr;
4846 struct compound_hdr hdr;
4847 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004848
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004850 status = decode_compound_hdr(&xdr, &hdr);
4851 if (status)
4852 goto out;
4853 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4854 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855 goto out;
4856 if ((status = decode_putrootfh(&xdr)) != 0)
4857 goto out;
4858 if ((status = decode_getfh(&xdr, res->fh)) == 0)
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004859 status = decode_getfattr(&xdr, res->fattr, res->server,
4860 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861out:
4862 return status;
4863}
4864
4865/*
4866 * Decode REMOVE response
4867 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004868static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004869{
4870 struct xdr_stream xdr;
4871 struct compound_hdr hdr;
4872 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004873
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004875 status = decode_compound_hdr(&xdr, &hdr);
4876 if (status)
4877 goto out;
4878 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4879 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04004881 if ((status = decode_putfh(&xdr)) != 0)
4882 goto out;
4883 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4884 goto out;
Trond Myklebustd3468902010-04-16 16:22:50 -04004885 decode_getfattr(&xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004886 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887out:
4888 return status;
4889}
4890
4891/*
4892 * Decode RENAME response
4893 */
Jeff Laytone8582a82010-09-17 17:31:06 -04004894static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895{
4896 struct xdr_stream xdr;
4897 struct compound_hdr hdr;
4898 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004899
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004901 status = decode_compound_hdr(&xdr, &hdr);
4902 if (status)
4903 goto out;
4904 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4905 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906 goto out;
4907 if ((status = decode_putfh(&xdr)) != 0)
4908 goto out;
4909 if ((status = decode_savefh(&xdr)) != 0)
4910 goto out;
4911 if ((status = decode_putfh(&xdr)) != 0)
4912 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004913 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4914 goto out;
4915 /* Current FH is target directory */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004916 if (decode_getfattr(&xdr, res->new_fattr, res->server,
4917 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004918 goto out;
4919 if ((status = decode_restorefh(&xdr)) != 0)
4920 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004921 decode_getfattr(&xdr, res->old_fattr, res->server,
4922 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004923out:
4924 return status;
4925}
4926
4927/*
4928 * Decode LINK response
4929 */
Al Viro8687b632006-10-19 23:28:48 -07004930static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004931{
4932 struct xdr_stream xdr;
4933 struct compound_hdr hdr;
4934 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004935
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004937 status = decode_compound_hdr(&xdr, &hdr);
4938 if (status)
4939 goto out;
4940 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4941 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942 goto out;
4943 if ((status = decode_putfh(&xdr)) != 0)
4944 goto out;
4945 if ((status = decode_savefh(&xdr)) != 0)
4946 goto out;
4947 if ((status = decode_putfh(&xdr)) != 0)
4948 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004949 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4950 goto out;
4951 /*
4952 * Note order: OP_LINK leaves the directory as the current
4953 * filehandle.
4954 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004955 if (decode_getfattr(&xdr, res->dir_attr, res->server,
4956 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004957 goto out;
4958 if ((status = decode_restorefh(&xdr)) != 0)
4959 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004960 decode_getfattr(&xdr, res->fattr, res->server,
4961 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962out:
4963 return status;
4964}
4965
4966/*
4967 * Decode CREATE response
4968 */
Al Viro8687b632006-10-19 23:28:48 -07004969static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970{
4971 struct xdr_stream xdr;
4972 struct compound_hdr hdr;
4973 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004974
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004976 status = decode_compound_hdr(&xdr, &hdr);
4977 if (status)
4978 goto out;
4979 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4980 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004981 goto out;
4982 if ((status = decode_putfh(&xdr)) != 0)
4983 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004984 if ((status = decode_savefh(&xdr)) != 0)
4985 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4987 goto out;
4988 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4989 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004990 if (decode_getfattr(&xdr, res->fattr, res->server,
4991 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004992 goto out;
4993 if ((status = decode_restorefh(&xdr)) != 0)
4994 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004995 decode_getfattr(&xdr, res->dir_fattr, res->server,
4996 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004997out:
4998 return status;
4999}
5000
5001/*
5002 * Decode SYMLINK response
5003 */
Al Viro8687b632006-10-19 23:28:48 -07005004static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005{
5006 return nfs4_xdr_dec_create(rqstp, p, res);
5007}
5008
5009/*
5010 * Decode GETATTR response
5011 */
Al Viro8687b632006-10-19 23:28:48 -07005012static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013{
5014 struct xdr_stream xdr;
5015 struct compound_hdr hdr;
5016 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005017
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5019 status = decode_compound_hdr(&xdr, &hdr);
5020 if (status)
5021 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005022 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5023 if (status)
5024 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 status = decode_putfh(&xdr);
5026 if (status)
5027 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005028 status = decode_getfattr(&xdr, res->fattr, res->server,
5029 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005030out:
5031 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032}
5033
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005034/*
5035 * Encode an SETACL request
5036 */
5037static int
Al Viro8687b632006-10-19 23:28:48 -07005038nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005039{
Andy Adamson05d564f2008-12-23 16:06:15 -05005040 struct xdr_stream xdr;
5041 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005042 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005043 };
5044 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005045
Andy Adamson05d564f2008-12-23 16:06:15 -05005046 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04005047 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005048 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05005049 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005050 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005051 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005052 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005053}
Andy Adamson05d564f2008-12-23 16:06:15 -05005054
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005055/*
5056 * Decode SETACL response
5057 */
5058static int
Benny Halevy73c403a2009-04-01 09:22:01 -04005059nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
5060 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005061{
5062 struct xdr_stream xdr;
5063 struct compound_hdr hdr;
5064 int status;
5065
5066 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5067 status = decode_compound_hdr(&xdr, &hdr);
5068 if (status)
5069 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005070 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5071 if (status)
5072 goto out;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005073 status = decode_putfh(&xdr);
5074 if (status)
5075 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005076 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005077out:
5078 return status;
5079}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005080
5081/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005082 * Decode GETACL response
5083 */
5084static int
Benny Halevy663c79b2009-04-01 09:21:59 -04005085nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
5086 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005087{
5088 struct xdr_stream xdr;
5089 struct compound_hdr hdr;
5090 int status;
5091
5092 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5093 status = decode_compound_hdr(&xdr, &hdr);
5094 if (status)
5095 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005096 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5097 if (status)
5098 goto out;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005099 status = decode_putfh(&xdr);
5100 if (status)
5101 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04005102 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005103
5104out:
5105 return status;
5106}
5107
5108/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109 * Decode CLOSE response
5110 */
Al Viro8687b632006-10-19 23:28:48 -07005111static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112{
Andy Adamson05d564f2008-12-23 16:06:15 -05005113 struct xdr_stream xdr;
5114 struct compound_hdr hdr;
5115 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116
Andy Adamson05d564f2008-12-23 16:06:15 -05005117 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5118 status = decode_compound_hdr(&xdr, &hdr);
5119 if (status)
5120 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005121 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5122 if (status)
5123 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005124 status = decode_putfh(&xdr);
5125 if (status)
5126 goto out;
5127 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005128 if (status != 0)
5129 goto out;
5130 /*
5131 * Note: Server may do delete on close for this file
5132 * in which case the getattr call will fail with
5133 * an ESTALE error. Shouldn't be a problem,
5134 * though, since fattr->valid will remain unset.
5135 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005136 decode_getfattr(&xdr, res->fattr, res->server,
5137 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005138out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005139 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005140}
5141
5142/*
5143 * Decode OPEN response
5144 */
Al Viro8687b632006-10-19 23:28:48 -07005145static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005146{
Andy Adamson05d564f2008-12-23 16:06:15 -05005147 struct xdr_stream xdr;
5148 struct compound_hdr hdr;
5149 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005150
Andy Adamson05d564f2008-12-23 16:06:15 -05005151 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5152 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005153 if (status)
5154 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005155 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5156 if (status)
5157 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005158 status = decode_putfh(&xdr);
5159 if (status)
5160 goto out;
5161 status = decode_savefh(&xdr);
5162 if (status)
5163 goto out;
5164 status = decode_open(&xdr, res);
5165 if (status)
5166 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04005167 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005169 if (decode_getfattr(&xdr, res->f_attr, res->server,
5170 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005171 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04005172 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005173 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005174 decode_getfattr(&xdr, res->dir_attr, res->server,
5175 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005176out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005177 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178}
5179
5180/*
5181 * Decode OPEN_CONFIRM response
5182 */
Al Viro8687b632006-10-19 23:28:48 -07005183static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005184{
Andy Adamson05d564f2008-12-23 16:06:15 -05005185 struct xdr_stream xdr;
5186 struct compound_hdr hdr;
5187 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005188
Andy Adamson05d564f2008-12-23 16:06:15 -05005189 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5190 status = decode_compound_hdr(&xdr, &hdr);
5191 if (status)
5192 goto out;
5193 status = decode_putfh(&xdr);
5194 if (status)
5195 goto out;
5196 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005197out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005198 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005199}
5200
5201/*
5202 * Decode OPEN response
5203 */
Al Viro8687b632006-10-19 23:28:48 -07005204static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205{
Andy Adamson05d564f2008-12-23 16:06:15 -05005206 struct xdr_stream xdr;
5207 struct compound_hdr hdr;
5208 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005209
Andy Adamson05d564f2008-12-23 16:06:15 -05005210 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5211 status = decode_compound_hdr(&xdr, &hdr);
5212 if (status)
5213 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005214 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5215 if (status)
5216 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005217 status = decode_putfh(&xdr);
5218 if (status)
5219 goto out;
5220 status = decode_open(&xdr, res);
5221 if (status)
5222 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005223 decode_getfattr(&xdr, res->f_attr, res->server,
5224 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005225out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005226 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227}
5228
5229/*
5230 * Decode SETATTR response
5231 */
Al Viro8687b632006-10-19 23:28:48 -07005232static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005233{
Andy Adamson05d564f2008-12-23 16:06:15 -05005234 struct xdr_stream xdr;
5235 struct compound_hdr hdr;
5236 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005237
Andy Adamson05d564f2008-12-23 16:06:15 -05005238 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5239 status = decode_compound_hdr(&xdr, &hdr);
5240 if (status)
5241 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005242 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5243 if (status)
5244 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005245 status = decode_putfh(&xdr);
5246 if (status)
5247 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005248 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005249 if (status)
5250 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005251 decode_getfattr(&xdr, res->fattr, res->server,
5252 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005253out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005254 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005255}
5256
5257/*
5258 * Decode LOCK response
5259 */
Al Viro8687b632006-10-19 23:28:48 -07005260static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005261{
5262 struct xdr_stream xdr;
5263 struct compound_hdr hdr;
5264 int status;
5265
5266 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5267 status = decode_compound_hdr(&xdr, &hdr);
5268 if (status)
5269 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005270 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5271 if (status)
5272 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005273 status = decode_putfh(&xdr);
5274 if (status)
5275 goto out;
5276 status = decode_lock(&xdr, res);
5277out:
5278 return status;
5279}
5280
5281/*
5282 * Decode LOCKT response
5283 */
Al Viro8687b632006-10-19 23:28:48 -07005284static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005285{
5286 struct xdr_stream xdr;
5287 struct compound_hdr hdr;
5288 int status;
5289
5290 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5291 status = decode_compound_hdr(&xdr, &hdr);
5292 if (status)
5293 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005294 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5295 if (status)
5296 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005297 status = decode_putfh(&xdr);
5298 if (status)
5299 goto out;
5300 status = decode_lockt(&xdr, res);
5301out:
5302 return status;
5303}
5304
5305/*
5306 * Decode LOCKU response
5307 */
Al Viro8687b632006-10-19 23:28:48 -07005308static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005309{
5310 struct xdr_stream xdr;
5311 struct compound_hdr hdr;
5312 int status;
5313
5314 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5315 status = decode_compound_hdr(&xdr, &hdr);
5316 if (status)
5317 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005318 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5319 if (status)
5320 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005321 status = decode_putfh(&xdr);
5322 if (status)
5323 goto out;
5324 status = decode_locku(&xdr, res);
5325out:
5326 return status;
5327}
5328
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005329static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
5330{
5331 struct xdr_stream xdr;
5332 struct compound_hdr hdr;
5333 int status;
5334
5335 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5336 status = decode_compound_hdr(&xdr, &hdr);
5337 if (!status)
5338 status = decode_release_lockowner(&xdr);
5339 return status;
5340}
5341
Linus Torvalds1da177e2005-04-16 15:20:36 -07005342/*
5343 * Decode READLINK response
5344 */
Benny Halevyf50c7002009-04-01 09:21:55 -04005345static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
5346 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005347{
5348 struct xdr_stream xdr;
5349 struct compound_hdr hdr;
5350 int status;
5351
5352 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5353 status = decode_compound_hdr(&xdr, &hdr);
5354 if (status)
5355 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005356 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5357 if (status)
5358 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005359 status = decode_putfh(&xdr);
5360 if (status)
5361 goto out;
5362 status = decode_readlink(&xdr, rqstp);
5363out:
5364 return status;
5365}
5366
5367/*
5368 * Decode READDIR response
5369 */
Al Viro8687b632006-10-19 23:28:48 -07005370static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005371{
5372 struct xdr_stream xdr;
5373 struct compound_hdr hdr;
5374 int status;
5375
5376 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5377 status = decode_compound_hdr(&xdr, &hdr);
5378 if (status)
5379 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005380 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5381 if (status)
5382 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005383 status = decode_putfh(&xdr);
5384 if (status)
5385 goto out;
5386 status = decode_readdir(&xdr, rqstp, res);
5387out:
5388 return status;
5389}
5390
5391/*
5392 * Decode Read response
5393 */
Al Viro8687b632006-10-19 23:28:48 -07005394static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005395{
5396 struct xdr_stream xdr;
5397 struct compound_hdr hdr;
5398 int status;
5399
5400 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5401 status = decode_compound_hdr(&xdr, &hdr);
5402 if (status)
5403 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005404 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5405 if (status)
5406 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005407 status = decode_putfh(&xdr);
5408 if (status)
5409 goto out;
5410 status = decode_read(&xdr, rqstp, res);
5411 if (!status)
5412 status = res->count;
5413out:
5414 return status;
5415}
5416
5417/*
5418 * Decode WRITE response
5419 */
Al Viro8687b632006-10-19 23:28:48 -07005420static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005421{
5422 struct xdr_stream xdr;
5423 struct compound_hdr hdr;
5424 int status;
5425
5426 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5427 status = decode_compound_hdr(&xdr, &hdr);
5428 if (status)
5429 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005430 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5431 if (status)
5432 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005433 status = decode_putfh(&xdr);
5434 if (status)
5435 goto out;
5436 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005437 if (status)
5438 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005439 decode_getfattr(&xdr, res->fattr, res->server,
5440 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005441 if (!status)
5442 status = res->count;
5443out:
5444 return status;
5445}
5446
5447/*
5448 * Decode COMMIT response
5449 */
Al Viro8687b632006-10-19 23:28:48 -07005450static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005451{
5452 struct xdr_stream xdr;
5453 struct compound_hdr hdr;
5454 int status;
5455
5456 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5457 status = decode_compound_hdr(&xdr, &hdr);
5458 if (status)
5459 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005460 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5461 if (status)
5462 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005463 status = decode_putfh(&xdr);
5464 if (status)
5465 goto out;
5466 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005467 if (status)
5468 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005469 decode_getfattr(&xdr, res->fattr, res->server,
5470 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005471out:
5472 return status;
5473}
5474
5475/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005476 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005477 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04005478static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
5479 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005480{
5481 struct xdr_stream xdr;
5482 struct compound_hdr hdr;
5483 int status;
5484
5485 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5486 status = decode_compound_hdr(&xdr, &hdr);
5487 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005488 status = decode_sequence(&xdr, &res->seq_res, req);
5489 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005490 status = decode_putfh(&xdr);
5491 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04005492 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005493 return status;
5494}
5495
5496/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005497 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005498 */
Benny Halevyd45b2982009-04-01 09:21:58 -04005499static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
5500 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005501{
5502 struct xdr_stream xdr;
5503 struct compound_hdr hdr;
5504 int status;
5505
5506 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5507 status = decode_compound_hdr(&xdr, &hdr);
5508 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005509 status = decode_sequence(&xdr, &res->seq_res, req);
5510 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005511 status = decode_putfh(&xdr);
5512 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04005513 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005514 return status;
5515}
5516
5517/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005518 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005519 */
Benny Halevy24ad1482009-04-01 09:21:56 -04005520static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
5521 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005522{
5523 struct xdr_stream xdr;
5524 struct compound_hdr hdr;
5525 int status;
5526
5527 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5528 status = decode_compound_hdr(&xdr, &hdr);
5529 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005530 status = decode_sequence(&xdr, &res->seq_res, req);
5531 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532 status = decode_putfh(&xdr);
5533 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04005534 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005535 return status;
5536}
5537
5538/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005539 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005540 */
Al Viro8687b632006-10-19 23:28:48 -07005541static 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 -07005542{
5543 struct xdr_stream xdr;
5544 struct compound_hdr hdr;
5545 int status;
5546
5547 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005548 status = decode_compound_hdr(&xdr, &hdr);
5549 if (status)
5550 goto out;
5551 status = decode_sequence(&xdr, &res->seq_res, req);
5552 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005553 goto out;
5554 if ((status = decode_putfh(&xdr)) != 0)
5555 goto out;
5556 status = decode_server_caps(&xdr, res);
5557out:
5558 return status;
5559}
5560
5561/*
5562 * Decode RENEW response
5563 */
Al Viro8687b632006-10-19 23:28:48 -07005564static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005565{
5566 struct xdr_stream xdr;
5567 struct compound_hdr hdr;
5568 int status;
5569
5570 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5571 status = decode_compound_hdr(&xdr, &hdr);
5572 if (!status)
5573 status = decode_renew(&xdr);
5574 return status;
5575}
5576
5577/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005578 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005579 */
Al Viro8687b632006-10-19 23:28:48 -07005580static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005581 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005582{
5583 struct xdr_stream xdr;
5584 struct compound_hdr hdr;
5585 int status;
5586
5587 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5588 status = decode_compound_hdr(&xdr, &hdr);
5589 if (!status)
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005590 status = decode_setclientid(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005591 return status;
5592}
5593
5594/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005595 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005596 */
Al Viro8687b632006-10-19 23:28:48 -07005597static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005598{
5599 struct xdr_stream xdr;
5600 struct compound_hdr hdr;
5601 int status;
5602
5603 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5604 status = decode_compound_hdr(&xdr, &hdr);
5605 if (!status)
5606 status = decode_setclientid_confirm(&xdr);
5607 if (!status)
5608 status = decode_putrootfh(&xdr);
5609 if (!status)
5610 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005611 return status;
5612}
5613
5614/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005615 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005616 */
Al Viro8687b632006-10-19 23:28:48 -07005617static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005618{
5619 struct xdr_stream xdr;
5620 struct compound_hdr hdr;
5621 int status;
5622
5623 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5624 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005625 if (status)
5626 goto out;
5627 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5628 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005629 goto out;
5630 status = decode_putfh(&xdr);
5631 if (status != 0)
5632 goto out;
5633 status = decode_delegreturn(&xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04005634 if (status != 0)
5635 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005636 decode_getfattr(&xdr, res->fattr, res->server,
5637 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01005638out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005639 return status;
5640}
5641
Trond Myklebust683b57b2006-06-09 09:34:22 -04005642/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005643 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04005644 */
Benny Halevy22958462009-04-01 09:22:02 -04005645static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
5646 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005647{
5648 struct xdr_stream xdr;
5649 struct compound_hdr hdr;
5650 int status;
5651
5652 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5653 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005654 if (status)
5655 goto out;
5656 status = decode_sequence(&xdr, &res->seq_res, req);
5657 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005658 goto out;
5659 if ((status = decode_putfh(&xdr)) != 0)
5660 goto out;
5661 if ((status = decode_lookup(&xdr)) != 0)
5662 goto out;
5663 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04005664 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005665 res->fs_locations->server,
5666 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04005667out:
5668 return status;
5669}
5670
Benny Halevy99fe60d2009-04-01 09:22:29 -04005671#if defined(CONFIG_NFS_V4_1)
5672/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005673 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04005674 */
5675static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
5676 void *res)
5677{
5678 struct xdr_stream xdr;
5679 struct compound_hdr hdr;
5680 int status;
5681
5682 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5683 status = decode_compound_hdr(&xdr, &hdr);
5684 if (!status)
5685 status = decode_exchange_id(&xdr, res);
5686 return status;
5687}
Andy Adamson2050f0c2009-04-01 09:22:30 -04005688
5689/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005690 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04005691 */
5692static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
5693 struct nfs41_create_session_res *res)
5694{
5695 struct xdr_stream xdr;
5696 struct compound_hdr hdr;
5697 int status;
5698
5699 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5700 status = decode_compound_hdr(&xdr, &hdr);
5701 if (!status)
5702 status = decode_create_session(&xdr, res);
5703 return status;
5704}
5705
5706/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005707 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005708 */
5709static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
5710 void *dummy)
5711{
5712 struct xdr_stream xdr;
5713 struct compound_hdr hdr;
5714 int status;
5715
5716 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5717 status = decode_compound_hdr(&xdr, &hdr);
5718 if (!status)
5719 status = decode_destroy_session(&xdr, dummy);
5720 return status;
5721}
5722
5723/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005724 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005725 */
5726static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p,
5727 struct nfs4_sequence_res *res)
5728{
5729 struct xdr_stream xdr;
5730 struct compound_hdr hdr;
5731 int status;
5732
5733 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5734 status = decode_compound_hdr(&xdr, &hdr);
5735 if (!status)
5736 status = decode_sequence(&xdr, res, rqstp);
5737 return status;
5738}
5739
5740/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005741 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04005742 */
5743static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
5744 struct nfs4_get_lease_time_res *res)
5745{
5746 struct xdr_stream xdr;
5747 struct compound_hdr hdr;
5748 int status;
5749
5750 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5751 status = decode_compound_hdr(&xdr, &hdr);
5752 if (!status)
5753 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
5754 if (!status)
5755 status = decode_putrootfh(&xdr);
5756 if (!status)
5757 status = decode_fsinfo(&xdr, res->lr_fsinfo);
5758 return status;
5759}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005760
5761/*
5762 * Decode RECLAIM_COMPLETE response
5763 */
5764static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, uint32_t *p,
5765 struct nfs41_reclaim_complete_res *res)
5766{
5767 struct xdr_stream xdr;
5768 struct compound_hdr hdr;
5769 int status;
5770
5771 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5772 status = decode_compound_hdr(&xdr, &hdr);
5773 if (!status)
5774 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5775 if (!status)
5776 status = decode_reclaim_complete(&xdr, (void *)NULL);
5777 return status;
5778}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005779#endif /* CONFIG_NFS_V4_1 */
5780
Bryan Schumaker82f2e542010-10-21 16:33:18 -04005781__be32 *nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
5782 struct nfs_server *server, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005783{
5784 uint32_t bitmap[2] = {0};
5785 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005786 __be32 *p = xdr_inline_decode(xdr, 4);
5787 if (unlikely(!p))
5788 goto out_overflow;
5789 if (!ntohl(*p++)) {
5790 p = xdr_inline_decode(xdr, 4);
5791 if (unlikely(!p))
5792 goto out_overflow;
5793 if (!ntohl(*p++))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005794 return ERR_PTR(-EAGAIN);
5795 entry->eof = 1;
5796 return ERR_PTR(-EBADCOOKIE);
5797 }
5798
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005799 p = xdr_inline_decode(xdr, 12);
5800 if (unlikely(!p))
5801 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005802 entry->prev_cookie = entry->cookie;
5803 p = xdr_decode_hyper(p, &entry->cookie);
5804 entry->len = ntohl(*p++);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005805
5806 p = xdr_inline_decode(xdr, entry->len + 4);
5807 if (unlikely(!p))
5808 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005809 entry->name = (const char *) p;
5810 p += XDR_QUADLEN(entry->len);
5811
5812 /*
5813 * In case the server doesn't return an inode number,
5814 * we fake one here. (We don't use inode number 0,
5815 * since glibc seems to choke on it...)
5816 */
5817 entry->ino = 1;
5818
5819 len = ntohl(*p++); /* bitmap length */
5820 if (len-- > 0) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005821 p = xdr_inline_decode(xdr, 4);
5822 if (unlikely(!p))
5823 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005824 bitmap[0] = ntohl(*p++);
5825 if (len-- > 0) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005826 p = xdr_inline_decode(xdr, 4);
5827 if (unlikely(!p))
5828 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005829 bitmap[1] = ntohl(*p++);
5830 p += len;
5831 }
5832 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005833 p = xdr_inline_decode(xdr, 4);
5834 if (unlikely(!p))
5835 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
5837 if (len > 0) {
Bryan Schumaker82f2e542010-10-21 16:33:18 -04005838 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, server, 1) < 0)
5839 goto out_overflow;
5840 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
5841 entry->ino = entry->fattr->fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005842 }
5843
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005844 p = xdr_inline_peek(xdr, 8);
5845 if (p != NULL)
5846 entry->eof = !p[0] && p[1];
5847 else
5848 entry->eof = 0;
5849
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 return p;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005851
5852out_overflow:
5853 print_overflow_msg(__func__, xdr);
5854 return ERR_PTR(-EIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005855}
5856
5857/*
5858 * We need to translate between nfs status return values and
5859 * the local errno values which may not be the same.
5860 */
5861static struct {
5862 int stat;
5863 int errno;
5864} nfs_errtbl[] = {
5865 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03005866 { NFS4ERR_PERM, -EPERM },
5867 { NFS4ERR_NOENT, -ENOENT },
5868 { NFS4ERR_IO, -errno_NFSERR_IO},
5869 { NFS4ERR_NXIO, -ENXIO },
5870 { NFS4ERR_ACCESS, -EACCES },
5871 { NFS4ERR_EXIST, -EEXIST },
5872 { NFS4ERR_XDEV, -EXDEV },
5873 { NFS4ERR_NOTDIR, -ENOTDIR },
5874 { NFS4ERR_ISDIR, -EISDIR },
5875 { NFS4ERR_INVAL, -EINVAL },
5876 { NFS4ERR_FBIG, -EFBIG },
5877 { NFS4ERR_NOSPC, -ENOSPC },
5878 { NFS4ERR_ROFS, -EROFS },
5879 { NFS4ERR_MLINK, -EMLINK },
5880 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5881 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5882 { NFS4ERR_DQUOT, -EDQUOT },
5883 { NFS4ERR_STALE, -ESTALE },
5884 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5885 { NFS4ERR_BADOWNER, -EINVAL },
5886 { NFS4ERR_BADNAME, -EINVAL },
5887 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5888 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5889 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005890 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03005891 { NFS4ERR_BADTYPE, -EBADTYPE },
5892 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03005893 { NFS4ERR_SYMLINK, -ELOOP },
5894 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5895 { NFS4ERR_DEADLOCK, -EDEADLK },
5896 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005897 * to be handled by a
5898 * middle-layer.
5899 */
Benny Halevy856dff32008-03-31 17:39:06 +03005900 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005901};
5902
5903/*
5904 * Convert an NFS error code to a local one.
5905 * This one is used jointly by NFSv2 and NFSv3.
5906 */
5907static int
David Howells0a8ea432006-08-22 20:06:08 -04005908nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909{
5910 int i;
5911 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5912 if (nfs_errtbl[i].stat == stat)
5913 return nfs_errtbl[i].errno;
5914 }
5915 if (stat <= 10000 || stat > 10100) {
5916 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005917 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005918 }
5919 /* If we cannot translate the error, the recovery routines should
5920 * handle it.
5921 * Note: remaining NFSv4 error codes have values > 10000, so should
5922 * not conflict with native Linux error codes.
5923 */
Benny Halevy856dff32008-03-31 17:39:06 +03005924 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005925}
5926
Linus Torvalds1da177e2005-04-16 15:20:36 -07005927#define PROC(proc, argtype, restype) \
5928[NFSPROC4_CLNT_##proc] = { \
5929 .p_proc = NFSPROC4_COMPOUND, \
5930 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5931 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04005932 .p_arglen = NFS4_##argtype##_sz, \
5933 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05005934 .p_statidx = NFSPROC4_CLNT_##proc, \
5935 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05005936}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005937
5938struct rpc_procinfo nfs4_procedures[] = {
5939 PROC(READ, enc_read, dec_read),
5940 PROC(WRITE, enc_write, dec_write),
5941 PROC(COMMIT, enc_commit, dec_commit),
5942 PROC(OPEN, enc_open, dec_open),
5943 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5944 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5945 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5946 PROC(CLOSE, enc_close, dec_close),
5947 PROC(SETATTR, enc_setattr, dec_setattr),
5948 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5949 PROC(RENEW, enc_renew, dec_renew),
5950 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5951 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5952 PROC(LOCK, enc_lock, dec_lock),
5953 PROC(LOCKT, enc_lockt, dec_lockt),
5954 PROC(LOCKU, enc_locku, dec_locku),
5955 PROC(ACCESS, enc_access, dec_access),
5956 PROC(GETATTR, enc_getattr, dec_getattr),
5957 PROC(LOOKUP, enc_lookup, dec_lookup),
5958 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5959 PROC(REMOVE, enc_remove, dec_remove),
5960 PROC(RENAME, enc_rename, dec_rename),
5961 PROC(LINK, enc_link, dec_link),
5962 PROC(SYMLINK, enc_symlink, dec_symlink),
5963 PROC(CREATE, enc_create, dec_create),
5964 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5965 PROC(STATFS, enc_statfs, dec_statfs),
5966 PROC(READLINK, enc_readlink, dec_readlink),
5967 PROC(READDIR, enc_readdir, dec_readdir),
5968 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5969 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00005970 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005971 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04005972 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005973 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005974#if defined(CONFIG_NFS_V4_1)
5975 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
Andy Adamsonfc931582009-04-01 09:22:31 -04005976 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005977 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005978 PROC(SEQUENCE, enc_sequence, dec_sequence),
Andy Adamson2050f0c2009-04-01 09:22:30 -04005979 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Ricardo Labiaga180197532009-12-05 16:08:40 -05005980 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005981#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005982};
5983
5984struct rpc_version nfs_version4 = {
5985 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08005986 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005987 .procs = nfs4_procedures
5988};
5989
5990/*
5991 * Local variables:
5992 * c-basic-offset: 8
5993 * End:
5994 */