blob: 85ee1d17a46194b6101cf087447df8ed6c96b09a [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)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400249#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
250 encode_verifier_maxsz + \
251 1 /* co_ownerid.len */ + \
252 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
253 1 /* flags */ + \
254 1 /* spa_how */ + \
255 0 /* SP4_NONE (for now) */ + \
256 1 /* zero implemetation id array */)
257#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
258 2 /* eir_clientid */ + \
259 1 /* eir_sequenceid */ + \
260 1 /* eir_flags */ + \
261 1 /* spr_how */ + \
262 0 /* SP4_NONE (for now) */ + \
263 2 /* eir_server_owner.so_minor_id */ + \
264 /* eir_server_owner.so_major_id<> */ \
265 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
266 /* eir_server_scope<> */ \
267 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
268 1 /* eir_server_impl_id array length */ + \
269 0 /* ignored eir_server_impl_id contents */)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400270#define encode_sequence_maxsz 0 /* stub */
271#define decode_sequence_maxsz 0 /* stub */
272#else /* CONFIG_NFS_V4_1 */
273#define encode_sequence_maxsz 0
274#define decode_sequence_maxsz 0
275#endif /* CONFIG_NFS_V4_1 */
276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
278#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
279#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400280 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400282 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400284 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400286 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400288 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400290 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400292 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400294 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400296 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400298 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400300 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400302 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400304 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400306 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400307 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400309 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400311 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400312 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400314 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400316 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400317 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400319 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400321 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400322 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400324 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400325 encode_putfh_maxsz + \
326 encode_savefh_maxsz + \
327 encode_open_maxsz + \
328 encode_getfh_maxsz + \
329 encode_getattr_maxsz + \
330 encode_restorefh_maxsz + \
331 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400333 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400334 decode_putfh_maxsz + \
335 decode_savefh_maxsz + \
336 decode_open_maxsz + \
337 decode_getfh_maxsz + \
338 decode_getattr_maxsz + \
339 decode_restorefh_maxsz + \
340 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400341#define NFS4_enc_open_confirm_sz \
342 (compound_encode_hdr_maxsz + \
343 encode_putfh_maxsz + \
344 encode_open_confirm_maxsz)
345#define NFS4_dec_open_confirm_sz \
346 (compound_decode_hdr_maxsz + \
347 decode_putfh_maxsz + \
348 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400350 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400352 encode_open_maxsz + \
353 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400355 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400357 decode_open_maxsz + \
358 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359#define NFS4_enc_open_downgrade_sz \
360 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400361 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400362 encode_putfh_maxsz + \
363 encode_open_downgrade_maxsz + \
364 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365#define NFS4_dec_open_downgrade_sz \
366 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400367 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400368 decode_putfh_maxsz + \
369 decode_open_downgrade_maxsz + \
370 decode_getattr_maxsz)
371#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400372 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400373 encode_putfh_maxsz + \
374 encode_close_maxsz + \
375 encode_getattr_maxsz)
376#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400377 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400378 decode_putfh_maxsz + \
379 decode_close_maxsz + \
380 decode_getattr_maxsz)
381#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400382 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400383 encode_putfh_maxsz + \
384 encode_setattr_maxsz + \
385 encode_getattr_maxsz)
386#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400387 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400388 decode_putfh_maxsz + \
389 decode_setattr_maxsz + \
390 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400392 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 encode_putfh_maxsz + \
394 encode_fsinfo_maxsz)
395#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400396 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 decode_putfh_maxsz + \
398 decode_fsinfo_maxsz)
399#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
400 encode_renew_maxsz)
401#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
402 decode_renew_maxsz)
403#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
404 encode_setclientid_maxsz)
405#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
406 decode_setclientid_maxsz)
407#define NFS4_enc_setclientid_confirm_sz \
408 (compound_encode_hdr_maxsz + \
409 encode_setclientid_confirm_maxsz + \
410 encode_putrootfh_maxsz + \
411 encode_fsinfo_maxsz)
412#define NFS4_dec_setclientid_confirm_sz \
413 (compound_decode_hdr_maxsz + \
414 decode_setclientid_confirm_maxsz + \
415 decode_putrootfh_maxsz + \
416 decode_fsinfo_maxsz)
417#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400418 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400420 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400426 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400428 encode_lockt_maxsz)
429#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400431 decode_putfh_maxsz + \
432 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400434 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400436 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400438 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400440 decode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400444 encode_access_maxsz + \
445 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400447 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400449 decode_access_maxsz + \
450 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400452 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 encode_putfh_maxsz + \
454 encode_getattr_maxsz)
455#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400456 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 decode_putfh_maxsz + \
458 decode_getattr_maxsz)
459#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400460 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 encode_putfh_maxsz + \
462 encode_lookup_maxsz + \
463 encode_getattr_maxsz + \
464 encode_getfh_maxsz)
465#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400466 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400468 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 decode_getattr_maxsz + \
470 decode_getfh_maxsz)
471#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400472 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 encode_putrootfh_maxsz + \
474 encode_getattr_maxsz + \
475 encode_getfh_maxsz)
476#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400477 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 decode_putrootfh_maxsz + \
479 decode_getattr_maxsz + \
480 decode_getfh_maxsz)
481#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400482 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400484 encode_remove_maxsz + \
485 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486#define NFS4_dec_remove_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 + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400489 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400490 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 encode_putfh_maxsz + \
494 encode_savefh_maxsz + \
495 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400496 encode_rename_maxsz + \
497 encode_getattr_maxsz + \
498 encode_restorefh_maxsz + \
499 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400501 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 decode_putfh_maxsz + \
503 decode_savefh_maxsz + \
504 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400505 decode_rename_maxsz + \
506 decode_getattr_maxsz + \
507 decode_restorefh_maxsz + \
508 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400510 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 encode_putfh_maxsz + \
512 encode_savefh_maxsz + \
513 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400514 encode_link_maxsz + \
515 decode_getattr_maxsz + \
516 encode_restorefh_maxsz + \
517 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400519 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 decode_putfh_maxsz + \
521 decode_savefh_maxsz + \
522 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400523 decode_link_maxsz + \
524 decode_getattr_maxsz + \
525 decode_restorefh_maxsz + \
526 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400528 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 encode_putfh_maxsz + \
530 encode_symlink_maxsz + \
531 encode_getattr_maxsz + \
532 encode_getfh_maxsz)
533#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 decode_putfh_maxsz + \
536 decode_symlink_maxsz + \
537 decode_getattr_maxsz + \
538 decode_getfh_maxsz)
539#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400540 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400542 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400544 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400546 encode_restorefh_maxsz + \
547 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400549 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400551 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400553 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400555 decode_restorefh_maxsz + \
556 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400558 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 encode_putfh_maxsz + \
560 encode_getattr_maxsz)
561#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 decode_putfh_maxsz + \
564 decode_getattr_maxsz)
565#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400568 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400572 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800575 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 encode_getattr_maxsz)
577#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400578 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800579 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 decode_getattr_maxsz)
581#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100584 encode_delegreturn_maxsz + \
585 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400587 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100588 decode_delegreturn_maxsz + \
589 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000590#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400591 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000592 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400593 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000594#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400595 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000596 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400597 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000598#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400599 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000600 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400601 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000602#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400603 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000604 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400605 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400606#define NFS4_enc_fs_locations_sz \
607 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400608 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400609 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400610 encode_lookup_maxsz + \
611 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400612#define NFS4_dec_fs_locations_sz \
613 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400614 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400615 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400616 decode_lookup_maxsz + \
617 decode_fs_locations_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400618#if defined(CONFIG_NFS_V4_1)
619#define NFS4_enc_exchange_id_sz \
620 (compound_encode_hdr_maxsz + \
621 encode_exchange_id_maxsz)
622#define NFS4_dec_exchange_id_sz \
623 (compound_decode_hdr_maxsz + \
624 decode_exchange_id_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400625#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
626 encode_sequence_maxsz + \
627 encode_putrootfh_maxsz + \
628 encode_fsinfo_maxsz)
629#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
630 decode_sequence_maxsz + \
631 decode_putrootfh_maxsz + \
632 decode_fsinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400633#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Trond Myklebustbca79472009-03-11 14:10:26 -0400635static const umode_t nfs_type2fmt[] = {
636 [NF4BAD] = 0,
637 [NF4REG] = S_IFREG,
638 [NF4DIR] = S_IFDIR,
639 [NF4BLK] = S_IFBLK,
640 [NF4CHR] = S_IFCHR,
641 [NF4LNK] = S_IFLNK,
642 [NF4SOCK] = S_IFSOCK,
643 [NF4FIFO] = S_IFIFO,
644 [NF4ATTRDIR] = 0,
645 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646};
647
648struct compound_hdr {
649 int32_t status;
650 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500651 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 uint32_t taglen;
653 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400654 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400655 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656};
657
658/*
659 * START OF "GENERIC" ENCODE ROUTINES.
660 * These may look a little ugly since they are imported from a "generic"
661 * set of XDR encode/decode routines which are intended to be shared by
662 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
663 *
664 * If the pain of reading these is too great, it should be a straightforward
665 * task to translate them into Linux-specific versions which are more
666 * consistent with the style used in NFSv2/v3...
667 */
668#define WRITE32(n) *p++ = htonl(n)
669#define WRITE64(n) do { \
670 *p++ = htonl((uint32_t)((n) >> 32)); \
671 *p++ = htonl((uint32_t)(n)); \
672} while (0)
673#define WRITEMEM(ptr,nbytes) do { \
674 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
675} while (0)
676
677#define RESERVE_SPACE(nbytes) do { \
678 p = xdr_reserve_space(xdr, nbytes); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 BUG_ON(!p); \
680} while (0)
681
682static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
683{
Al Viro8687b632006-10-19 23:28:48 -0700684 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
686 p = xdr_reserve_space(xdr, 4 + len);
687 BUG_ON(p == NULL);
688 xdr_encode_opaque(p, str, len);
689}
690
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400691static void encode_compound_hdr(struct xdr_stream *xdr,
692 struct rpc_rqst *req,
693 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694{
Al Viro8687b632006-10-19 23:28:48 -0700695 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400696 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
697
698 /* initialize running count of expected bytes in reply.
699 * NOTE: the replied tag SHOULD be the same is the one sent,
700 * but this is not required as a MUST for the server to do so. */
701 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
703 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
704 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
705 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
706 WRITE32(hdr->taglen);
707 WRITEMEM(hdr->tag, hdr->taglen);
Benny Halevy66cc0422009-04-01 09:22:10 -0400708 WRITE32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500709 hdr->nops_p = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 WRITE32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500711}
712
713static void encode_nops(struct compound_hdr *hdr)
714{
715 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716}
717
718static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
719{
Al Viro8687b632006-10-19 23:28:48 -0700720 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
722 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
723 BUG_ON(p == NULL);
724 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
725}
726
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500727static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728{
729 char owner_name[IDMAP_NAMESZ];
730 char owner_group[IDMAP_NAMESZ];
731 int owner_namelen = 0;
732 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700733 __be32 *p;
734 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 int len;
736 uint32_t bmval0 = 0;
737 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739 /*
740 * We reserve enough space to write the entire attribute buffer at once.
741 * In the worst-case, this would be
742 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
743 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000744 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 */
746 len = 16;
747
748 /* Sigh */
749 if (iap->ia_valid & ATTR_SIZE)
750 len += 8;
751 if (iap->ia_valid & ATTR_MODE)
752 len += 4;
753 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400754 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400756 dprintk("nfs: couldn't resolve uid %d to string\n",
757 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 /* XXX */
759 strcpy(owner_name, "nobody");
760 owner_namelen = sizeof("nobody") - 1;
761 /* goto out; */
762 }
763 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
764 }
765 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400766 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400768 dprintk("nfs: couldn't resolve gid %d to string\n",
769 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 strcpy(owner_group, "nobody");
771 owner_grouplen = sizeof("nobody") - 1;
772 /* goto out; */
773 }
774 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
775 }
776 if (iap->ia_valid & ATTR_ATIME_SET)
777 len += 16;
778 else if (iap->ia_valid & ATTR_ATIME)
779 len += 4;
780 if (iap->ia_valid & ATTR_MTIME_SET)
781 len += 16;
782 else if (iap->ia_valid & ATTR_MTIME)
783 len += 4;
784 RESERVE_SPACE(len);
785
786 /*
787 * We write the bitmap length now, but leave the bitmap and the attribute
788 * buffer length to be backfilled at the end of this routine.
789 */
790 WRITE32(2);
791 q = p;
792 p += 3;
793
794 if (iap->ia_valid & ATTR_SIZE) {
795 bmval0 |= FATTR4_WORD0_SIZE;
796 WRITE64(iap->ia_size);
797 }
798 if (iap->ia_valid & ATTR_MODE) {
799 bmval1 |= FATTR4_WORD1_MODE;
Trond Myklebustcf3fff52006-01-03 09:55:53 +0100800 WRITE32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 }
802 if (iap->ia_valid & ATTR_UID) {
803 bmval1 |= FATTR4_WORD1_OWNER;
804 WRITE32(owner_namelen);
805 WRITEMEM(owner_name, owner_namelen);
806 }
807 if (iap->ia_valid & ATTR_GID) {
808 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
809 WRITE32(owner_grouplen);
810 WRITEMEM(owner_group, owner_grouplen);
811 }
812 if (iap->ia_valid & ATTR_ATIME_SET) {
813 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
814 WRITE32(NFS4_SET_TO_CLIENT_TIME);
815 WRITE32(0);
816 WRITE32(iap->ia_mtime.tv_sec);
817 WRITE32(iap->ia_mtime.tv_nsec);
818 }
819 else if (iap->ia_valid & ATTR_ATIME) {
820 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
821 WRITE32(NFS4_SET_TO_SERVER_TIME);
822 }
823 if (iap->ia_valid & ATTR_MTIME_SET) {
824 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
825 WRITE32(NFS4_SET_TO_CLIENT_TIME);
826 WRITE32(0);
827 WRITE32(iap->ia_mtime.tv_sec);
828 WRITE32(iap->ia_mtime.tv_nsec);
829 }
830 else if (iap->ia_valid & ATTR_MTIME) {
831 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
832 WRITE32(NFS4_SET_TO_SERVER_TIME);
833 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 /*
836 * Now we backfill the bitmap and the attribute buffer length.
837 */
838 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400839 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 len, ((char *)p - (char *)q) + 4);
841 BUG();
842 }
843 len = (char *)p - (char *)q - 12;
844 *q++ = htonl(bmval0);
845 *q++ = htonl(bmval1);
846 *q++ = htonl(len);
847
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849}
850
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500851static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
Al Viro8687b632006-10-19 23:28:48 -0700853 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
855 RESERVE_SPACE(8);
856 WRITE32(OP_ACCESS);
857 WRITE32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500858 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400859 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860}
861
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500862static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863{
Al Viro8687b632006-10-19 23:28:48 -0700864 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400866 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 WRITE32(OP_CLOSE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700868 WRITE32(arg->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400869 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500870 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400871 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872}
873
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500874static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
Al Viro8687b632006-10-19 23:28:48 -0700876 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500877
Andy Adamson05d564f2008-12-23 16:06:15 -0500878 RESERVE_SPACE(16);
879 WRITE32(OP_COMMIT);
880 WRITE64(args->offset);
881 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500882 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400883 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884}
885
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500886static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887{
Al Viro8687b632006-10-19 23:28:48 -0700888 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500889
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 RESERVE_SPACE(8);
891 WRITE32(OP_CREATE);
892 WRITE32(create->ftype);
893
894 switch (create->ftype) {
895 case NF4LNK:
Chuck Lever94a6d752006-08-22 20:06:23 -0400896 RESERVE_SPACE(4);
897 WRITE32(create->u.symlink.len);
898 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 break;
900
901 case NF4BLK: case NF4CHR:
902 RESERVE_SPACE(8);
903 WRITE32(create->u.device.specdata1);
904 WRITE32(create->u.device.specdata2);
905 break;
906
907 default:
908 break;
909 }
910
911 RESERVE_SPACE(4 + create->name->len);
912 WRITE32(create->name->len);
913 WRITEMEM(create->name->name, create->name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500914 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400915 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500917 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918}
919
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500920static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921{
Andy Adamson05d564f2008-12-23 16:06:15 -0500922 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
Andy Adamson05d564f2008-12-23 16:06:15 -0500924 RESERVE_SPACE(12);
925 WRITE32(OP_GETATTR);
926 WRITE32(1);
927 WRITE32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500928 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400929 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930}
931
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500932static 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 -0700933{
Andy Adamson05d564f2008-12-23 16:06:15 -0500934 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Andy Adamson05d564f2008-12-23 16:06:15 -0500936 RESERVE_SPACE(16);
937 WRITE32(OP_GETATTR);
938 WRITE32(2);
939 WRITE32(bm0);
940 WRITE32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -0500941 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400942 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943}
944
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500945static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500947 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
948 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949}
950
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500951static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500953 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
954 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955}
956
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500957static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -0400958{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500959 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
960 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -0400961}
962
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500963static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964{
Al Viro8687b632006-10-19 23:28:48 -0700965 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
967 RESERVE_SPACE(4);
968 WRITE32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -0500969 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400970 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971}
972
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500973static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974{
Al Viro8687b632006-10-19 23:28:48 -0700975 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 RESERVE_SPACE(8 + name->len);
978 WRITE32(OP_LINK);
979 WRITE32(name->len);
980 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500981 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400982 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983}
984
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100985static inline int nfs4_lock_type(struct file_lock *fl, int block)
986{
987 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
988 return block ? NFS4_READW_LT : NFS4_READ_LT;
989 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
990}
991
992static inline uint64_t nfs4_lock_length(struct file_lock *fl)
993{
994 if (fl->fl_end == OFFSET_MAX)
995 return ~(uint64_t)0;
996 return fl->fl_end - fl->fl_start + 1;
997}
998
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999/*
1000 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1001 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1002 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001003static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004{
Al Viro8687b632006-10-19 23:28:48 -07001005 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
1007 RESERVE_SPACE(32);
1008 WRITE32(OP_LOCK);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001009 WRITE32(nfs4_lock_type(args->fl, args->block));
1010 WRITE32(args->reclaim);
1011 WRITE64(args->fl->fl_start);
1012 WRITE64(nfs4_lock_length(args->fl));
1013 WRITE32(args->new_lock_owner);
1014 if (args->new_lock_owner){
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001015 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001016 WRITE32(args->open_seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001017 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001018 WRITE32(args->lock_seqid->sequence->counter);
1019 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001020 WRITE32(16);
1021 WRITEMEM("lock id:", 8);
1022 WRITE64(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 }
1024 else {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001025 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
1026 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001027 WRITE32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 }
Andy Adamsond0179312008-12-23 16:06:17 -05001029 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001030 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031}
1032
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001033static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034{
Al Viro8687b632006-10-19 23:28:48 -07001035 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001037 RESERVE_SPACE(52);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 WRITE32(OP_LOCKT);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001039 WRITE32(nfs4_lock_type(args->fl, 0));
1040 WRITE64(args->fl->fl_start);
1041 WRITE64(nfs4_lock_length(args->fl));
1042 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001043 WRITE32(16);
1044 WRITEMEM("lock id:", 8);
1045 WRITE64(args->lock_owner.id);
Andy Adamsond0179312008-12-23 16:06:17 -05001046 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001047 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048}
1049
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001050static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051{
Al Viro8687b632006-10-19 23:28:48 -07001052 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001054 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 WRITE32(OP_LOCKU);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001056 WRITE32(nfs4_lock_type(args->fl, 0));
1057 WRITE32(args->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001058 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001059 WRITE64(args->fl->fl_start);
1060 WRITE64(nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001061 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001062 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063}
1064
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001065static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
1067 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001068 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
1070 RESERVE_SPACE(8 + len);
1071 WRITE32(OP_LOOKUP);
1072 WRITE32(len);
1073 WRITEMEM(name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001074 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001075 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076}
1077
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001078static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079{
Al Viro8687b632006-10-19 23:28:48 -07001080 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
1082 RESERVE_SPACE(8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001083 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001084 case FMODE_READ:
1085 WRITE32(NFS4_SHARE_ACCESS_READ);
1086 break;
1087 case FMODE_WRITE:
1088 WRITE32(NFS4_SHARE_ACCESS_WRITE);
1089 break;
1090 case FMODE_READ|FMODE_WRITE:
1091 WRITE32(NFS4_SHARE_ACCESS_BOTH);
1092 break;
1093 default:
1094 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 }
1096 WRITE32(0); /* for linux, share_deny = 0 always */
1097}
1098
1099static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1100{
Al Viro8687b632006-10-19 23:28:48 -07001101 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 /*
1103 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1104 * owner 4 = 32
1105 */
1106 RESERVE_SPACE(8);
1107 WRITE32(OP_OPEN);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001108 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001109 encode_share_access(xdr, arg->fmode);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001110 RESERVE_SPACE(28);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 WRITE64(arg->clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001112 WRITE32(16);
1113 WRITEMEM("open id:", 8);
1114 WRITE64(arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115}
1116
1117static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1118{
Al Viro8687b632006-10-19 23:28:48 -07001119 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
1121 RESERVE_SPACE(4);
1122 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001123 case 0:
1124 WRITE32(NFS4_CREATE_UNCHECKED);
1125 encode_attrs(xdr, arg->u.attrs, arg->server);
1126 break;
1127 default:
1128 WRITE32(NFS4_CREATE_EXCLUSIVE);
1129 encode_nfs4_verifier(xdr, &arg->u.verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 }
1131}
1132
1133static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1134{
Al Viro8687b632006-10-19 23:28:48 -07001135 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
1137 RESERVE_SPACE(4);
1138 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001139 case 0:
1140 WRITE32(NFS4_OPEN_NOCREATE);
1141 break;
1142 default:
1143 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1144 WRITE32(NFS4_OPEN_CREATE);
1145 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 }
1147}
1148
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001149static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150{
Al Viro8687b632006-10-19 23:28:48 -07001151 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
1153 RESERVE_SPACE(4);
1154 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001155 case 0:
1156 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1157 break;
1158 case FMODE_READ:
1159 WRITE32(NFS4_OPEN_DELEGATE_READ);
1160 break;
1161 case FMODE_WRITE|FMODE_READ:
1162 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1163 break;
1164 default:
1165 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 }
1167}
1168
1169static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1170{
Al Viro8687b632006-10-19 23:28:48 -07001171 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
1173 RESERVE_SPACE(4);
1174 WRITE32(NFS4_OPEN_CLAIM_NULL);
1175 encode_string(xdr, name->len, name->name);
1176}
1177
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001178static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179{
Al Viro8687b632006-10-19 23:28:48 -07001180 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
1182 RESERVE_SPACE(4);
1183 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1184 encode_delegation_type(xdr, type);
1185}
1186
1187static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1188{
Al Viro8687b632006-10-19 23:28:48 -07001189 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001191 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001193 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 encode_string(xdr, name->len, name->name);
1195}
1196
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001197static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198{
1199 encode_openhdr(xdr, arg);
1200 encode_opentype(xdr, arg);
1201 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001202 case NFS4_OPEN_CLAIM_NULL:
1203 encode_claim_null(xdr, arg->name);
1204 break;
1205 case NFS4_OPEN_CLAIM_PREVIOUS:
1206 encode_claim_previous(xdr, arg->u.delegation_type);
1207 break;
1208 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1209 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1210 break;
1211 default:
1212 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 }
Andy Adamsond0179312008-12-23 16:06:17 -05001214 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001215 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216}
1217
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001218static 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 -07001219{
Al Viro8687b632006-10-19 23:28:48 -07001220 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001222 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 WRITE32(OP_OPEN_CONFIRM);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001224 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001225 WRITE32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001226 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001227 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228}
1229
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001230static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231{
Al Viro8687b632006-10-19 23:28:48 -07001232 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001234 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 WRITE32(OP_OPEN_DOWNGRADE);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001236 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001237 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001238 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001239 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001240 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241}
1242
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001243static void
Andy Adamsond0179312008-12-23 16:06:17 -05001244encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245{
1246 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001247 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
1249 RESERVE_SPACE(8 + len);
1250 WRITE32(OP_PUTFH);
1251 WRITE32(len);
1252 WRITEMEM(fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001253 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001254 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255}
1256
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001257static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
Andy Adamson05d564f2008-12-23 16:06:15 -05001259 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001260
Andy Adamson05d564f2008-12-23 16:06:15 -05001261 RESERVE_SPACE(4);
1262 WRITE32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001263 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001264 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265}
1266
1267static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1268{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001270 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001272 RESERVE_SPACE(NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 if (ctx->state != NULL) {
1274 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001275 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 } else
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001277 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278}
1279
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001280static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281{
Al Viro8687b632006-10-19 23:28:48 -07001282 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
1284 RESERVE_SPACE(4);
1285 WRITE32(OP_READ);
1286
1287 encode_stateid(xdr, args->context);
1288
1289 RESERVE_SPACE(12);
1290 WRITE64(args->offset);
1291 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001292 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001293 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294}
1295
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001296static 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 -07001297{
Manoj Naik97d312d2005-06-22 17:16:39 +00001298 uint32_t attrs[2] = {
1299 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1300 FATTR4_WORD1_MOUNTED_ON_FILEID,
1301 };
Al Viro8687b632006-10-19 23:28:48 -07001302 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001304 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 WRITE32(OP_READDIR);
1306 WRITE64(readdir->cookie);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001307 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1309 WRITE32(readdir->count);
1310 WRITE32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001311 /* Switch to mounted_on_fileid if the server supports it */
1312 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1313 attrs[0] &= ~FATTR4_WORD0_FILEID;
1314 else
1315 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1316 WRITE32(attrs[0] & readdir->bitmask[0]);
1317 WRITE32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001318 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001319 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001320 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1321 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001322 (unsigned long long)readdir->cookie,
1323 ((u32 *)readdir->verifier.data)[0],
1324 ((u32 *)readdir->verifier.data)[1],
1325 attrs[0] & readdir->bitmask[0],
1326 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327}
1328
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001329static 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 -07001330{
Al Viro8687b632006-10-19 23:28:48 -07001331 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
1333 RESERVE_SPACE(4);
1334 WRITE32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001335 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001336 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337}
1338
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001339static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340{
Al Viro8687b632006-10-19 23:28:48 -07001341 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
1343 RESERVE_SPACE(8 + name->len);
1344 WRITE32(OP_REMOVE);
1345 WRITE32(name->len);
1346 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001347 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001348 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349}
1350
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001351static 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 -07001352{
Al Viro8687b632006-10-19 23:28:48 -07001353 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
1355 RESERVE_SPACE(8 + oldname->len);
1356 WRITE32(OP_RENAME);
1357 WRITE32(oldname->len);
1358 WRITEMEM(oldname->name, oldname->len);
Andy Adamson6c0195a2008-12-23 16:06:15 -05001359
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 RESERVE_SPACE(4 + newname->len);
1361 WRITE32(newname->len);
1362 WRITEMEM(newname->name, newname->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001363 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001364 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365}
1366
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001367static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368{
Al Viro8687b632006-10-19 23:28:48 -07001369 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
1371 RESERVE_SPACE(12);
1372 WRITE32(OP_RENEW);
1373 WRITE64(client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001374 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001375 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376}
1377
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001378static void
Andy Adamsond0179312008-12-23 16:06:17 -05001379encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001380{
Al Viro8687b632006-10-19 23:28:48 -07001381 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001382
1383 RESERVE_SPACE(4);
1384 WRITE32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001385 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001386 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001387}
1388
1389static int
Andy Adamsond0179312008-12-23 16:06:17 -05001390encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001391{
Al Viro8687b632006-10-19 23:28:48 -07001392 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001393
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001394 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001395 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001396 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001397 RESERVE_SPACE(2*4);
1398 WRITE32(1);
1399 WRITE32(FATTR4_WORD0_ACL);
1400 if (arg->acl_len % 4)
1401 return -EINVAL;
1402 RESERVE_SPACE(4);
1403 WRITE32(arg->acl_len);
1404 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001405 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001406 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001407 return 0;
1408}
1409
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001410static void
Andy Adamsond0179312008-12-23 16:06:17 -05001411encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412{
Al Viro8687b632006-10-19 23:28:48 -07001413 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
1415 RESERVE_SPACE(4);
1416 WRITE32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001417 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001418 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419}
1420
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001421static 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 -07001422{
Al Viro8687b632006-10-19 23:28:48 -07001423 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001424
Andy Adamson05d564f2008-12-23 16:06:15 -05001425 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1426 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001427 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001428 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001429 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001430 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431}
1432
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001433static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434{
Al Viro8687b632006-10-19 23:28:48 -07001435 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001437 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 WRITE32(OP_SETCLIENTID);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001439 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
1441 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1442 RESERVE_SPACE(4);
1443 WRITE32(setclientid->sc_prog);
1444 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1445 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1446 RESERVE_SPACE(4);
1447 WRITE32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001448 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001449 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450}
1451
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001452static 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 -07001453{
Andy Adamson05d564f2008-12-23 16:06:15 -05001454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Andy Adamson05d564f2008-12-23 16:06:15 -05001456 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1457 WRITE32(OP_SETCLIENTID_CONFIRM);
1458 WRITE64(client_state->cl_clientid);
1459 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001460 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001461 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462}
1463
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001464static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465{
Al Viro8687b632006-10-19 23:28:48 -07001466 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
1468 RESERVE_SPACE(4);
1469 WRITE32(OP_WRITE);
1470
1471 encode_stateid(xdr, args->context);
1472
1473 RESERVE_SPACE(16);
1474 WRITE64(args->offset);
1475 WRITE32(args->stable);
1476 WRITE32(args->count);
1477
1478 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001479 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001480 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481}
1482
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001483static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484{
Al Viro8687b632006-10-19 23:28:48 -07001485 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001487 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
1489 WRITE32(OP_DELEGRETURN);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001490 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001491 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001492 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001494
Benny Halevy99fe60d2009-04-01 09:22:29 -04001495#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001496/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001497static void encode_exchange_id(struct xdr_stream *xdr,
1498 struct nfs41_exchange_id_args *args,
1499 struct compound_hdr *hdr)
1500{
1501 __be32 *p;
1502
1503 RESERVE_SPACE(4 + sizeof(args->verifier->data));
1504 WRITE32(OP_EXCHANGE_ID);
1505 WRITEMEM(args->verifier->data, sizeof(args->verifier->data));
1506
1507 encode_string(xdr, args->id_len, args->id);
1508
1509 RESERVE_SPACE(12);
1510 WRITE32(args->flags);
1511 WRITE32(0); /* zero length state_protect4_a */
1512 WRITE32(0); /* zero length implementation id array */
1513 hdr->nops++;
1514 hdr->replen += decode_exchange_id_maxsz;
1515}
1516#endif /* CONFIG_NFS_V4_1 */
1517
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001518static void encode_sequence(struct xdr_stream *xdr,
1519 const struct nfs4_sequence_args *args,
1520 struct compound_hdr *hdr)
1521{
1522#if defined(CONFIG_NFS_V4_1)
1523 struct nfs4_session *session = args->sa_session;
1524
1525 if (!session)
1526 return;
1527
1528 /* stub */
1529 hdr->nops++;
1530 hdr->replen += decode_sequence_maxsz;
1531#endif /* CONFIG_NFS_V4_1 */
1532}
1533
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534/*
1535 * END OF "GENERIC" ENCODE ROUTINES.
1536 */
1537
Benny Halevy66cc0422009-04-01 09:22:10 -04001538static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1539{
1540#if defined(CONFIG_NFS_V4_1)
1541 if (args->sa_session)
1542 return args->sa_session->clp->cl_minorversion;
1543#endif /* CONFIG_NFS_V4_1 */
1544 return 0;
1545}
1546
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547/*
1548 * Encode an ACCESS request
1549 */
Al Viro8687b632006-10-19 23:28:48 -07001550static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
1552 struct xdr_stream xdr;
1553 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001554 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
1557 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001558 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001559 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001560 encode_putfh(&xdr, args->fh, &hdr);
1561 encode_access(&xdr, args->access, &hdr);
1562 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001563 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001564 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565}
1566
1567/*
1568 * Encode LOOKUP request
1569 */
Al Viro8687b632006-10-19 23:28:48 -07001570static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571{
1572 struct xdr_stream xdr;
1573 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001574 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
1577 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001578 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001579 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001580 encode_putfh(&xdr, args->dir_fh, &hdr);
1581 encode_lookup(&xdr, args->name, &hdr);
1582 encode_getfh(&xdr, &hdr);
1583 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001584 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001585 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586}
1587
1588/*
1589 * Encode LOOKUP_ROOT request
1590 */
Al Viro8687b632006-10-19 23:28:48 -07001591static 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 -07001592{
1593 struct xdr_stream xdr;
1594 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001595 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
1598 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001599 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001600 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001601 encode_putrootfh(&xdr, &hdr);
1602 encode_getfh(&xdr, &hdr);
1603 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001604 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001605 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606}
1607
1608/*
1609 * Encode REMOVE request
1610 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001611static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612{
1613 struct xdr_stream xdr;
1614 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001615 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
1618 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001619 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001620 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001621 encode_putfh(&xdr, args->fh, &hdr);
1622 encode_remove(&xdr, &args->name, &hdr);
1623 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001624 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001625 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626}
1627
1628/*
1629 * Encode RENAME request
1630 */
Al Viro8687b632006-10-19 23:28:48 -07001631static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632{
1633 struct xdr_stream xdr;
1634 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001635 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
1638 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001639 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001640 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001641 encode_putfh(&xdr, args->old_dir, &hdr);
1642 encode_savefh(&xdr, &hdr);
1643 encode_putfh(&xdr, args->new_dir, &hdr);
1644 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1645 encode_getfattr(&xdr, args->bitmask, &hdr);
1646 encode_restorefh(&xdr, &hdr);
1647 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001648 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001649 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650}
1651
1652/*
1653 * Encode LINK request
1654 */
Al Viro8687b632006-10-19 23:28:48 -07001655static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656{
1657 struct xdr_stream xdr;
1658 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001659 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661
1662 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001663 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001664 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001665 encode_putfh(&xdr, args->fh, &hdr);
1666 encode_savefh(&xdr, &hdr);
1667 encode_putfh(&xdr, args->dir_fh, &hdr);
1668 encode_link(&xdr, args->name, &hdr);
1669 encode_getfattr(&xdr, args->bitmask, &hdr);
1670 encode_restorefh(&xdr, &hdr);
1671 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001672 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001673 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674}
1675
1676/*
1677 * Encode CREATE request
1678 */
Al Viro8687b632006-10-19 23:28:48 -07001679static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680{
1681 struct xdr_stream xdr;
1682 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001683 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
1686 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001687 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001688 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001689 encode_putfh(&xdr, args->dir_fh, &hdr);
1690 encode_savefh(&xdr, &hdr);
1691 encode_create(&xdr, args, &hdr);
1692 encode_getfh(&xdr, &hdr);
1693 encode_getfattr(&xdr, args->bitmask, &hdr);
1694 encode_restorefh(&xdr, &hdr);
1695 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001696 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001697 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698}
1699
1700/*
1701 * Encode SYMLINK request
1702 */
Al Viro8687b632006-10-19 23:28:48 -07001703static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704{
1705 return nfs4_xdr_enc_create(req, p, args);
1706}
1707
1708/*
1709 * Encode GETATTR request
1710 */
Al Viro8687b632006-10-19 23:28:48 -07001711static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712{
1713 struct xdr_stream xdr;
1714 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001715 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717
1718 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001719 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001720 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001721 encode_putfh(&xdr, args->fh, &hdr);
1722 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001723 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001724 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725}
1726
1727/*
1728 * Encode a CLOSE request
1729 */
Al Viro8687b632006-10-19 23:28:48 -07001730static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731{
Andy Adamson05d564f2008-12-23 16:06:15 -05001732 struct xdr_stream xdr;
1733 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001734 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001735 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
Andy Adamson05d564f2008-12-23 16:06:15 -05001737 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001738 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001739 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001740 encode_putfh(&xdr, args->fh, &hdr);
1741 encode_close(&xdr, args, &hdr);
1742 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001743 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001744 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745}
1746
1747/*
1748 * Encode an OPEN request
1749 */
Al Viro8687b632006-10-19 23:28:48 -07001750static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751{
1752 struct xdr_stream xdr;
1753 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001754 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756
1757 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001758 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001759 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001760 encode_putfh(&xdr, args->fh, &hdr);
1761 encode_savefh(&xdr, &hdr);
1762 encode_open(&xdr, args, &hdr);
1763 encode_getfh(&xdr, &hdr);
1764 encode_getfattr(&xdr, args->bitmask, &hdr);
1765 encode_restorefh(&xdr, &hdr);
1766 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001767 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001768 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769}
1770
1771/*
1772 * Encode an OPEN_CONFIRM request
1773 */
Al Viro8687b632006-10-19 23:28:48 -07001774static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775{
1776 struct xdr_stream xdr;
1777 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001778 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780
1781 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001782 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001783 encode_putfh(&xdr, args->fh, &hdr);
1784 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001785 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001786 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787}
1788
1789/*
1790 * Encode an OPEN request with no attributes.
1791 */
Al Viro8687b632006-10-19 23:28:48 -07001792static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793{
1794 struct xdr_stream xdr;
1795 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001796 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
1799 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001800 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001801 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001802 encode_putfh(&xdr, args->fh, &hdr);
1803 encode_open(&xdr, args, &hdr);
1804 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001805 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001806 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807}
1808
1809/*
1810 * Encode an OPEN_DOWNGRADE request
1811 */
Al Viro8687b632006-10-19 23:28:48 -07001812static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813{
1814 struct xdr_stream xdr;
1815 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001816 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818
1819 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001820 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001821 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001822 encode_putfh(&xdr, args->fh, &hdr);
1823 encode_open_downgrade(&xdr, args, &hdr);
1824 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001825 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001826 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827}
1828
1829/*
1830 * Encode a LOCK request
1831 */
Al Viro8687b632006-10-19 23:28:48 -07001832static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833{
1834 struct xdr_stream xdr;
1835 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001836 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838
1839 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001840 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001841 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001842 encode_putfh(&xdr, args->fh, &hdr);
1843 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001844 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001845 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846}
1847
1848/*
1849 * Encode a LOCKT request
1850 */
Al Viro8687b632006-10-19 23:28:48 -07001851static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852{
1853 struct xdr_stream xdr;
1854 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001855 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857
1858 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001859 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001860 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001861 encode_putfh(&xdr, args->fh, &hdr);
1862 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001863 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001864 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865}
1866
1867/*
1868 * Encode a LOCKU request
1869 */
Al Viro8687b632006-10-19 23:28:48 -07001870static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871{
1872 struct xdr_stream xdr;
1873 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001874 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876
1877 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001878 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001879 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001880 encode_putfh(&xdr, args->fh, &hdr);
1881 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001882 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001883 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884}
1885
1886/*
1887 * Encode a READLINK request
1888 */
Al Viro8687b632006-10-19 23:28:48 -07001889static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890{
1891 struct xdr_stream xdr;
1892 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001893 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
1896 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001897 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001898 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001899 encode_putfh(&xdr, args->fh, &hdr);
1900 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04001901
Benny Halevy28f56692009-04-01 09:22:09 -04001902 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04001903 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05001904 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001905 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906}
1907
1908/*
1909 * Encode a READDIR request
1910 */
Al Viro8687b632006-10-19 23:28:48 -07001911static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912{
1913 struct xdr_stream xdr;
1914 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001915 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
1918 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001919 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001920 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001921 encode_putfh(&xdr, args->fh, &hdr);
1922 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001923
Benny Halevy28f56692009-04-01 09:22:09 -04001924 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001925 args->pgbase, args->count);
1926 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04001927 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001928 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001929 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001930 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931}
1932
1933/*
1934 * Encode a READ request
1935 */
Al Viro8687b632006-10-19 23:28:48 -07001936static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 struct xdr_stream xdr;
1939 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001940 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
1943 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001944 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001945 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001946 encode_putfh(&xdr, args->fh, &hdr);
1947 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
Benny Halevy28f56692009-04-01 09:22:09 -04001949 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04001951 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05001952 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001953 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954}
1955
1956/*
1957 * Encode an SETATTR request
1958 */
Al Viro8687b632006-10-19 23:28:48 -07001959static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960{
Andy Adamson05d564f2008-12-23 16:06:15 -05001961 struct xdr_stream xdr;
1962 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001963 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001964 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965
Andy Adamson05d564f2008-12-23 16:06:15 -05001966 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001967 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001968 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001969 encode_putfh(&xdr, args->fh, &hdr);
1970 encode_setattr(&xdr, args, args->server, &hdr);
1971 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001972 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001973 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974}
1975
1976/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00001977 * Encode a GETACL request
1978 */
1979static int
Al Viro8687b632006-10-19 23:28:48 -07001980nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001981 struct nfs_getaclargs *args)
1982{
1983 struct xdr_stream xdr;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001984 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001985 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00001986 };
Benny Halevy28f56692009-04-01 09:22:09 -04001987 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001988
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);
Benny Halevy28f56692009-04-01 09:22:09 -04001993 replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001994 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
1995
Benny Halevy28f56692009-04-01 09:22:09 -04001996 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001997 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001998 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001999 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002000}
2001
2002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 * Encode a WRITE request
2004 */
Al Viro8687b632006-10-19 23:28:48 -07002005static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006{
2007 struct xdr_stream xdr;
2008 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002009 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
2012 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002013 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002014 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002015 encode_putfh(&xdr, args->fh, &hdr);
2016 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002017 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002018 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002019 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002020 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021}
2022
2023/*
2024 * a COMMIT request
2025 */
Al Viro8687b632006-10-19 23:28:48 -07002026static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027{
2028 struct xdr_stream xdr;
2029 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002030 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032
2033 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002034 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002035 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002036 encode_putfh(&xdr, args->fh, &hdr);
2037 encode_commit(&xdr, args, &hdr);
2038 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002039 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002040 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041}
2042
2043/*
2044 * FSINFO request
2045 */
Al Viro8687b632006-10-19 23:28:48 -07002046static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047{
2048 struct xdr_stream xdr;
2049 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002050 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052
2053 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002054 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002055 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002056 encode_putfh(&xdr, args->fh, &hdr);
2057 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002058 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002059 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060}
2061
2062/*
2063 * a PATHCONF request
2064 */
Al Viro8687b632006-10-19 23:28:48 -07002065static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 struct xdr_stream xdr;
2068 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002069 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
2072 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002073 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002074 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002075 encode_putfh(&xdr, args->fh, &hdr);
2076 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2077 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002078 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002079 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080}
2081
2082/*
2083 * a STATFS request
2084 */
Al Viro8687b632006-10-19 23:28:48 -07002085static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 struct xdr_stream xdr;
2088 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002089 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
2092 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002093 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002094 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002095 encode_putfh(&xdr, args->fh, &hdr);
2096 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2097 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002098 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002099 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100}
2101
2102/*
2103 * GETATTR_BITMAP request
2104 */
Benny Halevy43652ad2009-04-01 09:21:54 -04002105static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2106 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107{
2108 struct xdr_stream xdr;
2109 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002110 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
2113 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002114 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002115 encode_sequence(&xdr, &args->seq_args, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04002116 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002117 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2118 FATTR4_WORD0_LINK_SUPPORT|
2119 FATTR4_WORD0_SYMLINK_SUPPORT|
2120 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002121 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002122 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123}
2124
2125/*
2126 * a RENEW request
2127 */
Al Viro8687b632006-10-19 23:28:48 -07002128static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129{
2130 struct xdr_stream xdr;
2131 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002132 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 };
2134
2135 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002136 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002137 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002138 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002139 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140}
2141
2142/*
2143 * a SETCLIENTID request
2144 */
Al Viro8687b632006-10-19 23:28:48 -07002145static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146{
2147 struct xdr_stream xdr;
2148 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002149 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 };
2151
2152 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002153 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002154 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002155 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002156 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157}
2158
2159/*
2160 * a SETCLIENTID_CONFIRM request
2161 */
Al Viro8687b632006-10-19 23:28:48 -07002162static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163{
2164 struct xdr_stream xdr;
2165 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002166 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 };
2168 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
2170 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002171 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002172 encode_setclientid_confirm(&xdr, clp, &hdr);
2173 encode_putrootfh(&xdr, &hdr);
2174 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002175 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002176 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177}
2178
2179/*
2180 * DELEGRETURN request
2181 */
Al Viro8687b632006-10-19 23:28:48 -07002182static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183{
2184 struct xdr_stream xdr;
2185 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002186 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
2189 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002190 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002191 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002192 encode_putfh(&xdr, args->fhandle, &hdr);
2193 encode_delegreturn(&xdr, args->stateid, &hdr);
2194 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002195 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002196 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197}
2198
2199/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002200 * Encode FS_LOCATIONS request
2201 */
Al Viro8687b632006-10-19 23:28:48 -07002202static 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 -04002203{
2204 struct xdr_stream xdr;
2205 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002206 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002207 };
Benny Halevy28f56692009-04-01 09:22:09 -04002208 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002209
2210 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002211 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002212 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002213 encode_putfh(&xdr, args->dir_fh, &hdr);
2214 encode_lookup(&xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002215 replen = hdr.replen; /* get the attribute into args->page */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002216 encode_fs_locations(&xdr, args->bitmask, &hdr);
2217
Benny Halevy28f56692009-04-01 09:22:09 -04002218 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002219 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002220 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002221 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002222}
2223
Benny Halevy99fe60d2009-04-01 09:22:29 -04002224#if defined(CONFIG_NFS_V4_1)
2225/*
2226 * EXCHANGE_ID request
2227 */
2228static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2229 struct nfs41_exchange_id_args *args)
2230{
2231 struct xdr_stream xdr;
2232 struct compound_hdr hdr = {
2233 .minorversion = args->client->cl_minorversion,
2234 };
2235
2236 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2237 encode_compound_hdr(&xdr, req, &hdr);
2238 encode_exchange_id(&xdr, args, &hdr);
2239 encode_nops(&hdr);
2240 return 0;
2241}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002242
2243/*
2244 * a GET_LEASE_TIME request
2245 */
2246static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2247 struct nfs4_get_lease_time_args *args)
2248{
2249 struct xdr_stream xdr;
2250 struct compound_hdr hdr = {
2251 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2252 };
2253 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2254
2255 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2256 encode_compound_hdr(&xdr, req, &hdr);
2257 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2258 encode_putrootfh(&xdr, &hdr);
2259 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2260 encode_nops(&hdr);
2261 return 0;
2262}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002263#endif /* CONFIG_NFS_V4_1 */
2264
Trond Myklebust683b57b2006-06-09 09:34:22 -04002265/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 * START OF "GENERIC" DECODE ROUTINES.
2267 * These may look a little ugly since they are imported from a "generic"
2268 * set of XDR encode/decode routines which are intended to be shared by
2269 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2270 *
2271 * If the pain of reading these is too great, it should be a straightforward
2272 * task to translate them into Linux-specific versions which are more
2273 * consistent with the style used in NFSv2/v3...
2274 */
2275#define READ32(x) (x) = ntohl(*p++)
2276#define READ64(x) do { \
2277 (x) = (u64)ntohl(*p++) << 32; \
2278 (x) |= ntohl(*p++); \
2279} while (0)
2280#define READTIME(x) do { \
2281 p++; \
2282 (x.tv_sec) = ntohl(*p++); \
2283 (x.tv_nsec) = ntohl(*p++); \
2284} while (0)
2285#define COPYMEM(x,nbytes) do { \
2286 memcpy((x), p, nbytes); \
2287 p += XDR_QUADLEN(nbytes); \
2288} while (0)
2289
2290#define READ_BUF(nbytes) do { \
2291 p = xdr_inline_decode(xdr, nbytes); \
Chuck Levere4cc6ee2007-05-08 18:23:28 -04002292 if (unlikely(!p)) { \
Chuck Leverfe82a182007-09-11 18:01:10 -04002293 dprintk("nfs: %s: prematurely hit end of receive" \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002294 " buffer\n", __func__); \
Chuck Leverfe82a182007-09-11 18:01:10 -04002295 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002296 __func__, xdr->p, nbytes, xdr->end); \
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 return -EIO; \
2298 } \
2299} while (0)
2300
Trond Myklebust683b57b2006-06-09 09:34:22 -04002301static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302{
Al Viro8687b632006-10-19 23:28:48 -07002303 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
2305 READ_BUF(4);
2306 READ32(*len);
2307 READ_BUF(*len);
2308 *string = (char *)p;
2309 return 0;
2310}
2311
2312static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2313{
Al Viro8687b632006-10-19 23:28:48 -07002314 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
2316 READ_BUF(8);
2317 READ32(hdr->status);
2318 READ32(hdr->taglen);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002319
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 READ_BUF(hdr->taglen + 4);
2321 hdr->tag = (char *)p;
2322 p += XDR_QUADLEN(hdr->taglen);
2323 READ32(hdr->nops);
Benny Halevyaadf6152008-12-23 16:06:13 -05002324 if (unlikely(hdr->nops < 1))
2325 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 return 0;
2327}
2328
2329static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2330{
Al Viro8687b632006-10-19 23:28:48 -07002331 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 uint32_t opnum;
2333 int32_t nfserr;
2334
2335 READ_BUF(8);
2336 READ32(opnum);
2337 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002338 dprintk("nfs: Server returned operation"
2339 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 opnum, expected);
2341 return -EIO;
2342 }
2343 READ32(nfserr);
2344 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002345 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 return 0;
2347}
2348
2349/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002350static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351{
Al Viro8687b632006-10-19 23:28:48 -07002352 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002353 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 char *str;
2355
2356 READ_BUF(12);
2357 return decode_opaque_inline(xdr, &strlen, &str);
2358}
2359
2360static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2361{
Al Viro8687b632006-10-19 23:28:48 -07002362 uint32_t bmlen;
2363 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
2365 READ_BUF(4);
2366 READ32(bmlen);
2367
2368 bitmap[0] = bitmap[1] = 0;
2369 READ_BUF((bmlen << 2));
2370 if (bmlen > 0) {
2371 READ32(bitmap[0]);
2372 if (bmlen > 1)
2373 READ32(bitmap[1]);
2374 }
2375 return 0;
2376}
2377
Al Viro8687b632006-10-19 23:28:48 -07002378static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379{
Al Viro8687b632006-10-19 23:28:48 -07002380 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
2382 READ_BUF(4);
2383 READ32(*attrlen);
2384 *savep = xdr->p;
2385 return 0;
2386}
2387
2388static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2389{
2390 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2391 decode_attr_bitmap(xdr, bitmask);
2392 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2393 } else
2394 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002395 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 return 0;
2397}
2398
2399static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2400{
Al Viro8687b632006-10-19 23:28:48 -07002401 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002402 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403
2404 *type = 0;
2405 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2406 return -EIO;
2407 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2408 READ_BUF(4);
2409 READ32(*type);
2410 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002411 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 return -EIO;
2413 }
2414 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002415 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002417 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002418 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419}
2420
2421static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2422{
Al Viro8687b632006-10-19 23:28:48 -07002423 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002424 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425
2426 *change = 0;
2427 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2428 return -EIO;
2429 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2430 READ_BUF(8);
2431 READ64(*change);
2432 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002433 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002435 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002437 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438}
2439
2440static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2441{
Al Viro8687b632006-10-19 23:28:48 -07002442 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002443 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
2445 *size = 0;
2446 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2447 return -EIO;
2448 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2449 READ_BUF(8);
2450 READ64(*size);
2451 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002452 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002454 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002455 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456}
2457
2458static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2459{
Al Viro8687b632006-10-19 23:28:48 -07002460 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461
2462 *res = 0;
2463 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2464 return -EIO;
2465 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2466 READ_BUF(4);
2467 READ32(*res);
2468 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2469 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002470 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 return 0;
2472}
2473
2474static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2475{
Al Viro8687b632006-10-19 23:28:48 -07002476 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477
2478 *res = 0;
2479 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2480 return -EIO;
2481 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2482 READ_BUF(4);
2483 READ32(*res);
2484 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2485 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002486 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 return 0;
2488}
2489
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002490static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491{
Al Viro8687b632006-10-19 23:28:48 -07002492 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002493 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494
2495 fsid->major = 0;
2496 fsid->minor = 0;
2497 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2498 return -EIO;
2499 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2500 READ_BUF(16);
2501 READ64(fsid->major);
2502 READ64(fsid->minor);
2503 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002504 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002506 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 (unsigned long long)fsid->major,
2508 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002509 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510}
2511
2512static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2513{
Al Viro8687b632006-10-19 23:28:48 -07002514 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515
2516 *res = 60;
2517 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2518 return -EIO;
2519 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2520 READ_BUF(4);
2521 READ32(*res);
2522 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2523 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002524 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 return 0;
2526}
2527
2528static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2529{
Al Viro8687b632006-10-19 23:28:48 -07002530 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
2532 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2533 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2534 return -EIO;
2535 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2536 READ_BUF(4);
2537 READ32(*res);
2538 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2539 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002540 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 return 0;
2542}
2543
2544static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2545{
Al Viro8687b632006-10-19 23:28:48 -07002546 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002547 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548
2549 *fileid = 0;
2550 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2551 return -EIO;
2552 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2553 READ_BUF(8);
2554 READ64(*fileid);
2555 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002556 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002558 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002559 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560}
2561
Manoj Naik99baf622006-06-09 09:34:24 -04002562static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2563{
Al Viro8687b632006-10-19 23:28:48 -07002564 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002565 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002566
2567 *fileid = 0;
2568 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2569 return -EIO;
2570 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2571 READ_BUF(8);
2572 READ64(*fileid);
2573 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002574 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002575 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002576 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002577 return ret;
Manoj Naik99baf622006-06-09 09:34:24 -04002578}
2579
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2581{
Al Viro8687b632006-10-19 23:28:48 -07002582 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 int status = 0;
2584
2585 *res = 0;
2586 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2587 return -EIO;
2588 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2589 READ_BUF(8);
2590 READ64(*res);
2591 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2592 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002593 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 return status;
2595}
2596
2597static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2598{
Al Viro8687b632006-10-19 23:28:48 -07002599 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 int status = 0;
2601
2602 *res = 0;
2603 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2604 return -EIO;
2605 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2606 READ_BUF(8);
2607 READ64(*res);
2608 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2609 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002610 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 return status;
2612}
2613
2614static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2615{
Al Viro8687b632006-10-19 23:28:48 -07002616 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 int status = 0;
2618
2619 *res = 0;
2620 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2621 return -EIO;
2622 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2623 READ_BUF(8);
2624 READ64(*res);
2625 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2626 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002627 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 return status;
2629}
2630
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002631static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2632{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002633 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002634 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002635 int status = 0;
2636
2637 READ_BUF(4);
2638 READ32(n);
Andy Adamson33a43f22006-06-09 09:34:30 -04002639 if (n == 0)
2640 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002641 dprintk("path ");
2642 path->ncomponents = 0;
2643 while (path->ncomponents < n) {
2644 struct nfs4_string *component = &path->components[path->ncomponents];
2645 status = decode_opaque_inline(xdr, &component->len, &component->data);
2646 if (unlikely(status != 0))
2647 goto out_eio;
2648 if (path->ncomponents != n)
2649 dprintk("/");
2650 dprintk("%s", component->data);
2651 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2652 path->ncomponents++;
2653 else {
2654 dprintk("cannot parse %d components in path\n", n);
2655 goto out_eio;
2656 }
2657 }
2658out:
2659 dprintk("\n");
2660 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002661root_path:
2662/* a root pathname is sent as a zero component4 */
2663 path->ncomponents = 1;
2664 path->components[0].len=0;
2665 path->components[0].data=NULL;
2666 dprintk("path /\n");
2667 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002668out_eio:
2669 dprintk(" status %d", status);
2670 status = -EIO;
2671 goto out;
2672}
2673
2674static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002675{
2676 int n;
Al Viro8687b632006-10-19 23:28:48 -07002677 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002678 int status = -EIO;
2679
2680 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2681 goto out;
2682 status = 0;
2683 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2684 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002685 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002686 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002687 if (unlikely(status != 0))
2688 goto out;
2689 READ_BUF(4);
2690 READ32(n);
2691 if (n <= 0)
2692 goto out_eio;
2693 res->nlocations = 0;
2694 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002695 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002696 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04002697
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002698 READ_BUF(4);
2699 READ32(m);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002700
2701 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002702 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002703 while (loc->nservers < m) {
2704 struct nfs4_string *server = &loc->servers[loc->nservers];
2705 status = decode_opaque_inline(xdr, &server->len, &server->data);
2706 if (unlikely(status != 0))
2707 goto out_eio;
2708 dprintk("%s ", server->data);
2709 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2710 loc->nservers++;
2711 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002712 unsigned int i;
2713 dprintk("%s: using first %u of %u servers "
2714 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002715 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04002716 NFS4_FS_LOCATION_MAXSERVERS,
2717 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002718 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002719 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002720 char *data;
2721 status = decode_opaque_inline(xdr, &len, &data);
2722 if (unlikely(status != 0))
2723 goto out_eio;
2724 }
2725 }
2726 }
2727 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002728 if (unlikely(status != 0))
2729 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002730 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002731 res->nlocations++;
2732 }
Trond Myklebust409924e2009-03-11 14:10:27 -04002733 if (res->nlocations != 0)
2734 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002735out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002736 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002737 return status;
2738out_eio:
2739 status = -EIO;
2740 goto out;
2741}
2742
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2744{
Al Viro8687b632006-10-19 23:28:48 -07002745 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 int status = 0;
2747
2748 *res = 0;
2749 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2750 return -EIO;
2751 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2752 READ_BUF(8);
2753 READ64(*res);
2754 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2755 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002756 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 return status;
2758}
2759
2760static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2761{
Al Viro8687b632006-10-19 23:28:48 -07002762 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 int status = 0;
2764
2765 *maxlink = 1;
2766 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2767 return -EIO;
2768 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2769 READ_BUF(4);
2770 READ32(*maxlink);
2771 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2772 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002773 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 return status;
2775}
2776
2777static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2778{
Al Viro8687b632006-10-19 23:28:48 -07002779 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 int status = 0;
2781
2782 *maxname = 1024;
2783 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2784 return -EIO;
2785 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2786 READ_BUF(4);
2787 READ32(*maxname);
2788 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2789 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002790 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 return status;
2792}
2793
2794static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2795{
Al Viro8687b632006-10-19 23:28:48 -07002796 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 int status = 0;
2798
2799 *res = 1024;
2800 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2801 return -EIO;
2802 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2803 uint64_t maxread;
2804 READ_BUF(8);
2805 READ64(maxread);
2806 if (maxread > 0x7FFFFFFF)
2807 maxread = 0x7FFFFFFF;
2808 *res = (uint32_t)maxread;
2809 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2810 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002811 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 return status;
2813}
2814
2815static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2816{
Al Viro8687b632006-10-19 23:28:48 -07002817 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 int status = 0;
2819
2820 *res = 1024;
2821 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2822 return -EIO;
2823 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2824 uint64_t maxwrite;
2825 READ_BUF(8);
2826 READ64(maxwrite);
2827 if (maxwrite > 0x7FFFFFFF)
2828 maxwrite = 0x7FFFFFFF;
2829 *res = (uint32_t)maxwrite;
2830 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2831 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002832 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 return status;
2834}
2835
Trond Myklebustbca79472009-03-11 14:10:26 -04002836static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837{
Trond Myklebustbca79472009-03-11 14:10:26 -04002838 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07002839 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002840 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841
2842 *mode = 0;
2843 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2844 return -EIO;
2845 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2846 READ_BUF(4);
Trond Myklebustbca79472009-03-11 14:10:26 -04002847 READ32(tmp);
2848 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002850 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002852 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04002853 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854}
2855
2856static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2857{
Al Viro8687b632006-10-19 23:28:48 -07002858 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002859 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860
2861 *nlink = 1;
2862 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2863 return -EIO;
2864 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2865 READ_BUF(4);
2866 READ32(*nlink);
2867 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04002868 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002870 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04002871 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872}
2873
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002874static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875{
Al Viro8687b632006-10-19 23:28:48 -07002876 uint32_t len;
2877 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002878 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879
2880 *uid = -2;
2881 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2882 return -EIO;
2883 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2884 READ_BUF(4);
2885 READ32(len);
2886 READ_BUF(len);
2887 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04002888 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
2889 ret = NFS_ATTR_FATTR_OWNER;
2890 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002892 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04002894 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002895 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2897 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002898 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002899 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900}
2901
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002902static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903{
Al Viro8687b632006-10-19 23:28:48 -07002904 uint32_t len;
2905 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002906 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907
2908 *gid = -2;
2909 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2910 return -EIO;
2911 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2912 READ_BUF(4);
2913 READ32(len);
2914 READ_BUF(len);
2915 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04002916 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
2917 ret = NFS_ATTR_FATTR_GROUP;
2918 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002920 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04002922 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002923 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2925 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002926 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002927 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928}
2929
2930static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2931{
Al Viro8687b632006-10-19 23:28:48 -07002932 uint32_t major = 0, minor = 0;
2933 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002934 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935
2936 *rdev = MKDEV(0,0);
2937 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2938 return -EIO;
2939 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2940 dev_t tmp;
2941
2942 READ_BUF(8);
2943 READ32(major);
2944 READ32(minor);
2945 tmp = MKDEV(major, minor);
2946 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2947 *rdev = tmp;
2948 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04002949 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002951 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002952 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953}
2954
2955static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2956{
Al Viro8687b632006-10-19 23:28:48 -07002957 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 int status = 0;
2959
2960 *res = 0;
2961 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2962 return -EIO;
2963 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2964 READ_BUF(8);
2965 READ64(*res);
2966 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2967 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002968 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 return status;
2970}
2971
2972static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2973{
Al Viro8687b632006-10-19 23:28:48 -07002974 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 int status = 0;
2976
2977 *res = 0;
2978 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2979 return -EIO;
2980 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2981 READ_BUF(8);
2982 READ64(*res);
2983 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2984 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002985 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 return status;
2987}
2988
2989static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2990{
Al Viro8687b632006-10-19 23:28:48 -07002991 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 int status = 0;
2993
2994 *res = 0;
2995 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2996 return -EIO;
2997 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2998 READ_BUF(8);
2999 READ64(*res);
3000 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3001 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003002 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 return status;
3004}
3005
3006static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3007{
Al Viro8687b632006-10-19 23:28:48 -07003008 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003009 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010
3011 *used = 0;
3012 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3013 return -EIO;
3014 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3015 READ_BUF(8);
3016 READ64(*used);
3017 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003018 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003020 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003022 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023}
3024
3025static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3026{
Al Viro8687b632006-10-19 23:28:48 -07003027 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 uint64_t sec;
3029 uint32_t nsec;
3030
3031 READ_BUF(12);
3032 READ64(sec);
3033 READ32(nsec);
3034 time->tv_sec = (time_t)sec;
3035 time->tv_nsec = (long)nsec;
3036 return 0;
3037}
3038
3039static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3040{
3041 int status = 0;
3042
3043 time->tv_sec = 0;
3044 time->tv_nsec = 0;
3045 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3046 return -EIO;
3047 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3048 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003049 if (status == 0)
3050 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3052 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003053 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 return status;
3055}
3056
3057static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3058{
3059 int status = 0;
3060
3061 time->tv_sec = 0;
3062 time->tv_nsec = 0;
3063 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3064 return -EIO;
3065 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3066 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003067 if (status == 0)
3068 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3070 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003071 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 return status;
3073}
3074
3075static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3076{
3077 int status = 0;
3078
3079 time->tv_sec = 0;
3080 time->tv_nsec = 0;
3081 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3082 return -EIO;
3083 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3084 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003085 if (status == 0)
3086 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3088 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003089 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 return status;
3091}
3092
Al Viro8687b632006-10-19 23:28:48 -07003093static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094{
3095 unsigned int attrwords = XDR_QUADLEN(attrlen);
3096 unsigned int nwords = xdr->p - savep;
3097
3098 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003099 dprintk("%s: server returned incorrect attribute length: "
3100 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003101 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 attrwords << 2,
3103 (attrwords < nwords) ? '<' : '>',
3104 nwords << 2);
3105 return -EIO;
3106 }
3107 return 0;
3108}
3109
3110static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3111{
Al Viro8687b632006-10-19 23:28:48 -07003112 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113
3114 READ_BUF(20);
3115 READ32(cinfo->atomic);
3116 READ64(cinfo->before);
3117 READ64(cinfo->after);
3118 return 0;
3119}
3120
3121static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3122{
Al Viro8687b632006-10-19 23:28:48 -07003123 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 uint32_t supp, acc;
3125 int status;
3126
3127 status = decode_op_hdr(xdr, OP_ACCESS);
3128 if (status)
3129 return status;
3130 READ_BUF(8);
3131 READ32(supp);
3132 READ32(acc);
3133 access->supported = supp;
3134 access->access = acc;
3135 return 0;
3136}
3137
3138static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3139{
Al Viro8687b632006-10-19 23:28:48 -07003140 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 int status;
3142
3143 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003144 if (status != -EIO)
3145 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 if (status)
3147 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003148 READ_BUF(NFS4_STATEID_SIZE);
3149 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 return 0;
3151}
3152
3153static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3154{
Al Viro8687b632006-10-19 23:28:48 -07003155 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 int status;
3157
3158 status = decode_op_hdr(xdr, OP_COMMIT);
3159 if (status)
3160 return status;
3161 READ_BUF(8);
3162 COPYMEM(res->verf->verifier, 8);
3163 return 0;
3164}
3165
3166static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3167{
Al Viro8687b632006-10-19 23:28:48 -07003168 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 uint32_t bmlen;
3170 int status;
3171
3172 status = decode_op_hdr(xdr, OP_CREATE);
3173 if (status)
3174 return status;
3175 if ((status = decode_change_info(xdr, cinfo)))
3176 return status;
3177 READ_BUF(4);
3178 READ32(bmlen);
3179 READ_BUF(bmlen << 2);
3180 return 0;
3181}
3182
3183static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3184{
Al Viro8687b632006-10-19 23:28:48 -07003185 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003186 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 int status;
3188
3189 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3190 goto xdr_error;
3191 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3192 goto xdr_error;
3193 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3194 goto xdr_error;
3195 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3196 goto xdr_error;
3197 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3198 goto xdr_error;
3199 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3200 goto xdr_error;
3201 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3202 goto xdr_error;
3203 status = verify_attr_len(xdr, savep, attrlen);
3204xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003205 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 return status;
3207}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003208
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3210{
Al Viro8687b632006-10-19 23:28:48 -07003211 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003212 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003214
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3216 goto xdr_error;
3217 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3218 goto xdr_error;
3219 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3220 goto xdr_error;
3221
3222 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3223 goto xdr_error;
3224 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3225 goto xdr_error;
3226 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3227 goto xdr_error;
3228 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3229 goto xdr_error;
3230 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3231 goto xdr_error;
3232 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3233 goto xdr_error;
3234
3235 status = verify_attr_len(xdr, savep, attrlen);
3236xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003237 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 return status;
3239}
3240
3241static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3242{
Al Viro8687b632006-10-19 23:28:48 -07003243 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003244 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003246
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3248 goto xdr_error;
3249 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3250 goto xdr_error;
3251 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3252 goto xdr_error;
3253
3254 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3255 goto xdr_error;
3256 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3257 goto xdr_error;
3258
3259 status = verify_attr_len(xdr, savep, attrlen);
3260xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003261 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 return status;
3263}
3264
3265static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3266{
Al Viro8687b632006-10-19 23:28:48 -07003267 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 uint32_t attrlen,
3269 bitmap[2] = {0},
3270 type;
Trond Myklebustbca79472009-03-11 14:10:26 -04003271 int status;
3272 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003273 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003275 status = decode_op_hdr(xdr, OP_GETATTR);
3276 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 goto xdr_error;
3278
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003279 status = decode_attr_bitmap(xdr, bitmap);
3280 if (status < 0)
3281 goto xdr_error;
3282
3283 status = decode_attr_length(xdr, &attrlen, &savep);
3284 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 goto xdr_error;
3286
3287
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003288 status = decode_attr_type(xdr, bitmap, &type);
3289 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003291 fattr->mode = 0;
3292 if (status != 0) {
3293 fattr->mode |= nfs_type2fmt[type];
3294 fattr->valid |= status;
3295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003297 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3298 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003300 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003301
3302 status = decode_attr_size(xdr, bitmap, &fattr->size);
3303 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003305 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003306
3307 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3308 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003310 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003311
3312 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3313 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003315 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003316
3317 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003318 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003319 fattr));
3320 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003321 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003322 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003323
3324 status = decode_attr_mode(xdr, bitmap, &fmode);
3325 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003327 if (status != 0) {
3328 fattr->mode |= fmode;
3329 fattr->valid |= status;
3330 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003331
3332 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3333 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003335 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003336
3337 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
3338 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003340 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003341
3342 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
3343 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003345 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003346
3347 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3348 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003350 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003351
3352 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3353 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003355 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003356
3357 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3358 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003360 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003361
3362 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3363 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003365 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003366
3367 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3368 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003370 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003371
3372 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3373 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003374 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003375 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003376 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003377 fattr->valid |= status;
3378 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003379
3380 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003382 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 return status;
3384}
3385
3386
3387static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3388{
Al Viro8687b632006-10-19 23:28:48 -07003389 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 uint32_t attrlen, bitmap[2];
3391 int status;
3392
3393 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3394 goto xdr_error;
3395 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3396 goto xdr_error;
3397 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3398 goto xdr_error;
3399
3400 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3401
3402 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3403 goto xdr_error;
3404 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3405 goto xdr_error;
3406 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3407 goto xdr_error;
3408 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3409 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3410 goto xdr_error;
3411 fsinfo->wtpref = fsinfo->wtmax;
3412
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}
3418
3419static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3420{
Al Viro8687b632006-10-19 23:28:48 -07003421 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 uint32_t len;
3423 int status;
3424
Trond Myklebust99367812007-07-17 21:52:41 -04003425 /* Zero handle first to allow comparisons */
3426 memset(fh, 0, sizeof(*fh));
3427
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 status = decode_op_hdr(xdr, OP_GETFH);
3429 if (status)
3430 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431
3432 READ_BUF(4);
3433 READ32(len);
3434 if (len > NFS4_FHSIZE)
3435 return -EIO;
3436 fh->size = len;
3437 READ_BUF(len);
3438 COPYMEM(fh->data, len);
3439 return 0;
3440}
3441
3442static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3443{
3444 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003445
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 status = decode_op_hdr(xdr, OP_LINK);
3447 if (status)
3448 return status;
3449 return decode_change_info(xdr, cinfo);
3450}
3451
3452/*
3453 * We create the owner, so we know a proper owner.id length is 4.
3454 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003455static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003457 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003458 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003459 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460
3461 READ_BUF(32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003462 READ64(offset);
3463 READ64(length);
3464 READ32(type);
3465 if (fl != NULL) {
3466 fl->fl_start = (loff_t)offset;
3467 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3468 if (length == ~(uint64_t)0)
3469 fl->fl_end = OFFSET_MAX;
3470 fl->fl_type = F_WRLCK;
3471 if (type & 1)
3472 fl->fl_type = F_RDLCK;
3473 fl->fl_pid = 0;
3474 }
3475 READ64(clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476 READ32(namelen);
3477 READ_BUF(namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478 return -NFS4ERR_DENIED;
3479}
3480
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003481static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482{
Al Viro8687b632006-10-19 23:28:48 -07003483 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 int status;
3485
3486 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003487 if (status == -EIO)
3488 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003490 READ_BUF(NFS4_STATEID_SIZE);
3491 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003493 status = decode_lock_denied(xdr, NULL);
3494 if (res->open_seqid != NULL)
3495 nfs_increment_open_seqid(status, res->open_seqid);
3496 nfs_increment_lock_seqid(status, res->lock_seqid);
3497out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 return status;
3499}
3500
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003501static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502{
3503 int status;
3504 status = decode_op_hdr(xdr, OP_LOCKT);
3505 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003506 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 return status;
3508}
3509
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003510static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511{
Al Viro8687b632006-10-19 23:28:48 -07003512 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513 int status;
3514
3515 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003516 if (status != -EIO)
3517 nfs_increment_lock_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003519 READ_BUF(NFS4_STATEID_SIZE);
3520 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 }
3522 return status;
3523}
3524
3525static int decode_lookup(struct xdr_stream *xdr)
3526{
3527 return decode_op_hdr(xdr, OP_LOOKUP);
3528}
3529
3530/* This is too sick! */
3531static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3532{
Andy Adamson05d564f2008-12-23 16:06:15 -05003533 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534 uint32_t limit_type, nblocks, blocksize;
3535
3536 READ_BUF(12);
3537 READ32(limit_type);
3538 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003539 case 1:
3540 READ64(*maxsize);
3541 break;
3542 case 2:
3543 READ32(nblocks);
3544 READ32(blocksize);
3545 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 }
3547 return 0;
3548}
3549
3550static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3551{
Andy Adamson05d564f2008-12-23 16:06:15 -05003552 __be32 *p;
3553 uint32_t delegation_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554
3555 READ_BUF(4);
3556 READ32(delegation_type);
3557 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3558 res->delegation_type = 0;
3559 return 0;
3560 }
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003561 READ_BUF(NFS4_STATEID_SIZE+4);
3562 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563 READ32(res->do_recall);
Andy Adamson05d564f2008-12-23 16:06:15 -05003564
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003566 case NFS4_OPEN_DELEGATE_READ:
3567 res->delegation_type = FMODE_READ;
3568 break;
3569 case NFS4_OPEN_DELEGATE_WRITE:
3570 res->delegation_type = FMODE_WRITE|FMODE_READ;
3571 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 return -EIO;
3573 }
David Howells7539bba2006-08-22 20:06:09 -04003574 return decode_ace(xdr, NULL, res->server->nfs_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575}
3576
3577static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3578{
Andy Adamson05d564f2008-12-23 16:06:15 -05003579 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003580 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05003581 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582
Andy Adamson05d564f2008-12-23 16:06:15 -05003583 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003584 if (status != -EIO)
3585 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003586 if (status)
3587 return status;
3588 READ_BUF(NFS4_STATEID_SIZE);
3589 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590
Andy Adamson05d564f2008-12-23 16:06:15 -05003591 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592
Andy Adamson05d564f2008-12-23 16:06:15 -05003593 READ_BUF(8);
3594 READ32(res->rflags);
3595 READ32(bmlen);
3596 if (bmlen > 10)
3597 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598
Andy Adamson05d564f2008-12-23 16:06:15 -05003599 READ_BUF(bmlen << 2);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003600 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3601 for (i = 0; i < savewords; ++i)
3602 READ32(res->attrset[i]);
3603 for (; i < NFS4_BITMAP_SIZE; i++)
3604 res->attrset[i] = 0;
3605
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 return decode_delegation(xdr, res);
3607xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003608 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609 return -EIO;
3610}
3611
3612static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3613{
Andy Adamson05d564f2008-12-23 16:06:15 -05003614 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 int status;
3616
Andy Adamson05d564f2008-12-23 16:06:15 -05003617 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003618 if (status != -EIO)
3619 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003620 if (status)
3621 return status;
3622 READ_BUF(NFS4_STATEID_SIZE);
3623 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3624 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625}
3626
3627static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3628{
Al Viro8687b632006-10-19 23:28:48 -07003629 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 int status;
3631
3632 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003633 if (status != -EIO)
3634 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 if (status)
3636 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003637 READ_BUF(NFS4_STATEID_SIZE);
3638 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639 return 0;
3640}
3641
3642static int decode_putfh(struct xdr_stream *xdr)
3643{
3644 return decode_op_hdr(xdr, OP_PUTFH);
3645}
3646
3647static int decode_putrootfh(struct xdr_stream *xdr)
3648{
3649 return decode_op_hdr(xdr, OP_PUTROOTFH);
3650}
3651
3652static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3653{
3654 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07003655 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656 uint32_t count, eof, recvd, hdrlen;
3657 int status;
3658
3659 status = decode_op_hdr(xdr, OP_READ);
3660 if (status)
3661 return status;
3662 READ_BUF(8);
3663 READ32(eof);
3664 READ32(count);
3665 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3666 recvd = req->rq_rcv_buf.len - hdrlen;
3667 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003668 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 "count %u > recvd %u\n", count, recvd);
3670 count = recvd;
3671 eof = 0;
3672 }
3673 xdr_read_pages(xdr, count);
3674 res->eof = eof;
3675 res->count = count;
3676 return 0;
3677}
3678
3679static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3680{
3681 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3682 struct page *page = *rcvbuf->pages;
3683 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003684 size_t hdrlen;
3685 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07003686 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003687 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04003688 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689
3690 status = decode_op_hdr(xdr, OP_READDIR);
3691 if (status)
3692 return status;
3693 READ_BUF(8);
3694 COPYMEM(readdir->verifier.data, 8);
Fred Isaman44109242008-04-02 15:21:15 +03003695 dprintk("%s: verifier = %08x:%08x\n",
3696 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00003697 ((u32 *)readdir->verifier.data)[0],
3698 ((u32 *)readdir->verifier.data)[1]);
3699
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700
3701 hdrlen = (char *) p - (char *) iov->iov_base;
3702 recvd = rcvbuf->len - hdrlen;
3703 if (pglen > recvd)
3704 pglen = recvd;
3705 xdr_read_pages(xdr, pglen);
3706
3707 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07003708 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04003709 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003711
3712 /* Make sure the packet actually has a value_follows and EOF entry */
3713 if ((entry + 1) > end)
3714 goto short_pkt;
3715
3716 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003717 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04003718 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003720 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 p += 2; /* cookie */
3722 len = ntohl(*p++); /* filename length */
3723 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003724 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3725 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 goto err_unmap;
3727 }
David Howellse8896492006-08-24 15:44:19 -04003728 xlen = XDR_QUADLEN(len);
3729 if (end - p < xlen + 1)
3730 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003731 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04003732 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04003734 if (end - p < len + 1)
3735 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04003738 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04003740 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741 entry = p;
3742 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003743 /*
3744 * Apparently some server sends responses that are a valid size, but
3745 * contain no entries, and have value_follows==0 and EOF==0. For
3746 * those, just set the EOF marker.
3747 */
3748 if (!nr && entry[1] == 0) {
3749 dprintk("NFS: readdir reply truncated!\n");
3750 entry[1] = 1;
3751 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05003752out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 kunmap_atomic(kaddr, KM_USER0);
3754 return 0;
3755short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003756 /*
3757 * When we get a short packet there are 2 possibilities. We can
3758 * return an error, or fix up the response to look like a valid
3759 * response and return what we have so far. If there are no
3760 * entries and the packet was short, then return -EIO. If there
3761 * are valid entries in the response, return them and pretend that
3762 * the call was successful, but incomplete. The caller can retry the
3763 * readdir starting at the last cookie.
3764 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07003765 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003767 if (nr)
3768 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769err_unmap:
3770 kunmap_atomic(kaddr, KM_USER0);
3771 return -errno_NFSERR_IO;
3772}
3773
3774static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3775{
3776 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3777 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003778 size_t hdrlen;
3779 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07003780 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 char *kaddr;
3782 int status;
3783
3784 status = decode_op_hdr(xdr, OP_READLINK);
3785 if (status)
3786 return status;
3787
3788 /* Convert length of symlink */
3789 READ_BUF(4);
3790 READ32(len);
3791 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003792 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 return -ENAMETOOLONG;
3794 }
3795 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3796 recvd = req->rq_rcv_buf.len - hdrlen;
3797 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003798 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799 "count %u > recvd %u\n", len, recvd);
3800 return -EIO;
3801 }
3802 xdr_read_pages(xdr, len);
3803 /*
3804 * The XDR encode routine has set things up so that
3805 * the link text will be copied directly into the
3806 * buffer. We just have to do overflow-checking,
3807 * and and null-terminate the text (the VFS expects
3808 * null-termination).
3809 */
3810 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3811 kaddr[len+rcvbuf->page_base] = '\0';
3812 kunmap_atomic(kaddr, KM_USER0);
3813 return 0;
3814}
3815
3816static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3817{
3818 int status;
3819
3820 status = decode_op_hdr(xdr, OP_REMOVE);
3821 if (status)
3822 goto out;
3823 status = decode_change_info(xdr, cinfo);
3824out:
3825 return status;
3826}
3827
3828static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3829 struct nfs4_change_info *new_cinfo)
3830{
3831 int status;
3832
3833 status = decode_op_hdr(xdr, OP_RENAME);
3834 if (status)
3835 goto out;
3836 if ((status = decode_change_info(xdr, old_cinfo)))
3837 goto out;
3838 status = decode_change_info(xdr, new_cinfo);
3839out:
3840 return status;
3841}
3842
3843static int decode_renew(struct xdr_stream *xdr)
3844{
3845 return decode_op_hdr(xdr, OP_RENEW);
3846}
3847
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003848static int
3849decode_restorefh(struct xdr_stream *xdr)
3850{
3851 return decode_op_hdr(xdr, OP_RESTOREFH);
3852}
3853
J. Bruce Fields029d1052005-06-22 17:16:22 +00003854static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3855 size_t *acl_len)
3856{
Al Viro8687b632006-10-19 23:28:48 -07003857 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003858 uint32_t attrlen,
3859 bitmap[2] = {0};
3860 struct kvec *iov = req->rq_rcv_buf.head;
3861 int status;
3862
3863 *acl_len = 0;
3864 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3865 goto out;
3866 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3867 goto out;
3868 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3869 goto out;
3870
3871 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3872 return -EIO;
3873 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003874 size_t hdrlen;
3875 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003876
3877 /* We ignore &savep and don't do consistency checks on
3878 * the attr length. Let userspace figure it out.... */
3879 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3880 recvd = req->rq_rcv_buf.len - hdrlen;
3881 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003882 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00003883 " acl reply: attrlen %u > recvd %u\n",
3884 attrlen, recvd);
3885 return -EINVAL;
3886 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04003887 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00003888 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04003889 } else
3890 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003891
3892out:
3893 return status;
3894}
3895
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896static int
3897decode_savefh(struct xdr_stream *xdr)
3898{
3899 return decode_op_hdr(xdr, OP_SAVEFH);
3900}
3901
Benny Halevy9e9ecc02009-04-01 09:22:00 -04003902static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903{
Al Viro8687b632006-10-19 23:28:48 -07003904 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 uint32_t bmlen;
3906 int status;
3907
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 status = decode_op_hdr(xdr, OP_SETATTR);
3909 if (status)
3910 return status;
3911 READ_BUF(4);
3912 READ32(bmlen);
3913 READ_BUF(bmlen << 2);
3914 return 0;
3915}
3916
David Howellsadfa6f92006-08-22 20:06:08 -04003917static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918{
Al Viro8687b632006-10-19 23:28:48 -07003919 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920 uint32_t opnum;
3921 int32_t nfserr;
3922
3923 READ_BUF(8);
3924 READ32(opnum);
3925 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003926 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05003927 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928 return -EIO;
3929 }
3930 READ32(nfserr);
3931 if (nfserr == NFS_OK) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003932 READ_BUF(8 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 READ64(clp->cl_clientid);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003934 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935 } else if (nfserr == NFSERR_CLID_INUSE) {
3936 uint32_t len;
3937
3938 /* skip netid string */
3939 READ_BUF(4);
3940 READ32(len);
3941 READ_BUF(len);
3942
3943 /* skip uaddr string */
3944 READ_BUF(4);
3945 READ32(len);
3946 READ_BUF(len);
3947 return -NFSERR_CLID_INUSE;
3948 } else
Benny Halevy856dff32008-03-31 17:39:06 +03003949 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950
3951 return 0;
3952}
3953
3954static int decode_setclientid_confirm(struct xdr_stream *xdr)
3955{
3956 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3957}
3958
3959static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3960{
Al Viro8687b632006-10-19 23:28:48 -07003961 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962 int status;
3963
3964 status = decode_op_hdr(xdr, OP_WRITE);
3965 if (status)
3966 return status;
3967
3968 READ_BUF(16);
3969 READ32(res->count);
3970 READ32(res->verf->committed);
3971 COPYMEM(res->verf->verifier, 8);
3972 return 0;
3973}
3974
3975static int decode_delegreturn(struct xdr_stream *xdr)
3976{
3977 return decode_op_hdr(xdr, OP_DELEGRETURN);
3978}
3979
Benny Halevy99fe60d2009-04-01 09:22:29 -04003980#if defined(CONFIG_NFS_V4_1)
3981static int decode_exchange_id(struct xdr_stream *xdr,
3982 struct nfs41_exchange_id_res *res)
3983{
3984 __be32 *p;
3985 uint32_t dummy;
3986 int status;
3987 struct nfs_client *clp = res->client;
3988
3989 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
3990 if (status)
3991 return status;
3992
3993 READ_BUF(8);
3994 READ64(clp->cl_ex_clid);
3995 READ_BUF(12);
3996 READ32(clp->cl_seqid);
3997 READ32(clp->cl_exchange_flags);
3998
3999 /* We ask for SP4_NONE */
4000 READ32(dummy);
4001 if (dummy != SP4_NONE)
4002 return -EIO;
4003
4004 /* Throw away minor_id */
4005 READ_BUF(8);
4006
4007 /* Throw away Major id */
4008 READ_BUF(4);
4009 READ32(dummy);
4010 READ_BUF(dummy);
4011
4012 /* Throw away server_scope */
4013 READ_BUF(4);
4014 READ32(dummy);
4015 READ_BUF(dummy);
4016
4017 /* Throw away Implementation id array */
4018 READ_BUF(4);
4019 READ32(dummy);
4020 READ_BUF(dummy);
4021
4022 return 0;
4023}
4024#endif /* CONFIG_NFS_V4_1 */
4025
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004026static int decode_sequence(struct xdr_stream *xdr,
4027 struct nfs4_sequence_res *res,
4028 struct rpc_rqst *rqstp)
4029{
4030#if defined(CONFIG_NFS_V4_1)
4031 if (!res->sr_session)
4032 return 0;
4033
4034 /* stub */
4035#endif /* CONFIG_NFS_V4_1 */
4036
4037 return 0;
4038}
4039
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040/*
Benny Halevy49c25592008-12-23 16:06:16 -05004041 * END OF "GENERIC" DECODE ROUTINES.
4042 */
4043
4044/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045 * Decode OPEN_DOWNGRADE response
4046 */
Al Viro8687b632006-10-19 23:28:48 -07004047static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048{
Andy Adamson05d564f2008-12-23 16:06:15 -05004049 struct xdr_stream xdr;
4050 struct compound_hdr hdr;
4051 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052
Andy Adamson05d564f2008-12-23 16:06:15 -05004053 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4054 status = decode_compound_hdr(&xdr, &hdr);
4055 if (status)
4056 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004057 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4058 if (status)
4059 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004060 status = decode_putfh(&xdr);
4061 if (status)
4062 goto out;
4063 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004064 if (status != 0)
4065 goto out;
4066 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004068 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069}
4070
4071/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072 * Decode ACCESS response
4073 */
Al Viro8687b632006-10-19 23:28:48 -07004074static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075{
4076 struct xdr_stream xdr;
4077 struct compound_hdr hdr;
4078 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004079
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004081 status = decode_compound_hdr(&xdr, &hdr);
4082 if (status)
4083 goto out;
4084 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4085 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04004087 status = decode_putfh(&xdr);
4088 if (status != 0)
4089 goto out;
4090 status = decode_access(&xdr, res);
4091 if (status != 0)
4092 goto out;
4093 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094out:
4095 return status;
4096}
4097
4098/*
4099 * Decode LOOKUP response
4100 */
Al Viro8687b632006-10-19 23:28:48 -07004101static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102{
4103 struct xdr_stream xdr;
4104 struct compound_hdr hdr;
4105 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004106
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004108 status = decode_compound_hdr(&xdr, &hdr);
4109 if (status)
4110 goto out;
4111 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4112 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113 goto out;
4114 if ((status = decode_putfh(&xdr)) != 0)
4115 goto out;
4116 if ((status = decode_lookup(&xdr)) != 0)
4117 goto out;
4118 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4119 goto out;
4120 status = decode_getfattr(&xdr, res->fattr, res->server);
4121out:
4122 return status;
4123}
4124
4125/*
4126 * Decode LOOKUP_ROOT response
4127 */
Al Viro8687b632006-10-19 23:28:48 -07004128static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129{
4130 struct xdr_stream xdr;
4131 struct compound_hdr hdr;
4132 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004133
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004135 status = decode_compound_hdr(&xdr, &hdr);
4136 if (status)
4137 goto out;
4138 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4139 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140 goto out;
4141 if ((status = decode_putrootfh(&xdr)) != 0)
4142 goto out;
4143 if ((status = decode_getfh(&xdr, res->fh)) == 0)
4144 status = decode_getfattr(&xdr, res->fattr, res->server);
4145out:
4146 return status;
4147}
4148
4149/*
4150 * Decode REMOVE response
4151 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004152static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153{
4154 struct xdr_stream xdr;
4155 struct compound_hdr hdr;
4156 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004157
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004159 status = decode_compound_hdr(&xdr, &hdr);
4160 if (status)
4161 goto out;
4162 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4163 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04004165 if ((status = decode_putfh(&xdr)) != 0)
4166 goto out;
4167 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4168 goto out;
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004169 decode_getfattr(&xdr, &res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170out:
4171 return status;
4172}
4173
4174/*
4175 * Decode RENAME response
4176 */
Al Viro8687b632006-10-19 23:28:48 -07004177static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178{
4179 struct xdr_stream xdr;
4180 struct compound_hdr hdr;
4181 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004182
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004184 status = decode_compound_hdr(&xdr, &hdr);
4185 if (status)
4186 goto out;
4187 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4188 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189 goto out;
4190 if ((status = decode_putfh(&xdr)) != 0)
4191 goto out;
4192 if ((status = decode_savefh(&xdr)) != 0)
4193 goto out;
4194 if ((status = decode_putfh(&xdr)) != 0)
4195 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004196 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4197 goto out;
4198 /* Current FH is target directory */
4199 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
4200 goto out;
4201 if ((status = decode_restorefh(&xdr)) != 0)
4202 goto out;
4203 decode_getfattr(&xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204out:
4205 return status;
4206}
4207
4208/*
4209 * Decode LINK response
4210 */
Al Viro8687b632006-10-19 23:28:48 -07004211static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212{
4213 struct xdr_stream xdr;
4214 struct compound_hdr hdr;
4215 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004216
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004218 status = decode_compound_hdr(&xdr, &hdr);
4219 if (status)
4220 goto out;
4221 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4222 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223 goto out;
4224 if ((status = decode_putfh(&xdr)) != 0)
4225 goto out;
4226 if ((status = decode_savefh(&xdr)) != 0)
4227 goto out;
4228 if ((status = decode_putfh(&xdr)) != 0)
4229 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004230 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4231 goto out;
4232 /*
4233 * Note order: OP_LINK leaves the directory as the current
4234 * filehandle.
4235 */
4236 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
4237 goto out;
4238 if ((status = decode_restorefh(&xdr)) != 0)
4239 goto out;
4240 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241out:
4242 return status;
4243}
4244
4245/*
4246 * Decode CREATE response
4247 */
Al Viro8687b632006-10-19 23:28:48 -07004248static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249{
4250 struct xdr_stream xdr;
4251 struct compound_hdr hdr;
4252 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004253
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004255 status = decode_compound_hdr(&xdr, &hdr);
4256 if (status)
4257 goto out;
4258 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4259 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260 goto out;
4261 if ((status = decode_putfh(&xdr)) != 0)
4262 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004263 if ((status = decode_savefh(&xdr)) != 0)
4264 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4266 goto out;
4267 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4268 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004269 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
4270 goto out;
4271 if ((status = decode_restorefh(&xdr)) != 0)
4272 goto out;
4273 decode_getfattr(&xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274out:
4275 return status;
4276}
4277
4278/*
4279 * Decode SYMLINK response
4280 */
Al Viro8687b632006-10-19 23:28:48 -07004281static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282{
4283 return nfs4_xdr_dec_create(rqstp, p, res);
4284}
4285
4286/*
4287 * Decode GETATTR response
4288 */
Al Viro8687b632006-10-19 23:28:48 -07004289static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004290{
4291 struct xdr_stream xdr;
4292 struct compound_hdr hdr;
4293 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004294
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4296 status = decode_compound_hdr(&xdr, &hdr);
4297 if (status)
4298 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004299 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4300 if (status)
4301 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 status = decode_putfh(&xdr);
4303 if (status)
4304 goto out;
4305 status = decode_getfattr(&xdr, res->fattr, res->server);
4306out:
4307 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308}
4309
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004310/*
4311 * Encode an SETACL request
4312 */
4313static int
Al Viro8687b632006-10-19 23:28:48 -07004314nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004315{
Andy Adamson05d564f2008-12-23 16:06:15 -05004316 struct xdr_stream xdr;
4317 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04004318 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05004319 };
4320 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004321
Andy Adamson05d564f2008-12-23 16:06:15 -05004322 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04004323 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004324 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05004325 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004326 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004327 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004328 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004329}
Andy Adamson05d564f2008-12-23 16:06:15 -05004330
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004331/*
4332 * Decode SETACL response
4333 */
4334static int
Benny Halevy73c403a2009-04-01 09:22:01 -04004335nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4336 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004337{
4338 struct xdr_stream xdr;
4339 struct compound_hdr hdr;
4340 int status;
4341
4342 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4343 status = decode_compound_hdr(&xdr, &hdr);
4344 if (status)
4345 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004346 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4347 if (status)
4348 goto out;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004349 status = decode_putfh(&xdr);
4350 if (status)
4351 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004352 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004353out:
4354 return status;
4355}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356
4357/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00004358 * Decode GETACL response
4359 */
4360static int
Benny Halevy663c79b2009-04-01 09:21:59 -04004361nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4362 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004363{
4364 struct xdr_stream xdr;
4365 struct compound_hdr hdr;
4366 int status;
4367
4368 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4369 status = decode_compound_hdr(&xdr, &hdr);
4370 if (status)
4371 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004372 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4373 if (status)
4374 goto out;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004375 status = decode_putfh(&xdr);
4376 if (status)
4377 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04004378 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004379
4380out:
4381 return status;
4382}
4383
4384/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385 * Decode CLOSE response
4386 */
Al Viro8687b632006-10-19 23:28:48 -07004387static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388{
Andy Adamson05d564f2008-12-23 16:06:15 -05004389 struct xdr_stream xdr;
4390 struct compound_hdr hdr;
4391 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392
Andy Adamson05d564f2008-12-23 16:06:15 -05004393 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4394 status = decode_compound_hdr(&xdr, &hdr);
4395 if (status)
4396 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004397 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4398 if (status)
4399 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004400 status = decode_putfh(&xdr);
4401 if (status)
4402 goto out;
4403 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004404 if (status != 0)
4405 goto out;
4406 /*
4407 * Note: Server may do delete on close for this file
4408 * in which case the getattr call will fail with
4409 * an ESTALE error. Shouldn't be a problem,
4410 * though, since fattr->valid will remain unset.
4411 */
4412 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004414 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415}
4416
4417/*
4418 * Decode OPEN response
4419 */
Al Viro8687b632006-10-19 23:28:48 -07004420static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421{
Andy Adamson05d564f2008-12-23 16:06:15 -05004422 struct xdr_stream xdr;
4423 struct compound_hdr hdr;
4424 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425
Andy Adamson05d564f2008-12-23 16:06:15 -05004426 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4427 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004428 if (status)
4429 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004430 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4431 if (status)
4432 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004433 status = decode_putfh(&xdr);
4434 if (status)
4435 goto out;
4436 status = decode_savefh(&xdr);
4437 if (status)
4438 goto out;
4439 status = decode_open(&xdr, res);
4440 if (status)
4441 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04004442 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004444 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4445 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04004446 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004447 goto out;
4448 decode_getfattr(&xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004450 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004451}
4452
4453/*
4454 * Decode OPEN_CONFIRM response
4455 */
Al Viro8687b632006-10-19 23:28:48 -07004456static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004457{
Andy Adamson05d564f2008-12-23 16:06:15 -05004458 struct xdr_stream xdr;
4459 struct compound_hdr hdr;
4460 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461
Andy Adamson05d564f2008-12-23 16:06:15 -05004462 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4463 status = decode_compound_hdr(&xdr, &hdr);
4464 if (status)
4465 goto out;
4466 status = decode_putfh(&xdr);
4467 if (status)
4468 goto out;
4469 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004471 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472}
4473
4474/*
4475 * Decode OPEN response
4476 */
Al Viro8687b632006-10-19 23:28:48 -07004477static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478{
Andy Adamson05d564f2008-12-23 16:06:15 -05004479 struct xdr_stream xdr;
4480 struct compound_hdr hdr;
4481 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482
Andy Adamson05d564f2008-12-23 16:06:15 -05004483 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4484 status = decode_compound_hdr(&xdr, &hdr);
4485 if (status)
4486 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004487 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4488 if (status)
4489 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004490 status = decode_putfh(&xdr);
4491 if (status)
4492 goto out;
4493 status = decode_open(&xdr, res);
4494 if (status)
4495 goto out;
Trond Myklebust864472e2006-01-03 09:55:15 +01004496 decode_getfattr(&xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004498 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499}
4500
4501/*
4502 * Decode SETATTR response
4503 */
Al Viro8687b632006-10-19 23:28:48 -07004504static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004505{
Andy Adamson05d564f2008-12-23 16:06:15 -05004506 struct xdr_stream xdr;
4507 struct compound_hdr hdr;
4508 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004509
Andy Adamson05d564f2008-12-23 16:06:15 -05004510 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4511 status = decode_compound_hdr(&xdr, &hdr);
4512 if (status)
4513 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004514 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4515 if (status)
4516 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004517 status = decode_putfh(&xdr);
4518 if (status)
4519 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004520 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004521 if (status)
4522 goto out;
Trond Myklebust78f945f2009-03-11 14:10:23 -04004523 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004524out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004525 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004526}
4527
4528/*
4529 * Decode LOCK response
4530 */
Al Viro8687b632006-10-19 23:28:48 -07004531static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532{
4533 struct xdr_stream xdr;
4534 struct compound_hdr hdr;
4535 int status;
4536
4537 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4538 status = decode_compound_hdr(&xdr, &hdr);
4539 if (status)
4540 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004541 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4542 if (status)
4543 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004544 status = decode_putfh(&xdr);
4545 if (status)
4546 goto out;
4547 status = decode_lock(&xdr, res);
4548out:
4549 return status;
4550}
4551
4552/*
4553 * Decode LOCKT response
4554 */
Al Viro8687b632006-10-19 23:28:48 -07004555static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004556{
4557 struct xdr_stream xdr;
4558 struct compound_hdr hdr;
4559 int status;
4560
4561 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4562 status = decode_compound_hdr(&xdr, &hdr);
4563 if (status)
4564 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004565 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4566 if (status)
4567 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568 status = decode_putfh(&xdr);
4569 if (status)
4570 goto out;
4571 status = decode_lockt(&xdr, res);
4572out:
4573 return status;
4574}
4575
4576/*
4577 * Decode LOCKU response
4578 */
Al Viro8687b632006-10-19 23:28:48 -07004579static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580{
4581 struct xdr_stream xdr;
4582 struct compound_hdr hdr;
4583 int status;
4584
4585 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4586 status = decode_compound_hdr(&xdr, &hdr);
4587 if (status)
4588 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004589 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4590 if (status)
4591 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 status = decode_putfh(&xdr);
4593 if (status)
4594 goto out;
4595 status = decode_locku(&xdr, res);
4596out:
4597 return status;
4598}
4599
4600/*
4601 * Decode READLINK response
4602 */
Benny Halevyf50c7002009-04-01 09:21:55 -04004603static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4604 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605{
4606 struct xdr_stream xdr;
4607 struct compound_hdr hdr;
4608 int status;
4609
4610 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4611 status = decode_compound_hdr(&xdr, &hdr);
4612 if (status)
4613 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004614 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4615 if (status)
4616 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617 status = decode_putfh(&xdr);
4618 if (status)
4619 goto out;
4620 status = decode_readlink(&xdr, rqstp);
4621out:
4622 return status;
4623}
4624
4625/*
4626 * Decode READDIR response
4627 */
Al Viro8687b632006-10-19 23:28:48 -07004628static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629{
4630 struct xdr_stream xdr;
4631 struct compound_hdr hdr;
4632 int status;
4633
4634 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4635 status = decode_compound_hdr(&xdr, &hdr);
4636 if (status)
4637 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004638 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4639 if (status)
4640 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641 status = decode_putfh(&xdr);
4642 if (status)
4643 goto out;
4644 status = decode_readdir(&xdr, rqstp, res);
4645out:
4646 return status;
4647}
4648
4649/*
4650 * Decode Read response
4651 */
Al Viro8687b632006-10-19 23:28:48 -07004652static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004653{
4654 struct xdr_stream xdr;
4655 struct compound_hdr hdr;
4656 int status;
4657
4658 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4659 status = decode_compound_hdr(&xdr, &hdr);
4660 if (status)
4661 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004662 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4663 if (status)
4664 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 status = decode_putfh(&xdr);
4666 if (status)
4667 goto out;
4668 status = decode_read(&xdr, rqstp, res);
4669 if (!status)
4670 status = res->count;
4671out:
4672 return status;
4673}
4674
4675/*
4676 * Decode WRITE response
4677 */
Al Viro8687b632006-10-19 23:28:48 -07004678static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004679{
4680 struct xdr_stream xdr;
4681 struct compound_hdr hdr;
4682 int status;
4683
4684 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4685 status = decode_compound_hdr(&xdr, &hdr);
4686 if (status)
4687 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004688 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4689 if (status)
4690 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691 status = decode_putfh(&xdr);
4692 if (status)
4693 goto out;
4694 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004695 if (status)
4696 goto out;
4697 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698 if (!status)
4699 status = res->count;
4700out:
4701 return status;
4702}
4703
4704/*
4705 * Decode COMMIT response
4706 */
Al Viro8687b632006-10-19 23:28:48 -07004707static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708{
4709 struct xdr_stream xdr;
4710 struct compound_hdr hdr;
4711 int status;
4712
4713 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4714 status = decode_compound_hdr(&xdr, &hdr);
4715 if (status)
4716 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004717 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4718 if (status)
4719 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720 status = decode_putfh(&xdr);
4721 if (status)
4722 goto out;
4723 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004724 if (status)
4725 goto out;
4726 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004727out:
4728 return status;
4729}
4730
4731/*
4732 * FSINFO request
4733 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04004734static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
4735 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736{
4737 struct xdr_stream xdr;
4738 struct compound_hdr hdr;
4739 int status;
4740
4741 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4742 status = decode_compound_hdr(&xdr, &hdr);
4743 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004744 status = decode_sequence(&xdr, &res->seq_res, req);
4745 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746 status = decode_putfh(&xdr);
4747 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04004748 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 return status;
4750}
4751
4752/*
4753 * PATHCONF request
4754 */
Benny Halevyd45b2982009-04-01 09:21:58 -04004755static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
4756 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757{
4758 struct xdr_stream xdr;
4759 struct compound_hdr hdr;
4760 int status;
4761
4762 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4763 status = decode_compound_hdr(&xdr, &hdr);
4764 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004765 status = decode_sequence(&xdr, &res->seq_res, req);
4766 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 status = decode_putfh(&xdr);
4768 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04004769 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 return status;
4771}
4772
4773/*
4774 * STATFS request
4775 */
Benny Halevy24ad1482009-04-01 09:21:56 -04004776static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
4777 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778{
4779 struct xdr_stream xdr;
4780 struct compound_hdr hdr;
4781 int status;
4782
4783 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4784 status = decode_compound_hdr(&xdr, &hdr);
4785 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004786 status = decode_sequence(&xdr, &res->seq_res, req);
4787 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788 status = decode_putfh(&xdr);
4789 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04004790 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004791 return status;
4792}
4793
4794/*
4795 * GETATTR_BITMAP request
4796 */
Al Viro8687b632006-10-19 23:28:48 -07004797static 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 -07004798{
4799 struct xdr_stream xdr;
4800 struct compound_hdr hdr;
4801 int status;
4802
4803 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004804 status = decode_compound_hdr(&xdr, &hdr);
4805 if (status)
4806 goto out;
4807 status = decode_sequence(&xdr, &res->seq_res, req);
4808 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004809 goto out;
4810 if ((status = decode_putfh(&xdr)) != 0)
4811 goto out;
4812 status = decode_server_caps(&xdr, res);
4813out:
4814 return status;
4815}
4816
4817/*
4818 * Decode RENEW response
4819 */
Al Viro8687b632006-10-19 23:28:48 -07004820static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821{
4822 struct xdr_stream xdr;
4823 struct compound_hdr hdr;
4824 int status;
4825
4826 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4827 status = decode_compound_hdr(&xdr, &hdr);
4828 if (!status)
4829 status = decode_renew(&xdr);
4830 return status;
4831}
4832
4833/*
4834 * a SETCLIENTID request
4835 */
Al Viro8687b632006-10-19 23:28:48 -07004836static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04004837 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838{
4839 struct xdr_stream xdr;
4840 struct compound_hdr hdr;
4841 int status;
4842
4843 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4844 status = decode_compound_hdr(&xdr, &hdr);
4845 if (!status)
4846 status = decode_setclientid(&xdr, clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847 return status;
4848}
4849
4850/*
4851 * a SETCLIENTID_CONFIRM request
4852 */
Al Viro8687b632006-10-19 23:28:48 -07004853static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854{
4855 struct xdr_stream xdr;
4856 struct compound_hdr hdr;
4857 int status;
4858
4859 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4860 status = decode_compound_hdr(&xdr, &hdr);
4861 if (!status)
4862 status = decode_setclientid_confirm(&xdr);
4863 if (!status)
4864 status = decode_putrootfh(&xdr);
4865 if (!status)
4866 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867 return status;
4868}
4869
4870/*
4871 * DELEGRETURN request
4872 */
Al Viro8687b632006-10-19 23:28:48 -07004873static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874{
4875 struct xdr_stream xdr;
4876 struct compound_hdr hdr;
4877 int status;
4878
4879 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4880 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004881 if (status)
4882 goto out;
4883 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4884 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01004885 goto out;
4886 status = decode_putfh(&xdr);
4887 if (status != 0)
4888 goto out;
4889 status = decode_delegreturn(&xdr);
4890 decode_getfattr(&xdr, res->fattr, res->server);
4891out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004892 return status;
4893}
4894
Trond Myklebust683b57b2006-06-09 09:34:22 -04004895/*
4896 * FS_LOCATIONS request
4897 */
Benny Halevy22958462009-04-01 09:22:02 -04004898static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
4899 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004900{
4901 struct xdr_stream xdr;
4902 struct compound_hdr hdr;
4903 int status;
4904
4905 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4906 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004907 if (status)
4908 goto out;
4909 status = decode_sequence(&xdr, &res->seq_res, req);
4910 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004911 goto out;
4912 if ((status = decode_putfh(&xdr)) != 0)
4913 goto out;
4914 if ((status = decode_lookup(&xdr)) != 0)
4915 goto out;
4916 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04004917 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
4918 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04004919out:
4920 return status;
4921}
4922
Benny Halevy99fe60d2009-04-01 09:22:29 -04004923#if defined(CONFIG_NFS_V4_1)
4924/*
4925 * EXCHANGE_ID request
4926 */
4927static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
4928 void *res)
4929{
4930 struct xdr_stream xdr;
4931 struct compound_hdr hdr;
4932 int status;
4933
4934 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4935 status = decode_compound_hdr(&xdr, &hdr);
4936 if (!status)
4937 status = decode_exchange_id(&xdr, res);
4938 return status;
4939}
Andy Adamson2050f0c2009-04-01 09:22:30 -04004940
4941/*
4942 * a GET_LEASE_TIME request
4943 */
4944static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
4945 struct nfs4_get_lease_time_res *res)
4946{
4947 struct xdr_stream xdr;
4948 struct compound_hdr hdr;
4949 int status;
4950
4951 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4952 status = decode_compound_hdr(&xdr, &hdr);
4953 if (!status)
4954 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
4955 if (!status)
4956 status = decode_putrootfh(&xdr);
4957 if (!status)
4958 status = decode_fsinfo(&xdr, res->lr_fsinfo);
4959 return status;
4960}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004961#endif /* CONFIG_NFS_V4_1 */
4962
Al Viro0dbb4c62006-10-19 23:28:49 -07004963__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964{
4965 uint32_t bitmap[2] = {0};
4966 uint32_t len;
4967
4968 if (!*p++) {
4969 if (!*p)
4970 return ERR_PTR(-EAGAIN);
4971 entry->eof = 1;
4972 return ERR_PTR(-EBADCOOKIE);
4973 }
4974
4975 entry->prev_cookie = entry->cookie;
4976 p = xdr_decode_hyper(p, &entry->cookie);
4977 entry->len = ntohl(*p++);
4978 entry->name = (const char *) p;
4979 p += XDR_QUADLEN(entry->len);
4980
4981 /*
4982 * In case the server doesn't return an inode number,
4983 * we fake one here. (We don't use inode number 0,
4984 * since glibc seems to choke on it...)
4985 */
4986 entry->ino = 1;
4987
4988 len = ntohl(*p++); /* bitmap length */
4989 if (len-- > 0) {
4990 bitmap[0] = ntohl(*p++);
4991 if (len-- > 0) {
4992 bitmap[1] = ntohl(*p++);
4993 p += len;
4994 }
4995 }
4996 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4997 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00004998 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4999 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
5000 /* Ignore the return value of rdattr_error for now */
5001 p++;
5002 len--;
5003 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005004 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
5005 xdr_decode_hyper(p, &entry->ino);
5006 else if (bitmap[0] == FATTR4_WORD0_FILEID)
5007 xdr_decode_hyper(p, &entry->ino);
5008 p += len;
5009 }
5010
5011 entry->eof = !p[0] && p[1];
5012 return p;
5013}
5014
5015/*
5016 * We need to translate between nfs status return values and
5017 * the local errno values which may not be the same.
5018 */
5019static struct {
5020 int stat;
5021 int errno;
5022} nfs_errtbl[] = {
5023 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03005024 { NFS4ERR_PERM, -EPERM },
5025 { NFS4ERR_NOENT, -ENOENT },
5026 { NFS4ERR_IO, -errno_NFSERR_IO},
5027 { NFS4ERR_NXIO, -ENXIO },
5028 { NFS4ERR_ACCESS, -EACCES },
5029 { NFS4ERR_EXIST, -EEXIST },
5030 { NFS4ERR_XDEV, -EXDEV },
5031 { NFS4ERR_NOTDIR, -ENOTDIR },
5032 { NFS4ERR_ISDIR, -EISDIR },
5033 { NFS4ERR_INVAL, -EINVAL },
5034 { NFS4ERR_FBIG, -EFBIG },
5035 { NFS4ERR_NOSPC, -ENOSPC },
5036 { NFS4ERR_ROFS, -EROFS },
5037 { NFS4ERR_MLINK, -EMLINK },
5038 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5039 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5040 { NFS4ERR_DQUOT, -EDQUOT },
5041 { NFS4ERR_STALE, -ESTALE },
5042 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5043 { NFS4ERR_BADOWNER, -EINVAL },
5044 { NFS4ERR_BADNAME, -EINVAL },
5045 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5046 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5047 { NFS4ERR_TOOSMALL, -ETOOSMALL },
5048 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
5049 { NFS4ERR_BADTYPE, -EBADTYPE },
5050 { NFS4ERR_LOCKED, -EAGAIN },
5051 { NFS4ERR_RESOURCE, -EREMOTEIO },
5052 { NFS4ERR_SYMLINK, -ELOOP },
5053 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5054 { NFS4ERR_DEADLOCK, -EDEADLK },
5055 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056 * to be handled by a
5057 * middle-layer.
5058 */
Benny Halevy856dff32008-03-31 17:39:06 +03005059 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005060};
5061
5062/*
5063 * Convert an NFS error code to a local one.
5064 * This one is used jointly by NFSv2 and NFSv3.
5065 */
5066static int
David Howells0a8ea432006-08-22 20:06:08 -04005067nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068{
5069 int i;
5070 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5071 if (nfs_errtbl[i].stat == stat)
5072 return nfs_errtbl[i].errno;
5073 }
5074 if (stat <= 10000 || stat > 10100) {
5075 /* The server is looney tunes. */
Benny Halevy856dff32008-03-31 17:39:06 +03005076 return -ESERVERFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077 }
5078 /* If we cannot translate the error, the recovery routines should
5079 * handle it.
5080 * Note: remaining NFSv4 error codes have values > 10000, so should
5081 * not conflict with native Linux error codes.
5082 */
Benny Halevy856dff32008-03-31 17:39:06 +03005083 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084}
5085
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086#define PROC(proc, argtype, restype) \
5087[NFSPROC4_CLNT_##proc] = { \
5088 .p_proc = NFSPROC4_COMPOUND, \
5089 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5090 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04005091 .p_arglen = NFS4_##argtype##_sz, \
5092 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05005093 .p_statidx = NFSPROC4_CLNT_##proc, \
5094 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05005095}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005096
5097struct rpc_procinfo nfs4_procedures[] = {
5098 PROC(READ, enc_read, dec_read),
5099 PROC(WRITE, enc_write, dec_write),
5100 PROC(COMMIT, enc_commit, dec_commit),
5101 PROC(OPEN, enc_open, dec_open),
5102 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5103 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5104 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5105 PROC(CLOSE, enc_close, dec_close),
5106 PROC(SETATTR, enc_setattr, dec_setattr),
5107 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5108 PROC(RENEW, enc_renew, dec_renew),
5109 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5110 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5111 PROC(LOCK, enc_lock, dec_lock),
5112 PROC(LOCKT, enc_lockt, dec_lockt),
5113 PROC(LOCKU, enc_locku, dec_locku),
5114 PROC(ACCESS, enc_access, dec_access),
5115 PROC(GETATTR, enc_getattr, dec_getattr),
5116 PROC(LOOKUP, enc_lookup, dec_lookup),
5117 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5118 PROC(REMOVE, enc_remove, dec_remove),
5119 PROC(RENAME, enc_rename, dec_rename),
5120 PROC(LINK, enc_link, dec_link),
5121 PROC(SYMLINK, enc_symlink, dec_symlink),
5122 PROC(CREATE, enc_create, dec_create),
5123 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5124 PROC(STATFS, enc_statfs, dec_statfs),
5125 PROC(READLINK, enc_readlink, dec_readlink),
5126 PROC(READDIR, enc_readdir, dec_readdir),
5127 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5128 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00005129 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005130 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04005131 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005132#if defined(CONFIG_NFS_V4_1)
5133 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
Andy Adamson2050f0c2009-04-01 09:22:30 -04005134 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005135#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136};
5137
5138struct rpc_version nfs_version4 = {
5139 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08005140 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005141 .procs = nfs4_procedures
5142};
5143
5144/*
5145 * Local variables:
5146 * c-basic-offset: 8
5147 * End:
5148 */