blob: e65cc2e650c89a447d3441aacfcc7ce02ddf8e21 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
41#include <linux/slab.h>
42#include <linux/utsname.h>
43#include <linux/errno.h>
44#include <linux/string.h>
45#include <linux/in.h>
46#include <linux/pagemap.h>
47#include <linux/proc_fs.h>
48#include <linux/kdev_t.h>
49#include <linux/sunrpc/clnt.h>
50#include <linux/nfs.h>
51#include <linux/nfs4.h>
52#include <linux/nfs_fs.h>
53#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000054#include "nfs4_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#define NFSDBG_FACILITY NFSDBG_XDR
57
58/* Mapping from NFS error code to "errno" error code. */
59#define errno_NFSERR_IO EIO
60
David Howells0a8ea432006-08-22 20:06:08 -040061static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
64#ifdef DEBUG
65#define NFS4_MAXTAGLEN 20
66#else
67#define NFS4_MAXTAGLEN 0
68#endif
69
Andy Adamson6c0195a2008-12-23 16:06:15 -050070/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040071 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 */
Trond Myklebust9f958ab2007-07-02 13:58:33 -040073#define open_owner_id_maxsz (1 + 4)
74#define lock_owner_id_maxsz (1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040075#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78#define op_encode_hdr_maxsz (1)
79#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040080#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
85 (NFS4_FHSIZE >> 2))
86#define decode_putfh_maxsz (op_decode_hdr_maxsz)
87#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89#define encode_getfh_maxsz (op_encode_hdr_maxsz)
90#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000092#define nfs4_fattr_bitmap_maxsz 3
93#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040096#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +000098/* This is based on getfattr, which uses the most attributes: */
99#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000101#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400104#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
105 1 + 2 + 1 + \
106 nfs4_owner_maxsz + \
107 nfs4_group_maxsz + \
108 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#define encode_savefh_maxsz (op_encode_hdr_maxsz)
110#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400111#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200113#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116#define decode_renew_maxsz (op_decode_hdr_maxsz)
117#define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
121 1 /* sc_prog */ + \
122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
124 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#define decode_setclientid_maxsz \
126 (op_decode_hdr_maxsz + \
127 2 + \
128 1024) /* large value for CLID_INUSE */
129#define encode_setclientid_confirm_maxsz \
130 (op_encode_hdr_maxsz + \
131 3 + (NFS4_VERIFIER_SIZE >> 2))
132#define decode_setclientid_confirm_maxsz \
133 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400134#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400136#define encode_share_access_maxsz \
137 (2)
Trond Myklebust9104a552007-07-17 21:52:42 -0400138#define encode_createmode_maxsz (1 + encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400139#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141#define encode_open_maxsz (op_encode_hdr_maxsz + \
142 2 + encode_share_access_maxsz + 2 + \
143 open_owner_id_maxsz + \
144 encode_opentype_maxsz + \
145 encode_claim_null_maxsz)
146#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400147#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400148 decode_ace_maxsz)
149#define decode_change_info_maxsz (5)
150#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400151 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400155#define encode_open_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 encode_stateid_maxsz + 1)
158#define decode_open_confirm_maxsz \
159 (op_decode_hdr_maxsz + \
160 decode_stateid_maxsz)
161#define encode_open_downgrade_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1 + \
164 encode_share_access_maxsz)
165#define decode_open_downgrade_maxsz \
166 (op_decode_hdr_maxsz + \
167 decode_stateid_maxsz)
168#define encode_close_maxsz (op_encode_hdr_maxsz + \
169 1 + encode_stateid_maxsz)
170#define decode_close_maxsz (op_decode_hdr_maxsz + \
171 decode_stateid_maxsz)
172#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + \
174 encode_attrs_maxsz)
175#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
176 nfs4_fattr_bitmap_maxsz)
177#define encode_read_maxsz (op_encode_hdr_maxsz + \
178 encode_stateid_maxsz + 3)
179#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
180#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
181 2 + encode_verifier_maxsz + 5)
182#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
183 decode_verifier_maxsz)
184#define encode_readlink_maxsz (op_encode_hdr_maxsz)
185#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
186#define encode_write_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 4)
188#define decode_write_maxsz (op_decode_hdr_maxsz + \
189 2 + decode_verifier_maxsz)
190#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
191#define decode_commit_maxsz (op_decode_hdr_maxsz + \
192 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193#define encode_remove_maxsz (op_encode_hdr_maxsz + \
194 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400195#define decode_remove_maxsz (op_decode_hdr_maxsz + \
196 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#define encode_rename_maxsz (op_encode_hdr_maxsz + \
198 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400199#define decode_rename_maxsz (op_decode_hdr_maxsz + \
200 decode_change_info_maxsz + \
201 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#define encode_link_maxsz (op_encode_hdr_maxsz + \
203 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400204#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400205#define encode_lock_maxsz (op_encode_hdr_maxsz + \
206 7 + \
207 1 + encode_stateid_maxsz + 8)
208#define decode_lock_denied_maxsz \
209 (8 + decode_lockowner_maxsz)
210#define decode_lock_maxsz (op_decode_hdr_maxsz + \
211 decode_lock_denied_maxsz)
212#define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
213#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
215#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
216 encode_stateid_maxsz + \
217 4)
218#define decode_locku_maxsz (op_decode_hdr_maxsz + \
219 decode_stateid_maxsz)
220#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
221#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
223 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400224 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000225 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
227#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400228 1 + 2 + nfs4_name_maxsz + \
229 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400230#define decode_create_maxsz (op_decode_hdr_maxsz + \
231 decode_change_info_maxsz + \
232 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400233#define encode_statfs_maxsz (encode_getattr_maxsz)
234#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
236#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400237#define encode_getacl_maxsz (encode_getattr_maxsz)
238#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
239 nfs4_fattr_bitmap_maxsz + 1)
240#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
241 encode_stateid_maxsz + 3)
242#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400243#define encode_fs_locations_maxsz \
244 (encode_getattr_maxsz)
245#define decode_fs_locations_maxsz \
246 (0)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400247
248#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400249#define NFS4_MAX_MACHINE_NAME_LEN (64)
250
Benny Halevy99fe60d2009-04-01 09:22:29 -0400251#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
252 encode_verifier_maxsz + \
253 1 /* co_ownerid.len */ + \
254 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
255 1 /* flags */ + \
256 1 /* spa_how */ + \
257 0 /* SP4_NONE (for now) */ + \
258 1 /* zero implemetation id array */)
259#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
260 2 /* eir_clientid */ + \
261 1 /* eir_sequenceid */ + \
262 1 /* eir_flags */ + \
263 1 /* spr_how */ + \
264 0 /* SP4_NONE (for now) */ + \
265 2 /* eir_server_owner.so_minor_id */ + \
266 /* eir_server_owner.so_major_id<> */ \
267 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
268 /* eir_server_scope<> */ \
269 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
270 1 /* eir_server_impl_id array length */ + \
271 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400272#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
273#define decode_channel_attrs_maxsz (6 + \
274 1 /* ca_rdma_ird.len */ + \
275 1 /* ca_rdma_ird */)
276#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
277 2 /* csa_clientid */ + \
278 1 /* csa_sequence */ + \
279 1 /* csa_flags */ + \
280 encode_channel_attrs_maxsz + \
281 encode_channel_attrs_maxsz + \
282 1 /* csa_cb_program */ + \
283 1 /* csa_sec_parms.len (1) */ + \
284 1 /* cb_secflavor (AUTH_SYS) */ + \
285 1 /* stamp */ + \
286 1 /* machinename.len */ + \
287 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
288 1 /* uid */ + \
289 1 /* gid */ + \
290 1 /* gids.len (0) */)
291#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
292 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
293 1 /* csr_sequence */ + \
294 1 /* csr_flags */ + \
295 decode_channel_attrs_maxsz + \
296 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400297#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
298#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400299#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
300 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
301#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
302 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400303#else /* CONFIG_NFS_V4_1 */
304#define encode_sequence_maxsz 0
305#define decode_sequence_maxsz 0
306#endif /* CONFIG_NFS_V4_1 */
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
309#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
310#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400311 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400313 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400315 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400317 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400319 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400321 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400323 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400325 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400327 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400329 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400331 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400333 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400335 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400337 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400338 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400340 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400342 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400343 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400345 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400347 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400348 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400350 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400352 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400353 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400355 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400356 encode_putfh_maxsz + \
357 encode_savefh_maxsz + \
358 encode_open_maxsz + \
359 encode_getfh_maxsz + \
360 encode_getattr_maxsz + \
361 encode_restorefh_maxsz + \
362 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400364 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400365 decode_putfh_maxsz + \
366 decode_savefh_maxsz + \
367 decode_open_maxsz + \
368 decode_getfh_maxsz + \
369 decode_getattr_maxsz + \
370 decode_restorefh_maxsz + \
371 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400372#define NFS4_enc_open_confirm_sz \
373 (compound_encode_hdr_maxsz + \
374 encode_putfh_maxsz + \
375 encode_open_confirm_maxsz)
376#define NFS4_dec_open_confirm_sz \
377 (compound_decode_hdr_maxsz + \
378 decode_putfh_maxsz + \
379 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400381 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400383 encode_open_maxsz + \
384 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400386 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400388 decode_open_maxsz + \
389 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#define NFS4_enc_open_downgrade_sz \
391 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400392 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400393 encode_putfh_maxsz + \
394 encode_open_downgrade_maxsz + \
395 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396#define NFS4_dec_open_downgrade_sz \
397 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400398 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400399 decode_putfh_maxsz + \
400 decode_open_downgrade_maxsz + \
401 decode_getattr_maxsz)
402#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400403 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400404 encode_putfh_maxsz + \
405 encode_close_maxsz + \
406 encode_getattr_maxsz)
407#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400409 decode_putfh_maxsz + \
410 decode_close_maxsz + \
411 decode_getattr_maxsz)
412#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400413 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 encode_putfh_maxsz + \
415 encode_setattr_maxsz + \
416 encode_getattr_maxsz)
417#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400418 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 decode_putfh_maxsz + \
420 decode_setattr_maxsz + \
421 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400423 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 encode_putfh_maxsz + \
425 encode_fsinfo_maxsz)
426#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 decode_putfh_maxsz + \
429 decode_fsinfo_maxsz)
430#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
431 encode_renew_maxsz)
432#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
433 decode_renew_maxsz)
434#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
435 encode_setclientid_maxsz)
436#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
437 decode_setclientid_maxsz)
438#define NFS4_enc_setclientid_confirm_sz \
439 (compound_encode_hdr_maxsz + \
440 encode_setclientid_confirm_maxsz + \
441 encode_putrootfh_maxsz + \
442 encode_fsinfo_maxsz)
443#define NFS4_dec_setclientid_confirm_sz \
444 (compound_decode_hdr_maxsz + \
445 decode_setclientid_confirm_maxsz + \
446 decode_putrootfh_maxsz + \
447 decode_fsinfo_maxsz)
448#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400449 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400451 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400453 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400455 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400457 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400459 encode_lockt_maxsz)
460#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400461 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400462 decode_putfh_maxsz + \
463 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400465 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400467 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400471 decode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400473 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400475 encode_access_maxsz + \
476 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400478 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400480 decode_access_maxsz + \
481 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400483 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 encode_putfh_maxsz + \
485 encode_getattr_maxsz)
486#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400487 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 decode_putfh_maxsz + \
489 decode_getattr_maxsz)
490#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400491 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 encode_putfh_maxsz + \
493 encode_lookup_maxsz + \
494 encode_getattr_maxsz + \
495 encode_getfh_maxsz)
496#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400497 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400499 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 decode_getattr_maxsz + \
501 decode_getfh_maxsz)
502#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400503 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 encode_putrootfh_maxsz + \
505 encode_getattr_maxsz + \
506 encode_getfh_maxsz)
507#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400508 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 decode_putrootfh_maxsz + \
510 decode_getattr_maxsz + \
511 decode_getfh_maxsz)
512#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400513 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400515 encode_remove_maxsz + \
516 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400518 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400520 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400521 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400523 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 encode_putfh_maxsz + \
525 encode_savefh_maxsz + \
526 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400527 encode_rename_maxsz + \
528 encode_getattr_maxsz + \
529 encode_restorefh_maxsz + \
530 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400532 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 decode_putfh_maxsz + \
534 decode_savefh_maxsz + \
535 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400536 decode_rename_maxsz + \
537 decode_getattr_maxsz + \
538 decode_restorefh_maxsz + \
539 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400541 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 encode_putfh_maxsz + \
543 encode_savefh_maxsz + \
544 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400545 encode_link_maxsz + \
546 decode_getattr_maxsz + \
547 encode_restorefh_maxsz + \
548 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400550 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 decode_putfh_maxsz + \
552 decode_savefh_maxsz + \
553 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400554 decode_link_maxsz + \
555 decode_getattr_maxsz + \
556 decode_restorefh_maxsz + \
557 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400559 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 encode_putfh_maxsz + \
561 encode_symlink_maxsz + \
562 encode_getattr_maxsz + \
563 encode_getfh_maxsz)
564#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400565 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 decode_putfh_maxsz + \
567 decode_symlink_maxsz + \
568 decode_getattr_maxsz + \
569 decode_getfh_maxsz)
570#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400571 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400573 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400575 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400577 encode_restorefh_maxsz + \
578 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400582 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400584 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400586 decode_restorefh_maxsz + \
587 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400589 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 encode_putfh_maxsz + \
591 encode_getattr_maxsz)
592#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400593 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 decode_putfh_maxsz + \
595 decode_getattr_maxsz)
596#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400597 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400599 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400603 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400605 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800606 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 encode_getattr_maxsz)
608#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400609 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800610 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 decode_getattr_maxsz)
612#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400613 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100615 encode_delegreturn_maxsz + \
616 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400618 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100619 decode_delegreturn_maxsz + \
620 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000621#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000623 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400624 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000625#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400626 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000627 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400628 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000629#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400630 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000631 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400632 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000633#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400634 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000635 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400636 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400637#define NFS4_enc_fs_locations_sz \
638 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400639 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400640 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400641 encode_lookup_maxsz + \
642 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400643#define NFS4_dec_fs_locations_sz \
644 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400645 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400646 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400647 decode_lookup_maxsz + \
648 decode_fs_locations_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400649#if defined(CONFIG_NFS_V4_1)
650#define NFS4_enc_exchange_id_sz \
651 (compound_encode_hdr_maxsz + \
652 encode_exchange_id_maxsz)
653#define NFS4_dec_exchange_id_sz \
654 (compound_decode_hdr_maxsz + \
655 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400656#define NFS4_enc_create_session_sz \
657 (compound_encode_hdr_maxsz + \
658 encode_create_session_maxsz)
659#define NFS4_dec_create_session_sz \
660 (compound_decode_hdr_maxsz + \
661 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400662#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
663 encode_destroy_session_maxsz)
664#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
665 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400666#define NFS4_enc_sequence_sz \
667 (compound_decode_hdr_maxsz + \
668 encode_sequence_maxsz)
669#define NFS4_dec_sequence_sz \
670 (compound_decode_hdr_maxsz + \
671 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400672#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
673 encode_sequence_maxsz + \
674 encode_putrootfh_maxsz + \
675 encode_fsinfo_maxsz)
676#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
677 decode_sequence_maxsz + \
678 decode_putrootfh_maxsz + \
679 decode_fsinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400680#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Trond Myklebustbca79472009-03-11 14:10:26 -0400682static const umode_t nfs_type2fmt[] = {
683 [NF4BAD] = 0,
684 [NF4REG] = S_IFREG,
685 [NF4DIR] = S_IFDIR,
686 [NF4BLK] = S_IFBLK,
687 [NF4CHR] = S_IFCHR,
688 [NF4LNK] = S_IFLNK,
689 [NF4SOCK] = S_IFSOCK,
690 [NF4FIFO] = S_IFIFO,
691 [NF4ATTRDIR] = 0,
692 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693};
694
695struct compound_hdr {
696 int32_t status;
697 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500698 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 uint32_t taglen;
700 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400701 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400702 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703};
704
705/*
706 * START OF "GENERIC" ENCODE ROUTINES.
707 * These may look a little ugly since they are imported from a "generic"
708 * set of XDR encode/decode routines which are intended to be shared by
709 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
710 *
711 * If the pain of reading these is too great, it should be a straightforward
712 * task to translate them into Linux-specific versions which are more
713 * consistent with the style used in NFSv2/v3...
714 */
715#define WRITE32(n) *p++ = htonl(n)
716#define WRITE64(n) do { \
717 *p++ = htonl((uint32_t)((n) >> 32)); \
718 *p++ = htonl((uint32_t)(n)); \
719} while (0)
720#define WRITEMEM(ptr,nbytes) do { \
721 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
722} while (0)
723
724#define RESERVE_SPACE(nbytes) do { \
725 p = xdr_reserve_space(xdr, nbytes); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 BUG_ON(!p); \
727} while (0)
728
729static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
730{
Al Viro8687b632006-10-19 23:28:48 -0700731 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 p = xdr_reserve_space(xdr, 4 + len);
734 BUG_ON(p == NULL);
735 xdr_encode_opaque(p, str, len);
736}
737
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400738static void encode_compound_hdr(struct xdr_stream *xdr,
739 struct rpc_rqst *req,
740 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741{
Al Viro8687b632006-10-19 23:28:48 -0700742 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400743 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
744
745 /* initialize running count of expected bytes in reply.
746 * NOTE: the replied tag SHOULD be the same is the one sent,
747 * but this is not required as a MUST for the server to do so. */
748 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
750 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
751 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
752 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
753 WRITE32(hdr->taglen);
754 WRITEMEM(hdr->tag, hdr->taglen);
Benny Halevy66cc0422009-04-01 09:22:10 -0400755 WRITE32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500756 hdr->nops_p = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 WRITE32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500758}
759
760static void encode_nops(struct compound_hdr *hdr)
761{
Andy Adamsonfc931582009-04-01 09:22:31 -0400762 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500763 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764}
765
766static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
767{
Al Viro8687b632006-10-19 23:28:48 -0700768 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
770 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
771 BUG_ON(p == NULL);
772 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
773}
774
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500775static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776{
777 char owner_name[IDMAP_NAMESZ];
778 char owner_group[IDMAP_NAMESZ];
779 int owner_namelen = 0;
780 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700781 __be32 *p;
782 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 int len;
784 uint32_t bmval0 = 0;
785 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 /*
788 * We reserve enough space to write the entire attribute buffer at once.
789 * In the worst-case, this would be
790 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
791 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000792 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 */
794 len = 16;
795
796 /* Sigh */
797 if (iap->ia_valid & ATTR_SIZE)
798 len += 8;
799 if (iap->ia_valid & ATTR_MODE)
800 len += 4;
801 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400802 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400804 dprintk("nfs: couldn't resolve uid %d to string\n",
805 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 /* XXX */
807 strcpy(owner_name, "nobody");
808 owner_namelen = sizeof("nobody") - 1;
809 /* goto out; */
810 }
811 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
812 }
813 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400814 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400816 dprintk("nfs: couldn't resolve gid %d to string\n",
817 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 strcpy(owner_group, "nobody");
819 owner_grouplen = sizeof("nobody") - 1;
820 /* goto out; */
821 }
822 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
823 }
824 if (iap->ia_valid & ATTR_ATIME_SET)
825 len += 16;
826 else if (iap->ia_valid & ATTR_ATIME)
827 len += 4;
828 if (iap->ia_valid & ATTR_MTIME_SET)
829 len += 16;
830 else if (iap->ia_valid & ATTR_MTIME)
831 len += 4;
832 RESERVE_SPACE(len);
833
834 /*
835 * We write the bitmap length now, but leave the bitmap and the attribute
836 * buffer length to be backfilled at the end of this routine.
837 */
838 WRITE32(2);
839 q = p;
840 p += 3;
841
842 if (iap->ia_valid & ATTR_SIZE) {
843 bmval0 |= FATTR4_WORD0_SIZE;
844 WRITE64(iap->ia_size);
845 }
846 if (iap->ia_valid & ATTR_MODE) {
847 bmval1 |= FATTR4_WORD1_MODE;
Trond Myklebustcf3fff52006-01-03 09:55:53 +0100848 WRITE32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 }
850 if (iap->ia_valid & ATTR_UID) {
851 bmval1 |= FATTR4_WORD1_OWNER;
852 WRITE32(owner_namelen);
853 WRITEMEM(owner_name, owner_namelen);
854 }
855 if (iap->ia_valid & ATTR_GID) {
856 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
857 WRITE32(owner_grouplen);
858 WRITEMEM(owner_group, owner_grouplen);
859 }
860 if (iap->ia_valid & ATTR_ATIME_SET) {
861 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
862 WRITE32(NFS4_SET_TO_CLIENT_TIME);
863 WRITE32(0);
864 WRITE32(iap->ia_mtime.tv_sec);
865 WRITE32(iap->ia_mtime.tv_nsec);
866 }
867 else if (iap->ia_valid & ATTR_ATIME) {
868 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
869 WRITE32(NFS4_SET_TO_SERVER_TIME);
870 }
871 if (iap->ia_valid & ATTR_MTIME_SET) {
872 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
873 WRITE32(NFS4_SET_TO_CLIENT_TIME);
874 WRITE32(0);
875 WRITE32(iap->ia_mtime.tv_sec);
876 WRITE32(iap->ia_mtime.tv_nsec);
877 }
878 else if (iap->ia_valid & ATTR_MTIME) {
879 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
880 WRITE32(NFS4_SET_TO_SERVER_TIME);
881 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500882
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 /*
884 * Now we backfill the bitmap and the attribute buffer length.
885 */
886 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400887 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 len, ((char *)p - (char *)q) + 4);
889 BUG();
890 }
891 len = (char *)p - (char *)q - 12;
892 *q++ = htonl(bmval0);
893 *q++ = htonl(bmval1);
894 *q++ = htonl(len);
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897}
898
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500899static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900{
Al Viro8687b632006-10-19 23:28:48 -0700901 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
903 RESERVE_SPACE(8);
904 WRITE32(OP_ACCESS);
905 WRITE32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500906 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400907 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908}
909
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500910static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911{
Al Viro8687b632006-10-19 23:28:48 -0700912 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400914 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 WRITE32(OP_CLOSE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700916 WRITE32(arg->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400917 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500918 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400919 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920}
921
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500922static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923{
Al Viro8687b632006-10-19 23:28:48 -0700924 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500925
Andy Adamson05d564f2008-12-23 16:06:15 -0500926 RESERVE_SPACE(16);
927 WRITE32(OP_COMMIT);
928 WRITE64(args->offset);
929 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500930 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400931 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932}
933
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500934static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935{
Al Viro8687b632006-10-19 23:28:48 -0700936 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500937
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 RESERVE_SPACE(8);
939 WRITE32(OP_CREATE);
940 WRITE32(create->ftype);
941
942 switch (create->ftype) {
943 case NF4LNK:
Chuck Lever94a6d752006-08-22 20:06:23 -0400944 RESERVE_SPACE(4);
945 WRITE32(create->u.symlink.len);
946 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 break;
948
949 case NF4BLK: case NF4CHR:
950 RESERVE_SPACE(8);
951 WRITE32(create->u.device.specdata1);
952 WRITE32(create->u.device.specdata2);
953 break;
954
955 default:
956 break;
957 }
958
959 RESERVE_SPACE(4 + create->name->len);
960 WRITE32(create->name->len);
961 WRITEMEM(create->name->name, create->name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500962 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400963 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500965 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966}
967
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500968static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969{
Andy Adamson05d564f2008-12-23 16:06:15 -0500970 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
Andy Adamson05d564f2008-12-23 16:06:15 -0500972 RESERVE_SPACE(12);
973 WRITE32(OP_GETATTR);
974 WRITE32(1);
975 WRITE32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500976 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400977 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978}
979
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500980static 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 -0700981{
Andy Adamson05d564f2008-12-23 16:06:15 -0500982 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Andy Adamson05d564f2008-12-23 16:06:15 -0500984 RESERVE_SPACE(16);
985 WRITE32(OP_GETATTR);
986 WRITE32(2);
987 WRITE32(bm0);
988 WRITE32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -0500989 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400990 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991}
992
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500993static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500995 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
996 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997}
998
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500999static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001001 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1002 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003}
1004
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001005static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001006{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001007 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1008 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001009}
1010
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001011static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012{
Al Viro8687b632006-10-19 23:28:48 -07001013 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
1015 RESERVE_SPACE(4);
1016 WRITE32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001017 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001018 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019}
1020
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001021static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022{
Al Viro8687b632006-10-19 23:28:48 -07001023 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
1025 RESERVE_SPACE(8 + name->len);
1026 WRITE32(OP_LINK);
1027 WRITE32(name->len);
1028 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001029 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001030 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031}
1032
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001033static inline int nfs4_lock_type(struct file_lock *fl, int block)
1034{
1035 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1036 return block ? NFS4_READW_LT : NFS4_READ_LT;
1037 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1038}
1039
1040static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1041{
1042 if (fl->fl_end == OFFSET_MAX)
1043 return ~(uint64_t)0;
1044 return fl->fl_end - fl->fl_start + 1;
1045}
1046
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047/*
1048 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1049 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1050 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001051static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052{
Al Viro8687b632006-10-19 23:28:48 -07001053 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
1055 RESERVE_SPACE(32);
1056 WRITE32(OP_LOCK);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001057 WRITE32(nfs4_lock_type(args->fl, args->block));
1058 WRITE32(args->reclaim);
1059 WRITE64(args->fl->fl_start);
1060 WRITE64(nfs4_lock_length(args->fl));
1061 WRITE32(args->new_lock_owner);
1062 if (args->new_lock_owner){
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001063 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001064 WRITE32(args->open_seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001065 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001066 WRITE32(args->lock_seqid->sequence->counter);
1067 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001068 WRITE32(16);
1069 WRITEMEM("lock id:", 8);
1070 WRITE64(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 }
1072 else {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001073 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
1074 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001075 WRITE32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 }
Andy Adamsond0179312008-12-23 16:06:17 -05001077 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001078 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079}
1080
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001081static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082{
Al Viro8687b632006-10-19 23:28:48 -07001083 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001085 RESERVE_SPACE(52);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 WRITE32(OP_LOCKT);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001087 WRITE32(nfs4_lock_type(args->fl, 0));
1088 WRITE64(args->fl->fl_start);
1089 WRITE64(nfs4_lock_length(args->fl));
1090 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001091 WRITE32(16);
1092 WRITEMEM("lock id:", 8);
1093 WRITE64(args->lock_owner.id);
Andy Adamsond0179312008-12-23 16:06:17 -05001094 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001095 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096}
1097
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001098static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099{
Al Viro8687b632006-10-19 23:28:48 -07001100 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001102 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 WRITE32(OP_LOCKU);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001104 WRITE32(nfs4_lock_type(args->fl, 0));
1105 WRITE32(args->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001106 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001107 WRITE64(args->fl->fl_start);
1108 WRITE64(nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001109 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001110 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111}
1112
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001113static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114{
1115 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001116 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
1118 RESERVE_SPACE(8 + len);
1119 WRITE32(OP_LOOKUP);
1120 WRITE32(len);
1121 WRITEMEM(name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001122 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001123 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124}
1125
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001126static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127{
Al Viro8687b632006-10-19 23:28:48 -07001128 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
1130 RESERVE_SPACE(8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001131 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001132 case FMODE_READ:
1133 WRITE32(NFS4_SHARE_ACCESS_READ);
1134 break;
1135 case FMODE_WRITE:
1136 WRITE32(NFS4_SHARE_ACCESS_WRITE);
1137 break;
1138 case FMODE_READ|FMODE_WRITE:
1139 WRITE32(NFS4_SHARE_ACCESS_BOTH);
1140 break;
1141 default:
1142 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 }
1144 WRITE32(0); /* for linux, share_deny = 0 always */
1145}
1146
1147static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1148{
Al Viro8687b632006-10-19 23:28:48 -07001149 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 /*
1151 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1152 * owner 4 = 32
1153 */
1154 RESERVE_SPACE(8);
1155 WRITE32(OP_OPEN);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001156 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001157 encode_share_access(xdr, arg->fmode);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001158 RESERVE_SPACE(28);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 WRITE64(arg->clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001160 WRITE32(16);
1161 WRITEMEM("open id:", 8);
1162 WRITE64(arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163}
1164
1165static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1166{
Al Viro8687b632006-10-19 23:28:48 -07001167 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
1169 RESERVE_SPACE(4);
1170 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001171 case 0:
1172 WRITE32(NFS4_CREATE_UNCHECKED);
1173 encode_attrs(xdr, arg->u.attrs, arg->server);
1174 break;
1175 default:
1176 WRITE32(NFS4_CREATE_EXCLUSIVE);
1177 encode_nfs4_verifier(xdr, &arg->u.verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 }
1179}
1180
1181static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1182{
Al Viro8687b632006-10-19 23:28:48 -07001183 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
1185 RESERVE_SPACE(4);
1186 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001187 case 0:
1188 WRITE32(NFS4_OPEN_NOCREATE);
1189 break;
1190 default:
1191 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1192 WRITE32(NFS4_OPEN_CREATE);
1193 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 }
1195}
1196
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001197static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198{
Al Viro8687b632006-10-19 23:28:48 -07001199 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
1201 RESERVE_SPACE(4);
1202 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001203 case 0:
1204 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1205 break;
1206 case FMODE_READ:
1207 WRITE32(NFS4_OPEN_DELEGATE_READ);
1208 break;
1209 case FMODE_WRITE|FMODE_READ:
1210 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1211 break;
1212 default:
1213 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 }
1215}
1216
1217static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1218{
Al Viro8687b632006-10-19 23:28:48 -07001219 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
1221 RESERVE_SPACE(4);
1222 WRITE32(NFS4_OPEN_CLAIM_NULL);
1223 encode_string(xdr, name->len, name->name);
1224}
1225
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001226static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227{
Al Viro8687b632006-10-19 23:28:48 -07001228 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230 RESERVE_SPACE(4);
1231 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1232 encode_delegation_type(xdr, type);
1233}
1234
1235static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1236{
Al Viro8687b632006-10-19 23:28:48 -07001237 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001239 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001241 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 encode_string(xdr, name->len, name->name);
1243}
1244
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001245static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246{
1247 encode_openhdr(xdr, arg);
1248 encode_opentype(xdr, arg);
1249 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001250 case NFS4_OPEN_CLAIM_NULL:
1251 encode_claim_null(xdr, arg->name);
1252 break;
1253 case NFS4_OPEN_CLAIM_PREVIOUS:
1254 encode_claim_previous(xdr, arg->u.delegation_type);
1255 break;
1256 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1257 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1258 break;
1259 default:
1260 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 }
Andy Adamsond0179312008-12-23 16:06:17 -05001262 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001263 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264}
1265
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001266static 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 -07001267{
Al Viro8687b632006-10-19 23:28:48 -07001268 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001270 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 WRITE32(OP_OPEN_CONFIRM);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001272 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001273 WRITE32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001274 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001275 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276}
1277
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001278static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279{
Al Viro8687b632006-10-19 23:28:48 -07001280 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001282 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 WRITE32(OP_OPEN_DOWNGRADE);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001284 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001285 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001286 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001287 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001288 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289}
1290
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001291static void
Andy Adamsond0179312008-12-23 16:06:17 -05001292encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293{
1294 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001295 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
1297 RESERVE_SPACE(8 + len);
1298 WRITE32(OP_PUTFH);
1299 WRITE32(len);
1300 WRITEMEM(fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001301 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001302 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303}
1304
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001305static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306{
Andy Adamson05d564f2008-12-23 16:06:15 -05001307 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001308
Andy Adamson05d564f2008-12-23 16:06:15 -05001309 RESERVE_SPACE(4);
1310 WRITE32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001311 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001312 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313}
1314
1315static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1316{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001318 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001320 RESERVE_SPACE(NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 if (ctx->state != NULL) {
1322 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001323 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 } else
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001325 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326}
1327
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001328static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329{
Al Viro8687b632006-10-19 23:28:48 -07001330 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
1332 RESERVE_SPACE(4);
1333 WRITE32(OP_READ);
1334
1335 encode_stateid(xdr, args->context);
1336
1337 RESERVE_SPACE(12);
1338 WRITE64(args->offset);
1339 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001340 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001341 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342}
1343
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001344static 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 -07001345{
Manoj Naik97d312d2005-06-22 17:16:39 +00001346 uint32_t attrs[2] = {
1347 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1348 FATTR4_WORD1_MOUNTED_ON_FILEID,
1349 };
Al Viro8687b632006-10-19 23:28:48 -07001350 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001352 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 WRITE32(OP_READDIR);
1354 WRITE64(readdir->cookie);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001355 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1357 WRITE32(readdir->count);
1358 WRITE32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001359 /* Switch to mounted_on_fileid if the server supports it */
1360 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1361 attrs[0] &= ~FATTR4_WORD0_FILEID;
1362 else
1363 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1364 WRITE32(attrs[0] & readdir->bitmask[0]);
1365 WRITE32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001366 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001367 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001368 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1369 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001370 (unsigned long long)readdir->cookie,
1371 ((u32 *)readdir->verifier.data)[0],
1372 ((u32 *)readdir->verifier.data)[1],
1373 attrs[0] & readdir->bitmask[0],
1374 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375}
1376
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001377static 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 -07001378{
Al Viro8687b632006-10-19 23:28:48 -07001379 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
1381 RESERVE_SPACE(4);
1382 WRITE32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001383 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001384 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385}
1386
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001387static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388{
Al Viro8687b632006-10-19 23:28:48 -07001389 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390
1391 RESERVE_SPACE(8 + name->len);
1392 WRITE32(OP_REMOVE);
1393 WRITE32(name->len);
1394 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001395 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001396 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397}
1398
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001399static 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 -07001400{
Al Viro8687b632006-10-19 23:28:48 -07001401 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
1403 RESERVE_SPACE(8 + oldname->len);
1404 WRITE32(OP_RENAME);
1405 WRITE32(oldname->len);
1406 WRITEMEM(oldname->name, oldname->len);
Andy Adamson6c0195a2008-12-23 16:06:15 -05001407
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 RESERVE_SPACE(4 + newname->len);
1409 WRITE32(newname->len);
1410 WRITEMEM(newname->name, newname->len);
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
1419 RESERVE_SPACE(12);
1420 WRITE32(OP_RENEW);
1421 WRITE64(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
1431 RESERVE_SPACE(4);
1432 WRITE32(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
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001442 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001443 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001444 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001445 RESERVE_SPACE(2*4);
1446 WRITE32(1);
1447 WRITE32(FATTR4_WORD0_ACL);
1448 if (arg->acl_len % 4)
1449 return -EINVAL;
1450 RESERVE_SPACE(4);
1451 WRITE32(arg->acl_len);
1452 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
1463 RESERVE_SPACE(4);
1464 WRITE32(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
Andy Adamson05d564f2008-12-23 16:06:15 -05001473 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1474 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001475 WRITEMEM(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
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001485 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 WRITE32(OP_SETCLIENTID);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001487 WRITEMEM(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);
1490 RESERVE_SPACE(4);
1491 WRITE32(setclientid->sc_prog);
1492 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1493 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1494 RESERVE_SPACE(4);
1495 WRITE32(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
Andy Adamson05d564f2008-12-23 16:06:15 -05001504 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1505 WRITE32(OP_SETCLIENTID_CONFIRM);
1506 WRITE64(client_state->cl_clientid);
1507 WRITEMEM(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
1516 RESERVE_SPACE(4);
1517 WRITE32(OP_WRITE);
1518
1519 encode_stateid(xdr, args->context);
1520
1521 RESERVE_SPACE(16);
1522 WRITE64(args->offset);
1523 WRITE32(args->stable);
1524 WRITE32(args->count);
1525
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
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001535 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
1537 WRITE32(OP_DELEGRETURN);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001538 WRITEMEM(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
1551 RESERVE_SPACE(4 + sizeof(args->verifier->data));
1552 WRITE32(OP_EXCHANGE_ID);
1553 WRITEMEM(args->verifier->data, sizeof(args->verifier->data));
1554
1555 encode_string(xdr, args->id_len, args->id);
1556
1557 RESERVE_SPACE(12);
1558 WRITE32(args->flags);
1559 WRITE32(0); /* zero length state_protect4_a */
1560 WRITE32(0); /* zero length implementation id array */
1561 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
1574 RESERVE_SPACE(4);
1575 WRITE32(OP_CREATE_SESSION);
1576
1577 RESERVE_SPACE(8);
1578 WRITE64(clp->cl_ex_clid);
1579
1580 RESERVE_SPACE(8);
1581 WRITE32(clp->cl_seqid); /*Sequence id */
1582 WRITE32(args->flags); /*flags */
1583
1584 RESERVE_SPACE(2*28); /* 2 channel_attrs */
1585 /* Fore Channel */
1586 WRITE32(args->fc_attrs.headerpadsz); /* header padding size */
1587 WRITE32(args->fc_attrs.max_rqst_sz); /* max req size */
1588 WRITE32(args->fc_attrs.max_resp_sz); /* max resp size */
1589 WRITE32(args->fc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1590 WRITE32(args->fc_attrs.max_ops); /* max operations */
1591 WRITE32(args->fc_attrs.max_reqs); /* max requests */
1592 WRITE32(0); /* rdmachannel_attrs */
1593
1594 /* Back Channel */
1595 WRITE32(args->fc_attrs.headerpadsz); /* header padding size */
1596 WRITE32(args->bc_attrs.max_rqst_sz); /* max req size */
1597 WRITE32(args->bc_attrs.max_resp_sz); /* max resp size */
1598 WRITE32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1599 WRITE32(args->bc_attrs.max_ops); /* max operations */
1600 WRITE32(args->bc_attrs.max_reqs); /* max requests */
1601 WRITE32(0); /* rdmachannel_attrs */
1602
1603 RESERVE_SPACE(4);
1604 WRITE32(args->cb_program); /* cb_program */
1605
1606 RESERVE_SPACE(4); /* # of security flavors */
1607 WRITE32(1);
1608
1609 RESERVE_SPACE(4);
1610 WRITE32(RPC_AUTH_UNIX); /* auth_sys */
1611
1612 /* authsys_parms rfc1831 */
1613 RESERVE_SPACE(4);
1614 WRITE32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
1615 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1616 clp->cl_ipaddr);
1617 RESERVE_SPACE(16 + len);
1618 WRITE32(len);
1619 WRITEMEM(machine_name, len);
1620 WRITE32(0); /* UID */
1621 WRITE32(0); /* GID */
1622 WRITE32(0); /* No more gids */
1623 hdr->nops++;
1624 hdr->replen += decode_create_session_maxsz;
1625}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001626
1627static void encode_destroy_session(struct xdr_stream *xdr,
1628 struct nfs4_session *session,
1629 struct compound_hdr *hdr)
1630{
1631 __be32 *p;
1632 RESERVE_SPACE(4 + NFS4_MAX_SESSIONID_LEN);
1633 WRITE32(OP_DESTROY_SESSION);
1634 WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1635 hdr->nops++;
1636 hdr->replen += decode_destroy_session_maxsz;
1637}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001638#endif /* CONFIG_NFS_V4_1 */
1639
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001640static void encode_sequence(struct xdr_stream *xdr,
1641 const struct nfs4_sequence_args *args,
1642 struct compound_hdr *hdr)
1643{
1644#if defined(CONFIG_NFS_V4_1)
1645 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001646 struct nfs4_slot_table *tp;
1647 struct nfs4_slot *slot;
1648 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001649
1650 if (!session)
1651 return;
1652
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001653 tp = &session->fc_slot_table;
1654
1655 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1656 slot = tp->slots + args->sa_slotid;
1657
1658 RESERVE_SPACE(4);
1659 WRITE32(OP_SEQUENCE);
1660
1661 /*
1662 * Sessionid + seqid + slotid + max slotid + cache_this
1663 */
1664 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1665 "max_slotid=%d cache_this=%d\n",
1666 __func__,
1667 ((u32 *)session->sess_id.data)[0],
1668 ((u32 *)session->sess_id.data)[1],
1669 ((u32 *)session->sess_id.data)[2],
1670 ((u32 *)session->sess_id.data)[3],
1671 slot->seq_nr, args->sa_slotid,
1672 tp->highest_used_slotid, args->sa_cache_this);
1673 RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 16);
1674 WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1675 WRITE32(slot->seq_nr);
1676 WRITE32(args->sa_slotid);
1677 WRITE32(tp->highest_used_slotid);
1678 WRITE32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001679 hdr->nops++;
1680 hdr->replen += decode_sequence_maxsz;
1681#endif /* CONFIG_NFS_V4_1 */
1682}
1683
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684/*
1685 * END OF "GENERIC" ENCODE ROUTINES.
1686 */
1687
Benny Halevy66cc0422009-04-01 09:22:10 -04001688static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1689{
1690#if defined(CONFIG_NFS_V4_1)
1691 if (args->sa_session)
1692 return args->sa_session->clp->cl_minorversion;
1693#endif /* CONFIG_NFS_V4_1 */
1694 return 0;
1695}
1696
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697/*
1698 * Encode an ACCESS request
1699 */
Al Viro8687b632006-10-19 23:28:48 -07001700static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701{
1702 struct xdr_stream xdr;
1703 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001704 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
1707 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001708 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001709 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001710 encode_putfh(&xdr, args->fh, &hdr);
1711 encode_access(&xdr, args->access, &hdr);
1712 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001713 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001714 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715}
1716
1717/*
1718 * Encode LOOKUP request
1719 */
Al Viro8687b632006-10-19 23:28:48 -07001720static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721{
1722 struct xdr_stream xdr;
1723 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001724 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
1727 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001728 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001729 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001730 encode_putfh(&xdr, args->dir_fh, &hdr);
1731 encode_lookup(&xdr, args->name, &hdr);
1732 encode_getfh(&xdr, &hdr);
1733 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001734 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001735 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736}
1737
1738/*
1739 * Encode LOOKUP_ROOT request
1740 */
Al Viro8687b632006-10-19 23:28:48 -07001741static 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 -07001742{
1743 struct xdr_stream xdr;
1744 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001745 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
1748 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001749 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001750 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001751 encode_putrootfh(&xdr, &hdr);
1752 encode_getfh(&xdr, &hdr);
1753 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001754 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001755 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756}
1757
1758/*
1759 * Encode REMOVE request
1760 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001761static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762{
1763 struct xdr_stream xdr;
1764 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001765 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767
1768 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001769 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001770 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001771 encode_putfh(&xdr, args->fh, &hdr);
1772 encode_remove(&xdr, &args->name, &hdr);
1773 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001774 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001775 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776}
1777
1778/*
1779 * Encode RENAME request
1780 */
Al Viro8687b632006-10-19 23:28:48 -07001781static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782{
1783 struct xdr_stream xdr;
1784 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001785 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
1788 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001789 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001790 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001791 encode_putfh(&xdr, args->old_dir, &hdr);
1792 encode_savefh(&xdr, &hdr);
1793 encode_putfh(&xdr, args->new_dir, &hdr);
1794 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1795 encode_getfattr(&xdr, args->bitmask, &hdr);
1796 encode_restorefh(&xdr, &hdr);
1797 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001798 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001799 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800}
1801
1802/*
1803 * Encode LINK request
1804 */
Al Viro8687b632006-10-19 23:28:48 -07001805static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806{
1807 struct xdr_stream xdr;
1808 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001809 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
1812 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001813 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001814 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001815 encode_putfh(&xdr, args->fh, &hdr);
1816 encode_savefh(&xdr, &hdr);
1817 encode_putfh(&xdr, args->dir_fh, &hdr);
1818 encode_link(&xdr, args->name, &hdr);
1819 encode_getfattr(&xdr, args->bitmask, &hdr);
1820 encode_restorefh(&xdr, &hdr);
1821 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001822 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001823 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824}
1825
1826/*
1827 * Encode CREATE request
1828 */
Al Viro8687b632006-10-19 23:28:48 -07001829static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830{
1831 struct xdr_stream xdr;
1832 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001833 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
1836 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001837 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001838 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001839 encode_putfh(&xdr, args->dir_fh, &hdr);
1840 encode_savefh(&xdr, &hdr);
1841 encode_create(&xdr, args, &hdr);
1842 encode_getfh(&xdr, &hdr);
1843 encode_getfattr(&xdr, args->bitmask, &hdr);
1844 encode_restorefh(&xdr, &hdr);
1845 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001846 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001847 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848}
1849
1850/*
1851 * Encode SYMLINK request
1852 */
Al Viro8687b632006-10-19 23:28:48 -07001853static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854{
1855 return nfs4_xdr_enc_create(req, p, args);
1856}
1857
1858/*
1859 * Encode GETATTR request
1860 */
Al Viro8687b632006-10-19 23:28:48 -07001861static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862{
1863 struct xdr_stream xdr;
1864 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001865 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867
1868 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001869 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001870 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001871 encode_putfh(&xdr, args->fh, &hdr);
1872 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001873 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001874 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875}
1876
1877/*
1878 * Encode a CLOSE request
1879 */
Al Viro8687b632006-10-19 23:28:48 -07001880static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881{
Andy Adamson05d564f2008-12-23 16:06:15 -05001882 struct xdr_stream xdr;
1883 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001884 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001885 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
Andy Adamson05d564f2008-12-23 16:06:15 -05001887 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001888 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001889 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001890 encode_putfh(&xdr, args->fh, &hdr);
1891 encode_close(&xdr, args, &hdr);
1892 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001893 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001894 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895}
1896
1897/*
1898 * Encode an OPEN request
1899 */
Al Viro8687b632006-10-19 23:28:48 -07001900static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901{
1902 struct xdr_stream xdr;
1903 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001904 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906
1907 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001908 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001909 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001910 encode_putfh(&xdr, args->fh, &hdr);
1911 encode_savefh(&xdr, &hdr);
1912 encode_open(&xdr, args, &hdr);
1913 encode_getfh(&xdr, &hdr);
1914 encode_getfattr(&xdr, args->bitmask, &hdr);
1915 encode_restorefh(&xdr, &hdr);
1916 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001917 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001918 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919}
1920
1921/*
1922 * Encode an OPEN_CONFIRM request
1923 */
Al Viro8687b632006-10-19 23:28:48 -07001924static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925{
1926 struct xdr_stream xdr;
1927 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001928 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930
1931 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001932 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001933 encode_putfh(&xdr, args->fh, &hdr);
1934 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001935 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001936 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937}
1938
1939/*
1940 * Encode an OPEN request with no attributes.
1941 */
Al Viro8687b632006-10-19 23:28:48 -07001942static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943{
1944 struct xdr_stream xdr;
1945 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001946 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
1949 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001950 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001951 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001952 encode_putfh(&xdr, args->fh, &hdr);
1953 encode_open(&xdr, args, &hdr);
1954 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001955 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001956 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957}
1958
1959/*
1960 * Encode an OPEN_DOWNGRADE request
1961 */
Al Viro8687b632006-10-19 23:28:48 -07001962static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963{
1964 struct xdr_stream xdr;
1965 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001966 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968
1969 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001970 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001971 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001972 encode_putfh(&xdr, args->fh, &hdr);
1973 encode_open_downgrade(&xdr, args, &hdr);
1974 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001975 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001976 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977}
1978
1979/*
1980 * Encode a LOCK request
1981 */
Al Viro8687b632006-10-19 23:28:48 -07001982static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983{
1984 struct xdr_stream xdr;
1985 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001986 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
1989 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001990 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001991 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001992 encode_putfh(&xdr, args->fh, &hdr);
1993 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001994 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001995 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996}
1997
1998/*
1999 * Encode a LOCKT request
2000 */
Al Viro8687b632006-10-19 23:28:48 -07002001static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002{
2003 struct xdr_stream xdr;
2004 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002005 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007
2008 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002009 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002010 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002011 encode_putfh(&xdr, args->fh, &hdr);
2012 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002013 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002014 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015}
2016
2017/*
2018 * Encode a LOCKU request
2019 */
Al Viro8687b632006-10-19 23:28:48 -07002020static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021{
2022 struct xdr_stream xdr;
2023 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002024 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
2027 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002028 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002029 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002030 encode_putfh(&xdr, args->fh, &hdr);
2031 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002032 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002033 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034}
2035
2036/*
2037 * Encode a READLINK request
2038 */
Al Viro8687b632006-10-19 23:28:48 -07002039static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040{
2041 struct xdr_stream xdr;
2042 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002043 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
2046 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002047 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002048 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002049 encode_putfh(&xdr, args->fh, &hdr);
2050 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002051
Benny Halevy28f56692009-04-01 09:22:09 -04002052 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002053 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002054 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002055 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056}
2057
2058/*
2059 * Encode a READDIR request
2060 */
Al Viro8687b632006-10-19 23:28:48 -07002061static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062{
2063 struct xdr_stream xdr;
2064 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002065 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067
2068 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002069 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002070 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002071 encode_putfh(&xdr, args->fh, &hdr);
2072 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002073
Benny Halevy28f56692009-04-01 09:22:09 -04002074 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002075 args->pgbase, args->count);
2076 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002077 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002078 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002079 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002080 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081}
2082
2083/*
2084 * Encode a READ request
2085 */
Al Viro8687b632006-10-19 23:28:48 -07002086static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 struct xdr_stream xdr;
2089 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002090 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092
2093 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002094 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002095 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002096 encode_putfh(&xdr, args->fh, &hdr);
2097 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
Benny Halevy28f56692009-04-01 09:22:09 -04002099 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002101 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002102 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002103 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104}
2105
2106/*
2107 * Encode an SETATTR request
2108 */
Al Viro8687b632006-10-19 23:28:48 -07002109static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110{
Andy Adamson05d564f2008-12-23 16:06:15 -05002111 struct xdr_stream xdr;
2112 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002113 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002114 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
Andy Adamson05d564f2008-12-23 16:06:15 -05002116 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002117 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002118 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002119 encode_putfh(&xdr, args->fh, &hdr);
2120 encode_setattr(&xdr, args, args->server, &hdr);
2121 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002122 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002123 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124}
2125
2126/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002127 * Encode a GETACL request
2128 */
2129static int
Al Viro8687b632006-10-19 23:28:48 -07002130nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002131 struct nfs_getaclargs *args)
2132{
2133 struct xdr_stream xdr;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002134 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002135 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002136 };
Benny Halevy28f56692009-04-01 09:22:09 -04002137 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002138
2139 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002140 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002141 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002142 encode_putfh(&xdr, args->fh, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002143 replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002144 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2145
Benny Halevy28f56692009-04-01 09:22:09 -04002146 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002147 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002148 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002149 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002150}
2151
2152/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 * Encode a WRITE request
2154 */
Al Viro8687b632006-10-19 23:28:48 -07002155static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156{
2157 struct xdr_stream xdr;
2158 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002159 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
2162 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002163 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002164 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002165 encode_putfh(&xdr, args->fh, &hdr);
2166 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002167 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002168 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002169 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002170 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171}
2172
2173/*
2174 * a COMMIT request
2175 */
Al Viro8687b632006-10-19 23:28:48 -07002176static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177{
2178 struct xdr_stream xdr;
2179 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002180 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
2183 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002184 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002185 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002186 encode_putfh(&xdr, args->fh, &hdr);
2187 encode_commit(&xdr, args, &hdr);
2188 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002189 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002190 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191}
2192
2193/*
2194 * FSINFO request
2195 */
Al Viro8687b632006-10-19 23:28:48 -07002196static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197{
2198 struct xdr_stream xdr;
2199 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002200 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
2203 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002204 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002205 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002206 encode_putfh(&xdr, args->fh, &hdr);
2207 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002208 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002209 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210}
2211
2212/*
2213 * a PATHCONF request
2214 */
Al Viro8687b632006-10-19 23:28:48 -07002215static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 struct xdr_stream xdr;
2218 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002219 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
2222 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002223 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002224 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002225 encode_putfh(&xdr, args->fh, &hdr);
2226 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2227 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002228 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002229 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230}
2231
2232/*
2233 * a STATFS request
2234 */
Al Viro8687b632006-10-19 23:28:48 -07002235static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 struct xdr_stream xdr;
2238 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002239 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
2242 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002243 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002244 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002245 encode_putfh(&xdr, args->fh, &hdr);
2246 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2247 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002248 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002249 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250}
2251
2252/*
2253 * GETATTR_BITMAP request
2254 */
Benny Halevy43652ad2009-04-01 09:21:54 -04002255static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2256 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257{
2258 struct xdr_stream xdr;
2259 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002260 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
2263 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002264 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002265 encode_sequence(&xdr, &args->seq_args, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04002266 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002267 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2268 FATTR4_WORD0_LINK_SUPPORT|
2269 FATTR4_WORD0_SYMLINK_SUPPORT|
2270 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002271 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002272 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273}
2274
2275/*
2276 * a RENEW request
2277 */
Al Viro8687b632006-10-19 23:28:48 -07002278static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279{
2280 struct xdr_stream xdr;
2281 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002282 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 };
2284
2285 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002286 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002287 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002288 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002289 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290}
2291
2292/*
2293 * a SETCLIENTID request
2294 */
Al Viro8687b632006-10-19 23:28:48 -07002295static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296{
2297 struct xdr_stream xdr;
2298 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002299 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 };
2301
2302 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002303 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002304 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002305 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002306 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307}
2308
2309/*
2310 * a SETCLIENTID_CONFIRM request
2311 */
Al Viro8687b632006-10-19 23:28:48 -07002312static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313{
2314 struct xdr_stream xdr;
2315 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002316 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 };
2318 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319
2320 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002321 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002322 encode_setclientid_confirm(&xdr, clp, &hdr);
2323 encode_putrootfh(&xdr, &hdr);
2324 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002325 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002326 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327}
2328
2329/*
2330 * DELEGRETURN request
2331 */
Al Viro8687b632006-10-19 23:28:48 -07002332static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333{
2334 struct xdr_stream xdr;
2335 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002336 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
2339 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002340 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002341 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002342 encode_putfh(&xdr, args->fhandle, &hdr);
2343 encode_delegreturn(&xdr, args->stateid, &hdr);
2344 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002345 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002346 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347}
2348
2349/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002350 * Encode FS_LOCATIONS request
2351 */
Al Viro8687b632006-10-19 23:28:48 -07002352static 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 -04002353{
2354 struct xdr_stream xdr;
2355 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002356 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002357 };
Benny Halevy28f56692009-04-01 09:22:09 -04002358 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002359
2360 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002361 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002362 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002363 encode_putfh(&xdr, args->dir_fh, &hdr);
2364 encode_lookup(&xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002365 replen = hdr.replen; /* get the attribute into args->page */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002366 encode_fs_locations(&xdr, args->bitmask, &hdr);
2367
Benny Halevy28f56692009-04-01 09:22:09 -04002368 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002369 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002370 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002371 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002372}
2373
Benny Halevy99fe60d2009-04-01 09:22:29 -04002374#if defined(CONFIG_NFS_V4_1)
2375/*
2376 * EXCHANGE_ID request
2377 */
2378static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2379 struct nfs41_exchange_id_args *args)
2380{
2381 struct xdr_stream xdr;
2382 struct compound_hdr hdr = {
2383 .minorversion = args->client->cl_minorversion,
2384 };
2385
2386 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2387 encode_compound_hdr(&xdr, req, &hdr);
2388 encode_exchange_id(&xdr, args, &hdr);
2389 encode_nops(&hdr);
2390 return 0;
2391}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002392
2393/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002394 * a CREATE_SESSION request
2395 */
2396static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2397 struct nfs41_create_session_args *args)
2398{
2399 struct xdr_stream xdr;
2400 struct compound_hdr hdr = {
2401 .minorversion = args->client->cl_minorversion,
2402 };
2403
2404 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2405 encode_compound_hdr(&xdr, req, &hdr);
2406 encode_create_session(&xdr, args, &hdr);
2407 encode_nops(&hdr);
2408 return 0;
2409}
2410
2411/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002412 * a DESTROY_SESSION request
2413 */
2414static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2415 struct nfs4_session *session)
2416{
2417 struct xdr_stream xdr;
2418 struct compound_hdr hdr = {
2419 .minorversion = session->clp->cl_minorversion,
2420 };
2421
2422 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2423 encode_compound_hdr(&xdr, req, &hdr);
2424 encode_destroy_session(&xdr, session, &hdr);
2425 encode_nops(&hdr);
2426 return 0;
2427}
2428
2429/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002430 * a SEQUENCE request
2431 */
2432static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p,
2433 struct nfs4_sequence_args *args)
2434{
2435 struct xdr_stream xdr;
2436 struct compound_hdr hdr = {
2437 .minorversion = nfs4_xdr_minorversion(args),
2438 };
2439
2440 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2441 encode_compound_hdr(&xdr, req, &hdr);
2442 encode_sequence(&xdr, args, &hdr);
2443 encode_nops(&hdr);
2444 return 0;
2445}
2446
2447/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002448 * a GET_LEASE_TIME request
2449 */
2450static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2451 struct nfs4_get_lease_time_args *args)
2452{
2453 struct xdr_stream xdr;
2454 struct compound_hdr hdr = {
2455 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2456 };
2457 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2458
2459 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2460 encode_compound_hdr(&xdr, req, &hdr);
2461 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2462 encode_putrootfh(&xdr, &hdr);
2463 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2464 encode_nops(&hdr);
2465 return 0;
2466}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002467#endif /* CONFIG_NFS_V4_1 */
2468
Trond Myklebust683b57b2006-06-09 09:34:22 -04002469/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 * START OF "GENERIC" DECODE ROUTINES.
2471 * These may look a little ugly since they are imported from a "generic"
2472 * set of XDR encode/decode routines which are intended to be shared by
2473 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2474 *
2475 * If the pain of reading these is too great, it should be a straightforward
2476 * task to translate them into Linux-specific versions which are more
2477 * consistent with the style used in NFSv2/v3...
2478 */
2479#define READ32(x) (x) = ntohl(*p++)
2480#define READ64(x) do { \
2481 (x) = (u64)ntohl(*p++) << 32; \
2482 (x) |= ntohl(*p++); \
2483} while (0)
2484#define READTIME(x) do { \
2485 p++; \
2486 (x.tv_sec) = ntohl(*p++); \
2487 (x.tv_nsec) = ntohl(*p++); \
2488} while (0)
2489#define COPYMEM(x,nbytes) do { \
2490 memcpy((x), p, nbytes); \
2491 p += XDR_QUADLEN(nbytes); \
2492} while (0)
2493
2494#define READ_BUF(nbytes) do { \
2495 p = xdr_inline_decode(xdr, nbytes); \
Chuck Levere4cc6ee2007-05-08 18:23:28 -04002496 if (unlikely(!p)) { \
Chuck Leverfe82a182007-09-11 18:01:10 -04002497 dprintk("nfs: %s: prematurely hit end of receive" \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002498 " buffer\n", __func__); \
Chuck Leverfe82a182007-09-11 18:01:10 -04002499 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002500 __func__, xdr->p, nbytes, xdr->end); \
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 return -EIO; \
2502 } \
2503} while (0)
2504
Trond Myklebust683b57b2006-06-09 09:34:22 -04002505static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506{
Al Viro8687b632006-10-19 23:28:48 -07002507 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508
2509 READ_BUF(4);
2510 READ32(*len);
2511 READ_BUF(*len);
2512 *string = (char *)p;
2513 return 0;
2514}
2515
2516static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2517{
Al Viro8687b632006-10-19 23:28:48 -07002518 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519
2520 READ_BUF(8);
2521 READ32(hdr->status);
2522 READ32(hdr->taglen);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002523
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 READ_BUF(hdr->taglen + 4);
2525 hdr->tag = (char *)p;
2526 p += XDR_QUADLEN(hdr->taglen);
2527 READ32(hdr->nops);
Benny Halevyaadf6152008-12-23 16:06:13 -05002528 if (unlikely(hdr->nops < 1))
2529 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 return 0;
2531}
2532
2533static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2534{
Al Viro8687b632006-10-19 23:28:48 -07002535 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 uint32_t opnum;
2537 int32_t nfserr;
2538
2539 READ_BUF(8);
2540 READ32(opnum);
2541 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002542 dprintk("nfs: Server returned operation"
2543 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 opnum, expected);
2545 return -EIO;
2546 }
2547 READ32(nfserr);
2548 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002549 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 return 0;
2551}
2552
2553/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002554static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555{
Al Viro8687b632006-10-19 23:28:48 -07002556 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002557 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 char *str;
2559
2560 READ_BUF(12);
2561 return decode_opaque_inline(xdr, &strlen, &str);
2562}
2563
2564static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2565{
Al Viro8687b632006-10-19 23:28:48 -07002566 uint32_t bmlen;
2567 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568
2569 READ_BUF(4);
2570 READ32(bmlen);
2571
2572 bitmap[0] = bitmap[1] = 0;
2573 READ_BUF((bmlen << 2));
2574 if (bmlen > 0) {
2575 READ32(bitmap[0]);
2576 if (bmlen > 1)
2577 READ32(bitmap[1]);
2578 }
2579 return 0;
2580}
2581
Al Viro8687b632006-10-19 23:28:48 -07002582static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583{
Al Viro8687b632006-10-19 23:28:48 -07002584 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585
2586 READ_BUF(4);
2587 READ32(*attrlen);
2588 *savep = xdr->p;
2589 return 0;
2590}
2591
2592static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2593{
2594 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2595 decode_attr_bitmap(xdr, bitmask);
2596 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2597 } else
2598 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002599 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 return 0;
2601}
2602
2603static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2604{
Al Viro8687b632006-10-19 23:28:48 -07002605 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002606 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607
2608 *type = 0;
2609 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2610 return -EIO;
2611 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2612 READ_BUF(4);
2613 READ32(*type);
2614 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002615 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 return -EIO;
2617 }
2618 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002619 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002621 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002622 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623}
2624
2625static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2626{
Al Viro8687b632006-10-19 23:28:48 -07002627 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002628 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629
2630 *change = 0;
2631 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2632 return -EIO;
2633 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2634 READ_BUF(8);
2635 READ64(*change);
2636 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002637 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002639 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002641 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642}
2643
2644static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2645{
Al Viro8687b632006-10-19 23:28:48 -07002646 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002647 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648
2649 *size = 0;
2650 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2651 return -EIO;
2652 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2653 READ_BUF(8);
2654 READ64(*size);
2655 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002656 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002658 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002659 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660}
2661
2662static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2663{
Al Viro8687b632006-10-19 23:28:48 -07002664 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665
2666 *res = 0;
2667 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2668 return -EIO;
2669 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2670 READ_BUF(4);
2671 READ32(*res);
2672 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2673 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002674 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 return 0;
2676}
2677
2678static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2679{
Al Viro8687b632006-10-19 23:28:48 -07002680 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681
2682 *res = 0;
2683 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2684 return -EIO;
2685 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2686 READ_BUF(4);
2687 READ32(*res);
2688 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2689 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002690 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 return 0;
2692}
2693
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002694static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695{
Al Viro8687b632006-10-19 23:28:48 -07002696 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002697 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
2699 fsid->major = 0;
2700 fsid->minor = 0;
2701 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2702 return -EIO;
2703 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2704 READ_BUF(16);
2705 READ64(fsid->major);
2706 READ64(fsid->minor);
2707 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002708 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002710 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 (unsigned long long)fsid->major,
2712 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002713 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714}
2715
2716static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2717{
Al Viro8687b632006-10-19 23:28:48 -07002718 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719
2720 *res = 60;
2721 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2722 return -EIO;
2723 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2724 READ_BUF(4);
2725 READ32(*res);
2726 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2727 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002728 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 return 0;
2730}
2731
2732static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2733{
Al Viro8687b632006-10-19 23:28:48 -07002734 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735
2736 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2737 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2738 return -EIO;
2739 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2740 READ_BUF(4);
2741 READ32(*res);
2742 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2743 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002744 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 return 0;
2746}
2747
2748static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2749{
Al Viro8687b632006-10-19 23:28:48 -07002750 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002751 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752
2753 *fileid = 0;
2754 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2755 return -EIO;
2756 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2757 READ_BUF(8);
2758 READ64(*fileid);
2759 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002760 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002762 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002763 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764}
2765
Manoj Naik99baf622006-06-09 09:34:24 -04002766static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2767{
Al Viro8687b632006-10-19 23:28:48 -07002768 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002769 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002770
2771 *fileid = 0;
2772 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2773 return -EIO;
2774 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2775 READ_BUF(8);
2776 READ64(*fileid);
2777 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002778 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002779 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002780 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002781 return ret;
Manoj Naik99baf622006-06-09 09:34:24 -04002782}
2783
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2785{
Al Viro8687b632006-10-19 23:28:48 -07002786 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 int status = 0;
2788
2789 *res = 0;
2790 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2791 return -EIO;
2792 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2793 READ_BUF(8);
2794 READ64(*res);
2795 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2796 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002797 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 return status;
2799}
2800
2801static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2802{
Al Viro8687b632006-10-19 23:28:48 -07002803 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 int status = 0;
2805
2806 *res = 0;
2807 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2808 return -EIO;
2809 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2810 READ_BUF(8);
2811 READ64(*res);
2812 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2813 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002814 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 return status;
2816}
2817
2818static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2819{
Al Viro8687b632006-10-19 23:28:48 -07002820 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 int status = 0;
2822
2823 *res = 0;
2824 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2825 return -EIO;
2826 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2827 READ_BUF(8);
2828 READ64(*res);
2829 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2830 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002831 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 return status;
2833}
2834
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002835static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2836{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002837 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002838 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002839 int status = 0;
2840
2841 READ_BUF(4);
2842 READ32(n);
Andy Adamson33a43f22006-06-09 09:34:30 -04002843 if (n == 0)
2844 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002845 dprintk("path ");
2846 path->ncomponents = 0;
2847 while (path->ncomponents < n) {
2848 struct nfs4_string *component = &path->components[path->ncomponents];
2849 status = decode_opaque_inline(xdr, &component->len, &component->data);
2850 if (unlikely(status != 0))
2851 goto out_eio;
2852 if (path->ncomponents != n)
2853 dprintk("/");
2854 dprintk("%s", component->data);
2855 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2856 path->ncomponents++;
2857 else {
2858 dprintk("cannot parse %d components in path\n", n);
2859 goto out_eio;
2860 }
2861 }
2862out:
2863 dprintk("\n");
2864 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002865root_path:
2866/* a root pathname is sent as a zero component4 */
2867 path->ncomponents = 1;
2868 path->components[0].len=0;
2869 path->components[0].data=NULL;
2870 dprintk("path /\n");
2871 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002872out_eio:
2873 dprintk(" status %d", status);
2874 status = -EIO;
2875 goto out;
2876}
2877
2878static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002879{
2880 int n;
Al Viro8687b632006-10-19 23:28:48 -07002881 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002882 int status = -EIO;
2883
2884 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2885 goto out;
2886 status = 0;
2887 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2888 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002889 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002890 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002891 if (unlikely(status != 0))
2892 goto out;
2893 READ_BUF(4);
2894 READ32(n);
2895 if (n <= 0)
2896 goto out_eio;
2897 res->nlocations = 0;
2898 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002899 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002900 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04002901
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002902 READ_BUF(4);
2903 READ32(m);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002904
2905 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002906 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002907 while (loc->nservers < m) {
2908 struct nfs4_string *server = &loc->servers[loc->nservers];
2909 status = decode_opaque_inline(xdr, &server->len, &server->data);
2910 if (unlikely(status != 0))
2911 goto out_eio;
2912 dprintk("%s ", server->data);
2913 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2914 loc->nservers++;
2915 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002916 unsigned int i;
2917 dprintk("%s: using first %u of %u servers "
2918 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002919 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04002920 NFS4_FS_LOCATION_MAXSERVERS,
2921 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002922 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002923 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002924 char *data;
2925 status = decode_opaque_inline(xdr, &len, &data);
2926 if (unlikely(status != 0))
2927 goto out_eio;
2928 }
2929 }
2930 }
2931 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002932 if (unlikely(status != 0))
2933 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002934 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002935 res->nlocations++;
2936 }
Trond Myklebust409924e2009-03-11 14:10:27 -04002937 if (res->nlocations != 0)
2938 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002939out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002940 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002941 return status;
2942out_eio:
2943 status = -EIO;
2944 goto out;
2945}
2946
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2948{
Al Viro8687b632006-10-19 23:28:48 -07002949 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 int status = 0;
2951
2952 *res = 0;
2953 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2954 return -EIO;
2955 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2956 READ_BUF(8);
2957 READ64(*res);
2958 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2959 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002960 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 return status;
2962}
2963
2964static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2965{
Al Viro8687b632006-10-19 23:28:48 -07002966 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 int status = 0;
2968
2969 *maxlink = 1;
2970 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2971 return -EIO;
2972 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2973 READ_BUF(4);
2974 READ32(*maxlink);
2975 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2976 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002977 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 return status;
2979}
2980
2981static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2982{
Al Viro8687b632006-10-19 23:28:48 -07002983 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 int status = 0;
2985
2986 *maxname = 1024;
2987 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2988 return -EIO;
2989 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2990 READ_BUF(4);
2991 READ32(*maxname);
2992 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2993 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002994 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 return status;
2996}
2997
2998static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2999{
Al Viro8687b632006-10-19 23:28:48 -07003000 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 int status = 0;
3002
3003 *res = 1024;
3004 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3005 return -EIO;
3006 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3007 uint64_t maxread;
3008 READ_BUF(8);
3009 READ64(maxread);
3010 if (maxread > 0x7FFFFFFF)
3011 maxread = 0x7FFFFFFF;
3012 *res = (uint32_t)maxread;
3013 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3014 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003015 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 return status;
3017}
3018
3019static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3020{
Al Viro8687b632006-10-19 23:28:48 -07003021 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 int status = 0;
3023
3024 *res = 1024;
3025 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3026 return -EIO;
3027 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3028 uint64_t maxwrite;
3029 READ_BUF(8);
3030 READ64(maxwrite);
3031 if (maxwrite > 0x7FFFFFFF)
3032 maxwrite = 0x7FFFFFFF;
3033 *res = (uint32_t)maxwrite;
3034 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3035 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003036 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 return status;
3038}
3039
Trond Myklebustbca79472009-03-11 14:10:26 -04003040static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041{
Trond Myklebustbca79472009-03-11 14:10:26 -04003042 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003043 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003044 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045
3046 *mode = 0;
3047 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3048 return -EIO;
3049 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3050 READ_BUF(4);
Trond Myklebustbca79472009-03-11 14:10:26 -04003051 READ32(tmp);
3052 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003054 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003056 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003057 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058}
3059
3060static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3061{
Al Viro8687b632006-10-19 23:28:48 -07003062 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003063 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064
3065 *nlink = 1;
3066 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3067 return -EIO;
3068 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3069 READ_BUF(4);
3070 READ32(*nlink);
3071 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003072 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003074 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003075 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076}
3077
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003078static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3079 struct nfs_client *clp, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080{
Al Viro8687b632006-10-19 23:28:48 -07003081 uint32_t len;
3082 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003083 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084
3085 *uid = -2;
3086 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3087 return -EIO;
3088 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3089 READ_BUF(4);
3090 READ32(len);
3091 READ_BUF(len);
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003092 if (!may_sleep) {
3093 /* do nothing */
3094 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003095 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3096 ret = NFS_ATTR_FATTR_OWNER;
3097 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003099 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003101 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003102 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3104 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003105 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003106 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107}
3108
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003109static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3110 struct nfs_client *clp, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111{
Al Viro8687b632006-10-19 23:28:48 -07003112 uint32_t len;
3113 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003114 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115
3116 *gid = -2;
3117 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3118 return -EIO;
3119 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3120 READ_BUF(4);
3121 READ32(len);
3122 READ_BUF(len);
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003123 if (!may_sleep) {
3124 /* do nothing */
3125 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003126 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3127 ret = NFS_ATTR_FATTR_GROUP;
3128 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003130 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003132 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003133 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3135 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003136 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003137 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138}
3139
3140static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3141{
Al Viro8687b632006-10-19 23:28:48 -07003142 uint32_t major = 0, minor = 0;
3143 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003144 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145
3146 *rdev = MKDEV(0,0);
3147 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3148 return -EIO;
3149 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3150 dev_t tmp;
3151
3152 READ_BUF(8);
3153 READ32(major);
3154 READ32(minor);
3155 tmp = MKDEV(major, minor);
3156 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3157 *rdev = tmp;
3158 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003159 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003161 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003162 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163}
3164
3165static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3166{
Al Viro8687b632006-10-19 23:28:48 -07003167 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 int status = 0;
3169
3170 *res = 0;
3171 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3172 return -EIO;
3173 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3174 READ_BUF(8);
3175 READ64(*res);
3176 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3177 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003178 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 return status;
3180}
3181
3182static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3183{
Al Viro8687b632006-10-19 23:28:48 -07003184 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 int status = 0;
3186
3187 *res = 0;
3188 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3189 return -EIO;
3190 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3191 READ_BUF(8);
3192 READ64(*res);
3193 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3194 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003195 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 return status;
3197}
3198
3199static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3200{
Al Viro8687b632006-10-19 23:28:48 -07003201 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 int status = 0;
3203
3204 *res = 0;
3205 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3206 return -EIO;
3207 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3208 READ_BUF(8);
3209 READ64(*res);
3210 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3211 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003212 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 return status;
3214}
3215
3216static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3217{
Al Viro8687b632006-10-19 23:28:48 -07003218 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003219 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220
3221 *used = 0;
3222 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3223 return -EIO;
3224 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3225 READ_BUF(8);
3226 READ64(*used);
3227 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003228 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003230 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003232 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233}
3234
3235static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3236{
Al Viro8687b632006-10-19 23:28:48 -07003237 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 uint64_t sec;
3239 uint32_t nsec;
3240
3241 READ_BUF(12);
3242 READ64(sec);
3243 READ32(nsec);
3244 time->tv_sec = (time_t)sec;
3245 time->tv_nsec = (long)nsec;
3246 return 0;
3247}
3248
3249static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3250{
3251 int status = 0;
3252
3253 time->tv_sec = 0;
3254 time->tv_nsec = 0;
3255 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3256 return -EIO;
3257 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3258 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003259 if (status == 0)
3260 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3262 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003263 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 return status;
3265}
3266
3267static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3268{
3269 int status = 0;
3270
3271 time->tv_sec = 0;
3272 time->tv_nsec = 0;
3273 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3274 return -EIO;
3275 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3276 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003277 if (status == 0)
3278 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3280 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003281 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 return status;
3283}
3284
3285static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3286{
3287 int status = 0;
3288
3289 time->tv_sec = 0;
3290 time->tv_nsec = 0;
3291 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3292 return -EIO;
3293 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3294 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003295 if (status == 0)
3296 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3298 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003299 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 return status;
3301}
3302
Al Viro8687b632006-10-19 23:28:48 -07003303static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304{
3305 unsigned int attrwords = XDR_QUADLEN(attrlen);
3306 unsigned int nwords = xdr->p - savep;
3307
3308 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003309 dprintk("%s: server returned incorrect attribute length: "
3310 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003311 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 attrwords << 2,
3313 (attrwords < nwords) ? '<' : '>',
3314 nwords << 2);
3315 return -EIO;
3316 }
3317 return 0;
3318}
3319
3320static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3321{
Al Viro8687b632006-10-19 23:28:48 -07003322 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323
3324 READ_BUF(20);
3325 READ32(cinfo->atomic);
3326 READ64(cinfo->before);
3327 READ64(cinfo->after);
3328 return 0;
3329}
3330
3331static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3332{
Al Viro8687b632006-10-19 23:28:48 -07003333 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 uint32_t supp, acc;
3335 int status;
3336
3337 status = decode_op_hdr(xdr, OP_ACCESS);
3338 if (status)
3339 return status;
3340 READ_BUF(8);
3341 READ32(supp);
3342 READ32(acc);
3343 access->supported = supp;
3344 access->access = acc;
3345 return 0;
3346}
3347
3348static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3349{
Al Viro8687b632006-10-19 23:28:48 -07003350 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 int status;
3352
3353 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003354 if (status != -EIO)
3355 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 if (status)
3357 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003358 READ_BUF(NFS4_STATEID_SIZE);
3359 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 return 0;
3361}
3362
3363static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3364{
Al Viro8687b632006-10-19 23:28:48 -07003365 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 int status;
3367
3368 status = decode_op_hdr(xdr, OP_COMMIT);
3369 if (status)
3370 return status;
3371 READ_BUF(8);
3372 COPYMEM(res->verf->verifier, 8);
3373 return 0;
3374}
3375
3376static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3377{
Al Viro8687b632006-10-19 23:28:48 -07003378 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 uint32_t bmlen;
3380 int status;
3381
3382 status = decode_op_hdr(xdr, OP_CREATE);
3383 if (status)
3384 return status;
3385 if ((status = decode_change_info(xdr, cinfo)))
3386 return status;
3387 READ_BUF(4);
3388 READ32(bmlen);
3389 READ_BUF(bmlen << 2);
3390 return 0;
3391}
3392
3393static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3394{
Al Viro8687b632006-10-19 23:28:48 -07003395 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003396 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397 int status;
3398
3399 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3400 goto xdr_error;
3401 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3402 goto xdr_error;
3403 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3404 goto xdr_error;
3405 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3406 goto xdr_error;
3407 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3408 goto xdr_error;
3409 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3410 goto xdr_error;
3411 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3412 goto xdr_error;
3413 status = verify_attr_len(xdr, savep, attrlen);
3414xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003415 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 return status;
3417}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003418
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3420{
Al Viro8687b632006-10-19 23:28:48 -07003421 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003422 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003424
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3426 goto xdr_error;
3427 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3428 goto xdr_error;
3429 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3430 goto xdr_error;
3431
3432 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3433 goto xdr_error;
3434 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3435 goto xdr_error;
3436 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3437 goto xdr_error;
3438 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3439 goto xdr_error;
3440 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3441 goto xdr_error;
3442 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3443 goto xdr_error;
3444
3445 status = verify_attr_len(xdr, savep, attrlen);
3446xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003447 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 return status;
3449}
3450
3451static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3452{
Al Viro8687b632006-10-19 23:28:48 -07003453 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003454 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003456
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3458 goto xdr_error;
3459 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3460 goto xdr_error;
3461 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3462 goto xdr_error;
3463
3464 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3465 goto xdr_error;
3466 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3467 goto xdr_error;
3468
3469 status = verify_attr_len(xdr, savep, attrlen);
3470xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003471 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 return status;
3473}
3474
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003475static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3476 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477{
Al Viro8687b632006-10-19 23:28:48 -07003478 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 uint32_t attrlen,
3480 bitmap[2] = {0},
3481 type;
Trond Myklebustbca79472009-03-11 14:10:26 -04003482 int status;
3483 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003484 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003486 status = decode_op_hdr(xdr, OP_GETATTR);
3487 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 goto xdr_error;
3489
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003490 status = decode_attr_bitmap(xdr, bitmap);
3491 if (status < 0)
3492 goto xdr_error;
3493
3494 status = decode_attr_length(xdr, &attrlen, &savep);
3495 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496 goto xdr_error;
3497
3498
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003499 status = decode_attr_type(xdr, bitmap, &type);
3500 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003502 fattr->mode = 0;
3503 if (status != 0) {
3504 fattr->mode |= nfs_type2fmt[type];
3505 fattr->valid |= status;
3506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003508 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3509 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003511 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003512
3513 status = decode_attr_size(xdr, bitmap, &fattr->size);
3514 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003516 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003517
3518 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3519 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003521 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003522
3523 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3524 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003526 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003527
3528 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003529 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003530 fattr));
3531 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003532 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003533 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003534
3535 status = decode_attr_mode(xdr, bitmap, &fmode);
3536 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003538 if (status != 0) {
3539 fattr->mode |= fmode;
3540 fattr->valid |= status;
3541 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003542
3543 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3544 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003546 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003547
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003548 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3549 &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003550 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003552 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003553
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003554 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3555 &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003556 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003558 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003559
3560 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3561 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003563 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003564
3565 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3566 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003568 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003569
3570 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3571 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003573 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003574
3575 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3576 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003578 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003579
3580 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3581 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003583 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003584
3585 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3586 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003587 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003588 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003589 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003590 fattr->valid |= status;
3591 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003592
3593 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594xdr_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}
3598
3599
3600static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3601{
Al Viro8687b632006-10-19 23:28:48 -07003602 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 uint32_t attrlen, bitmap[2];
3604 int status;
3605
3606 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3607 goto xdr_error;
3608 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3609 goto xdr_error;
3610 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3611 goto xdr_error;
3612
3613 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3614
3615 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3616 goto xdr_error;
3617 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3618 goto xdr_error;
3619 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3620 goto xdr_error;
3621 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3622 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3623 goto xdr_error;
3624 fsinfo->wtpref = fsinfo->wtmax;
3625
3626 status = verify_attr_len(xdr, savep, attrlen);
3627xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003628 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 return status;
3630}
3631
3632static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3633{
Al Viro8687b632006-10-19 23:28:48 -07003634 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 uint32_t len;
3636 int status;
3637
Trond Myklebust99367812007-07-17 21:52:41 -04003638 /* Zero handle first to allow comparisons */
3639 memset(fh, 0, sizeof(*fh));
3640
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 status = decode_op_hdr(xdr, OP_GETFH);
3642 if (status)
3643 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644
3645 READ_BUF(4);
3646 READ32(len);
3647 if (len > NFS4_FHSIZE)
3648 return -EIO;
3649 fh->size = len;
3650 READ_BUF(len);
3651 COPYMEM(fh->data, len);
3652 return 0;
3653}
3654
3655static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3656{
3657 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003658
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 status = decode_op_hdr(xdr, OP_LINK);
3660 if (status)
3661 return status;
3662 return decode_change_info(xdr, cinfo);
3663}
3664
3665/*
3666 * We create the owner, so we know a proper owner.id length is 4.
3667 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003668static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003670 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003671 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003672 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673
3674 READ_BUF(32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003675 READ64(offset);
3676 READ64(length);
3677 READ32(type);
3678 if (fl != NULL) {
3679 fl->fl_start = (loff_t)offset;
3680 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3681 if (length == ~(uint64_t)0)
3682 fl->fl_end = OFFSET_MAX;
3683 fl->fl_type = F_WRLCK;
3684 if (type & 1)
3685 fl->fl_type = F_RDLCK;
3686 fl->fl_pid = 0;
3687 }
3688 READ64(clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 READ32(namelen);
3690 READ_BUF(namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 return -NFS4ERR_DENIED;
3692}
3693
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003694static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695{
Al Viro8687b632006-10-19 23:28:48 -07003696 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 int status;
3698
3699 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003700 if (status == -EIO)
3701 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003703 READ_BUF(NFS4_STATEID_SIZE);
3704 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003706 status = decode_lock_denied(xdr, NULL);
3707 if (res->open_seqid != NULL)
3708 nfs_increment_open_seqid(status, res->open_seqid);
3709 nfs_increment_lock_seqid(status, res->lock_seqid);
3710out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 return status;
3712}
3713
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003714static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715{
3716 int status;
3717 status = decode_op_hdr(xdr, OP_LOCKT);
3718 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003719 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 return status;
3721}
3722
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003723static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724{
Al Viro8687b632006-10-19 23:28:48 -07003725 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 int status;
3727
3728 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003729 if (status != -EIO)
3730 nfs_increment_lock_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003732 READ_BUF(NFS4_STATEID_SIZE);
3733 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734 }
3735 return status;
3736}
3737
3738static int decode_lookup(struct xdr_stream *xdr)
3739{
3740 return decode_op_hdr(xdr, OP_LOOKUP);
3741}
3742
3743/* This is too sick! */
3744static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3745{
Andy Adamson05d564f2008-12-23 16:06:15 -05003746 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747 uint32_t limit_type, nblocks, blocksize;
3748
3749 READ_BUF(12);
3750 READ32(limit_type);
3751 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003752 case 1:
3753 READ64(*maxsize);
3754 break;
3755 case 2:
3756 READ32(nblocks);
3757 READ32(blocksize);
3758 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759 }
3760 return 0;
3761}
3762
3763static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3764{
Andy Adamson05d564f2008-12-23 16:06:15 -05003765 __be32 *p;
3766 uint32_t delegation_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767
3768 READ_BUF(4);
3769 READ32(delegation_type);
3770 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3771 res->delegation_type = 0;
3772 return 0;
3773 }
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003774 READ_BUF(NFS4_STATEID_SIZE+4);
3775 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776 READ32(res->do_recall);
Andy Adamson05d564f2008-12-23 16:06:15 -05003777
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003779 case NFS4_OPEN_DELEGATE_READ:
3780 res->delegation_type = FMODE_READ;
3781 break;
3782 case NFS4_OPEN_DELEGATE_WRITE:
3783 res->delegation_type = FMODE_WRITE|FMODE_READ;
3784 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 return -EIO;
3786 }
David Howells7539bba2006-08-22 20:06:09 -04003787 return decode_ace(xdr, NULL, res->server->nfs_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788}
3789
3790static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3791{
Andy Adamson05d564f2008-12-23 16:06:15 -05003792 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003793 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05003794 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795
Andy Adamson05d564f2008-12-23 16:06:15 -05003796 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003797 if (status != -EIO)
3798 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003799 if (status)
3800 return status;
3801 READ_BUF(NFS4_STATEID_SIZE);
3802 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803
Andy Adamson05d564f2008-12-23 16:06:15 -05003804 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805
Andy Adamson05d564f2008-12-23 16:06:15 -05003806 READ_BUF(8);
3807 READ32(res->rflags);
3808 READ32(bmlen);
3809 if (bmlen > 10)
3810 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811
Andy Adamson05d564f2008-12-23 16:06:15 -05003812 READ_BUF(bmlen << 2);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003813 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3814 for (i = 0; i < savewords; ++i)
3815 READ32(res->attrset[i]);
3816 for (; i < NFS4_BITMAP_SIZE; i++)
3817 res->attrset[i] = 0;
3818
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 return decode_delegation(xdr, res);
3820xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003821 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 return -EIO;
3823}
3824
3825static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3826{
Andy Adamson05d564f2008-12-23 16:06:15 -05003827 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 int status;
3829
Andy Adamson05d564f2008-12-23 16:06:15 -05003830 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003831 if (status != -EIO)
3832 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003833 if (status)
3834 return status;
3835 READ_BUF(NFS4_STATEID_SIZE);
3836 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3837 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838}
3839
3840static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3841{
Al Viro8687b632006-10-19 23:28:48 -07003842 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 int status;
3844
3845 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003846 if (status != -EIO)
3847 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 if (status)
3849 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003850 READ_BUF(NFS4_STATEID_SIZE);
3851 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852 return 0;
3853}
3854
3855static int decode_putfh(struct xdr_stream *xdr)
3856{
3857 return decode_op_hdr(xdr, OP_PUTFH);
3858}
3859
3860static int decode_putrootfh(struct xdr_stream *xdr)
3861{
3862 return decode_op_hdr(xdr, OP_PUTROOTFH);
3863}
3864
3865static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3866{
3867 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07003868 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 uint32_t count, eof, recvd, hdrlen;
3870 int status;
3871
3872 status = decode_op_hdr(xdr, OP_READ);
3873 if (status)
3874 return status;
3875 READ_BUF(8);
3876 READ32(eof);
3877 READ32(count);
3878 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3879 recvd = req->rq_rcv_buf.len - hdrlen;
3880 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003881 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882 "count %u > recvd %u\n", count, recvd);
3883 count = recvd;
3884 eof = 0;
3885 }
3886 xdr_read_pages(xdr, count);
3887 res->eof = eof;
3888 res->count = count;
3889 return 0;
3890}
3891
3892static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3893{
3894 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3895 struct page *page = *rcvbuf->pages;
3896 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003897 size_t hdrlen;
3898 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07003899 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003900 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04003901 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902
3903 status = decode_op_hdr(xdr, OP_READDIR);
3904 if (status)
3905 return status;
3906 READ_BUF(8);
3907 COPYMEM(readdir->verifier.data, 8);
Fred Isaman44109242008-04-02 15:21:15 +03003908 dprintk("%s: verifier = %08x:%08x\n",
3909 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00003910 ((u32 *)readdir->verifier.data)[0],
3911 ((u32 *)readdir->verifier.data)[1]);
3912
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913
3914 hdrlen = (char *) p - (char *) iov->iov_base;
3915 recvd = rcvbuf->len - hdrlen;
3916 if (pglen > recvd)
3917 pglen = recvd;
3918 xdr_read_pages(xdr, pglen);
3919
3920 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07003921 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04003922 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003924
3925 /* Make sure the packet actually has a value_follows and EOF entry */
3926 if ((entry + 1) > end)
3927 goto short_pkt;
3928
3929 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003930 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04003931 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003933 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 p += 2; /* cookie */
3935 len = ntohl(*p++); /* filename length */
3936 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003937 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3938 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 goto err_unmap;
3940 }
David Howellse8896492006-08-24 15:44:19 -04003941 xlen = XDR_QUADLEN(len);
3942 if (end - p < xlen + 1)
3943 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003944 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04003945 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04003947 if (end - p < len + 1)
3948 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04003951 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04003953 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 entry = p;
3955 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003956 /*
3957 * Apparently some server sends responses that are a valid size, but
3958 * contain no entries, and have value_follows==0 and EOF==0. For
3959 * those, just set the EOF marker.
3960 */
3961 if (!nr && entry[1] == 0) {
3962 dprintk("NFS: readdir reply truncated!\n");
3963 entry[1] = 1;
3964 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05003965out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 kunmap_atomic(kaddr, KM_USER0);
3967 return 0;
3968short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003969 /*
3970 * When we get a short packet there are 2 possibilities. We can
3971 * return an error, or fix up the response to look like a valid
3972 * response and return what we have so far. If there are no
3973 * entries and the packet was short, then return -EIO. If there
3974 * are valid entries in the response, return them and pretend that
3975 * the call was successful, but incomplete. The caller can retry the
3976 * readdir starting at the last cookie.
3977 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07003978 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003980 if (nr)
3981 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982err_unmap:
3983 kunmap_atomic(kaddr, KM_USER0);
3984 return -errno_NFSERR_IO;
3985}
3986
3987static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3988{
3989 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3990 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003991 size_t hdrlen;
3992 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07003993 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994 char *kaddr;
3995 int status;
3996
3997 status = decode_op_hdr(xdr, OP_READLINK);
3998 if (status)
3999 return status;
4000
4001 /* Convert length of symlink */
4002 READ_BUF(4);
4003 READ32(len);
4004 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004005 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 return -ENAMETOOLONG;
4007 }
4008 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4009 recvd = req->rq_rcv_buf.len - hdrlen;
4010 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004011 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 "count %u > recvd %u\n", len, recvd);
4013 return -EIO;
4014 }
4015 xdr_read_pages(xdr, len);
4016 /*
4017 * The XDR encode routine has set things up so that
4018 * the link text will be copied directly into the
4019 * buffer. We just have to do overflow-checking,
4020 * and and null-terminate the text (the VFS expects
4021 * null-termination).
4022 */
4023 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
4024 kaddr[len+rcvbuf->page_base] = '\0';
4025 kunmap_atomic(kaddr, KM_USER0);
4026 return 0;
4027}
4028
4029static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4030{
4031 int status;
4032
4033 status = decode_op_hdr(xdr, OP_REMOVE);
4034 if (status)
4035 goto out;
4036 status = decode_change_info(xdr, cinfo);
4037out:
4038 return status;
4039}
4040
4041static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4042 struct nfs4_change_info *new_cinfo)
4043{
4044 int status;
4045
4046 status = decode_op_hdr(xdr, OP_RENAME);
4047 if (status)
4048 goto out;
4049 if ((status = decode_change_info(xdr, old_cinfo)))
4050 goto out;
4051 status = decode_change_info(xdr, new_cinfo);
4052out:
4053 return status;
4054}
4055
4056static int decode_renew(struct xdr_stream *xdr)
4057{
4058 return decode_op_hdr(xdr, OP_RENEW);
4059}
4060
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004061static int
4062decode_restorefh(struct xdr_stream *xdr)
4063{
4064 return decode_op_hdr(xdr, OP_RESTOREFH);
4065}
4066
J. Bruce Fields029d1052005-06-22 17:16:22 +00004067static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4068 size_t *acl_len)
4069{
Al Viro8687b632006-10-19 23:28:48 -07004070 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004071 uint32_t attrlen,
4072 bitmap[2] = {0};
4073 struct kvec *iov = req->rq_rcv_buf.head;
4074 int status;
4075
4076 *acl_len = 0;
4077 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4078 goto out;
4079 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4080 goto out;
4081 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4082 goto out;
4083
4084 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4085 return -EIO;
4086 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004087 size_t hdrlen;
4088 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004089
4090 /* We ignore &savep and don't do consistency checks on
4091 * the attr length. Let userspace figure it out.... */
4092 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4093 recvd = req->rq_rcv_buf.len - hdrlen;
4094 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004095 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004096 " acl reply: attrlen %u > recvd %u\n",
4097 attrlen, recvd);
4098 return -EINVAL;
4099 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004100 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004101 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004102 } else
4103 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004104
4105out:
4106 return status;
4107}
4108
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109static int
4110decode_savefh(struct xdr_stream *xdr)
4111{
4112 return decode_op_hdr(xdr, OP_SAVEFH);
4113}
4114
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004115static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116{
Al Viro8687b632006-10-19 23:28:48 -07004117 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118 uint32_t bmlen;
4119 int status;
4120
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 status = decode_op_hdr(xdr, OP_SETATTR);
4122 if (status)
4123 return status;
4124 READ_BUF(4);
4125 READ32(bmlen);
4126 READ_BUF(bmlen << 2);
4127 return 0;
4128}
4129
David Howellsadfa6f92006-08-22 20:06:08 -04004130static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131{
Al Viro8687b632006-10-19 23:28:48 -07004132 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133 uint32_t opnum;
4134 int32_t nfserr;
4135
4136 READ_BUF(8);
4137 READ32(opnum);
4138 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004139 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004140 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141 return -EIO;
4142 }
4143 READ32(nfserr);
4144 if (nfserr == NFS_OK) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04004145 READ_BUF(8 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 READ64(clp->cl_clientid);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04004147 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148 } else if (nfserr == NFSERR_CLID_INUSE) {
4149 uint32_t len;
4150
4151 /* skip netid string */
4152 READ_BUF(4);
4153 READ32(len);
4154 READ_BUF(len);
4155
4156 /* skip uaddr string */
4157 READ_BUF(4);
4158 READ32(len);
4159 READ_BUF(len);
4160 return -NFSERR_CLID_INUSE;
4161 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004162 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163
4164 return 0;
4165}
4166
4167static int decode_setclientid_confirm(struct xdr_stream *xdr)
4168{
4169 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4170}
4171
4172static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4173{
Al Viro8687b632006-10-19 23:28:48 -07004174 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175 int status;
4176
4177 status = decode_op_hdr(xdr, OP_WRITE);
4178 if (status)
4179 return status;
4180
4181 READ_BUF(16);
4182 READ32(res->count);
4183 READ32(res->verf->committed);
4184 COPYMEM(res->verf->verifier, 8);
4185 return 0;
4186}
4187
4188static int decode_delegreturn(struct xdr_stream *xdr)
4189{
4190 return decode_op_hdr(xdr, OP_DELEGRETURN);
4191}
4192
Benny Halevy99fe60d2009-04-01 09:22:29 -04004193#if defined(CONFIG_NFS_V4_1)
4194static int decode_exchange_id(struct xdr_stream *xdr,
4195 struct nfs41_exchange_id_res *res)
4196{
4197 __be32 *p;
4198 uint32_t dummy;
4199 int status;
4200 struct nfs_client *clp = res->client;
4201
4202 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4203 if (status)
4204 return status;
4205
4206 READ_BUF(8);
4207 READ64(clp->cl_ex_clid);
4208 READ_BUF(12);
4209 READ32(clp->cl_seqid);
4210 READ32(clp->cl_exchange_flags);
4211
4212 /* We ask for SP4_NONE */
4213 READ32(dummy);
4214 if (dummy != SP4_NONE)
4215 return -EIO;
4216
4217 /* Throw away minor_id */
4218 READ_BUF(8);
4219
4220 /* Throw away Major id */
4221 READ_BUF(4);
4222 READ32(dummy);
4223 READ_BUF(dummy);
4224
4225 /* Throw away server_scope */
4226 READ_BUF(4);
4227 READ32(dummy);
4228 READ_BUF(dummy);
4229
4230 /* Throw away Implementation id array */
4231 READ_BUF(4);
4232 READ32(dummy);
4233 READ_BUF(dummy);
4234
4235 return 0;
4236}
Andy Adamsonfc931582009-04-01 09:22:31 -04004237
4238static int decode_chan_attrs(struct xdr_stream *xdr,
4239 struct nfs4_channel_attrs *attrs)
4240{
4241 __be32 *p;
4242 u32 nr_attrs;
4243
4244 READ_BUF(28);
4245 READ32(attrs->headerpadsz);
4246 READ32(attrs->max_rqst_sz);
4247 READ32(attrs->max_resp_sz);
4248 READ32(attrs->max_resp_sz_cached);
4249 READ32(attrs->max_ops);
4250 READ32(attrs->max_reqs);
4251 READ32(nr_attrs);
4252 if (unlikely(nr_attrs > 1)) {
4253 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4254 __func__, nr_attrs);
4255 return -EINVAL;
4256 }
4257 if (nr_attrs == 1)
4258 READ_BUF(4); /* skip rdma_attrs */
4259 return 0;
4260}
4261
4262static int decode_create_session(struct xdr_stream *xdr,
4263 struct nfs41_create_session_res *res)
4264{
4265 __be32 *p;
4266 int status;
4267 struct nfs_client *clp = res->client;
4268 struct nfs4_session *session = clp->cl_session;
4269
4270 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
4271
4272 if (status)
4273 return status;
4274
4275 /* sessionid */
4276 READ_BUF(NFS4_MAX_SESSIONID_LEN);
4277 COPYMEM(&session->sess_id, NFS4_MAX_SESSIONID_LEN);
4278
4279 /* seqid, flags */
4280 READ_BUF(8);
4281 READ32(clp->cl_seqid);
4282 READ32(session->flags);
4283
4284 /* Channel attributes */
4285 status = decode_chan_attrs(xdr, &session->fc_attrs);
4286 if (!status)
4287 status = decode_chan_attrs(xdr, &session->bc_attrs);
4288 return status;
4289}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004290
4291static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4292{
4293 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4294}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004295#endif /* CONFIG_NFS_V4_1 */
4296
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004297static int decode_sequence(struct xdr_stream *xdr,
4298 struct nfs4_sequence_res *res,
4299 struct rpc_rqst *rqstp)
4300{
4301#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004302 struct nfs4_slot *slot;
4303 struct nfs4_sessionid id;
4304 u32 dummy;
4305 int status;
4306 __be32 *p;
4307
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004308 if (!res->sr_session)
4309 return 0;
4310
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004311 status = decode_op_hdr(xdr, OP_SEQUENCE);
4312 if (status)
4313 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004314
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004315 /*
4316 * If the server returns different values for sessionID, slotID or
4317 * sequence number, the server is looney tunes.
4318 */
4319 status = -ESERVERFAULT;
4320
4321 slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid];
4322 READ_BUF(NFS4_MAX_SESSIONID_LEN + 20);
4323 COPYMEM(id.data, NFS4_MAX_SESSIONID_LEN);
4324 if (memcmp(id.data, res->sr_session->sess_id.data,
4325 NFS4_MAX_SESSIONID_LEN)) {
4326 dprintk("%s Invalid session id\n", __func__);
4327 goto out_err;
4328 }
4329 /* seqid */
4330 READ32(dummy);
4331 if (dummy != slot->seq_nr) {
4332 dprintk("%s Invalid sequence number\n", __func__);
4333 goto out_err;
4334 }
4335 /* slot id */
4336 READ32(dummy);
4337 if (dummy != res->sr_slotid) {
4338 dprintk("%s Invalid slot id\n", __func__);
4339 goto out_err;
4340 }
4341 /* highest slot id - currently not processed */
4342 READ32(dummy);
4343 /* target highest slot id - currently not processed */
4344 READ32(dummy);
4345 /* result flags - currently not processed */
4346 READ32(dummy);
4347 status = 0;
4348out_err:
4349 res->sr_status = status;
4350 return status;
4351#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004352 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004353#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004354}
4355
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356/*
Benny Halevy49c25592008-12-23 16:06:16 -05004357 * END OF "GENERIC" DECODE ROUTINES.
4358 */
4359
4360/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361 * Decode OPEN_DOWNGRADE response
4362 */
Al Viro8687b632006-10-19 23:28:48 -07004363static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004364{
Andy Adamson05d564f2008-12-23 16:06:15 -05004365 struct xdr_stream xdr;
4366 struct compound_hdr hdr;
4367 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368
Andy Adamson05d564f2008-12-23 16:06:15 -05004369 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4370 status = decode_compound_hdr(&xdr, &hdr);
4371 if (status)
4372 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004373 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4374 if (status)
4375 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004376 status = decode_putfh(&xdr);
4377 if (status)
4378 goto out;
4379 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004380 if (status != 0)
4381 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004382 decode_getfattr(&xdr, res->fattr, res->server,
4383 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004385 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386}
4387
4388/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 * Decode ACCESS response
4390 */
Al Viro8687b632006-10-19 23:28:48 -07004391static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392{
4393 struct xdr_stream xdr;
4394 struct compound_hdr hdr;
4395 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004396
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004398 status = decode_compound_hdr(&xdr, &hdr);
4399 if (status)
4400 goto out;
4401 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4402 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004403 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04004404 status = decode_putfh(&xdr);
4405 if (status != 0)
4406 goto out;
4407 status = decode_access(&xdr, res);
4408 if (status != 0)
4409 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004410 decode_getfattr(&xdr, res->fattr, res->server,
4411 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004412out:
4413 return status;
4414}
4415
4416/*
4417 * Decode LOOKUP response
4418 */
Al Viro8687b632006-10-19 23:28:48 -07004419static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420{
4421 struct xdr_stream xdr;
4422 struct compound_hdr hdr;
4423 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004424
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004426 status = decode_compound_hdr(&xdr, &hdr);
4427 if (status)
4428 goto out;
4429 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4430 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431 goto out;
4432 if ((status = decode_putfh(&xdr)) != 0)
4433 goto out;
4434 if ((status = decode_lookup(&xdr)) != 0)
4435 goto out;
4436 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4437 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004438 status = decode_getfattr(&xdr, res->fattr, res->server
4439 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440out:
4441 return status;
4442}
4443
4444/*
4445 * Decode LOOKUP_ROOT response
4446 */
Al Viro8687b632006-10-19 23:28:48 -07004447static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448{
4449 struct xdr_stream xdr;
4450 struct compound_hdr hdr;
4451 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004452
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004454 status = decode_compound_hdr(&xdr, &hdr);
4455 if (status)
4456 goto out;
4457 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4458 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459 goto out;
4460 if ((status = decode_putrootfh(&xdr)) != 0)
4461 goto out;
4462 if ((status = decode_getfh(&xdr, res->fh)) == 0)
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004463 status = decode_getfattr(&xdr, res->fattr, res->server,
4464 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465out:
4466 return status;
4467}
4468
4469/*
4470 * Decode REMOVE response
4471 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004472static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473{
4474 struct xdr_stream xdr;
4475 struct compound_hdr hdr;
4476 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004477
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004479 status = decode_compound_hdr(&xdr, &hdr);
4480 if (status)
4481 goto out;
4482 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4483 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004484 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04004485 if ((status = decode_putfh(&xdr)) != 0)
4486 goto out;
4487 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4488 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004489 decode_getfattr(&xdr, &res->dir_attr, res->server,
4490 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491out:
4492 return status;
4493}
4494
4495/*
4496 * Decode RENAME response
4497 */
Al Viro8687b632006-10-19 23:28:48 -07004498static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499{
4500 struct xdr_stream xdr;
4501 struct compound_hdr hdr;
4502 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004503
Linus Torvalds1da177e2005-04-16 15:20:36 -07004504 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004505 status = decode_compound_hdr(&xdr, &hdr);
4506 if (status)
4507 goto out;
4508 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4509 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510 goto out;
4511 if ((status = decode_putfh(&xdr)) != 0)
4512 goto out;
4513 if ((status = decode_savefh(&xdr)) != 0)
4514 goto out;
4515 if ((status = decode_putfh(&xdr)) != 0)
4516 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004517 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4518 goto out;
4519 /* Current FH is target directory */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004520 if (decode_getfattr(&xdr, res->new_fattr, res->server,
4521 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004522 goto out;
4523 if ((status = decode_restorefh(&xdr)) != 0)
4524 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004525 decode_getfattr(&xdr, res->old_fattr, res->server,
4526 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527out:
4528 return status;
4529}
4530
4531/*
4532 * Decode LINK response
4533 */
Al Viro8687b632006-10-19 23:28:48 -07004534static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004535{
4536 struct xdr_stream xdr;
4537 struct compound_hdr hdr;
4538 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004539
Linus Torvalds1da177e2005-04-16 15:20:36 -07004540 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004541 status = decode_compound_hdr(&xdr, &hdr);
4542 if (status)
4543 goto out;
4544 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4545 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004546 goto out;
4547 if ((status = decode_putfh(&xdr)) != 0)
4548 goto out;
4549 if ((status = decode_savefh(&xdr)) != 0)
4550 goto out;
4551 if ((status = decode_putfh(&xdr)) != 0)
4552 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004553 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4554 goto out;
4555 /*
4556 * Note order: OP_LINK leaves the directory as the current
4557 * filehandle.
4558 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004559 if (decode_getfattr(&xdr, res->dir_attr, res->server,
4560 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004561 goto out;
4562 if ((status = decode_restorefh(&xdr)) != 0)
4563 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004564 decode_getfattr(&xdr, res->fattr, res->server,
4565 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566out:
4567 return status;
4568}
4569
4570/*
4571 * Decode CREATE response
4572 */
Al Viro8687b632006-10-19 23:28:48 -07004573static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574{
4575 struct xdr_stream xdr;
4576 struct compound_hdr hdr;
4577 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004578
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004580 status = decode_compound_hdr(&xdr, &hdr);
4581 if (status)
4582 goto out;
4583 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4584 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585 goto out;
4586 if ((status = decode_putfh(&xdr)) != 0)
4587 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004588 if ((status = decode_savefh(&xdr)) != 0)
4589 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4591 goto out;
4592 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4593 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004594 if (decode_getfattr(&xdr, res->fattr, res->server,
4595 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004596 goto out;
4597 if ((status = decode_restorefh(&xdr)) != 0)
4598 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004599 decode_getfattr(&xdr, res->dir_fattr, res->server,
4600 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601out:
4602 return status;
4603}
4604
4605/*
4606 * Decode SYMLINK response
4607 */
Al Viro8687b632006-10-19 23:28:48 -07004608static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004609{
4610 return nfs4_xdr_dec_create(rqstp, p, res);
4611}
4612
4613/*
4614 * Decode GETATTR response
4615 */
Al Viro8687b632006-10-19 23:28:48 -07004616static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617{
4618 struct xdr_stream xdr;
4619 struct compound_hdr hdr;
4620 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004621
Linus Torvalds1da177e2005-04-16 15:20:36 -07004622 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4623 status = decode_compound_hdr(&xdr, &hdr);
4624 if (status)
4625 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004626 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4627 if (status)
4628 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629 status = decode_putfh(&xdr);
4630 if (status)
4631 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004632 status = decode_getfattr(&xdr, res->fattr, res->server,
4633 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634out:
4635 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004636}
4637
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004638/*
4639 * Encode an SETACL request
4640 */
4641static int
Al Viro8687b632006-10-19 23:28:48 -07004642nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004643{
Andy Adamson05d564f2008-12-23 16:06:15 -05004644 struct xdr_stream xdr;
4645 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04004646 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05004647 };
4648 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004649
Andy Adamson05d564f2008-12-23 16:06:15 -05004650 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04004651 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004652 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05004653 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004654 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004655 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004656 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004657}
Andy Adamson05d564f2008-12-23 16:06:15 -05004658
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004659/*
4660 * Decode SETACL response
4661 */
4662static int
Benny Halevy73c403a2009-04-01 09:22:01 -04004663nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4664 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004665{
4666 struct xdr_stream xdr;
4667 struct compound_hdr hdr;
4668 int status;
4669
4670 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4671 status = decode_compound_hdr(&xdr, &hdr);
4672 if (status)
4673 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004674 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4675 if (status)
4676 goto out;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004677 status = decode_putfh(&xdr);
4678 if (status)
4679 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004680 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004681out:
4682 return status;
4683}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684
4685/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00004686 * Decode GETACL response
4687 */
4688static int
Benny Halevy663c79b2009-04-01 09:21:59 -04004689nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4690 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004691{
4692 struct xdr_stream xdr;
4693 struct compound_hdr hdr;
4694 int status;
4695
4696 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4697 status = decode_compound_hdr(&xdr, &hdr);
4698 if (status)
4699 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004700 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4701 if (status)
4702 goto out;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004703 status = decode_putfh(&xdr);
4704 if (status)
4705 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04004706 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004707
4708out:
4709 return status;
4710}
4711
4712/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004713 * Decode CLOSE response
4714 */
Al Viro8687b632006-10-19 23:28:48 -07004715static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716{
Andy Adamson05d564f2008-12-23 16:06:15 -05004717 struct xdr_stream xdr;
4718 struct compound_hdr hdr;
4719 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720
Andy Adamson05d564f2008-12-23 16:06:15 -05004721 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4722 status = decode_compound_hdr(&xdr, &hdr);
4723 if (status)
4724 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004725 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4726 if (status)
4727 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004728 status = decode_putfh(&xdr);
4729 if (status)
4730 goto out;
4731 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004732 if (status != 0)
4733 goto out;
4734 /*
4735 * Note: Server may do delete on close for this file
4736 * in which case the getattr call will fail with
4737 * an ESTALE error. Shouldn't be a problem,
4738 * though, since fattr->valid will remain unset.
4739 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004740 decode_getfattr(&xdr, res->fattr, res->server,
4741 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004742out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004743 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744}
4745
4746/*
4747 * Decode OPEN response
4748 */
Al Viro8687b632006-10-19 23:28:48 -07004749static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750{
Andy Adamson05d564f2008-12-23 16:06:15 -05004751 struct xdr_stream xdr;
4752 struct compound_hdr hdr;
4753 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754
Andy Adamson05d564f2008-12-23 16:06:15 -05004755 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4756 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004757 if (status)
4758 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004759 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4760 if (status)
4761 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004762 status = decode_putfh(&xdr);
4763 if (status)
4764 goto out;
4765 status = decode_savefh(&xdr);
4766 if (status)
4767 goto out;
4768 status = decode_open(&xdr, res);
4769 if (status)
4770 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04004771 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004773 if (decode_getfattr(&xdr, res->f_attr, res->server,
4774 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004775 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04004776 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004777 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004778 decode_getfattr(&xdr, res->dir_attr, res->server,
4779 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004781 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782}
4783
4784/*
4785 * Decode OPEN_CONFIRM response
4786 */
Al Viro8687b632006-10-19 23:28:48 -07004787static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788{
Andy Adamson05d564f2008-12-23 16:06:15 -05004789 struct xdr_stream xdr;
4790 struct compound_hdr hdr;
4791 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792
Andy Adamson05d564f2008-12-23 16:06:15 -05004793 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4794 status = decode_compound_hdr(&xdr, &hdr);
4795 if (status)
4796 goto out;
4797 status = decode_putfh(&xdr);
4798 if (status)
4799 goto out;
4800 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004802 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803}
4804
4805/*
4806 * Decode OPEN response
4807 */
Al Viro8687b632006-10-19 23:28:48 -07004808static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004809{
Andy Adamson05d564f2008-12-23 16:06:15 -05004810 struct xdr_stream xdr;
4811 struct compound_hdr hdr;
4812 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813
Andy Adamson05d564f2008-12-23 16:06:15 -05004814 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4815 status = decode_compound_hdr(&xdr, &hdr);
4816 if (status)
4817 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004818 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4819 if (status)
4820 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004821 status = decode_putfh(&xdr);
4822 if (status)
4823 goto out;
4824 status = decode_open(&xdr, res);
4825 if (status)
4826 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004827 decode_getfattr(&xdr, res->f_attr, res->server,
4828 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004829out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004830 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004831}
4832
4833/*
4834 * Decode SETATTR response
4835 */
Al Viro8687b632006-10-19 23:28:48 -07004836static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837{
Andy Adamson05d564f2008-12-23 16:06:15 -05004838 struct xdr_stream xdr;
4839 struct compound_hdr hdr;
4840 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841
Andy Adamson05d564f2008-12-23 16:06:15 -05004842 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4843 status = decode_compound_hdr(&xdr, &hdr);
4844 if (status)
4845 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004846 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4847 if (status)
4848 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004849 status = decode_putfh(&xdr);
4850 if (status)
4851 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004852 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004853 if (status)
4854 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004855 decode_getfattr(&xdr, res->fattr, res->server,
4856 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004858 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004859}
4860
4861/*
4862 * Decode LOCK response
4863 */
Al Viro8687b632006-10-19 23:28:48 -07004864static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865{
4866 struct xdr_stream xdr;
4867 struct compound_hdr hdr;
4868 int status;
4869
4870 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4871 status = decode_compound_hdr(&xdr, &hdr);
4872 if (status)
4873 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004874 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4875 if (status)
4876 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004877 status = decode_putfh(&xdr);
4878 if (status)
4879 goto out;
4880 status = decode_lock(&xdr, res);
4881out:
4882 return status;
4883}
4884
4885/*
4886 * Decode LOCKT response
4887 */
Al Viro8687b632006-10-19 23:28:48 -07004888static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889{
4890 struct xdr_stream xdr;
4891 struct compound_hdr hdr;
4892 int status;
4893
4894 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4895 status = decode_compound_hdr(&xdr, &hdr);
4896 if (status)
4897 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004898 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4899 if (status)
4900 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901 status = decode_putfh(&xdr);
4902 if (status)
4903 goto out;
4904 status = decode_lockt(&xdr, res);
4905out:
4906 return status;
4907}
4908
4909/*
4910 * Decode LOCKU response
4911 */
Al Viro8687b632006-10-19 23:28:48 -07004912static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913{
4914 struct xdr_stream xdr;
4915 struct compound_hdr hdr;
4916 int status;
4917
4918 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4919 status = decode_compound_hdr(&xdr, &hdr);
4920 if (status)
4921 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004922 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4923 if (status)
4924 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925 status = decode_putfh(&xdr);
4926 if (status)
4927 goto out;
4928 status = decode_locku(&xdr, res);
4929out:
4930 return status;
4931}
4932
4933/*
4934 * Decode READLINK response
4935 */
Benny Halevyf50c7002009-04-01 09:21:55 -04004936static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4937 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004938{
4939 struct xdr_stream xdr;
4940 struct compound_hdr hdr;
4941 int status;
4942
4943 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4944 status = decode_compound_hdr(&xdr, &hdr);
4945 if (status)
4946 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004947 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4948 if (status)
4949 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004950 status = decode_putfh(&xdr);
4951 if (status)
4952 goto out;
4953 status = decode_readlink(&xdr, rqstp);
4954out:
4955 return status;
4956}
4957
4958/*
4959 * Decode READDIR response
4960 */
Al Viro8687b632006-10-19 23:28:48 -07004961static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962{
4963 struct xdr_stream xdr;
4964 struct compound_hdr hdr;
4965 int status;
4966
4967 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4968 status = decode_compound_hdr(&xdr, &hdr);
4969 if (status)
4970 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004971 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4972 if (status)
4973 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974 status = decode_putfh(&xdr);
4975 if (status)
4976 goto out;
4977 status = decode_readdir(&xdr, rqstp, res);
4978out:
4979 return status;
4980}
4981
4982/*
4983 * Decode Read response
4984 */
Al Viro8687b632006-10-19 23:28:48 -07004985static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986{
4987 struct xdr_stream xdr;
4988 struct compound_hdr hdr;
4989 int status;
4990
4991 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4992 status = decode_compound_hdr(&xdr, &hdr);
4993 if (status)
4994 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004995 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4996 if (status)
4997 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998 status = decode_putfh(&xdr);
4999 if (status)
5000 goto out;
5001 status = decode_read(&xdr, rqstp, res);
5002 if (!status)
5003 status = res->count;
5004out:
5005 return status;
5006}
5007
5008/*
5009 * Decode WRITE response
5010 */
Al Viro8687b632006-10-19 23:28:48 -07005011static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005012{
5013 struct xdr_stream xdr;
5014 struct compound_hdr hdr;
5015 int status;
5016
5017 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5018 status = decode_compound_hdr(&xdr, &hdr);
5019 if (status)
5020 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005021 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5022 if (status)
5023 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005024 status = decode_putfh(&xdr);
5025 if (status)
5026 goto out;
5027 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005028 if (status)
5029 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005030 decode_getfattr(&xdr, res->fattr, res->server,
5031 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032 if (!status)
5033 status = res->count;
5034out:
5035 return status;
5036}
5037
5038/*
5039 * Decode COMMIT response
5040 */
Al Viro8687b632006-10-19 23:28:48 -07005041static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005042{
5043 struct xdr_stream xdr;
5044 struct compound_hdr hdr;
5045 int status;
5046
5047 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5048 status = decode_compound_hdr(&xdr, &hdr);
5049 if (status)
5050 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005051 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5052 if (status)
5053 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054 status = decode_putfh(&xdr);
5055 if (status)
5056 goto out;
5057 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005058 if (status)
5059 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005060 decode_getfattr(&xdr, res->fattr, res->server,
5061 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005062out:
5063 return status;
5064}
5065
5066/*
5067 * FSINFO request
5068 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04005069static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
5070 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071{
5072 struct xdr_stream xdr;
5073 struct compound_hdr hdr;
5074 int status;
5075
5076 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5077 status = decode_compound_hdr(&xdr, &hdr);
5078 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005079 status = decode_sequence(&xdr, &res->seq_res, req);
5080 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081 status = decode_putfh(&xdr);
5082 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04005083 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084 return status;
5085}
5086
5087/*
5088 * PATHCONF request
5089 */
Benny Halevyd45b2982009-04-01 09:21:58 -04005090static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
5091 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005092{
5093 struct xdr_stream xdr;
5094 struct compound_hdr hdr;
5095 int status;
5096
5097 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5098 status = decode_compound_hdr(&xdr, &hdr);
5099 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005100 status = decode_sequence(&xdr, &res->seq_res, req);
5101 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102 status = decode_putfh(&xdr);
5103 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04005104 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005105 return status;
5106}
5107
5108/*
5109 * STATFS request
5110 */
Benny Halevy24ad1482009-04-01 09:21:56 -04005111static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
5112 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113{
5114 struct xdr_stream xdr;
5115 struct compound_hdr hdr;
5116 int status;
5117
5118 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5119 status = decode_compound_hdr(&xdr, &hdr);
5120 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005121 status = decode_sequence(&xdr, &res->seq_res, req);
5122 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123 status = decode_putfh(&xdr);
5124 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04005125 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005126 return status;
5127}
5128
5129/*
5130 * GETATTR_BITMAP request
5131 */
Al Viro8687b632006-10-19 23:28:48 -07005132static 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 -07005133{
5134 struct xdr_stream xdr;
5135 struct compound_hdr hdr;
5136 int status;
5137
5138 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005139 status = decode_compound_hdr(&xdr, &hdr);
5140 if (status)
5141 goto out;
5142 status = decode_sequence(&xdr, &res->seq_res, req);
5143 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144 goto out;
5145 if ((status = decode_putfh(&xdr)) != 0)
5146 goto out;
5147 status = decode_server_caps(&xdr, res);
5148out:
5149 return status;
5150}
5151
5152/*
5153 * Decode RENEW response
5154 */
Al Viro8687b632006-10-19 23:28:48 -07005155static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156{
5157 struct xdr_stream xdr;
5158 struct compound_hdr hdr;
5159 int status;
5160
5161 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5162 status = decode_compound_hdr(&xdr, &hdr);
5163 if (!status)
5164 status = decode_renew(&xdr);
5165 return status;
5166}
5167
5168/*
5169 * a SETCLIENTID request
5170 */
Al Viro8687b632006-10-19 23:28:48 -07005171static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04005172 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173{
5174 struct xdr_stream xdr;
5175 struct compound_hdr hdr;
5176 int status;
5177
5178 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5179 status = decode_compound_hdr(&xdr, &hdr);
5180 if (!status)
5181 status = decode_setclientid(&xdr, clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182 return status;
5183}
5184
5185/*
5186 * a SETCLIENTID_CONFIRM request
5187 */
Al Viro8687b632006-10-19 23:28:48 -07005188static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
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, &req->rq_rcv_buf, p);
5195 status = decode_compound_hdr(&xdr, &hdr);
5196 if (!status)
5197 status = decode_setclientid_confirm(&xdr);
5198 if (!status)
5199 status = decode_putrootfh(&xdr);
5200 if (!status)
5201 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005202 return status;
5203}
5204
5205/*
5206 * DELEGRETURN request
5207 */
Al Viro8687b632006-10-19 23:28:48 -07005208static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005209{
5210 struct xdr_stream xdr;
5211 struct compound_hdr hdr;
5212 int status;
5213
5214 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5215 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005216 if (status)
5217 goto out;
5218 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5219 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005220 goto out;
5221 status = decode_putfh(&xdr);
5222 if (status != 0)
5223 goto out;
5224 status = decode_delegreturn(&xdr);
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005225 decode_getfattr(&xdr, res->fattr, res->server,
5226 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01005227out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228 return status;
5229}
5230
Trond Myklebust683b57b2006-06-09 09:34:22 -04005231/*
5232 * FS_LOCATIONS request
5233 */
Benny Halevy22958462009-04-01 09:22:02 -04005234static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
5235 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005236{
5237 struct xdr_stream xdr;
5238 struct compound_hdr hdr;
5239 int status;
5240
5241 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5242 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005243 if (status)
5244 goto out;
5245 status = decode_sequence(&xdr, &res->seq_res, req);
5246 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005247 goto out;
5248 if ((status = decode_putfh(&xdr)) != 0)
5249 goto out;
5250 if ((status = decode_lookup(&xdr)) != 0)
5251 goto out;
5252 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04005253 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005254 res->fs_locations->server,
5255 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04005256out:
5257 return status;
5258}
5259
Benny Halevy99fe60d2009-04-01 09:22:29 -04005260#if defined(CONFIG_NFS_V4_1)
5261/*
5262 * EXCHANGE_ID request
5263 */
5264static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
5265 void *res)
5266{
5267 struct xdr_stream xdr;
5268 struct compound_hdr hdr;
5269 int status;
5270
5271 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5272 status = decode_compound_hdr(&xdr, &hdr);
5273 if (!status)
5274 status = decode_exchange_id(&xdr, res);
5275 return status;
5276}
Andy Adamson2050f0c2009-04-01 09:22:30 -04005277
5278/*
Andy Adamsonfc931582009-04-01 09:22:31 -04005279 * a CREATE_SESSION request
5280 */
5281static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
5282 struct nfs41_create_session_res *res)
5283{
5284 struct xdr_stream xdr;
5285 struct compound_hdr hdr;
5286 int status;
5287
5288 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5289 status = decode_compound_hdr(&xdr, &hdr);
5290 if (!status)
5291 status = decode_create_session(&xdr, res);
5292 return status;
5293}
5294
5295/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005296 * a DESTROY_SESSION request
5297 */
5298static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
5299 void *dummy)
5300{
5301 struct xdr_stream xdr;
5302 struct compound_hdr hdr;
5303 int status;
5304
5305 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5306 status = decode_compound_hdr(&xdr, &hdr);
5307 if (!status)
5308 status = decode_destroy_session(&xdr, dummy);
5309 return status;
5310}
5311
5312/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005313 * a SEQUENCE request
5314 */
5315static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p,
5316 struct nfs4_sequence_res *res)
5317{
5318 struct xdr_stream xdr;
5319 struct compound_hdr hdr;
5320 int status;
5321
5322 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5323 status = decode_compound_hdr(&xdr, &hdr);
5324 if (!status)
5325 status = decode_sequence(&xdr, res, rqstp);
5326 return status;
5327}
5328
5329/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04005330 * a GET_LEASE_TIME request
5331 */
5332static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
5333 struct nfs4_get_lease_time_res *res)
5334{
5335 struct xdr_stream xdr;
5336 struct compound_hdr hdr;
5337 int status;
5338
5339 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5340 status = decode_compound_hdr(&xdr, &hdr);
5341 if (!status)
5342 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
5343 if (!status)
5344 status = decode_putrootfh(&xdr);
5345 if (!status)
5346 status = decode_fsinfo(&xdr, res->lr_fsinfo);
5347 return status;
5348}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005349#endif /* CONFIG_NFS_V4_1 */
5350
Al Viro0dbb4c62006-10-19 23:28:49 -07005351__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005352{
5353 uint32_t bitmap[2] = {0};
5354 uint32_t len;
5355
5356 if (!*p++) {
5357 if (!*p)
5358 return ERR_PTR(-EAGAIN);
5359 entry->eof = 1;
5360 return ERR_PTR(-EBADCOOKIE);
5361 }
5362
5363 entry->prev_cookie = entry->cookie;
5364 p = xdr_decode_hyper(p, &entry->cookie);
5365 entry->len = ntohl(*p++);
5366 entry->name = (const char *) p;
5367 p += XDR_QUADLEN(entry->len);
5368
5369 /*
5370 * In case the server doesn't return an inode number,
5371 * we fake one here. (We don't use inode number 0,
5372 * since glibc seems to choke on it...)
5373 */
5374 entry->ino = 1;
5375
5376 len = ntohl(*p++); /* bitmap length */
5377 if (len-- > 0) {
5378 bitmap[0] = ntohl(*p++);
5379 if (len-- > 0) {
5380 bitmap[1] = ntohl(*p++);
5381 p += len;
5382 }
5383 }
5384 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
5385 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00005386 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
5387 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
5388 /* Ignore the return value of rdattr_error for now */
5389 p++;
5390 len--;
5391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005392 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
5393 xdr_decode_hyper(p, &entry->ino);
5394 else if (bitmap[0] == FATTR4_WORD0_FILEID)
5395 xdr_decode_hyper(p, &entry->ino);
5396 p += len;
5397 }
5398
5399 entry->eof = !p[0] && p[1];
5400 return p;
5401}
5402
5403/*
5404 * We need to translate between nfs status return values and
5405 * the local errno values which may not be the same.
5406 */
5407static struct {
5408 int stat;
5409 int errno;
5410} nfs_errtbl[] = {
5411 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03005412 { NFS4ERR_PERM, -EPERM },
5413 { NFS4ERR_NOENT, -ENOENT },
5414 { NFS4ERR_IO, -errno_NFSERR_IO},
5415 { NFS4ERR_NXIO, -ENXIO },
5416 { NFS4ERR_ACCESS, -EACCES },
5417 { NFS4ERR_EXIST, -EEXIST },
5418 { NFS4ERR_XDEV, -EXDEV },
5419 { NFS4ERR_NOTDIR, -ENOTDIR },
5420 { NFS4ERR_ISDIR, -EISDIR },
5421 { NFS4ERR_INVAL, -EINVAL },
5422 { NFS4ERR_FBIG, -EFBIG },
5423 { NFS4ERR_NOSPC, -ENOSPC },
5424 { NFS4ERR_ROFS, -EROFS },
5425 { NFS4ERR_MLINK, -EMLINK },
5426 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5427 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5428 { NFS4ERR_DQUOT, -EDQUOT },
5429 { NFS4ERR_STALE, -ESTALE },
5430 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5431 { NFS4ERR_BADOWNER, -EINVAL },
5432 { NFS4ERR_BADNAME, -EINVAL },
5433 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5434 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5435 { NFS4ERR_TOOSMALL, -ETOOSMALL },
5436 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
5437 { NFS4ERR_BADTYPE, -EBADTYPE },
5438 { NFS4ERR_LOCKED, -EAGAIN },
5439 { NFS4ERR_RESOURCE, -EREMOTEIO },
5440 { NFS4ERR_SYMLINK, -ELOOP },
5441 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5442 { NFS4ERR_DEADLOCK, -EDEADLK },
5443 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005444 * to be handled by a
5445 * middle-layer.
5446 */
Benny Halevy856dff32008-03-31 17:39:06 +03005447 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005448};
5449
5450/*
5451 * Convert an NFS error code to a local one.
5452 * This one is used jointly by NFSv2 and NFSv3.
5453 */
5454static int
David Howells0a8ea432006-08-22 20:06:08 -04005455nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005456{
5457 int i;
5458 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5459 if (nfs_errtbl[i].stat == stat)
5460 return nfs_errtbl[i].errno;
5461 }
5462 if (stat <= 10000 || stat > 10100) {
5463 /* The server is looney tunes. */
Benny Halevy856dff32008-03-31 17:39:06 +03005464 return -ESERVERFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005465 }
5466 /* If we cannot translate the error, the recovery routines should
5467 * handle it.
5468 * Note: remaining NFSv4 error codes have values > 10000, so should
5469 * not conflict with native Linux error codes.
5470 */
Benny Halevy856dff32008-03-31 17:39:06 +03005471 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005472}
5473
Linus Torvalds1da177e2005-04-16 15:20:36 -07005474#define PROC(proc, argtype, restype) \
5475[NFSPROC4_CLNT_##proc] = { \
5476 .p_proc = NFSPROC4_COMPOUND, \
5477 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5478 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04005479 .p_arglen = NFS4_##argtype##_sz, \
5480 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05005481 .p_statidx = NFSPROC4_CLNT_##proc, \
5482 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05005483}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005484
5485struct rpc_procinfo nfs4_procedures[] = {
5486 PROC(READ, enc_read, dec_read),
5487 PROC(WRITE, enc_write, dec_write),
5488 PROC(COMMIT, enc_commit, dec_commit),
5489 PROC(OPEN, enc_open, dec_open),
5490 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5491 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5492 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5493 PROC(CLOSE, enc_close, dec_close),
5494 PROC(SETATTR, enc_setattr, dec_setattr),
5495 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5496 PROC(RENEW, enc_renew, dec_renew),
5497 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5498 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5499 PROC(LOCK, enc_lock, dec_lock),
5500 PROC(LOCKT, enc_lockt, dec_lockt),
5501 PROC(LOCKU, enc_locku, dec_locku),
5502 PROC(ACCESS, enc_access, dec_access),
5503 PROC(GETATTR, enc_getattr, dec_getattr),
5504 PROC(LOOKUP, enc_lookup, dec_lookup),
5505 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5506 PROC(REMOVE, enc_remove, dec_remove),
5507 PROC(RENAME, enc_rename, dec_rename),
5508 PROC(LINK, enc_link, dec_link),
5509 PROC(SYMLINK, enc_symlink, dec_symlink),
5510 PROC(CREATE, enc_create, dec_create),
5511 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5512 PROC(STATFS, enc_statfs, dec_statfs),
5513 PROC(READLINK, enc_readlink, dec_readlink),
5514 PROC(READDIR, enc_readdir, dec_readdir),
5515 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5516 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00005517 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005518 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04005519 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005520#if defined(CONFIG_NFS_V4_1)
5521 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
Andy Adamsonfc931582009-04-01 09:22:31 -04005522 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005523 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005524 PROC(SEQUENCE, enc_sequence, dec_sequence),
Andy Adamson2050f0c2009-04-01 09:22:30 -04005525 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005526#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005527};
5528
5529struct rpc_version nfs_version4 = {
5530 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08005531 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532 .procs = nfs4_procedures
5533};
5534
5535/*
5536 * Local variables:
5537 * c-basic-offset: 8
5538 * End:
5539 */