blob: 4ddd04a1113e395c575cd23c0b7f27913e348a28 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
41#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/errno.h>
43#include <linux/string.h>
44#include <linux/in.h>
45#include <linux/pagemap.h>
46#include <linux/proc_fs.h>
47#include <linux/kdev_t.h>
48#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050049#include <linux/sunrpc/msg_prot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/nfs.h>
51#include <linux/nfs4.h>
52#include <linux/nfs_fs.h>
53#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000054#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050055#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#define NFSDBG_FACILITY NFSDBG_XDR
58
59/* Mapping from NFS error code to "errno" error code. */
60#define errno_NFSERR_IO EIO
61
David Howells0a8ea432006-08-22 20:06:08 -040062static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65#ifdef DEBUG
66#define NFS4_MAXTAGLEN 20
67#else
68#define NFS4_MAXTAGLEN 0
69#endif
70
Andy Adamson6c0195a2008-12-23 16:06:15 -050071/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040072 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 */
Trond Myklebust9f958ab2007-07-02 13:58:33 -040074#define open_owner_id_maxsz (1 + 4)
75#define lock_owner_id_maxsz (1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040076#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79#define op_encode_hdr_maxsz (1)
80#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040081#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
84#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
86 (NFS4_FHSIZE >> 2))
87#define decode_putfh_maxsz (op_decode_hdr_maxsz)
88#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
89#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
90#define encode_getfh_maxsz (op_encode_hdr_maxsz)
91#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
92 ((3+NFS4_FHSIZE) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000093#define nfs4_fattr_bitmap_maxsz 3
94#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
96#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040097#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +000099/* This is based on getfattr, which uses the most attributes: */
100#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400101 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000102#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
103 nfs4_fattr_value_maxsz)
104#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400105#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
106 1 + 2 + 1 + \
107 nfs4_owner_maxsz + \
108 nfs4_group_maxsz + \
109 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#define encode_savefh_maxsz (op_encode_hdr_maxsz)
111#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400112#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
113#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200114#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
116#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
117#define decode_renew_maxsz (op_decode_hdr_maxsz)
118#define encode_setclientid_maxsz \
119 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500120 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
121 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
122 1 /* sc_prog */ + \
123 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
124 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
125 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#define decode_setclientid_maxsz \
127 (op_decode_hdr_maxsz + \
128 2 + \
129 1024) /* large value for CLID_INUSE */
130#define encode_setclientid_confirm_maxsz \
131 (op_encode_hdr_maxsz + \
132 3 + (NFS4_VERIFIER_SIZE >> 2))
133#define decode_setclientid_confirm_maxsz \
134 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400135#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
136#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400137#define encode_share_access_maxsz \
138 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500139#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400140#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
141#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
142#define encode_open_maxsz (op_encode_hdr_maxsz + \
143 2 + encode_share_access_maxsz + 2 + \
144 open_owner_id_maxsz + \
145 encode_opentype_maxsz + \
146 encode_claim_null_maxsz)
147#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400148#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400149 decode_ace_maxsz)
150#define decode_change_info_maxsz (5)
151#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400152 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400153 decode_change_info_maxsz + 1 + \
154 nfs4_fattr_bitmap_maxsz + \
155 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400156#define encode_open_confirm_maxsz \
157 (op_encode_hdr_maxsz + \
158 encode_stateid_maxsz + 1)
159#define decode_open_confirm_maxsz \
160 (op_decode_hdr_maxsz + \
161 decode_stateid_maxsz)
162#define encode_open_downgrade_maxsz \
163 (op_encode_hdr_maxsz + \
164 encode_stateid_maxsz + 1 + \
165 encode_share_access_maxsz)
166#define decode_open_downgrade_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169#define encode_close_maxsz (op_encode_hdr_maxsz + \
170 1 + encode_stateid_maxsz)
171#define decode_close_maxsz (op_decode_hdr_maxsz + \
172 decode_stateid_maxsz)
173#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
174 encode_stateid_maxsz + \
175 encode_attrs_maxsz)
176#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
177 nfs4_fattr_bitmap_maxsz)
178#define encode_read_maxsz (op_encode_hdr_maxsz + \
179 encode_stateid_maxsz + 3)
180#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
181#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
182 2 + encode_verifier_maxsz + 5)
183#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
184 decode_verifier_maxsz)
185#define encode_readlink_maxsz (op_encode_hdr_maxsz)
186#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
187#define encode_write_maxsz (op_encode_hdr_maxsz + \
188 encode_stateid_maxsz + 4)
189#define decode_write_maxsz (op_decode_hdr_maxsz + \
190 2 + decode_verifier_maxsz)
191#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
192#define decode_commit_maxsz (op_decode_hdr_maxsz + \
193 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194#define encode_remove_maxsz (op_encode_hdr_maxsz + \
195 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400196#define decode_remove_maxsz (op_decode_hdr_maxsz + \
197 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#define encode_rename_maxsz (op_encode_hdr_maxsz + \
199 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400200#define decode_rename_maxsz (op_decode_hdr_maxsz + \
201 decode_change_info_maxsz + \
202 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203#define encode_link_maxsz (op_encode_hdr_maxsz + \
204 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400205#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400206#define encode_lock_maxsz (op_encode_hdr_maxsz + \
207 7 + \
208 1 + encode_stateid_maxsz + 8)
209#define decode_lock_denied_maxsz \
210 (8 + decode_lockowner_maxsz)
211#define decode_lock_maxsz (op_decode_hdr_maxsz + \
212 decode_lock_denied_maxsz)
213#define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
214#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
215 decode_lock_denied_maxsz)
216#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
217 encode_stateid_maxsz + \
218 4)
219#define decode_locku_maxsz (op_decode_hdr_maxsz + \
220 decode_stateid_maxsz)
221#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
222#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
224 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400225 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000226 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
228#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400229 1 + 2 + nfs4_name_maxsz + \
230 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400231#define decode_create_maxsz (op_decode_hdr_maxsz + \
232 decode_change_info_maxsz + \
233 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400234#define encode_statfs_maxsz (encode_getattr_maxsz)
235#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
237#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400238#define encode_getacl_maxsz (encode_getattr_maxsz)
239#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
240 nfs4_fattr_bitmap_maxsz + 1)
241#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
242 encode_stateid_maxsz + 3)
243#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400244#define encode_fs_locations_maxsz \
245 (encode_getattr_maxsz)
246#define decode_fs_locations_maxsz \
247 (0)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400248
249#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400250#define NFS4_MAX_MACHINE_NAME_LEN (64)
251
Benny Halevy99fe60d2009-04-01 09:22:29 -0400252#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
253 encode_verifier_maxsz + \
254 1 /* co_ownerid.len */ + \
255 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
256 1 /* flags */ + \
257 1 /* spa_how */ + \
258 0 /* SP4_NONE (for now) */ + \
259 1 /* zero implemetation id array */)
260#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
261 2 /* eir_clientid */ + \
262 1 /* eir_sequenceid */ + \
263 1 /* eir_flags */ + \
264 1 /* spr_how */ + \
265 0 /* SP4_NONE (for now) */ + \
266 2 /* eir_server_owner.so_minor_id */ + \
267 /* eir_server_owner.so_major_id<> */ \
268 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
269 /* eir_server_scope<> */ \
270 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
271 1 /* eir_server_impl_id array length */ + \
272 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400273#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
274#define decode_channel_attrs_maxsz (6 + \
275 1 /* ca_rdma_ird.len */ + \
276 1 /* ca_rdma_ird */)
277#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
278 2 /* csa_clientid */ + \
279 1 /* csa_sequence */ + \
280 1 /* csa_flags */ + \
281 encode_channel_attrs_maxsz + \
282 encode_channel_attrs_maxsz + \
283 1 /* csa_cb_program */ + \
284 1 /* csa_sec_parms.len (1) */ + \
285 1 /* cb_secflavor (AUTH_SYS) */ + \
286 1 /* stamp */ + \
287 1 /* machinename.len */ + \
288 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
289 1 /* uid */ + \
290 1 /* gid */ + \
291 1 /* gids.len (0) */)
292#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
293 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
294 1 /* csr_sequence */ + \
295 1 /* csr_flags */ + \
296 decode_channel_attrs_maxsz + \
297 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400298#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
299#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400300#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
301 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
302#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
303 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400304#else /* CONFIG_NFS_V4_1 */
305#define encode_sequence_maxsz 0
306#define decode_sequence_maxsz 0
307#endif /* CONFIG_NFS_V4_1 */
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
310#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
311#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400312 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400314 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400316 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400318 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400320 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400322 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400324 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400326 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400328 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400330 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400332 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400334 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400336 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400338 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400339 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340#define NFS4_dec_write_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_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400344 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400346 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400348 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400349 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400351 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400353 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400354 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400356 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400357 encode_putfh_maxsz + \
358 encode_savefh_maxsz + \
359 encode_open_maxsz + \
360 encode_getfh_maxsz + \
361 encode_getattr_maxsz + \
362 encode_restorefh_maxsz + \
363 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400365 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400366 decode_putfh_maxsz + \
367 decode_savefh_maxsz + \
368 decode_open_maxsz + \
369 decode_getfh_maxsz + \
370 decode_getattr_maxsz + \
371 decode_restorefh_maxsz + \
372 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400373#define NFS4_enc_open_confirm_sz \
374 (compound_encode_hdr_maxsz + \
375 encode_putfh_maxsz + \
376 encode_open_confirm_maxsz)
377#define NFS4_dec_open_confirm_sz \
378 (compound_decode_hdr_maxsz + \
379 decode_putfh_maxsz + \
380 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400382 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400384 encode_open_maxsz + \
385 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400387 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400389 decode_open_maxsz + \
390 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#define NFS4_enc_open_downgrade_sz \
392 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400393 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400394 encode_putfh_maxsz + \
395 encode_open_downgrade_maxsz + \
396 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397#define NFS4_dec_open_downgrade_sz \
398 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400399 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400400 decode_putfh_maxsz + \
401 decode_open_downgrade_maxsz + \
402 decode_getattr_maxsz)
403#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400404 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400405 encode_putfh_maxsz + \
406 encode_close_maxsz + \
407 encode_getattr_maxsz)
408#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400409 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400410 decode_putfh_maxsz + \
411 decode_close_maxsz + \
412 decode_getattr_maxsz)
413#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400414 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400415 encode_putfh_maxsz + \
416 encode_setattr_maxsz + \
417 encode_getattr_maxsz)
418#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400419 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400420 decode_putfh_maxsz + \
421 decode_setattr_maxsz + \
422 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400424 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 encode_putfh_maxsz + \
426 encode_fsinfo_maxsz)
427#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400428 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 decode_putfh_maxsz + \
430 decode_fsinfo_maxsz)
431#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
432 encode_renew_maxsz)
433#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
434 decode_renew_maxsz)
435#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
436 encode_setclientid_maxsz)
437#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
438 decode_setclientid_maxsz)
439#define NFS4_enc_setclientid_confirm_sz \
440 (compound_encode_hdr_maxsz + \
441 encode_setclientid_confirm_maxsz + \
442 encode_putrootfh_maxsz + \
443 encode_fsinfo_maxsz)
444#define NFS4_dec_setclientid_confirm_sz \
445 (compound_decode_hdr_maxsz + \
446 decode_setclientid_confirm_maxsz + \
447 decode_putrootfh_maxsz + \
448 decode_fsinfo_maxsz)
449#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400450 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400452 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400454 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400456 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400460 encode_lockt_maxsz)
461#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400462 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400463 decode_putfh_maxsz + \
464 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400466 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400468 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400470 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400472 decode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400474 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400476 encode_access_maxsz + \
477 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478#define NFS4_dec_access_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 Myklebust76b32992007-08-10 17:45:11 -0400481 decode_access_maxsz + \
482 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400484 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 encode_putfh_maxsz + \
486 encode_getattr_maxsz)
487#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400488 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 decode_putfh_maxsz + \
490 decode_getattr_maxsz)
491#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 encode_putfh_maxsz + \
494 encode_lookup_maxsz + \
495 encode_getattr_maxsz + \
496 encode_getfh_maxsz)
497#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400498 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400500 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 decode_getattr_maxsz + \
502 decode_getfh_maxsz)
503#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400504 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 encode_putrootfh_maxsz + \
506 encode_getattr_maxsz + \
507 encode_getfh_maxsz)
508#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400509 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 decode_putrootfh_maxsz + \
511 decode_getattr_maxsz + \
512 decode_getfh_maxsz)
513#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400514 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400516 encode_remove_maxsz + \
517 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400519 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400521 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400522 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400524 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 encode_putfh_maxsz + \
526 encode_savefh_maxsz + \
527 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400528 encode_rename_maxsz + \
529 encode_getattr_maxsz + \
530 encode_restorefh_maxsz + \
531 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400533 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 decode_putfh_maxsz + \
535 decode_savefh_maxsz + \
536 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400537 decode_rename_maxsz + \
538 decode_getattr_maxsz + \
539 decode_restorefh_maxsz + \
540 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 encode_putfh_maxsz + \
544 encode_savefh_maxsz + \
545 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400546 encode_link_maxsz + \
547 decode_getattr_maxsz + \
548 encode_restorefh_maxsz + \
549 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400551 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 decode_putfh_maxsz + \
553 decode_savefh_maxsz + \
554 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400555 decode_link_maxsz + \
556 decode_getattr_maxsz + \
557 decode_restorefh_maxsz + \
558 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400560 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 encode_putfh_maxsz + \
562 encode_symlink_maxsz + \
563 encode_getattr_maxsz + \
564 encode_getfh_maxsz)
565#define NFS4_dec_symlink_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_symlink_maxsz + \
569 decode_getattr_maxsz + \
570 decode_getfh_maxsz)
571#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400574 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400576 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400578 encode_restorefh_maxsz + \
579 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580#define NFS4_dec_create_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 + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400583 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400585 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400587 decode_restorefh_maxsz + \
588 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 encode_putfh_maxsz + \
592 encode_getattr_maxsz)
593#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400594 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 decode_putfh_maxsz + \
596 decode_getattr_maxsz)
597#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400598 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400600 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400602 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400604 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800607 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 encode_getattr_maxsz)
609#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400610 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800611 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 decode_getattr_maxsz)
613#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400614 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100616 encode_delegreturn_maxsz + \
617 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400619 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100620 decode_delegreturn_maxsz + \
621 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000622#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400623 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000624 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400625 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000626#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400627 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000628 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400629 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000630#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400631 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000632 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400633 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000634#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400635 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000636 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400637 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400638#define NFS4_enc_fs_locations_sz \
639 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400640 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400641 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400642 encode_lookup_maxsz + \
643 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400644#define NFS4_dec_fs_locations_sz \
645 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400646 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400647 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400648 decode_lookup_maxsz + \
649 decode_fs_locations_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400650#if defined(CONFIG_NFS_V4_1)
651#define NFS4_enc_exchange_id_sz \
652 (compound_encode_hdr_maxsz + \
653 encode_exchange_id_maxsz)
654#define NFS4_dec_exchange_id_sz \
655 (compound_decode_hdr_maxsz + \
656 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400657#define NFS4_enc_create_session_sz \
658 (compound_encode_hdr_maxsz + \
659 encode_create_session_maxsz)
660#define NFS4_dec_create_session_sz \
661 (compound_decode_hdr_maxsz + \
662 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400663#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
664 encode_destroy_session_maxsz)
665#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
666 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400667#define NFS4_enc_sequence_sz \
668 (compound_decode_hdr_maxsz + \
669 encode_sequence_maxsz)
670#define NFS4_dec_sequence_sz \
671 (compound_decode_hdr_maxsz + \
672 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400673#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
674 encode_sequence_maxsz + \
675 encode_putrootfh_maxsz + \
676 encode_fsinfo_maxsz)
677#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
678 decode_sequence_maxsz + \
679 decode_putrootfh_maxsz + \
680 decode_fsinfo_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500681
682const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
683 compound_encode_hdr_maxsz +
684 encode_sequence_maxsz +
685 encode_putfh_maxsz +
686 encode_getattr_maxsz) *
687 XDR_UNIT);
688
689const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
690 compound_decode_hdr_maxsz +
691 decode_sequence_maxsz +
692 decode_putfh_maxsz) *
693 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400694#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Trond Myklebustbca79472009-03-11 14:10:26 -0400696static const umode_t nfs_type2fmt[] = {
697 [NF4BAD] = 0,
698 [NF4REG] = S_IFREG,
699 [NF4DIR] = S_IFDIR,
700 [NF4BLK] = S_IFBLK,
701 [NF4CHR] = S_IFCHR,
702 [NF4LNK] = S_IFLNK,
703 [NF4SOCK] = S_IFSOCK,
704 [NF4FIFO] = S_IFIFO,
705 [NF4ATTRDIR] = 0,
706 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707};
708
709struct compound_hdr {
710 int32_t status;
711 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500712 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 uint32_t taglen;
714 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400715 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400716 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717};
718
Benny Halevy13c65ce2009-08-14 17:19:25 +0300719static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
720{
721 __be32 *p = xdr_reserve_space(xdr, nbytes);
722 BUG_ON(!p);
723 return p;
724}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
726static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
727{
Al Viro8687b632006-10-19 23:28:48 -0700728 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730 p = xdr_reserve_space(xdr, 4 + len);
731 BUG_ON(p == NULL);
732 xdr_encode_opaque(p, str, len);
733}
734
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400735static void encode_compound_hdr(struct xdr_stream *xdr,
736 struct rpc_rqst *req,
737 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738{
Al Viro8687b632006-10-19 23:28:48 -0700739 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400740 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
741
742 /* initialize running count of expected bytes in reply.
743 * NOTE: the replied tag SHOULD be the same is the one sent,
744 * but this is not required as a MUST for the server to do so. */
745 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
748 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300749 p = reserve_space(xdr, 4 + hdr->taglen + 8);
750 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300751 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500752 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300753 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500754}
755
756static void encode_nops(struct compound_hdr *hdr)
757{
Andy Adamsonfc931582009-04-01 09:22:31 -0400758 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500759 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760}
761
762static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
763{
Al Viro8687b632006-10-19 23:28:48 -0700764 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
766 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
767 BUG_ON(p == NULL);
768 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
769}
770
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500771static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772{
773 char owner_name[IDMAP_NAMESZ];
774 char owner_group[IDMAP_NAMESZ];
775 int owner_namelen = 0;
776 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700777 __be32 *p;
778 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 int len;
780 uint32_t bmval0 = 0;
781 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
783 /*
784 * We reserve enough space to write the entire attribute buffer at once.
785 * In the worst-case, this would be
786 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
787 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000788 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 */
790 len = 16;
791
792 /* Sigh */
793 if (iap->ia_valid & ATTR_SIZE)
794 len += 8;
795 if (iap->ia_valid & ATTR_MODE)
796 len += 4;
797 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400798 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400800 dprintk("nfs: couldn't resolve uid %d to string\n",
801 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 /* XXX */
803 strcpy(owner_name, "nobody");
804 owner_namelen = sizeof("nobody") - 1;
805 /* goto out; */
806 }
807 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
808 }
809 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400810 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400812 dprintk("nfs: couldn't resolve gid %d to string\n",
813 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 strcpy(owner_group, "nobody");
815 owner_grouplen = sizeof("nobody") - 1;
816 /* goto out; */
817 }
818 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
819 }
820 if (iap->ia_valid & ATTR_ATIME_SET)
821 len += 16;
822 else if (iap->ia_valid & ATTR_ATIME)
823 len += 4;
824 if (iap->ia_valid & ATTR_MTIME_SET)
825 len += 16;
826 else if (iap->ia_valid & ATTR_MTIME)
827 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300828 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 /*
831 * We write the bitmap length now, but leave the bitmap and the attribute
832 * buffer length to be backfilled at the end of this routine.
833 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300834 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 q = p;
836 p += 3;
837
838 if (iap->ia_valid & ATTR_SIZE) {
839 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300840 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 }
842 if (iap->ia_valid & ATTR_MODE) {
843 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300844 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 }
846 if (iap->ia_valid & ATTR_UID) {
847 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300848 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 }
850 if (iap->ia_valid & ATTR_GID) {
851 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300852 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 }
854 if (iap->ia_valid & ATTR_ATIME_SET) {
855 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300856 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
857 *p++ = cpu_to_be32(0);
858 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
859 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 }
861 else if (iap->ia_valid & ATTR_ATIME) {
862 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300863 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 }
865 if (iap->ia_valid & ATTR_MTIME_SET) {
866 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300867 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
868 *p++ = cpu_to_be32(0);
869 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
870 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 }
872 else if (iap->ia_valid & ATTR_MTIME) {
873 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300874 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 /*
878 * Now we backfill the bitmap and the attribute buffer length.
879 */
880 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400881 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 len, ((char *)p - (char *)q) + 4);
883 BUG();
884 }
885 len = (char *)p - (char *)q - 12;
886 *q++ = htonl(bmval0);
887 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300888 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891}
892
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500893static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894{
Al Viro8687b632006-10-19 23:28:48 -0700895 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Benny Halevy13c65ce2009-08-14 17:19:25 +0300897 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300898 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +0300899 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500900 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400901 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902}
903
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500904static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
Al Viro8687b632006-10-19 23:28:48 -0700906 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Benny Halevy13c65ce2009-08-14 17:19:25 +0300908 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300909 *p++ = cpu_to_be32(OP_CLOSE);
910 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +0300911 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500912 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400913 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914}
915
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500916static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917{
Al Viro8687b632006-10-19 23:28:48 -0700918 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500919
Benny Halevy13c65ce2009-08-14 17:19:25 +0300920 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300921 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +0300922 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +0300923 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500924 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400925 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926}
927
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500928static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929{
Al Viro8687b632006-10-19 23:28:48 -0700930 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500931
Benny Halevy13c65ce2009-08-14 17:19:25 +0300932 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300933 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +0300934 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936 switch (create->ftype) {
937 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300938 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +0300939 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -0400940 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 break;
942
943 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300944 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300945 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +0300946 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 break;
948
949 default:
950 break;
951 }
952
Benny Halevy811652b2009-08-14 17:19:34 +0300953 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -0500954 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400955 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500957 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958}
959
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500960static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961{
Andy Adamson05d564f2008-12-23 16:06:15 -0500962 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
Benny Halevy13c65ce2009-08-14 17:19:25 +0300964 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300965 *p++ = cpu_to_be32(OP_GETATTR);
966 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +0300967 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500968 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400969 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970}
971
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500972static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973{
Andy Adamson05d564f2008-12-23 16:06:15 -0500974 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
Benny Halevy13c65ce2009-08-14 17:19:25 +0300976 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300977 *p++ = cpu_to_be32(OP_GETATTR);
978 *p++ = cpu_to_be32(2);
979 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +0300980 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -0500981 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400982 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983}
984
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500985static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500987 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
988 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500991static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500993 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
994 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995}
996
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500997static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -0400998{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500999 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1000 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001001}
1002
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001003static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004{
Al Viro8687b632006-10-19 23:28:48 -07001005 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
Benny Halevy13c65ce2009-08-14 17:19:25 +03001007 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001008 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001009 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001010 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011}
1012
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001013static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014{
Al Viro8687b632006-10-19 23:28:48 -07001015 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
Benny Halevy13c65ce2009-08-14 17:19:25 +03001017 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001018 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001019 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001020 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001021 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022}
1023
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001024static inline int nfs4_lock_type(struct file_lock *fl, int block)
1025{
1026 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1027 return block ? NFS4_READW_LT : NFS4_READ_LT;
1028 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1029}
1030
1031static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1032{
1033 if (fl->fl_end == OFFSET_MAX)
1034 return ~(uint64_t)0;
1035 return fl->fl_end - fl->fl_start + 1;
1036}
1037
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038/*
1039 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1040 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1041 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001042static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043{
Al Viro8687b632006-10-19 23:28:48 -07001044 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
Benny Halevy13c65ce2009-08-14 17:19:25 +03001046 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001047 *p++ = cpu_to_be32(OP_LOCK);
1048 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1049 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001050 p = xdr_encode_hyper(p, args->fl->fl_start);
1051 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001052 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001053 if (args->new_lock_owner){
Benny Halevy13c65ce2009-08-14 17:19:25 +03001054 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001055 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001056 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001057 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001058 p = xdr_encode_hyper(p, args->lock_owner.clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001059 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001060 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001061 xdr_encode_hyper(p, args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
1063 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001064 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001065 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001066 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 }
Andy Adamsond0179312008-12-23 16:06:17 -05001068 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001069 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070}
1071
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001072static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073{
Al Viro8687b632006-10-19 23:28:48 -07001074 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
Benny Halevy13c65ce2009-08-14 17:19:25 +03001076 p = reserve_space(xdr, 52);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001077 *p++ = cpu_to_be32(OP_LOCKT);
1078 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001079 p = xdr_encode_hyper(p, args->fl->fl_start);
1080 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1081 p = xdr_encode_hyper(p, args->lock_owner.clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001082 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001083 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001084 xdr_encode_hyper(p, args->lock_owner.id);
Andy Adamsond0179312008-12-23 16:06:17 -05001085 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001086 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087}
1088
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001089static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090{
Al Viro8687b632006-10-19 23:28:48 -07001091 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Benny Halevy13c65ce2009-08-14 17:19:25 +03001093 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001094 *p++ = cpu_to_be32(OP_LOCKU);
1095 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1096 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001097 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001098 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001099 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001100 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001101 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102}
1103
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001104static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105{
1106 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001107 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
Benny Halevy13c65ce2009-08-14 17:19:25 +03001109 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001110 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001111 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001112 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001113 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114}
1115
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001116static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117{
Al Viro8687b632006-10-19 23:28:48 -07001118 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Benny Halevy13c65ce2009-08-14 17:19:25 +03001120 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001121 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001122 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001123 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001124 break;
1125 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001126 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001127 break;
1128 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001129 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001130 break;
1131 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001132 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 }
Benny Halevy34558512009-08-14 17:19:30 +03001134 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135}
1136
1137static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1138{
Al Viro8687b632006-10-19 23:28:48 -07001139 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 /*
1141 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1142 * owner 4 = 32
1143 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001144 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001145 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001146 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001147 encode_share_access(xdr, arg->fmode);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001148 p = reserve_space(xdr, 28);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001149 p = xdr_encode_hyper(p, arg->clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001150 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001151 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001152 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153}
1154
1155static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1156{
Al Viro8687b632006-10-19 23:28:48 -07001157 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001158 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
Benny Halevy13c65ce2009-08-14 17:19:25 +03001160 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001162 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001163 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001164 encode_attrs(xdr, arg->u.attrs, arg->server);
1165 break;
1166 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001167 clp = arg->server->nfs_client;
1168 if (clp->cl_minorversion > 0) {
1169 if (nfs4_has_persistent_session(clp)) {
1170 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1171 encode_attrs(xdr, arg->u.attrs, arg->server);
1172 } else {
1173 struct iattr dummy;
1174
1175 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1176 encode_nfs4_verifier(xdr, &arg->u.verifier);
1177 dummy.ia_valid = 0;
1178 encode_attrs(xdr, &dummy, arg->server);
1179 }
1180 } else {
1181 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1182 encode_nfs4_verifier(xdr, &arg->u.verifier);
1183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 }
1185}
1186
1187static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1188{
Al Viro8687b632006-10-19 23:28:48 -07001189 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
Benny Halevy13c65ce2009-08-14 17:19:25 +03001191 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001193 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001194 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001195 break;
1196 default:
1197 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001198 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001199 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 }
1201}
1202
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001203static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204{
Al Viro8687b632006-10-19 23:28:48 -07001205 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Benny Halevy13c65ce2009-08-14 17:19:25 +03001207 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001209 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001210 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001211 break;
1212 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001213 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001214 break;
1215 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001216 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001217 break;
1218 default:
1219 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 }
1221}
1222
1223static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1224{
Al Viro8687b632006-10-19 23:28:48 -07001225 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
Benny Halevy13c65ce2009-08-14 17:19:25 +03001227 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001228 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 encode_string(xdr, name->len, name->name);
1230}
1231
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001232static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233{
Al Viro8687b632006-10-19 23:28:48 -07001234 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
Benny Halevy13c65ce2009-08-14 17:19:25 +03001236 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001237 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 encode_delegation_type(xdr, type);
1239}
1240
1241static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1242{
Al Viro8687b632006-10-19 23:28:48 -07001243 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
Benny Halevy13c65ce2009-08-14 17:19:25 +03001245 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001246 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001247 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 encode_string(xdr, name->len, name->name);
1249}
1250
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001251static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252{
1253 encode_openhdr(xdr, arg);
1254 encode_opentype(xdr, arg);
1255 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001256 case NFS4_OPEN_CLAIM_NULL:
1257 encode_claim_null(xdr, arg->name);
1258 break;
1259 case NFS4_OPEN_CLAIM_PREVIOUS:
1260 encode_claim_previous(xdr, arg->u.delegation_type);
1261 break;
1262 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1263 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1264 break;
1265 default:
1266 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 }
Andy Adamsond0179312008-12-23 16:06:17 -05001268 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001269 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270}
1271
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001272static 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 -07001273{
Al Viro8687b632006-10-19 23:28:48 -07001274 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
Benny Halevy13c65ce2009-08-14 17:19:25 +03001276 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001277 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001278 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001279 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001280 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001281 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282}
1283
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001284static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285{
Al Viro8687b632006-10-19 23:28:48 -07001286 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Benny Halevy13c65ce2009-08-14 17:19:25 +03001288 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001289 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001290 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001291 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001292 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001293 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001294 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295}
1296
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001297static void
Andy Adamsond0179312008-12-23 16:06:17 -05001298encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299{
1300 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001301 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
Benny Halevy13c65ce2009-08-14 17:19:25 +03001303 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001304 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001305 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001306 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001307 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308}
1309
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001310static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311{
Andy Adamson05d564f2008-12-23 16:06:15 -05001312 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001313
Benny Halevy13c65ce2009-08-14 17:19:25 +03001314 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001315 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001316 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001317 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318}
1319
1320static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1321{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 nfs4_stateid stateid;
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, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 if (ctx->state != NULL) {
1327 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
Benny Halevy34558512009-08-14 17:19:30 +03001328 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 } else
Benny Halevy34558512009-08-14 17:19:30 +03001330 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331}
1332
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001333static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334{
Al Viro8687b632006-10-19 23:28:48 -07001335 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Benny Halevy13c65ce2009-08-14 17:19:25 +03001337 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001338 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
1340 encode_stateid(xdr, args->context);
1341
Benny Halevy13c65ce2009-08-14 17:19:25 +03001342 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001343 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001344 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001345 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001346 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001349static 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 -07001350{
Manoj Naik97d312d2005-06-22 17:16:39 +00001351 uint32_t attrs[2] = {
1352 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1353 FATTR4_WORD1_MOUNTED_ON_FILEID,
1354 };
Al Viro8687b632006-10-19 23:28:48 -07001355 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
Benny Halevy13c65ce2009-08-14 17:19:25 +03001357 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001358 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001359 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001360 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001361 *p++ = cpu_to_be32(readdir->count >> 1); /* We're not doing readdirplus */
1362 *p++ = cpu_to_be32(readdir->count);
1363 *p++ = cpu_to_be32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001364 /* Switch to mounted_on_fileid if the server supports it */
1365 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1366 attrs[0] &= ~FATTR4_WORD0_FILEID;
1367 else
1368 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001369 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001370 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001371 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001372 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001373 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1374 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001375 (unsigned long long)readdir->cookie,
1376 ((u32 *)readdir->verifier.data)[0],
1377 ((u32 *)readdir->verifier.data)[1],
1378 attrs[0] & readdir->bitmask[0],
1379 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380}
1381
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001382static 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 -07001383{
Al Viro8687b632006-10-19 23:28:48 -07001384 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
Benny Halevy13c65ce2009-08-14 17:19:25 +03001386 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001387 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001388 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001389 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390}
1391
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001392static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393{
Al Viro8687b632006-10-19 23:28:48 -07001394 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Benny Halevy13c65ce2009-08-14 17:19:25 +03001396 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001397 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001398 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001399 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001400 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401}
1402
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001403static 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 -07001404{
Al Viro8687b632006-10-19 23:28:48 -07001405 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Benny Halevy811652b2009-08-14 17:19:34 +03001407 p = reserve_space(xdr, 4);
1408 *p = cpu_to_be32(OP_RENAME);
1409 encode_string(xdr, oldname->len, oldname->name);
1410 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001411 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001412 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413}
1414
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001415static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416{
Al Viro8687b632006-10-19 23:28:48 -07001417 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Benny Halevy13c65ce2009-08-14 17:19:25 +03001419 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001420 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001421 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001422 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001423 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424}
1425
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001426static void
Andy Adamsond0179312008-12-23 16:06:17 -05001427encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001428{
Al Viro8687b632006-10-19 23:28:48 -07001429 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001430
Benny Halevy13c65ce2009-08-14 17:19:25 +03001431 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001432 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001433 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001434 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001435}
1436
1437static int
Andy Adamsond0179312008-12-23 16:06:17 -05001438encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001439{
Al Viro8687b632006-10-19 23:28:48 -07001440 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001441
Benny Halevy13c65ce2009-08-14 17:19:25 +03001442 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001443 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001444 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001445 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001446 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001447 *p = cpu_to_be32(FATTR4_WORD0_ACL);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001448 if (arg->acl_len % 4)
1449 return -EINVAL;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001450 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001451 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001452 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001453 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001454 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001455 return 0;
1456}
1457
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001458static void
Andy Adamsond0179312008-12-23 16:06:17 -05001459encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460{
Al Viro8687b632006-10-19 23:28:48 -07001461 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Benny Halevy13c65ce2009-08-14 17:19:25 +03001463 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001464 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001465 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001466 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467}
1468
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001469static 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 -07001470{
Al Viro8687b632006-10-19 23:28:48 -07001471 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001472
Benny Halevy13c65ce2009-08-14 17:19:25 +03001473 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001474 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001475 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001476 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001477 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001478 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001481static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482{
Al Viro8687b632006-10-19 23:28:48 -07001483 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
Benny Halevy13c65ce2009-08-14 17:19:25 +03001485 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001486 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001487 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
1489 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001490 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001491 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1493 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001494 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001495 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001496 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001497 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498}
1499
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001500static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501{
Andy Adamson05d564f2008-12-23 16:06:15 -05001502 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503
Benny Halevy13c65ce2009-08-14 17:19:25 +03001504 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001505 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001506 p = xdr_encode_hyper(p, client_state->cl_clientid);
Benny Halevy34558512009-08-14 17:19:30 +03001507 xdr_encode_opaque_fixed(p, client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001508 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001509 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510}
1511
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001512static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513{
Al Viro8687b632006-10-19 23:28:48 -07001514 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
Benny Halevy13c65ce2009-08-14 17:19:25 +03001516 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001517 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
1519 encode_stateid(xdr, args->context);
1520
Benny Halevy13c65ce2009-08-14 17:19:25 +03001521 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001522 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001523 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001524 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
1526 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001527 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001528 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529}
1530
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001531static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532{
Al Viro8687b632006-10-19 23:28:48 -07001533 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
Benny Halevy13c65ce2009-08-14 17:19:25 +03001535 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Benny Halevye75bc1c2009-08-14 17:18:54 +03001537 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001538 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001539 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001540 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001542
Benny Halevy99fe60d2009-04-01 09:22:29 -04001543#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001544/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001545static void encode_exchange_id(struct xdr_stream *xdr,
1546 struct nfs41_exchange_id_args *args,
1547 struct compound_hdr *hdr)
1548{
1549 __be32 *p;
1550
Benny Halevy13c65ce2009-08-14 17:19:25 +03001551 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001552 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001553 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001554
1555 encode_string(xdr, args->id_len, args->id);
1556
Benny Halevy13c65ce2009-08-14 17:19:25 +03001557 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001558 *p++ = cpu_to_be32(args->flags);
1559 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001560 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001561 hdr->nops++;
1562 hdr->replen += decode_exchange_id_maxsz;
1563}
Andy Adamsonfc931582009-04-01 09:22:31 -04001564
1565static void encode_create_session(struct xdr_stream *xdr,
1566 struct nfs41_create_session_args *args,
1567 struct compound_hdr *hdr)
1568{
1569 __be32 *p;
1570 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1571 uint32_t len;
1572 struct nfs_client *clp = args->client;
1573
Andy Adamsonfc931582009-04-01 09:22:31 -04001574 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1575 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001576
Benny Halevy13c65ce2009-08-14 17:19:25 +03001577 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001578 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001579 p = xdr_encode_hyper(p, clp->cl_ex_clid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001580 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1581 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001582
Andy Adamsonfc931582009-04-01 09:22:31 -04001583 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001584 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1585 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1586 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1587 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1588 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1589 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1590 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001591
1592 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001593 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1594 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1595 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1596 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1597 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1598 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1599 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001600
Benny Halevye75bc1c2009-08-14 17:18:54 +03001601 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001602 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001603 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001604
1605 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001606 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001607 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001608 *p++ = cpu_to_be32(0); /* UID */
1609 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001610 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001611 hdr->nops++;
1612 hdr->replen += decode_create_session_maxsz;
1613}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001614
1615static void encode_destroy_session(struct xdr_stream *xdr,
1616 struct nfs4_session *session,
1617 struct compound_hdr *hdr)
1618{
1619 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001620 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001621 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001622 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001623 hdr->nops++;
1624 hdr->replen += decode_destroy_session_maxsz;
1625}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001626#endif /* CONFIG_NFS_V4_1 */
1627
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001628static void encode_sequence(struct xdr_stream *xdr,
1629 const struct nfs4_sequence_args *args,
1630 struct compound_hdr *hdr)
1631{
1632#if defined(CONFIG_NFS_V4_1)
1633 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001634 struct nfs4_slot_table *tp;
1635 struct nfs4_slot *slot;
1636 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001637
1638 if (!session)
1639 return;
1640
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001641 tp = &session->fc_slot_table;
1642
1643 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1644 slot = tp->slots + args->sa_slotid;
1645
Benny Halevy13c65ce2009-08-14 17:19:25 +03001646 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001647 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001648
1649 /*
1650 * Sessionid + seqid + slotid + max slotid + cache_this
1651 */
1652 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1653 "max_slotid=%d cache_this=%d\n",
1654 __func__,
1655 ((u32 *)session->sess_id.data)[0],
1656 ((u32 *)session->sess_id.data)[1],
1657 ((u32 *)session->sess_id.data)[2],
1658 ((u32 *)session->sess_id.data)[3],
1659 slot->seq_nr, args->sa_slotid,
1660 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001661 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001662 *p++ = cpu_to_be32(slot->seq_nr);
1663 *p++ = cpu_to_be32(args->sa_slotid);
1664 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001665 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001666 hdr->nops++;
1667 hdr->replen += decode_sequence_maxsz;
1668#endif /* CONFIG_NFS_V4_1 */
1669}
1670
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671/*
1672 * END OF "GENERIC" ENCODE ROUTINES.
1673 */
1674
Benny Halevy66cc0422009-04-01 09:22:10 -04001675static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1676{
1677#if defined(CONFIG_NFS_V4_1)
1678 if (args->sa_session)
1679 return args->sa_session->clp->cl_minorversion;
1680#endif /* CONFIG_NFS_V4_1 */
1681 return 0;
1682}
1683
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684/*
1685 * Encode an ACCESS request
1686 */
Al Viro8687b632006-10-19 23:28:48 -07001687static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688{
1689 struct xdr_stream xdr;
1690 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001691 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
1694 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001695 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001696 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001697 encode_putfh(&xdr, args->fh, &hdr);
1698 encode_access(&xdr, args->access, &hdr);
1699 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001700 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001701 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702}
1703
1704/*
1705 * Encode LOOKUP request
1706 */
Al Viro8687b632006-10-19 23:28:48 -07001707static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708{
1709 struct xdr_stream xdr;
1710 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001711 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713
1714 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001715 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001716 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001717 encode_putfh(&xdr, args->dir_fh, &hdr);
1718 encode_lookup(&xdr, args->name, &hdr);
1719 encode_getfh(&xdr, &hdr);
1720 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001721 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001722 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723}
1724
1725/*
1726 * Encode LOOKUP_ROOT request
1727 */
Al Viro8687b632006-10-19 23:28:48 -07001728static 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 -07001729{
1730 struct xdr_stream xdr;
1731 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001732 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
1735 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001736 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001737 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001738 encode_putrootfh(&xdr, &hdr);
1739 encode_getfh(&xdr, &hdr);
1740 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001741 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001742 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743}
1744
1745/*
1746 * Encode REMOVE request
1747 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001748static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749{
1750 struct xdr_stream xdr;
1751 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001752 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
1755 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001756 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001757 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001758 encode_putfh(&xdr, args->fh, &hdr);
1759 encode_remove(&xdr, &args->name, &hdr);
1760 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001761 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001762 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763}
1764
1765/*
1766 * Encode RENAME request
1767 */
Al Viro8687b632006-10-19 23:28:48 -07001768static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769{
1770 struct xdr_stream xdr;
1771 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001772 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
1775 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001776 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001777 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001778 encode_putfh(&xdr, args->old_dir, &hdr);
1779 encode_savefh(&xdr, &hdr);
1780 encode_putfh(&xdr, args->new_dir, &hdr);
1781 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1782 encode_getfattr(&xdr, args->bitmask, &hdr);
1783 encode_restorefh(&xdr, &hdr);
1784 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001785 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001786 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787}
1788
1789/*
1790 * Encode LINK request
1791 */
Al Viro8687b632006-10-19 23:28:48 -07001792static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793{
1794 struct xdr_stream xdr;
1795 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001796 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
1799 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001800 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001801 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001802 encode_putfh(&xdr, args->fh, &hdr);
1803 encode_savefh(&xdr, &hdr);
1804 encode_putfh(&xdr, args->dir_fh, &hdr);
1805 encode_link(&xdr, args->name, &hdr);
1806 encode_getfattr(&xdr, args->bitmask, &hdr);
1807 encode_restorefh(&xdr, &hdr);
1808 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001809 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001810 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811}
1812
1813/*
1814 * Encode CREATE request
1815 */
Al Viro8687b632006-10-19 23:28:48 -07001816static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817{
1818 struct xdr_stream xdr;
1819 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001820 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
1823 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001824 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001825 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001826 encode_putfh(&xdr, args->dir_fh, &hdr);
1827 encode_savefh(&xdr, &hdr);
1828 encode_create(&xdr, args, &hdr);
1829 encode_getfh(&xdr, &hdr);
1830 encode_getfattr(&xdr, args->bitmask, &hdr);
1831 encode_restorefh(&xdr, &hdr);
1832 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001833 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001834 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835}
1836
1837/*
1838 * Encode SYMLINK request
1839 */
Al Viro8687b632006-10-19 23:28:48 -07001840static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841{
1842 return nfs4_xdr_enc_create(req, p, args);
1843}
1844
1845/*
1846 * Encode GETATTR request
1847 */
Al Viro8687b632006-10-19 23:28:48 -07001848static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849{
1850 struct xdr_stream xdr;
1851 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001852 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854
1855 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001856 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001857 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001858 encode_putfh(&xdr, args->fh, &hdr);
1859 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001860 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001861 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862}
1863
1864/*
1865 * Encode a CLOSE request
1866 */
Al Viro8687b632006-10-19 23:28:48 -07001867static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868{
Andy Adamson05d564f2008-12-23 16:06:15 -05001869 struct xdr_stream xdr;
1870 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001871 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001872 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873
Andy Adamson05d564f2008-12-23 16:06:15 -05001874 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001875 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001876 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001877 encode_putfh(&xdr, args->fh, &hdr);
1878 encode_close(&xdr, args, &hdr);
1879 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001880 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001881 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882}
1883
1884/*
1885 * Encode an OPEN request
1886 */
Al Viro8687b632006-10-19 23:28:48 -07001887static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888{
1889 struct xdr_stream xdr;
1890 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001891 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
1894 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001895 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001896 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001897 encode_putfh(&xdr, args->fh, &hdr);
1898 encode_savefh(&xdr, &hdr);
1899 encode_open(&xdr, args, &hdr);
1900 encode_getfh(&xdr, &hdr);
1901 encode_getfattr(&xdr, args->bitmask, &hdr);
1902 encode_restorefh(&xdr, &hdr);
1903 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001904 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001905 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906}
1907
1908/*
1909 * Encode an OPEN_CONFIRM request
1910 */
Al Viro8687b632006-10-19 23:28:48 -07001911static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912{
1913 struct xdr_stream xdr;
1914 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001915 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
1918 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001919 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001920 encode_putfh(&xdr, args->fh, &hdr);
1921 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001922 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001923 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924}
1925
1926/*
1927 * Encode an OPEN request with no attributes.
1928 */
Al Viro8687b632006-10-19 23:28:48 -07001929static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930{
1931 struct xdr_stream xdr;
1932 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001933 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935
1936 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001937 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001938 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001939 encode_putfh(&xdr, args->fh, &hdr);
1940 encode_open(&xdr, args, &hdr);
1941 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001942 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001943 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944}
1945
1946/*
1947 * Encode an OPEN_DOWNGRADE request
1948 */
Al Viro8687b632006-10-19 23:28:48 -07001949static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950{
1951 struct xdr_stream xdr;
1952 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001953 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
1956 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001957 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001958 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001959 encode_putfh(&xdr, args->fh, &hdr);
1960 encode_open_downgrade(&xdr, args, &hdr);
1961 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001962 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001963 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964}
1965
1966/*
1967 * Encode a LOCK request
1968 */
Al Viro8687b632006-10-19 23:28:48 -07001969static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970{
1971 struct xdr_stream xdr;
1972 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001973 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975
1976 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001977 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001978 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001979 encode_putfh(&xdr, args->fh, &hdr);
1980 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001981 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001982 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983}
1984
1985/*
1986 * Encode a LOCKT request
1987 */
Al Viro8687b632006-10-19 23:28:48 -07001988static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989{
1990 struct xdr_stream xdr;
1991 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001992 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994
1995 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001996 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001997 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001998 encode_putfh(&xdr, args->fh, &hdr);
1999 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002000 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002001 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002}
2003
2004/*
2005 * Encode a LOCKU request
2006 */
Al Viro8687b632006-10-19 23:28:48 -07002007static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008{
2009 struct xdr_stream xdr;
2010 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002011 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
2014 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002015 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002016 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002017 encode_putfh(&xdr, args->fh, &hdr);
2018 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002019 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002020 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021}
2022
2023/*
2024 * Encode a READLINK request
2025 */
Al Viro8687b632006-10-19 23:28:48 -07002026static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027{
2028 struct xdr_stream xdr;
2029 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002030 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032
2033 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002034 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002035 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002036 encode_putfh(&xdr, args->fh, &hdr);
2037 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002038
Benny Halevy28f56692009-04-01 09:22:09 -04002039 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002040 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002041 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002042 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043}
2044
2045/*
2046 * Encode a READDIR request
2047 */
Al Viro8687b632006-10-19 23:28:48 -07002048static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049{
2050 struct xdr_stream xdr;
2051 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002052 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
2055 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002056 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002057 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002058 encode_putfh(&xdr, args->fh, &hdr);
2059 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002060
Benny Halevy28f56692009-04-01 09:22:09 -04002061 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002062 args->pgbase, args->count);
2063 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002064 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002065 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002066 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002067 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068}
2069
2070/*
2071 * Encode a READ request
2072 */
Al Viro8687b632006-10-19 23:28:48 -07002073static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 struct xdr_stream xdr;
2076 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002077 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079
2080 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002081 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002082 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002083 encode_putfh(&xdr, args->fh, &hdr);
2084 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
Benny Halevy28f56692009-04-01 09:22:09 -04002086 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002088 req->rq_rcv_buf.flags |= XDRBUF_READ;
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
2093/*
2094 * Encode an SETATTR request
2095 */
Al Viro8687b632006-10-19 23:28:48 -07002096static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097{
Andy Adamson05d564f2008-12-23 16:06:15 -05002098 struct xdr_stream xdr;
2099 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002100 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002101 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
Andy Adamson05d564f2008-12-23 16:06:15 -05002103 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002104 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002105 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002106 encode_putfh(&xdr, args->fh, &hdr);
2107 encode_setattr(&xdr, args, args->server, &hdr);
2108 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002109 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002110 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111}
2112
2113/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002114 * Encode a GETACL request
2115 */
2116static int
Al Viro8687b632006-10-19 23:28:48 -07002117nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002118 struct nfs_getaclargs *args)
2119{
2120 struct xdr_stream xdr;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002121 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002122 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002123 };
Benny Halevy28f56692009-04-01 09:22:09 -04002124 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002125
2126 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002127 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002128 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002129 encode_putfh(&xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002130 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002131 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2132
Benny Halevy28f56692009-04-01 09:22:09 -04002133 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002134 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002135 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002136 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002137}
2138
2139/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 * Encode a WRITE request
2141 */
Al Viro8687b632006-10-19 23:28:48 -07002142static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143{
2144 struct xdr_stream xdr;
2145 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002146 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148
2149 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002150 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002151 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002152 encode_putfh(&xdr, args->fh, &hdr);
2153 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002154 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002155 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002156 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002157 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158}
2159
2160/*
2161 * a COMMIT request
2162 */
Al Viro8687b632006-10-19 23:28:48 -07002163static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164{
2165 struct xdr_stream xdr;
2166 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002167 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
2170 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002171 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002172 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002173 encode_putfh(&xdr, args->fh, &hdr);
2174 encode_commit(&xdr, args, &hdr);
2175 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002176 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002177 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178}
2179
2180/*
2181 * FSINFO request
2182 */
Al Viro8687b632006-10-19 23:28:48 -07002183static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184{
2185 struct xdr_stream xdr;
2186 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002187 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189
2190 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002191 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002192 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002193 encode_putfh(&xdr, args->fh, &hdr);
2194 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002195 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002196 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197}
2198
2199/*
2200 * a PATHCONF request
2201 */
Al Viro8687b632006-10-19 23:28:48 -07002202static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 struct xdr_stream xdr;
2205 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002206 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208
2209 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002210 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002211 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002212 encode_putfh(&xdr, args->fh, &hdr);
2213 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2214 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002215 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002216 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217}
2218
2219/*
2220 * a STATFS request
2221 */
Al Viro8687b632006-10-19 23:28:48 -07002222static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 struct xdr_stream xdr;
2225 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002226 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228
2229 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002230 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002231 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002232 encode_putfh(&xdr, args->fh, &hdr);
2233 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2234 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002235 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002236 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237}
2238
2239/*
2240 * GETATTR_BITMAP request
2241 */
Benny Halevy43652ad2009-04-01 09:21:54 -04002242static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2243 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244{
2245 struct xdr_stream xdr;
2246 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002247 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249
2250 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002251 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002252 encode_sequence(&xdr, &args->seq_args, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04002253 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002254 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2255 FATTR4_WORD0_LINK_SUPPORT|
2256 FATTR4_WORD0_SYMLINK_SUPPORT|
2257 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002258 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002259 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260}
2261
2262/*
2263 * a RENEW request
2264 */
Al Viro8687b632006-10-19 23:28:48 -07002265static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266{
2267 struct xdr_stream xdr;
2268 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002269 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 };
2271
2272 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002273 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002274 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002275 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002276 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277}
2278
2279/*
2280 * a SETCLIENTID request
2281 */
Al Viro8687b632006-10-19 23:28:48 -07002282static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283{
2284 struct xdr_stream xdr;
2285 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002286 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 };
2288
2289 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002290 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002291 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002292 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002293 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294}
2295
2296/*
2297 * a SETCLIENTID_CONFIRM request
2298 */
Al Viro8687b632006-10-19 23:28:48 -07002299static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300{
2301 struct xdr_stream xdr;
2302 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002303 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 };
2305 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306
2307 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002308 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002309 encode_setclientid_confirm(&xdr, clp, &hdr);
2310 encode_putrootfh(&xdr, &hdr);
2311 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002312 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002313 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314}
2315
2316/*
2317 * DELEGRETURN request
2318 */
Al Viro8687b632006-10-19 23:28:48 -07002319static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320{
2321 struct xdr_stream xdr;
2322 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002323 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
2326 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002327 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002328 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002329 encode_putfh(&xdr, args->fhandle, &hdr);
2330 encode_delegreturn(&xdr, args->stateid, &hdr);
2331 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002332 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002333 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334}
2335
2336/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002337 * Encode FS_LOCATIONS request
2338 */
Al Viro8687b632006-10-19 23:28:48 -07002339static 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 -04002340{
2341 struct xdr_stream xdr;
2342 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002343 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002344 };
Benny Halevy28f56692009-04-01 09:22:09 -04002345 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002346
2347 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002348 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002349 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002350 encode_putfh(&xdr, args->dir_fh, &hdr);
2351 encode_lookup(&xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002352 replen = hdr.replen; /* get the attribute into args->page */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002353 encode_fs_locations(&xdr, args->bitmask, &hdr);
2354
Benny Halevy28f56692009-04-01 09:22:09 -04002355 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002356 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002357 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002358 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002359}
2360
Benny Halevy99fe60d2009-04-01 09:22:29 -04002361#if defined(CONFIG_NFS_V4_1)
2362/*
2363 * EXCHANGE_ID request
2364 */
2365static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2366 struct nfs41_exchange_id_args *args)
2367{
2368 struct xdr_stream xdr;
2369 struct compound_hdr hdr = {
2370 .minorversion = args->client->cl_minorversion,
2371 };
2372
2373 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2374 encode_compound_hdr(&xdr, req, &hdr);
2375 encode_exchange_id(&xdr, args, &hdr);
2376 encode_nops(&hdr);
2377 return 0;
2378}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002379
2380/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002381 * a CREATE_SESSION request
2382 */
2383static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2384 struct nfs41_create_session_args *args)
2385{
2386 struct xdr_stream xdr;
2387 struct compound_hdr hdr = {
2388 .minorversion = args->client->cl_minorversion,
2389 };
2390
2391 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2392 encode_compound_hdr(&xdr, req, &hdr);
2393 encode_create_session(&xdr, args, &hdr);
2394 encode_nops(&hdr);
2395 return 0;
2396}
2397
2398/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002399 * a DESTROY_SESSION request
2400 */
2401static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2402 struct nfs4_session *session)
2403{
2404 struct xdr_stream xdr;
2405 struct compound_hdr hdr = {
2406 .minorversion = session->clp->cl_minorversion,
2407 };
2408
2409 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2410 encode_compound_hdr(&xdr, req, &hdr);
2411 encode_destroy_session(&xdr, session, &hdr);
2412 encode_nops(&hdr);
2413 return 0;
2414}
2415
2416/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002417 * a SEQUENCE request
2418 */
2419static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p,
2420 struct nfs4_sequence_args *args)
2421{
2422 struct xdr_stream xdr;
2423 struct compound_hdr hdr = {
2424 .minorversion = nfs4_xdr_minorversion(args),
2425 };
2426
2427 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2428 encode_compound_hdr(&xdr, req, &hdr);
2429 encode_sequence(&xdr, args, &hdr);
2430 encode_nops(&hdr);
2431 return 0;
2432}
2433
2434/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002435 * a GET_LEASE_TIME request
2436 */
2437static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2438 struct nfs4_get_lease_time_args *args)
2439{
2440 struct xdr_stream xdr;
2441 struct compound_hdr hdr = {
2442 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2443 };
2444 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2445
2446 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2447 encode_compound_hdr(&xdr, req, &hdr);
2448 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2449 encode_putrootfh(&xdr, &hdr);
2450 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2451 encode_nops(&hdr);
2452 return 0;
2453}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002454#endif /* CONFIG_NFS_V4_1 */
2455
Benny Halevy686841b2009-08-14 17:19:48 +03002456static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2457{
2458 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2459 "Remaining buffer length is %tu words.\n",
2460 func, xdr->end - xdr->p);
2461}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462
Trond Myklebust683b57b2006-06-09 09:34:22 -04002463static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464{
Al Viro8687b632006-10-19 23:28:48 -07002465 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466
Benny Halevyc0eae662009-08-14 17:20:14 +03002467 p = xdr_inline_decode(xdr, 4);
2468 if (unlikely(!p))
2469 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002470 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002471 p = xdr_inline_decode(xdr, *len);
2472 if (unlikely(!p))
2473 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 *string = (char *)p;
2475 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002476out_overflow:
2477 print_overflow_msg(__func__, xdr);
2478 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479}
2480
2481static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2482{
Al Viro8687b632006-10-19 23:28:48 -07002483 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484
Benny Halevyc0eae662009-08-14 17:20:14 +03002485 p = xdr_inline_decode(xdr, 8);
2486 if (unlikely(!p))
2487 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002488 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002489 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002490
Benny Halevyc0eae662009-08-14 17:20:14 +03002491 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2492 if (unlikely(!p))
2493 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 hdr->tag = (char *)p;
2495 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002496 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002497 if (unlikely(hdr->nops < 1))
2498 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002500out_overflow:
2501 print_overflow_msg(__func__, xdr);
2502 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503}
2504
2505static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2506{
Al Viro8687b632006-10-19 23:28:48 -07002507 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 uint32_t opnum;
2509 int32_t nfserr;
2510
Benny Halevyc0eae662009-08-14 17:20:14 +03002511 p = xdr_inline_decode(xdr, 8);
2512 if (unlikely(!p))
2513 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002514 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002516 dprintk("nfs: Server returned operation"
2517 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 opnum, expected);
2519 return -EIO;
2520 }
Benny Halevycccddf42009-08-14 17:20:19 +03002521 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002523 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002525out_overflow:
2526 print_overflow_msg(__func__, xdr);
2527 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528}
2529
2530/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002531static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532{
Al Viro8687b632006-10-19 23:28:48 -07002533 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002534 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 char *str;
2536
Benny Halevyc0eae662009-08-14 17:20:14 +03002537 p = xdr_inline_decode(xdr, 12);
2538 if (likely(p))
2539 return decode_opaque_inline(xdr, &strlen, &str);
2540 print_overflow_msg(__func__, xdr);
2541 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542}
2543
2544static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2545{
Al Viro8687b632006-10-19 23:28:48 -07002546 uint32_t bmlen;
2547 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548
Benny Halevyc0eae662009-08-14 17:20:14 +03002549 p = xdr_inline_decode(xdr, 4);
2550 if (unlikely(!p))
2551 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002552 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553
2554 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002555 p = xdr_inline_decode(xdr, (bmlen << 2));
2556 if (unlikely(!p))
2557 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002559 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002561 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 }
2563 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002564out_overflow:
2565 print_overflow_msg(__func__, xdr);
2566 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567}
2568
Al Viro8687b632006-10-19 23:28:48 -07002569static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570{
Al Viro8687b632006-10-19 23:28:48 -07002571 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572
Benny Halevyc0eae662009-08-14 17:20:14 +03002573 p = xdr_inline_decode(xdr, 4);
2574 if (unlikely(!p))
2575 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002576 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 *savep = xdr->p;
2578 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002579out_overflow:
2580 print_overflow_msg(__func__, xdr);
2581 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582}
2583
2584static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2585{
2586 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2587 decode_attr_bitmap(xdr, bitmask);
2588 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2589 } else
2590 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002591 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 return 0;
2593}
2594
2595static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2596{
Al Viro8687b632006-10-19 23:28:48 -07002597 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002598 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599
2600 *type = 0;
2601 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2602 return -EIO;
2603 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002604 p = xdr_inline_decode(xdr, 4);
2605 if (unlikely(!p))
2606 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002607 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002609 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 return -EIO;
2611 }
2612 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002613 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002615 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002616 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002617out_overflow:
2618 print_overflow_msg(__func__, xdr);
2619 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620}
2621
2622static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2623{
Al Viro8687b632006-10-19 23:28:48 -07002624 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002625 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
2627 *change = 0;
2628 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2629 return -EIO;
2630 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002631 p = xdr_inline_decode(xdr, 8);
2632 if (unlikely(!p))
2633 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002634 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002636 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002638 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002640 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002641out_overflow:
2642 print_overflow_msg(__func__, xdr);
2643 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644}
2645
2646static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2647{
Al Viro8687b632006-10-19 23:28:48 -07002648 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002649 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650
2651 *size = 0;
2652 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2653 return -EIO;
2654 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002655 p = xdr_inline_decode(xdr, 8);
2656 if (unlikely(!p))
2657 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002658 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002660 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002662 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002663 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002664out_overflow:
2665 print_overflow_msg(__func__, xdr);
2666 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667}
2668
2669static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2670{
Al Viro8687b632006-10-19 23:28:48 -07002671 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672
2673 *res = 0;
2674 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2675 return -EIO;
2676 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
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 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2682 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002683 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002685out_overflow:
2686 print_overflow_msg(__func__, xdr);
2687 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688}
2689
2690static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2691{
Al Viro8687b632006-10-19 23:28:48 -07002692 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693
2694 *res = 0;
2695 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2696 return -EIO;
2697 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002698 p = xdr_inline_decode(xdr, 4);
2699 if (unlikely(!p))
2700 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002701 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2703 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002704 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002706out_overflow:
2707 print_overflow_msg(__func__, xdr);
2708 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709}
2710
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002711static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712{
Al Viro8687b632006-10-19 23:28:48 -07002713 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002714 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715
2716 fsid->major = 0;
2717 fsid->minor = 0;
2718 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2719 return -EIO;
2720 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002721 p = xdr_inline_decode(xdr, 16);
2722 if (unlikely(!p))
2723 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03002724 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03002725 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002727 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002729 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 (unsigned long long)fsid->major,
2731 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002732 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002733out_overflow:
2734 print_overflow_msg(__func__, xdr);
2735 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736}
2737
2738static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2739{
Al Viro8687b632006-10-19 23:28:48 -07002740 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741
2742 *res = 60;
2743 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2744 return -EIO;
2745 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002746 p = xdr_inline_decode(xdr, 4);
2747 if (unlikely(!p))
2748 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002749 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2751 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002752 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002754out_overflow:
2755 print_overflow_msg(__func__, xdr);
2756 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757}
2758
2759static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2760{
Al Viro8687b632006-10-19 23:28:48 -07002761 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762
2763 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2764 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2765 return -EIO;
2766 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002767 p = xdr_inline_decode(xdr, 4);
2768 if (unlikely(!p))
2769 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002770 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2772 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002773 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002775out_overflow:
2776 print_overflow_msg(__func__, xdr);
2777 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778}
2779
2780static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2781{
Al Viro8687b632006-10-19 23:28:48 -07002782 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002783 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784
2785 *fileid = 0;
2786 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2787 return -EIO;
2788 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002789 p = xdr_inline_decode(xdr, 8);
2790 if (unlikely(!p))
2791 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002792 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002794 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002796 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002797 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002798out_overflow:
2799 print_overflow_msg(__func__, xdr);
2800 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801}
2802
Manoj Naik99baf622006-06-09 09:34:24 -04002803static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2804{
Al Viro8687b632006-10-19 23:28:48 -07002805 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002806 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002807
2808 *fileid = 0;
2809 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2810 return -EIO;
2811 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002812 p = xdr_inline_decode(xdr, 8);
2813 if (unlikely(!p))
2814 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002815 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04002816 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002817 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002818 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002819 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002820 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002821out_overflow:
2822 print_overflow_msg(__func__, xdr);
2823 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04002824}
2825
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2827{
Al Viro8687b632006-10-19 23:28:48 -07002828 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 int status = 0;
2830
2831 *res = 0;
2832 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2833 return -EIO;
2834 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002835 p = xdr_inline_decode(xdr, 8);
2836 if (unlikely(!p))
2837 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002838 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2840 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002841 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002843out_overflow:
2844 print_overflow_msg(__func__, xdr);
2845 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846}
2847
2848static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2849{
Al Viro8687b632006-10-19 23:28:48 -07002850 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 int status = 0;
2852
2853 *res = 0;
2854 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2855 return -EIO;
2856 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002857 p = xdr_inline_decode(xdr, 8);
2858 if (unlikely(!p))
2859 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002860 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2862 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002863 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002865out_overflow:
2866 print_overflow_msg(__func__, xdr);
2867 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868}
2869
2870static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2871{
Al Viro8687b632006-10-19 23:28:48 -07002872 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 int status = 0;
2874
2875 *res = 0;
2876 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2877 return -EIO;
2878 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002879 p = xdr_inline_decode(xdr, 8);
2880 if (unlikely(!p))
2881 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002882 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2884 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002885 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002887out_overflow:
2888 print_overflow_msg(__func__, xdr);
2889 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890}
2891
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002892static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2893{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002894 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002895 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002896 int status = 0;
2897
Benny Halevyc0eae662009-08-14 17:20:14 +03002898 p = xdr_inline_decode(xdr, 4);
2899 if (unlikely(!p))
2900 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002901 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04002902 if (n == 0)
2903 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002904 dprintk("path ");
2905 path->ncomponents = 0;
2906 while (path->ncomponents < n) {
2907 struct nfs4_string *component = &path->components[path->ncomponents];
2908 status = decode_opaque_inline(xdr, &component->len, &component->data);
2909 if (unlikely(status != 0))
2910 goto out_eio;
2911 if (path->ncomponents != n)
2912 dprintk("/");
2913 dprintk("%s", component->data);
2914 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2915 path->ncomponents++;
2916 else {
2917 dprintk("cannot parse %d components in path\n", n);
2918 goto out_eio;
2919 }
2920 }
2921out:
2922 dprintk("\n");
2923 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002924root_path:
2925/* a root pathname is sent as a zero component4 */
2926 path->ncomponents = 1;
2927 path->components[0].len=0;
2928 path->components[0].data=NULL;
2929 dprintk("path /\n");
2930 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002931out_eio:
2932 dprintk(" status %d", status);
2933 status = -EIO;
2934 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03002935out_overflow:
2936 print_overflow_msg(__func__, xdr);
2937 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002938}
2939
2940static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002941{
2942 int n;
Al Viro8687b632006-10-19 23:28:48 -07002943 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002944 int status = -EIO;
2945
2946 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2947 goto out;
2948 status = 0;
2949 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2950 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002951 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002952 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002953 if (unlikely(status != 0))
2954 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03002955 p = xdr_inline_decode(xdr, 4);
2956 if (unlikely(!p))
2957 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002958 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002959 if (n <= 0)
2960 goto out_eio;
2961 res->nlocations = 0;
2962 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002963 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002964 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04002965
Benny Halevyc0eae662009-08-14 17:20:14 +03002966 p = xdr_inline_decode(xdr, 4);
2967 if (unlikely(!p))
2968 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002969 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002970
2971 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002972 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002973 while (loc->nservers < m) {
2974 struct nfs4_string *server = &loc->servers[loc->nservers];
2975 status = decode_opaque_inline(xdr, &server->len, &server->data);
2976 if (unlikely(status != 0))
2977 goto out_eio;
2978 dprintk("%s ", server->data);
2979 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2980 loc->nservers++;
2981 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002982 unsigned int i;
2983 dprintk("%s: using first %u of %u servers "
2984 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002985 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04002986 NFS4_FS_LOCATION_MAXSERVERS,
2987 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002988 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002989 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002990 char *data;
2991 status = decode_opaque_inline(xdr, &len, &data);
2992 if (unlikely(status != 0))
2993 goto out_eio;
2994 }
2995 }
2996 }
2997 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002998 if (unlikely(status != 0))
2999 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003000 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003001 res->nlocations++;
3002 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003003 if (res->nlocations != 0)
3004 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003005out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003006 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003007 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003008out_overflow:
3009 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003010out_eio:
3011 status = -EIO;
3012 goto out;
3013}
3014
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3016{
Al Viro8687b632006-10-19 23:28:48 -07003017 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 int status = 0;
3019
3020 *res = 0;
3021 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3022 return -EIO;
3023 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003024 p = xdr_inline_decode(xdr, 8);
3025 if (unlikely(!p))
3026 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003027 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3029 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003030 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003032out_overflow:
3033 print_overflow_msg(__func__, xdr);
3034 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035}
3036
3037static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3038{
Al Viro8687b632006-10-19 23:28:48 -07003039 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 int status = 0;
3041
3042 *maxlink = 1;
3043 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3044 return -EIO;
3045 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003046 p = xdr_inline_decode(xdr, 4);
3047 if (unlikely(!p))
3048 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003049 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3051 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003052 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003054out_overflow:
3055 print_overflow_msg(__func__, xdr);
3056 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057}
3058
3059static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3060{
Al Viro8687b632006-10-19 23:28:48 -07003061 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 int status = 0;
3063
3064 *maxname = 1024;
3065 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3066 return -EIO;
3067 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003068 p = xdr_inline_decode(xdr, 4);
3069 if (unlikely(!p))
3070 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003071 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3073 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003074 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003076out_overflow:
3077 print_overflow_msg(__func__, xdr);
3078 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079}
3080
3081static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3082{
Al Viro8687b632006-10-19 23:28:48 -07003083 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 int status = 0;
3085
3086 *res = 1024;
3087 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3088 return -EIO;
3089 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3090 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003091 p = xdr_inline_decode(xdr, 8);
3092 if (unlikely(!p))
3093 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003094 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 if (maxread > 0x7FFFFFFF)
3096 maxread = 0x7FFFFFFF;
3097 *res = (uint32_t)maxread;
3098 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3099 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003100 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003102out_overflow:
3103 print_overflow_msg(__func__, xdr);
3104 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105}
3106
3107static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3108{
Al Viro8687b632006-10-19 23:28:48 -07003109 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 int status = 0;
3111
3112 *res = 1024;
3113 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3114 return -EIO;
3115 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3116 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003117 p = xdr_inline_decode(xdr, 8);
3118 if (unlikely(!p))
3119 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003120 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 if (maxwrite > 0x7FFFFFFF)
3122 maxwrite = 0x7FFFFFFF;
3123 *res = (uint32_t)maxwrite;
3124 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3125 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003126 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003128out_overflow:
3129 print_overflow_msg(__func__, xdr);
3130 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131}
3132
Trond Myklebustbca79472009-03-11 14:10:26 -04003133static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134{
Trond Myklebustbca79472009-03-11 14:10:26 -04003135 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003136 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003137 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138
3139 *mode = 0;
3140 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3141 return -EIO;
3142 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003143 p = xdr_inline_decode(xdr, 4);
3144 if (unlikely(!p))
3145 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003146 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003147 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003149 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003151 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003152 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003153out_overflow:
3154 print_overflow_msg(__func__, xdr);
3155 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156}
3157
3158static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3159{
Al Viro8687b632006-10-19 23:28:48 -07003160 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003161 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162
3163 *nlink = 1;
3164 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3165 return -EIO;
3166 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003167 p = xdr_inline_decode(xdr, 4);
3168 if (unlikely(!p))
3169 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003170 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003172 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003174 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003175 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003176out_overflow:
3177 print_overflow_msg(__func__, xdr);
3178 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179}
3180
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003181static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3182 struct nfs_client *clp, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183{
Al Viro8687b632006-10-19 23:28:48 -07003184 uint32_t len;
3185 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003186 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187
3188 *uid = -2;
3189 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3190 return -EIO;
3191 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003192 p = xdr_inline_decode(xdr, 4);
3193 if (unlikely(!p))
3194 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003195 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003196 p = xdr_inline_decode(xdr, len);
3197 if (unlikely(!p))
3198 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003199 if (!may_sleep) {
3200 /* do nothing */
3201 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003202 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3203 ret = NFS_ATTR_FATTR_OWNER;
3204 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003206 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003208 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003209 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3211 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003212 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003213 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003214out_overflow:
3215 print_overflow_msg(__func__, xdr);
3216 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217}
3218
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003219static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3220 struct nfs_client *clp, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221{
Al Viro8687b632006-10-19 23:28:48 -07003222 uint32_t len;
3223 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003224 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225
3226 *gid = -2;
3227 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3228 return -EIO;
3229 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003230 p = xdr_inline_decode(xdr, 4);
3231 if (unlikely(!p))
3232 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003233 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003234 p = xdr_inline_decode(xdr, len);
3235 if (unlikely(!p))
3236 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003237 if (!may_sleep) {
3238 /* do nothing */
3239 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003240 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3241 ret = NFS_ATTR_FATTR_GROUP;
3242 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003244 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003246 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003247 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3249 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003250 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003251 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003252out_overflow:
3253 print_overflow_msg(__func__, xdr);
3254 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255}
3256
3257static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3258{
Al Viro8687b632006-10-19 23:28:48 -07003259 uint32_t major = 0, minor = 0;
3260 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003261 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262
3263 *rdev = MKDEV(0,0);
3264 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3265 return -EIO;
3266 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3267 dev_t tmp;
3268
Benny Halevyc0eae662009-08-14 17:20:14 +03003269 p = xdr_inline_decode(xdr, 8);
3270 if (unlikely(!p))
3271 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003272 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003273 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 tmp = MKDEV(major, minor);
3275 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3276 *rdev = tmp;
3277 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003278 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003280 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003281 return ret;
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
3287static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3288{
Al Viro8687b632006-10-19 23:28:48 -07003289 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 int status = 0;
3291
3292 *res = 0;
3293 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3294 return -EIO;
3295 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003296 p = xdr_inline_decode(xdr, 8);
3297 if (unlikely(!p))
3298 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003299 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3301 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003302 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003304out_overflow:
3305 print_overflow_msg(__func__, xdr);
3306 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307}
3308
3309static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3310{
Al Viro8687b632006-10-19 23:28:48 -07003311 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 int status = 0;
3313
3314 *res = 0;
3315 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3316 return -EIO;
3317 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003318 p = xdr_inline_decode(xdr, 8);
3319 if (unlikely(!p))
3320 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003321 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3323 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003324 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003326out_overflow:
3327 print_overflow_msg(__func__, xdr);
3328 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329}
3330
3331static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3332{
Al Viro8687b632006-10-19 23:28:48 -07003333 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 int status = 0;
3335
3336 *res = 0;
3337 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3338 return -EIO;
3339 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003340 p = xdr_inline_decode(xdr, 8);
3341 if (unlikely(!p))
3342 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003343 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3345 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003346 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003348out_overflow:
3349 print_overflow_msg(__func__, xdr);
3350 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351}
3352
3353static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3354{
Al Viro8687b632006-10-19 23:28:48 -07003355 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003356 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357
3358 *used = 0;
3359 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3360 return -EIO;
3361 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003362 p = xdr_inline_decode(xdr, 8);
3363 if (unlikely(!p))
3364 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003365 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003367 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003369 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003371 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003372out_overflow:
3373 print_overflow_msg(__func__, xdr);
3374 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375}
3376
3377static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3378{
Al Viro8687b632006-10-19 23:28:48 -07003379 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 uint64_t sec;
3381 uint32_t nsec;
3382
Benny Halevyc0eae662009-08-14 17:20:14 +03003383 p = xdr_inline_decode(xdr, 12);
3384 if (unlikely(!p))
3385 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003386 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003387 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 time->tv_sec = (time_t)sec;
3389 time->tv_nsec = (long)nsec;
3390 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003391out_overflow:
3392 print_overflow_msg(__func__, xdr);
3393 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394}
3395
3396static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3397{
3398 int status = 0;
3399
3400 time->tv_sec = 0;
3401 time->tv_nsec = 0;
3402 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3403 return -EIO;
3404 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3405 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003406 if (status == 0)
3407 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3409 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003410 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 return status;
3412}
3413
3414static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3415{
3416 int status = 0;
3417
3418 time->tv_sec = 0;
3419 time->tv_nsec = 0;
3420 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3421 return -EIO;
3422 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3423 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003424 if (status == 0)
3425 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3427 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003428 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 return status;
3430}
3431
3432static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3433{
3434 int status = 0;
3435
3436 time->tv_sec = 0;
3437 time->tv_nsec = 0;
3438 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3439 return -EIO;
3440 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3441 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003442 if (status == 0)
3443 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3445 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003446 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447 return status;
3448}
3449
Al Viro8687b632006-10-19 23:28:48 -07003450static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451{
3452 unsigned int attrwords = XDR_QUADLEN(attrlen);
3453 unsigned int nwords = xdr->p - savep;
3454
3455 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003456 dprintk("%s: server returned incorrect attribute length: "
3457 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003458 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 attrwords << 2,
3460 (attrwords < nwords) ? '<' : '>',
3461 nwords << 2);
3462 return -EIO;
3463 }
3464 return 0;
3465}
3466
3467static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3468{
Al Viro8687b632006-10-19 23:28:48 -07003469 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470
Benny Halevyc0eae662009-08-14 17:20:14 +03003471 p = xdr_inline_decode(xdr, 20);
3472 if (unlikely(!p))
3473 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003474 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003475 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003476 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003478out_overflow:
3479 print_overflow_msg(__func__, xdr);
3480 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481}
3482
3483static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3484{
Al Viro8687b632006-10-19 23:28:48 -07003485 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 uint32_t supp, acc;
3487 int status;
3488
3489 status = decode_op_hdr(xdr, OP_ACCESS);
3490 if (status)
3491 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003492 p = xdr_inline_decode(xdr, 8);
3493 if (unlikely(!p))
3494 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003495 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003496 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 access->supported = supp;
3498 access->access = acc;
3499 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003500out_overflow:
3501 print_overflow_msg(__func__, xdr);
3502 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503}
3504
Benny Halevy07d30432009-08-14 17:19:52 +03003505static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506{
Al Viro8687b632006-10-19 23:28:48 -07003507 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003508
3509 p = xdr_inline_decode(xdr, len);
3510 if (likely(p)) {
3511 memcpy(buf, p, len);
3512 return 0;
3513 }
3514 print_overflow_msg(__func__, xdr);
3515 return -EIO;
3516}
3517
3518static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3519{
3520 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521}
3522
3523static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3524{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 int status;
3526
3527 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003528 if (status != -EIO)
3529 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003530 if (!status)
3531 status = decode_stateid(xdr, &res->stateid);
3532 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533}
3534
Benny Halevydb942bb2009-08-14 17:19:56 +03003535static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3536{
3537 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538}
3539
3540static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3541{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 int status;
3543
3544 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003545 if (!status)
3546 status = decode_verifier(xdr, res->verf->verifier);
3547 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548}
3549
3550static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3551{
Al Viro8687b632006-10-19 23:28:48 -07003552 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553 uint32_t bmlen;
3554 int status;
3555
3556 status = decode_op_hdr(xdr, OP_CREATE);
3557 if (status)
3558 return status;
3559 if ((status = decode_change_info(xdr, cinfo)))
3560 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003561 p = xdr_inline_decode(xdr, 4);
3562 if (unlikely(!p))
3563 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003564 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003565 p = xdr_inline_decode(xdr, bmlen << 2);
3566 if (likely(p))
3567 return 0;
3568out_overflow:
3569 print_overflow_msg(__func__, xdr);
3570 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571}
3572
3573static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3574{
Al Viro8687b632006-10-19 23:28:48 -07003575 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003576 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577 int status;
3578
3579 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3580 goto xdr_error;
3581 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3582 goto xdr_error;
3583 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3584 goto xdr_error;
3585 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3586 goto xdr_error;
3587 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3588 goto xdr_error;
3589 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3590 goto xdr_error;
3591 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3592 goto xdr_error;
3593 status = verify_attr_len(xdr, savep, attrlen);
3594xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003595 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596 return status;
3597}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003598
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3600{
Al Viro8687b632006-10-19 23:28:48 -07003601 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003602 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003604
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3606 goto xdr_error;
3607 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3608 goto xdr_error;
3609 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3610 goto xdr_error;
3611
3612 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3613 goto xdr_error;
3614 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3615 goto xdr_error;
3616 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3617 goto xdr_error;
3618 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3619 goto xdr_error;
3620 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3621 goto xdr_error;
3622 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3623 goto xdr_error;
3624
3625 status = verify_attr_len(xdr, savep, attrlen);
3626xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003627 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 return status;
3629}
3630
3631static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3632{
Al Viro8687b632006-10-19 23:28:48 -07003633 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003634 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003636
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3638 goto xdr_error;
3639 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3640 goto xdr_error;
3641 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3642 goto xdr_error;
3643
3644 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3645 goto xdr_error;
3646 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3647 goto xdr_error;
3648
3649 status = verify_attr_len(xdr, savep, attrlen);
3650xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003651 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652 return status;
3653}
3654
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003655static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3656 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657{
Al Viro8687b632006-10-19 23:28:48 -07003658 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 uint32_t attrlen,
3660 bitmap[2] = {0},
3661 type;
Trond Myklebustbca79472009-03-11 14:10:26 -04003662 int status;
3663 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003664 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003666 status = decode_op_hdr(xdr, OP_GETATTR);
3667 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 goto xdr_error;
3669
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003670 status = decode_attr_bitmap(xdr, bitmap);
3671 if (status < 0)
3672 goto xdr_error;
3673
3674 status = decode_attr_length(xdr, &attrlen, &savep);
3675 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 goto xdr_error;
3677
3678
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003679 status = decode_attr_type(xdr, bitmap, &type);
3680 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003682 fattr->mode = 0;
3683 if (status != 0) {
3684 fattr->mode |= nfs_type2fmt[type];
3685 fattr->valid |= status;
3686 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003688 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3689 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003691 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003692
3693 status = decode_attr_size(xdr, bitmap, &fattr->size);
3694 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003696 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003697
3698 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3699 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003701 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003702
3703 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3704 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003706 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003707
3708 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003709 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003710 fattr));
3711 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003712 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003713 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003714
3715 status = decode_attr_mode(xdr, bitmap, &fmode);
3716 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003718 if (status != 0) {
3719 fattr->mode |= fmode;
3720 fattr->valid |= status;
3721 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003722
3723 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3724 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003726 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003727
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003728 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3729 &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003730 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003732 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003733
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003734 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3735 &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003736 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003738 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003739
3740 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3741 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003743 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003744
3745 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3746 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003748 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003749
3750 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3751 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003753 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003754
3755 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3756 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003758 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003759
3760 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3761 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003763 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003764
3765 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3766 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003767 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003768 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003769 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003770 fattr->valid |= status;
3771 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003772
3773 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003775 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776 return status;
3777}
3778
3779
3780static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3781{
Al Viro8687b632006-10-19 23:28:48 -07003782 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783 uint32_t attrlen, bitmap[2];
3784 int status;
3785
3786 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3787 goto xdr_error;
3788 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3789 goto xdr_error;
3790 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3791 goto xdr_error;
3792
3793 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3794
3795 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3796 goto xdr_error;
3797 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3798 goto xdr_error;
3799 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3800 goto xdr_error;
3801 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3802 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3803 goto xdr_error;
3804 fsinfo->wtpref = fsinfo->wtmax;
3805
3806 status = verify_attr_len(xdr, savep, attrlen);
3807xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003808 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 return status;
3810}
3811
3812static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3813{
Al Viro8687b632006-10-19 23:28:48 -07003814 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 uint32_t len;
3816 int status;
3817
Trond Myklebust99367812007-07-17 21:52:41 -04003818 /* Zero handle first to allow comparisons */
3819 memset(fh, 0, sizeof(*fh));
3820
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821 status = decode_op_hdr(xdr, OP_GETFH);
3822 if (status)
3823 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824
Benny Halevyc0eae662009-08-14 17:20:14 +03003825 p = xdr_inline_decode(xdr, 4);
3826 if (unlikely(!p))
3827 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003828 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 if (len > NFS4_FHSIZE)
3830 return -EIO;
3831 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03003832 p = xdr_inline_decode(xdr, len);
3833 if (unlikely(!p))
3834 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03003835 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003837out_overflow:
3838 print_overflow_msg(__func__, xdr);
3839 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840}
3841
3842static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3843{
3844 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003845
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846 status = decode_op_hdr(xdr, OP_LINK);
3847 if (status)
3848 return status;
3849 return decode_change_info(xdr, cinfo);
3850}
3851
3852/*
3853 * We create the owner, so we know a proper owner.id length is 4.
3854 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003855static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003857 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003858 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003859 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860
Benny Halevyc0eae662009-08-14 17:20:14 +03003861 p = xdr_inline_decode(xdr, 32);
3862 if (unlikely(!p))
3863 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003864 p = xdr_decode_hyper(p, &offset);
3865 p = xdr_decode_hyper(p, &length);
Benny Halevy6f723f72009-08-14 17:19:37 +03003866 type = be32_to_cpup(p++);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003867 if (fl != NULL) {
3868 fl->fl_start = (loff_t)offset;
3869 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3870 if (length == ~(uint64_t)0)
3871 fl->fl_end = OFFSET_MAX;
3872 fl->fl_type = F_WRLCK;
3873 if (type & 1)
3874 fl->fl_type = F_RDLCK;
3875 fl->fl_pid = 0;
3876 }
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003877 p = xdr_decode_hyper(p, &clientid);
Benny Halevycccddf42009-08-14 17:20:19 +03003878 namelen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003879 p = xdr_inline_decode(xdr, namelen);
3880 if (likely(p))
3881 return -NFS4ERR_DENIED;
3882out_overflow:
3883 print_overflow_msg(__func__, xdr);
3884 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885}
3886
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003887static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889 int status;
3890
3891 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003892 if (status == -EIO)
3893 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03003895 status = decode_stateid(xdr, &res->stateid);
3896 if (unlikely(status))
3897 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003899 status = decode_lock_denied(xdr, NULL);
3900 if (res->open_seqid != NULL)
3901 nfs_increment_open_seqid(status, res->open_seqid);
3902 nfs_increment_lock_seqid(status, res->lock_seqid);
3903out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 return status;
3905}
3906
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003907static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908{
3909 int status;
3910 status = decode_op_hdr(xdr, OP_LOCKT);
3911 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003912 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 return status;
3914}
3915
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003916static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 int status;
3919
3920 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003921 if (status != -EIO)
3922 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003923 if (status == 0)
3924 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925 return status;
3926}
3927
3928static int decode_lookup(struct xdr_stream *xdr)
3929{
3930 return decode_op_hdr(xdr, OP_LOOKUP);
3931}
3932
3933/* This is too sick! */
3934static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3935{
Andy Adamson05d564f2008-12-23 16:06:15 -05003936 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 uint32_t limit_type, nblocks, blocksize;
3938
Benny Halevyc0eae662009-08-14 17:20:14 +03003939 p = xdr_inline_decode(xdr, 12);
3940 if (unlikely(!p))
3941 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003942 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003944 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03003945 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05003946 break;
3947 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03003948 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003949 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05003950 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 }
3952 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003953out_overflow:
3954 print_overflow_msg(__func__, xdr);
3955 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956}
3957
3958static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3959{
Andy Adamson05d564f2008-12-23 16:06:15 -05003960 __be32 *p;
3961 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03003962 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963
Benny Halevyc0eae662009-08-14 17:20:14 +03003964 p = xdr_inline_decode(xdr, 4);
3965 if (unlikely(!p))
3966 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003967 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3969 res->delegation_type = 0;
3970 return 0;
3971 }
Benny Halevy07d30432009-08-14 17:19:52 +03003972 status = decode_stateid(xdr, &res->delegation);
3973 if (unlikely(status))
3974 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003975 p = xdr_inline_decode(xdr, 4);
3976 if (unlikely(!p))
3977 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003978 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05003979
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003981 case NFS4_OPEN_DELEGATE_READ:
3982 res->delegation_type = FMODE_READ;
3983 break;
3984 case NFS4_OPEN_DELEGATE_WRITE:
3985 res->delegation_type = FMODE_WRITE|FMODE_READ;
3986 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 return -EIO;
3988 }
David Howells7539bba2006-08-22 20:06:09 -04003989 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03003990out_overflow:
3991 print_overflow_msg(__func__, xdr);
3992 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993}
3994
3995static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3996{
Andy Adamson05d564f2008-12-23 16:06:15 -05003997 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003998 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05003999 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000
Andy Adamson05d564f2008-12-23 16:06:15 -05004001 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004002 if (status != -EIO)
4003 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004004 if (!status)
4005 status = decode_stateid(xdr, &res->stateid);
4006 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004007 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008
Andy Adamson05d564f2008-12-23 16:06:15 -05004009 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010
Benny Halevyc0eae662009-08-14 17:20:14 +03004011 p = xdr_inline_decode(xdr, 8);
4012 if (unlikely(!p))
4013 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004014 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004015 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004016 if (bmlen > 10)
4017 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018
Benny Halevyc0eae662009-08-14 17:20:14 +03004019 p = xdr_inline_decode(xdr, bmlen << 2);
4020 if (unlikely(!p))
4021 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004022 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4023 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004024 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004025 for (; i < NFS4_BITMAP_SIZE; i++)
4026 res->attrset[i] = 0;
4027
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028 return decode_delegation(xdr, res);
4029xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004030 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004032out_overflow:
4033 print_overflow_msg(__func__, xdr);
4034 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035}
4036
4037static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4038{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039 int status;
4040
Andy Adamson05d564f2008-12-23 16:06:15 -05004041 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004042 if (status != -EIO)
4043 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004044 if (!status)
4045 status = decode_stateid(xdr, &res->stateid);
4046 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047}
4048
4049static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4050{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004051 int status;
4052
4053 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004054 if (status != -EIO)
4055 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004056 if (!status)
4057 status = decode_stateid(xdr, &res->stateid);
4058 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059}
4060
4061static int decode_putfh(struct xdr_stream *xdr)
4062{
4063 return decode_op_hdr(xdr, OP_PUTFH);
4064}
4065
4066static int decode_putrootfh(struct xdr_stream *xdr)
4067{
4068 return decode_op_hdr(xdr, OP_PUTROOTFH);
4069}
4070
4071static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4072{
4073 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004074 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 uint32_t count, eof, recvd, hdrlen;
4076 int status;
4077
4078 status = decode_op_hdr(xdr, OP_READ);
4079 if (status)
4080 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004081 p = xdr_inline_decode(xdr, 8);
4082 if (unlikely(!p))
4083 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004084 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004085 count = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
4087 recvd = req->rq_rcv_buf.len - hdrlen;
4088 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004089 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090 "count %u > recvd %u\n", count, recvd);
4091 count = recvd;
4092 eof = 0;
4093 }
4094 xdr_read_pages(xdr, count);
4095 res->eof = eof;
4096 res->count = count;
4097 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004098out_overflow:
4099 print_overflow_msg(__func__, xdr);
4100 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101}
4102
4103static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4104{
4105 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4106 struct page *page = *rcvbuf->pages;
4107 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004108 size_t hdrlen;
4109 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07004110 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004111 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04004112 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113
4114 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004115 if (!status)
4116 status = decode_verifier(xdr, readdir->verifier.data);
4117 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004119 dprintk("%s: verifier = %08x:%08x\n",
4120 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004121 ((u32 *)readdir->verifier.data)[0],
4122 ((u32 *)readdir->verifier.data)[1]);
4123
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124
Benny Halevydb942bb2009-08-14 17:19:56 +03004125 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126 recvd = rcvbuf->len - hdrlen;
4127 if (pglen > recvd)
4128 pglen = recvd;
4129 xdr_read_pages(xdr, pglen);
4130
4131 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07004132 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04004133 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004135
4136 /* Make sure the packet actually has a value_follows and EOF entry */
4137 if ((entry + 1) > end)
4138 goto short_pkt;
4139
4140 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004141 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04004142 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00004144 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145 p += 2; /* cookie */
4146 len = ntohl(*p++); /* filename length */
4147 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004148 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
4149 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150 goto err_unmap;
4151 }
David Howellse8896492006-08-24 15:44:19 -04004152 xlen = XDR_QUADLEN(len);
4153 if (end - p < xlen + 1)
4154 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00004155 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04004156 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04004158 if (end - p < len + 1)
4159 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04004162 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04004164 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004165 entry = p;
4166 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004167 /*
4168 * Apparently some server sends responses that are a valid size, but
4169 * contain no entries, and have value_follows==0 and EOF==0. For
4170 * those, just set the EOF marker.
4171 */
4172 if (!nr && entry[1] == 0) {
4173 dprintk("NFS: readdir reply truncated!\n");
4174 entry[1] = 1;
4175 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05004176out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177 kunmap_atomic(kaddr, KM_USER0);
4178 return 0;
4179short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004180 /*
4181 * When we get a short packet there are 2 possibilities. We can
4182 * return an error, or fix up the response to look like a valid
4183 * response and return what we have so far. If there are no
4184 * entries and the packet was short, then return -EIO. If there
4185 * are valid entries in the response, return them and pretend that
4186 * the call was successful, but incomplete. The caller can retry the
4187 * readdir starting at the last cookie.
4188 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07004189 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004191 if (nr)
4192 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193err_unmap:
4194 kunmap_atomic(kaddr, KM_USER0);
4195 return -errno_NFSERR_IO;
4196}
4197
4198static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4199{
4200 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4201 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004202 size_t hdrlen;
4203 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004204 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205 char *kaddr;
4206 int status;
4207
4208 status = decode_op_hdr(xdr, OP_READLINK);
4209 if (status)
4210 return status;
4211
4212 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004213 p = xdr_inline_decode(xdr, 4);
4214 if (unlikely(!p))
4215 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004216 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004218 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219 return -ENAMETOOLONG;
4220 }
4221 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4222 recvd = req->rq_rcv_buf.len - hdrlen;
4223 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004224 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225 "count %u > recvd %u\n", len, recvd);
4226 return -EIO;
4227 }
4228 xdr_read_pages(xdr, len);
4229 /*
4230 * The XDR encode routine has set things up so that
4231 * the link text will be copied directly into the
4232 * buffer. We just have to do overflow-checking,
4233 * and and null-terminate the text (the VFS expects
4234 * null-termination).
4235 */
4236 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
4237 kaddr[len+rcvbuf->page_base] = '\0';
4238 kunmap_atomic(kaddr, KM_USER0);
4239 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004240out_overflow:
4241 print_overflow_msg(__func__, xdr);
4242 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243}
4244
4245static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4246{
4247 int status;
4248
4249 status = decode_op_hdr(xdr, OP_REMOVE);
4250 if (status)
4251 goto out;
4252 status = decode_change_info(xdr, cinfo);
4253out:
4254 return status;
4255}
4256
4257static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4258 struct nfs4_change_info *new_cinfo)
4259{
4260 int status;
4261
4262 status = decode_op_hdr(xdr, OP_RENAME);
4263 if (status)
4264 goto out;
4265 if ((status = decode_change_info(xdr, old_cinfo)))
4266 goto out;
4267 status = decode_change_info(xdr, new_cinfo);
4268out:
4269 return status;
4270}
4271
4272static int decode_renew(struct xdr_stream *xdr)
4273{
4274 return decode_op_hdr(xdr, OP_RENEW);
4275}
4276
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004277static int
4278decode_restorefh(struct xdr_stream *xdr)
4279{
4280 return decode_op_hdr(xdr, OP_RESTOREFH);
4281}
4282
J. Bruce Fields029d1052005-06-22 17:16:22 +00004283static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4284 size_t *acl_len)
4285{
Al Viro8687b632006-10-19 23:28:48 -07004286 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004287 uint32_t attrlen,
4288 bitmap[2] = {0};
4289 struct kvec *iov = req->rq_rcv_buf.head;
4290 int status;
4291
4292 *acl_len = 0;
4293 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4294 goto out;
4295 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4296 goto out;
4297 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4298 goto out;
4299
4300 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4301 return -EIO;
4302 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004303 size_t hdrlen;
4304 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004305
4306 /* We ignore &savep and don't do consistency checks on
4307 * the attr length. Let userspace figure it out.... */
4308 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4309 recvd = req->rq_rcv_buf.len - hdrlen;
4310 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004311 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004312 " acl reply: attrlen %u > recvd %u\n",
4313 attrlen, recvd);
4314 return -EINVAL;
4315 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004316 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004317 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004318 } else
4319 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004320
4321out:
4322 return status;
4323}
4324
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325static int
4326decode_savefh(struct xdr_stream *xdr)
4327{
4328 return decode_op_hdr(xdr, OP_SAVEFH);
4329}
4330
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004331static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332{
Al Viro8687b632006-10-19 23:28:48 -07004333 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334 uint32_t bmlen;
4335 int status;
4336
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337 status = decode_op_hdr(xdr, OP_SETATTR);
4338 if (status)
4339 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004340 p = xdr_inline_decode(xdr, 4);
4341 if (unlikely(!p))
4342 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004343 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004344 p = xdr_inline_decode(xdr, bmlen << 2);
4345 if (likely(p))
4346 return 0;
4347out_overflow:
4348 print_overflow_msg(__func__, xdr);
4349 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350}
4351
David Howellsadfa6f92006-08-22 20:06:08 -04004352static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353{
Al Viro8687b632006-10-19 23:28:48 -07004354 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355 uint32_t opnum;
4356 int32_t nfserr;
4357
Benny Halevyc0eae662009-08-14 17:20:14 +03004358 p = xdr_inline_decode(xdr, 8);
4359 if (unlikely(!p))
4360 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004361 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004362 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004363 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004364 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365 return -EIO;
4366 }
Benny Halevycccddf42009-08-14 17:20:19 +03004367 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004369 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4370 if (unlikely(!p))
4371 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004372 p = xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevy99398d02009-08-14 17:20:05 +03004373 memcpy(clp->cl_confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374 } else if (nfserr == NFSERR_CLID_INUSE) {
4375 uint32_t len;
4376
4377 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004378 p = xdr_inline_decode(xdr, 4);
4379 if (unlikely(!p))
4380 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004381 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004382 p = xdr_inline_decode(xdr, len);
4383 if (unlikely(!p))
4384 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385
4386 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004387 p = xdr_inline_decode(xdr, 4);
4388 if (unlikely(!p))
4389 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004390 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004391 p = xdr_inline_decode(xdr, len);
4392 if (unlikely(!p))
4393 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 return -NFSERR_CLID_INUSE;
4395 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004396 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397
4398 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004399out_overflow:
4400 print_overflow_msg(__func__, xdr);
4401 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402}
4403
4404static int decode_setclientid_confirm(struct xdr_stream *xdr)
4405{
4406 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4407}
4408
4409static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4410{
Al Viro8687b632006-10-19 23:28:48 -07004411 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004412 int status;
4413
4414 status = decode_op_hdr(xdr, OP_WRITE);
4415 if (status)
4416 return status;
4417
Benny Halevyc0eae662009-08-14 17:20:14 +03004418 p = xdr_inline_decode(xdr, 16);
4419 if (unlikely(!p))
4420 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004421 res->count = be32_to_cpup(p++);
4422 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004423 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004424 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004425out_overflow:
4426 print_overflow_msg(__func__, xdr);
4427 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428}
4429
4430static int decode_delegreturn(struct xdr_stream *xdr)
4431{
4432 return decode_op_hdr(xdr, OP_DELEGRETURN);
4433}
4434
Benny Halevy99fe60d2009-04-01 09:22:29 -04004435#if defined(CONFIG_NFS_V4_1)
4436static int decode_exchange_id(struct xdr_stream *xdr,
4437 struct nfs41_exchange_id_res *res)
4438{
4439 __be32 *p;
4440 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004441 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004442 int status;
4443 struct nfs_client *clp = res->client;
4444
4445 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4446 if (status)
4447 return status;
4448
Benny Halevyc0eae662009-08-14 17:20:14 +03004449 p = xdr_inline_decode(xdr, 8);
4450 if (unlikely(!p))
4451 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004452 xdr_decode_hyper(p, &clp->cl_ex_clid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004453 p = xdr_inline_decode(xdr, 12);
4454 if (unlikely(!p))
4455 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004456 clp->cl_seqid = be32_to_cpup(p++);
4457 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004458
4459 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004460 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004461 if (dummy != SP4_NONE)
4462 return -EIO;
4463
4464 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004465 p = xdr_inline_decode(xdr, 8);
4466 if (unlikely(!p))
4467 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004468
4469 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004470 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4471 if (unlikely(status))
4472 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004473
4474 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004475 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4476 if (unlikely(status))
4477 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004478
4479 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004480 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4481 if (unlikely(status))
4482 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004483
4484 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004485out_overflow:
4486 print_overflow_msg(__func__, xdr);
4487 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004488}
Andy Adamsonfc931582009-04-01 09:22:31 -04004489
4490static int decode_chan_attrs(struct xdr_stream *xdr,
4491 struct nfs4_channel_attrs *attrs)
4492{
4493 __be32 *p;
4494 u32 nr_attrs;
4495
Benny Halevyc0eae662009-08-14 17:20:14 +03004496 p = xdr_inline_decode(xdr, 28);
4497 if (unlikely(!p))
4498 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004499 attrs->headerpadsz = be32_to_cpup(p++);
4500 attrs->max_rqst_sz = be32_to_cpup(p++);
4501 attrs->max_resp_sz = be32_to_cpup(p++);
4502 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4503 attrs->max_ops = be32_to_cpup(p++);
4504 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004505 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004506 if (unlikely(nr_attrs > 1)) {
4507 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4508 __func__, nr_attrs);
4509 return -EINVAL;
4510 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004511 if (nr_attrs == 1) {
4512 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4513 if (unlikely(!p))
4514 goto out_overflow;
4515 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004516 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004517out_overflow:
4518 print_overflow_msg(__func__, xdr);
4519 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004520}
4521
Benny Halevye78291e2009-08-14 17:20:00 +03004522static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4523{
4524 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004525}
4526
4527static int decode_create_session(struct xdr_stream *xdr,
4528 struct nfs41_create_session_res *res)
4529{
4530 __be32 *p;
4531 int status;
4532 struct nfs_client *clp = res->client;
4533 struct nfs4_session *session = clp->cl_session;
4534
4535 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004536 if (!status)
4537 status = decode_sessionid(xdr, &session->sess_id);
4538 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004539 return status;
4540
Andy Adamsonfc931582009-04-01 09:22:31 -04004541 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004542 p = xdr_inline_decode(xdr, 8);
4543 if (unlikely(!p))
4544 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004545 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004546 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004547
4548 /* Channel attributes */
4549 status = decode_chan_attrs(xdr, &session->fc_attrs);
4550 if (!status)
4551 status = decode_chan_attrs(xdr, &session->bc_attrs);
4552 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004553out_overflow:
4554 print_overflow_msg(__func__, xdr);
4555 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004556}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004557
4558static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4559{
4560 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4561}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004562#endif /* CONFIG_NFS_V4_1 */
4563
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004564static int decode_sequence(struct xdr_stream *xdr,
4565 struct nfs4_sequence_res *res,
4566 struct rpc_rqst *rqstp)
4567{
4568#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004569 struct nfs4_slot *slot;
4570 struct nfs4_sessionid id;
4571 u32 dummy;
4572 int status;
4573 __be32 *p;
4574
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004575 if (!res->sr_session)
4576 return 0;
4577
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004578 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03004579 if (!status)
4580 status = decode_sessionid(xdr, &id);
4581 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004582 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004583
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004584 /*
4585 * If the server returns different values for sessionID, slotID or
4586 * sequence number, the server is looney tunes.
4587 */
4588 status = -ESERVERFAULT;
4589
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004590 if (memcmp(id.data, res->sr_session->sess_id.data,
4591 NFS4_MAX_SESSIONID_LEN)) {
4592 dprintk("%s Invalid session id\n", __func__);
4593 goto out_err;
4594 }
Benny Halevye78291e2009-08-14 17:20:00 +03004595
Benny Halevyc0eae662009-08-14 17:20:14 +03004596 p = xdr_inline_decode(xdr, 20);
4597 if (unlikely(!p))
4598 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03004599
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004600 /* seqid */
Benny Halevye78291e2009-08-14 17:20:00 +03004601 slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid];
Benny Halevy6f723f72009-08-14 17:19:37 +03004602 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004603 if (dummy != slot->seq_nr) {
4604 dprintk("%s Invalid sequence number\n", __func__);
4605 goto out_err;
4606 }
4607 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03004608 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004609 if (dummy != res->sr_slotid) {
4610 dprintk("%s Invalid slot id\n", __func__);
4611 goto out_err;
4612 }
4613 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004614 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004615 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004616 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004617 /* result flags - currently not processed */
Benny Halevycccddf42009-08-14 17:20:19 +03004618 dummy = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004619 status = 0;
4620out_err:
4621 res->sr_status = status;
4622 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004623out_overflow:
4624 print_overflow_msg(__func__, xdr);
4625 status = -EIO;
4626 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004627#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004628 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004629#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004630}
4631
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632/*
Benny Halevy49c25592008-12-23 16:06:16 -05004633 * END OF "GENERIC" DECODE ROUTINES.
4634 */
4635
4636/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637 * Decode OPEN_DOWNGRADE response
4638 */
Al Viro8687b632006-10-19 23:28:48 -07004639static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640{
Andy Adamson05d564f2008-12-23 16:06:15 -05004641 struct xdr_stream xdr;
4642 struct compound_hdr hdr;
4643 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644
Andy Adamson05d564f2008-12-23 16:06:15 -05004645 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4646 status = decode_compound_hdr(&xdr, &hdr);
4647 if (status)
4648 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004649 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4650 if (status)
4651 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004652 status = decode_putfh(&xdr);
4653 if (status)
4654 goto out;
4655 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004656 if (status != 0)
4657 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004658 decode_getfattr(&xdr, res->fattr, res->server,
4659 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004661 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662}
4663
4664/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 * Decode ACCESS response
4666 */
Al Viro8687b632006-10-19 23:28:48 -07004667static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004668{
4669 struct xdr_stream xdr;
4670 struct compound_hdr hdr;
4671 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004672
Linus Torvalds1da177e2005-04-16 15:20:36 -07004673 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004674 status = decode_compound_hdr(&xdr, &hdr);
4675 if (status)
4676 goto out;
4677 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4678 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004679 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04004680 status = decode_putfh(&xdr);
4681 if (status != 0)
4682 goto out;
4683 status = decode_access(&xdr, res);
4684 if (status != 0)
4685 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004686 decode_getfattr(&xdr, res->fattr, res->server,
4687 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004688out:
4689 return status;
4690}
4691
4692/*
4693 * Decode LOOKUP response
4694 */
Al Viro8687b632006-10-19 23:28:48 -07004695static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696{
4697 struct xdr_stream xdr;
4698 struct compound_hdr hdr;
4699 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004700
Linus Torvalds1da177e2005-04-16 15:20:36 -07004701 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004702 status = decode_compound_hdr(&xdr, &hdr);
4703 if (status)
4704 goto out;
4705 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4706 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004707 goto out;
4708 if ((status = decode_putfh(&xdr)) != 0)
4709 goto out;
4710 if ((status = decode_lookup(&xdr)) != 0)
4711 goto out;
4712 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4713 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004714 status = decode_getfattr(&xdr, res->fattr, res->server
4715 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716out:
4717 return status;
4718}
4719
4720/*
4721 * Decode LOOKUP_ROOT response
4722 */
Al Viro8687b632006-10-19 23:28:48 -07004723static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724{
4725 struct xdr_stream xdr;
4726 struct compound_hdr hdr;
4727 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004728
Linus Torvalds1da177e2005-04-16 15:20:36 -07004729 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004730 status = decode_compound_hdr(&xdr, &hdr);
4731 if (status)
4732 goto out;
4733 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4734 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 goto out;
4736 if ((status = decode_putrootfh(&xdr)) != 0)
4737 goto out;
4738 if ((status = decode_getfh(&xdr, res->fh)) == 0)
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004739 status = decode_getfattr(&xdr, res->fattr, res->server,
4740 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741out:
4742 return status;
4743}
4744
4745/*
4746 * Decode REMOVE response
4747 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004748static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749{
4750 struct xdr_stream xdr;
4751 struct compound_hdr hdr;
4752 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004753
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004755 status = decode_compound_hdr(&xdr, &hdr);
4756 if (status)
4757 goto out;
4758 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4759 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04004761 if ((status = decode_putfh(&xdr)) != 0)
4762 goto out;
4763 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4764 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004765 decode_getfattr(&xdr, &res->dir_attr, res->server,
4766 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767out:
4768 return status;
4769}
4770
4771/*
4772 * Decode RENAME response
4773 */
Al Viro8687b632006-10-19 23:28:48 -07004774static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004775{
4776 struct xdr_stream xdr;
4777 struct compound_hdr hdr;
4778 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004779
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004781 status = decode_compound_hdr(&xdr, &hdr);
4782 if (status)
4783 goto out;
4784 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4785 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 goto out;
4787 if ((status = decode_putfh(&xdr)) != 0)
4788 goto out;
4789 if ((status = decode_savefh(&xdr)) != 0)
4790 goto out;
4791 if ((status = decode_putfh(&xdr)) != 0)
4792 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004793 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4794 goto out;
4795 /* Current FH is target directory */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004796 if (decode_getfattr(&xdr, res->new_fattr, res->server,
4797 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004798 goto out;
4799 if ((status = decode_restorefh(&xdr)) != 0)
4800 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004801 decode_getfattr(&xdr, res->old_fattr, res->server,
4802 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803out:
4804 return status;
4805}
4806
4807/*
4808 * Decode LINK response
4809 */
Al Viro8687b632006-10-19 23:28:48 -07004810static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811{
4812 struct xdr_stream xdr;
4813 struct compound_hdr hdr;
4814 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004815
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004817 status = decode_compound_hdr(&xdr, &hdr);
4818 if (status)
4819 goto out;
4820 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4821 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822 goto out;
4823 if ((status = decode_putfh(&xdr)) != 0)
4824 goto out;
4825 if ((status = decode_savefh(&xdr)) != 0)
4826 goto out;
4827 if ((status = decode_putfh(&xdr)) != 0)
4828 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004829 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4830 goto out;
4831 /*
4832 * Note order: OP_LINK leaves the directory as the current
4833 * filehandle.
4834 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004835 if (decode_getfattr(&xdr, res->dir_attr, res->server,
4836 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004837 goto out;
4838 if ((status = decode_restorefh(&xdr)) != 0)
4839 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004840 decode_getfattr(&xdr, res->fattr, res->server,
4841 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842out:
4843 return status;
4844}
4845
4846/*
4847 * Decode CREATE response
4848 */
Al Viro8687b632006-10-19 23:28:48 -07004849static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850{
4851 struct xdr_stream xdr;
4852 struct compound_hdr hdr;
4853 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004854
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004856 status = decode_compound_hdr(&xdr, &hdr);
4857 if (status)
4858 goto out;
4859 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4860 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861 goto out;
4862 if ((status = decode_putfh(&xdr)) != 0)
4863 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004864 if ((status = decode_savefh(&xdr)) != 0)
4865 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4867 goto out;
4868 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4869 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004870 if (decode_getfattr(&xdr, res->fattr, res->server,
4871 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004872 goto out;
4873 if ((status = decode_restorefh(&xdr)) != 0)
4874 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004875 decode_getfattr(&xdr, res->dir_fattr, res->server,
4876 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004877out:
4878 return status;
4879}
4880
4881/*
4882 * Decode SYMLINK response
4883 */
Al Viro8687b632006-10-19 23:28:48 -07004884static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885{
4886 return nfs4_xdr_dec_create(rqstp, p, res);
4887}
4888
4889/*
4890 * Decode GETATTR response
4891 */
Al Viro8687b632006-10-19 23:28:48 -07004892static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893{
4894 struct xdr_stream xdr;
4895 struct compound_hdr hdr;
4896 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004897
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4899 status = decode_compound_hdr(&xdr, &hdr);
4900 if (status)
4901 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004902 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4903 if (status)
4904 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905 status = decode_putfh(&xdr);
4906 if (status)
4907 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004908 status = decode_getfattr(&xdr, res->fattr, res->server,
4909 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910out:
4911 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004912}
4913
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004914/*
4915 * Encode an SETACL request
4916 */
4917static int
Al Viro8687b632006-10-19 23:28:48 -07004918nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004919{
Andy Adamson05d564f2008-12-23 16:06:15 -05004920 struct xdr_stream xdr;
4921 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04004922 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05004923 };
4924 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004925
Andy Adamson05d564f2008-12-23 16:06:15 -05004926 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04004927 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004928 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05004929 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004930 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004931 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004932 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004933}
Andy Adamson05d564f2008-12-23 16:06:15 -05004934
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004935/*
4936 * Decode SETACL response
4937 */
4938static int
Benny Halevy73c403a2009-04-01 09:22:01 -04004939nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4940 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004941{
4942 struct xdr_stream xdr;
4943 struct compound_hdr hdr;
4944 int status;
4945
4946 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4947 status = decode_compound_hdr(&xdr, &hdr);
4948 if (status)
4949 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004950 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4951 if (status)
4952 goto out;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004953 status = decode_putfh(&xdr);
4954 if (status)
4955 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004956 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004957out:
4958 return status;
4959}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960
4961/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00004962 * Decode GETACL response
4963 */
4964static int
Benny Halevy663c79b2009-04-01 09:21:59 -04004965nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4966 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004967{
4968 struct xdr_stream xdr;
4969 struct compound_hdr hdr;
4970 int status;
4971
4972 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4973 status = decode_compound_hdr(&xdr, &hdr);
4974 if (status)
4975 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004976 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4977 if (status)
4978 goto out;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004979 status = decode_putfh(&xdr);
4980 if (status)
4981 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04004982 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004983
4984out:
4985 return status;
4986}
4987
4988/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989 * Decode CLOSE response
4990 */
Al Viro8687b632006-10-19 23:28:48 -07004991static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992{
Andy Adamson05d564f2008-12-23 16:06:15 -05004993 struct xdr_stream xdr;
4994 struct compound_hdr hdr;
4995 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996
Andy Adamson05d564f2008-12-23 16:06:15 -05004997 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4998 status = decode_compound_hdr(&xdr, &hdr);
4999 if (status)
5000 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005001 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5002 if (status)
5003 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005004 status = decode_putfh(&xdr);
5005 if (status)
5006 goto out;
5007 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005008 if (status != 0)
5009 goto out;
5010 /*
5011 * Note: Server may do delete on close for this file
5012 * in which case the getattr call will fail with
5013 * an ESTALE error. Shouldn't be a problem,
5014 * though, since fattr->valid will remain unset.
5015 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005016 decode_getfattr(&xdr, res->fattr, res->server,
5017 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005019 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005020}
5021
5022/*
5023 * Decode OPEN response
5024 */
Al Viro8687b632006-10-19 23:28:48 -07005025static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026{
Andy Adamson05d564f2008-12-23 16:06:15 -05005027 struct xdr_stream xdr;
5028 struct compound_hdr hdr;
5029 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005030
Andy Adamson05d564f2008-12-23 16:06:15 -05005031 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5032 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005033 if (status)
5034 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005035 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5036 if (status)
5037 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005038 status = decode_putfh(&xdr);
5039 if (status)
5040 goto out;
5041 status = decode_savefh(&xdr);
5042 if (status)
5043 goto out;
5044 status = decode_open(&xdr, res);
5045 if (status)
5046 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04005047 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005049 if (decode_getfattr(&xdr, res->f_attr, res->server,
5050 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005051 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04005052 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005053 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005054 decode_getfattr(&xdr, res->dir_attr, res->server,
5055 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005057 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058}
5059
5060/*
5061 * Decode OPEN_CONFIRM response
5062 */
Al Viro8687b632006-10-19 23:28:48 -07005063static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005064{
Andy Adamson05d564f2008-12-23 16:06:15 -05005065 struct xdr_stream xdr;
5066 struct compound_hdr hdr;
5067 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068
Andy Adamson05d564f2008-12-23 16:06:15 -05005069 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5070 status = decode_compound_hdr(&xdr, &hdr);
5071 if (status)
5072 goto out;
5073 status = decode_putfh(&xdr);
5074 if (status)
5075 goto out;
5076 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005078 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079}
5080
5081/*
5082 * Decode OPEN response
5083 */
Al Viro8687b632006-10-19 23:28:48 -07005084static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085{
Andy Adamson05d564f2008-12-23 16:06:15 -05005086 struct xdr_stream xdr;
5087 struct compound_hdr hdr;
5088 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005089
Andy Adamson05d564f2008-12-23 16:06:15 -05005090 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5091 status = decode_compound_hdr(&xdr, &hdr);
5092 if (status)
5093 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005094 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5095 if (status)
5096 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005097 status = decode_putfh(&xdr);
5098 if (status)
5099 goto out;
5100 status = decode_open(&xdr, res);
5101 if (status)
5102 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005103 decode_getfattr(&xdr, res->f_attr, res->server,
5104 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005105out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005106 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107}
5108
5109/*
5110 * Decode SETATTR response
5111 */
Al Viro8687b632006-10-19 23:28:48 -07005112static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113{
Andy Adamson05d564f2008-12-23 16:06:15 -05005114 struct xdr_stream xdr;
5115 struct compound_hdr hdr;
5116 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117
Andy Adamson05d564f2008-12-23 16:06:15 -05005118 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5119 status = decode_compound_hdr(&xdr, &hdr);
5120 if (status)
5121 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005122 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5123 if (status)
5124 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005125 status = decode_putfh(&xdr);
5126 if (status)
5127 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005128 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005129 if (status)
5130 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005131 decode_getfattr(&xdr, res->fattr, res->server,
5132 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005134 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005135}
5136
5137/*
5138 * Decode LOCK response
5139 */
Al Viro8687b632006-10-19 23:28:48 -07005140static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005141{
5142 struct xdr_stream xdr;
5143 struct compound_hdr hdr;
5144 int status;
5145
5146 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5147 status = decode_compound_hdr(&xdr, &hdr);
5148 if (status)
5149 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005150 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5151 if (status)
5152 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153 status = decode_putfh(&xdr);
5154 if (status)
5155 goto out;
5156 status = decode_lock(&xdr, res);
5157out:
5158 return status;
5159}
5160
5161/*
5162 * Decode LOCKT response
5163 */
Al Viro8687b632006-10-19 23:28:48 -07005164static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005165{
5166 struct xdr_stream xdr;
5167 struct compound_hdr hdr;
5168 int status;
5169
5170 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5171 status = decode_compound_hdr(&xdr, &hdr);
5172 if (status)
5173 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005174 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5175 if (status)
5176 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177 status = decode_putfh(&xdr);
5178 if (status)
5179 goto out;
5180 status = decode_lockt(&xdr, res);
5181out:
5182 return status;
5183}
5184
5185/*
5186 * Decode LOCKU response
5187 */
Al Viro8687b632006-10-19 23:28:48 -07005188static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005189{
5190 struct xdr_stream xdr;
5191 struct compound_hdr hdr;
5192 int status;
5193
5194 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5195 status = decode_compound_hdr(&xdr, &hdr);
5196 if (status)
5197 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005198 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5199 if (status)
5200 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005201 status = decode_putfh(&xdr);
5202 if (status)
5203 goto out;
5204 status = decode_locku(&xdr, res);
5205out:
5206 return status;
5207}
5208
5209/*
5210 * Decode READLINK response
5211 */
Benny Halevyf50c7002009-04-01 09:21:55 -04005212static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
5213 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214{
5215 struct xdr_stream xdr;
5216 struct compound_hdr hdr;
5217 int status;
5218
5219 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5220 status = decode_compound_hdr(&xdr, &hdr);
5221 if (status)
5222 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005223 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5224 if (status)
5225 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005226 status = decode_putfh(&xdr);
5227 if (status)
5228 goto out;
5229 status = decode_readlink(&xdr, rqstp);
5230out:
5231 return status;
5232}
5233
5234/*
5235 * Decode READDIR response
5236 */
Al Viro8687b632006-10-19 23:28:48 -07005237static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238{
5239 struct xdr_stream xdr;
5240 struct compound_hdr hdr;
5241 int status;
5242
5243 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5244 status = decode_compound_hdr(&xdr, &hdr);
5245 if (status)
5246 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005247 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5248 if (status)
5249 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250 status = decode_putfh(&xdr);
5251 if (status)
5252 goto out;
5253 status = decode_readdir(&xdr, rqstp, res);
5254out:
5255 return status;
5256}
5257
5258/*
5259 * Decode Read response
5260 */
Al Viro8687b632006-10-19 23:28:48 -07005261static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262{
5263 struct xdr_stream xdr;
5264 struct compound_hdr hdr;
5265 int status;
5266
5267 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5268 status = decode_compound_hdr(&xdr, &hdr);
5269 if (status)
5270 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005271 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5272 if (status)
5273 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274 status = decode_putfh(&xdr);
5275 if (status)
5276 goto out;
5277 status = decode_read(&xdr, rqstp, res);
5278 if (!status)
5279 status = res->count;
5280out:
5281 return status;
5282}
5283
5284/*
5285 * Decode WRITE response
5286 */
Al Viro8687b632006-10-19 23:28:48 -07005287static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005288{
5289 struct xdr_stream xdr;
5290 struct compound_hdr hdr;
5291 int status;
5292
5293 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5294 status = decode_compound_hdr(&xdr, &hdr);
5295 if (status)
5296 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005297 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5298 if (status)
5299 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005300 status = decode_putfh(&xdr);
5301 if (status)
5302 goto out;
5303 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005304 if (status)
5305 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005306 decode_getfattr(&xdr, res->fattr, res->server,
5307 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005308 if (!status)
5309 status = res->count;
5310out:
5311 return status;
5312}
5313
5314/*
5315 * Decode COMMIT response
5316 */
Al Viro8687b632006-10-19 23:28:48 -07005317static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005318{
5319 struct xdr_stream xdr;
5320 struct compound_hdr hdr;
5321 int status;
5322
5323 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5324 status = decode_compound_hdr(&xdr, &hdr);
5325 if (status)
5326 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005327 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5328 if (status)
5329 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005330 status = decode_putfh(&xdr);
5331 if (status)
5332 goto out;
5333 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005334 if (status)
5335 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005336 decode_getfattr(&xdr, res->fattr, res->server,
5337 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005338out:
5339 return status;
5340}
5341
5342/*
5343 * FSINFO request
5344 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04005345static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
5346 struct nfs4_fsinfo_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, &req->rq_rcv_buf, p);
5353 status = decode_compound_hdr(&xdr, &hdr);
5354 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005355 status = decode_sequence(&xdr, &res->seq_res, req);
5356 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005357 status = decode_putfh(&xdr);
5358 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04005359 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005360 return status;
5361}
5362
5363/*
5364 * PATHCONF request
5365 */
Benny Halevyd45b2982009-04-01 09:21:58 -04005366static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
5367 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005368{
5369 struct xdr_stream xdr;
5370 struct compound_hdr hdr;
5371 int status;
5372
5373 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5374 status = decode_compound_hdr(&xdr, &hdr);
5375 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005376 status = decode_sequence(&xdr, &res->seq_res, req);
5377 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378 status = decode_putfh(&xdr);
5379 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04005380 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005381 return status;
5382}
5383
5384/*
5385 * STATFS request
5386 */
Benny Halevy24ad1482009-04-01 09:21:56 -04005387static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
5388 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389{
5390 struct xdr_stream xdr;
5391 struct compound_hdr hdr;
5392 int status;
5393
5394 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5395 status = decode_compound_hdr(&xdr, &hdr);
5396 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005397 status = decode_sequence(&xdr, &res->seq_res, req);
5398 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005399 status = decode_putfh(&xdr);
5400 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04005401 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005402 return status;
5403}
5404
5405/*
5406 * GETATTR_BITMAP request
5407 */
Al Viro8687b632006-10-19 23:28:48 -07005408static 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 -07005409{
5410 struct xdr_stream xdr;
5411 struct compound_hdr hdr;
5412 int status;
5413
5414 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005415 status = decode_compound_hdr(&xdr, &hdr);
5416 if (status)
5417 goto out;
5418 status = decode_sequence(&xdr, &res->seq_res, req);
5419 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005420 goto out;
5421 if ((status = decode_putfh(&xdr)) != 0)
5422 goto out;
5423 status = decode_server_caps(&xdr, res);
5424out:
5425 return status;
5426}
5427
5428/*
5429 * Decode RENEW response
5430 */
Al Viro8687b632006-10-19 23:28:48 -07005431static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005432{
5433 struct xdr_stream xdr;
5434 struct compound_hdr hdr;
5435 int status;
5436
5437 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5438 status = decode_compound_hdr(&xdr, &hdr);
5439 if (!status)
5440 status = decode_renew(&xdr);
5441 return status;
5442}
5443
5444/*
5445 * a SETCLIENTID request
5446 */
Al Viro8687b632006-10-19 23:28:48 -07005447static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04005448 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005449{
5450 struct xdr_stream xdr;
5451 struct compound_hdr hdr;
5452 int status;
5453
5454 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5455 status = decode_compound_hdr(&xdr, &hdr);
5456 if (!status)
5457 status = decode_setclientid(&xdr, clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005458 return status;
5459}
5460
5461/*
5462 * a SETCLIENTID_CONFIRM request
5463 */
Al Viro8687b632006-10-19 23:28:48 -07005464static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005465{
5466 struct xdr_stream xdr;
5467 struct compound_hdr hdr;
5468 int status;
5469
5470 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5471 status = decode_compound_hdr(&xdr, &hdr);
5472 if (!status)
5473 status = decode_setclientid_confirm(&xdr);
5474 if (!status)
5475 status = decode_putrootfh(&xdr);
5476 if (!status)
5477 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005478 return status;
5479}
5480
5481/*
5482 * DELEGRETURN request
5483 */
Al Viro8687b632006-10-19 23:28:48 -07005484static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005485{
5486 struct xdr_stream xdr;
5487 struct compound_hdr hdr;
5488 int status;
5489
5490 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5491 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005492 if (status)
5493 goto out;
5494 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5495 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005496 goto out;
5497 status = decode_putfh(&xdr);
5498 if (status != 0)
5499 goto out;
5500 status = decode_delegreturn(&xdr);
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005501 decode_getfattr(&xdr, res->fattr, res->server,
5502 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01005503out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005504 return status;
5505}
5506
Trond Myklebust683b57b2006-06-09 09:34:22 -04005507/*
5508 * FS_LOCATIONS request
5509 */
Benny Halevy22958462009-04-01 09:22:02 -04005510static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
5511 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005512{
5513 struct xdr_stream xdr;
5514 struct compound_hdr hdr;
5515 int status;
5516
5517 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5518 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005519 if (status)
5520 goto out;
5521 status = decode_sequence(&xdr, &res->seq_res, req);
5522 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005523 goto out;
5524 if ((status = decode_putfh(&xdr)) != 0)
5525 goto out;
5526 if ((status = decode_lookup(&xdr)) != 0)
5527 goto out;
5528 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04005529 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005530 res->fs_locations->server,
5531 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04005532out:
5533 return status;
5534}
5535
Benny Halevy99fe60d2009-04-01 09:22:29 -04005536#if defined(CONFIG_NFS_V4_1)
5537/*
5538 * EXCHANGE_ID request
5539 */
5540static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
5541 void *res)
5542{
5543 struct xdr_stream xdr;
5544 struct compound_hdr hdr;
5545 int status;
5546
5547 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5548 status = decode_compound_hdr(&xdr, &hdr);
5549 if (!status)
5550 status = decode_exchange_id(&xdr, res);
5551 return status;
5552}
Andy Adamson2050f0c2009-04-01 09:22:30 -04005553
5554/*
Andy Adamsonfc931582009-04-01 09:22:31 -04005555 * a CREATE_SESSION request
5556 */
5557static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
5558 struct nfs41_create_session_res *res)
5559{
5560 struct xdr_stream xdr;
5561 struct compound_hdr hdr;
5562 int status;
5563
5564 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5565 status = decode_compound_hdr(&xdr, &hdr);
5566 if (!status)
5567 status = decode_create_session(&xdr, res);
5568 return status;
5569}
5570
5571/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005572 * a DESTROY_SESSION request
5573 */
5574static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
5575 void *dummy)
5576{
5577 struct xdr_stream xdr;
5578 struct compound_hdr hdr;
5579 int status;
5580
5581 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5582 status = decode_compound_hdr(&xdr, &hdr);
5583 if (!status)
5584 status = decode_destroy_session(&xdr, dummy);
5585 return status;
5586}
5587
5588/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005589 * a SEQUENCE request
5590 */
5591static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p,
5592 struct nfs4_sequence_res *res)
5593{
5594 struct xdr_stream xdr;
5595 struct compound_hdr hdr;
5596 int status;
5597
5598 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5599 status = decode_compound_hdr(&xdr, &hdr);
5600 if (!status)
5601 status = decode_sequence(&xdr, res, rqstp);
5602 return status;
5603}
5604
5605/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04005606 * a GET_LEASE_TIME request
5607 */
5608static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
5609 struct nfs4_get_lease_time_res *res)
5610{
5611 struct xdr_stream xdr;
5612 struct compound_hdr hdr;
5613 int status;
5614
5615 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5616 status = decode_compound_hdr(&xdr, &hdr);
5617 if (!status)
5618 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
5619 if (!status)
5620 status = decode_putrootfh(&xdr);
5621 if (!status)
5622 status = decode_fsinfo(&xdr, res->lr_fsinfo);
5623 return status;
5624}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005625#endif /* CONFIG_NFS_V4_1 */
5626
Al Viro0dbb4c62006-10-19 23:28:49 -07005627__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005628{
5629 uint32_t bitmap[2] = {0};
5630 uint32_t len;
5631
5632 if (!*p++) {
5633 if (!*p)
5634 return ERR_PTR(-EAGAIN);
5635 entry->eof = 1;
5636 return ERR_PTR(-EBADCOOKIE);
5637 }
5638
5639 entry->prev_cookie = entry->cookie;
5640 p = xdr_decode_hyper(p, &entry->cookie);
5641 entry->len = ntohl(*p++);
5642 entry->name = (const char *) p;
5643 p += XDR_QUADLEN(entry->len);
5644
5645 /*
5646 * In case the server doesn't return an inode number,
5647 * we fake one here. (We don't use inode number 0,
5648 * since glibc seems to choke on it...)
5649 */
5650 entry->ino = 1;
5651
5652 len = ntohl(*p++); /* bitmap length */
5653 if (len-- > 0) {
5654 bitmap[0] = ntohl(*p++);
5655 if (len-- > 0) {
5656 bitmap[1] = ntohl(*p++);
5657 p += len;
5658 }
5659 }
5660 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
5661 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00005662 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
5663 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
5664 /* Ignore the return value of rdattr_error for now */
5665 p++;
5666 len--;
5667 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005668 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
5669 xdr_decode_hyper(p, &entry->ino);
5670 else if (bitmap[0] == FATTR4_WORD0_FILEID)
5671 xdr_decode_hyper(p, &entry->ino);
5672 p += len;
5673 }
5674
5675 entry->eof = !p[0] && p[1];
5676 return p;
5677}
5678
5679/*
5680 * We need to translate between nfs status return values and
5681 * the local errno values which may not be the same.
5682 */
5683static struct {
5684 int stat;
5685 int errno;
5686} nfs_errtbl[] = {
5687 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03005688 { NFS4ERR_PERM, -EPERM },
5689 { NFS4ERR_NOENT, -ENOENT },
5690 { NFS4ERR_IO, -errno_NFSERR_IO},
5691 { NFS4ERR_NXIO, -ENXIO },
5692 { NFS4ERR_ACCESS, -EACCES },
5693 { NFS4ERR_EXIST, -EEXIST },
5694 { NFS4ERR_XDEV, -EXDEV },
5695 { NFS4ERR_NOTDIR, -ENOTDIR },
5696 { NFS4ERR_ISDIR, -EISDIR },
5697 { NFS4ERR_INVAL, -EINVAL },
5698 { NFS4ERR_FBIG, -EFBIG },
5699 { NFS4ERR_NOSPC, -ENOSPC },
5700 { NFS4ERR_ROFS, -EROFS },
5701 { NFS4ERR_MLINK, -EMLINK },
5702 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5703 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5704 { NFS4ERR_DQUOT, -EDQUOT },
5705 { NFS4ERR_STALE, -ESTALE },
5706 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5707 { NFS4ERR_BADOWNER, -EINVAL },
5708 { NFS4ERR_BADNAME, -EINVAL },
5709 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5710 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5711 { NFS4ERR_TOOSMALL, -ETOOSMALL },
5712 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
5713 { NFS4ERR_BADTYPE, -EBADTYPE },
5714 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03005715 { NFS4ERR_SYMLINK, -ELOOP },
5716 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5717 { NFS4ERR_DEADLOCK, -EDEADLK },
5718 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005719 * to be handled by a
5720 * middle-layer.
5721 */
Benny Halevy856dff32008-03-31 17:39:06 +03005722 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005723};
5724
5725/*
5726 * Convert an NFS error code to a local one.
5727 * This one is used jointly by NFSv2 and NFSv3.
5728 */
5729static int
David Howells0a8ea432006-08-22 20:06:08 -04005730nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005731{
5732 int i;
5733 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5734 if (nfs_errtbl[i].stat == stat)
5735 return nfs_errtbl[i].errno;
5736 }
5737 if (stat <= 10000 || stat > 10100) {
5738 /* The server is looney tunes. */
Benny Halevy856dff32008-03-31 17:39:06 +03005739 return -ESERVERFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005740 }
5741 /* If we cannot translate the error, the recovery routines should
5742 * handle it.
5743 * Note: remaining NFSv4 error codes have values > 10000, so should
5744 * not conflict with native Linux error codes.
5745 */
Benny Halevy856dff32008-03-31 17:39:06 +03005746 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005747}
5748
Linus Torvalds1da177e2005-04-16 15:20:36 -07005749#define PROC(proc, argtype, restype) \
5750[NFSPROC4_CLNT_##proc] = { \
5751 .p_proc = NFSPROC4_COMPOUND, \
5752 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5753 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04005754 .p_arglen = NFS4_##argtype##_sz, \
5755 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05005756 .p_statidx = NFSPROC4_CLNT_##proc, \
5757 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05005758}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005759
5760struct rpc_procinfo nfs4_procedures[] = {
5761 PROC(READ, enc_read, dec_read),
5762 PROC(WRITE, enc_write, dec_write),
5763 PROC(COMMIT, enc_commit, dec_commit),
5764 PROC(OPEN, enc_open, dec_open),
5765 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5766 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5767 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5768 PROC(CLOSE, enc_close, dec_close),
5769 PROC(SETATTR, enc_setattr, dec_setattr),
5770 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5771 PROC(RENEW, enc_renew, dec_renew),
5772 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5773 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5774 PROC(LOCK, enc_lock, dec_lock),
5775 PROC(LOCKT, enc_lockt, dec_lockt),
5776 PROC(LOCKU, enc_locku, dec_locku),
5777 PROC(ACCESS, enc_access, dec_access),
5778 PROC(GETATTR, enc_getattr, dec_getattr),
5779 PROC(LOOKUP, enc_lookup, dec_lookup),
5780 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5781 PROC(REMOVE, enc_remove, dec_remove),
5782 PROC(RENAME, enc_rename, dec_rename),
5783 PROC(LINK, enc_link, dec_link),
5784 PROC(SYMLINK, enc_symlink, dec_symlink),
5785 PROC(CREATE, enc_create, dec_create),
5786 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5787 PROC(STATFS, enc_statfs, dec_statfs),
5788 PROC(READLINK, enc_readlink, dec_readlink),
5789 PROC(READDIR, enc_readdir, dec_readdir),
5790 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5791 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00005792 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005793 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04005794 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005795#if defined(CONFIG_NFS_V4_1)
5796 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
Andy Adamsonfc931582009-04-01 09:22:31 -04005797 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005798 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005799 PROC(SEQUENCE, enc_sequence, dec_sequence),
Andy Adamson2050f0c2009-04-01 09:22:30 -04005800 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005801#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005802};
5803
5804struct rpc_version nfs_version4 = {
5805 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08005806 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005807 .procs = nfs4_procedures
5808};
5809
5810/*
5811 * Local variables:
5812 * c-basic-offset: 8
5813 * End:
5814 */