blob: 20b4e30e6c828e5e0aed77ea01c445a52caab0ee [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
41#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/errno.h>
43#include <linux/string.h>
44#include <linux/in.h>
45#include <linux/pagemap.h>
46#include <linux/proc_fs.h>
47#include <linux/kdev_t.h>
48#include <linux/sunrpc/clnt.h>
49#include <linux/nfs.h>
50#include <linux/nfs4.h>
51#include <linux/nfs_fs.h>
52#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000053#include "nfs4_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55#define NFSDBG_FACILITY NFSDBG_XDR
56
57/* Mapping from NFS error code to "errno" error code. */
58#define errno_NFSERR_IO EIO
59
David Howells0a8ea432006-08-22 20:06:08 -040060static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
63#ifdef DEBUG
64#define NFS4_MAXTAGLEN 20
65#else
66#define NFS4_MAXTAGLEN 0
67#endif
68
Andy Adamson6c0195a2008-12-23 16:06:15 -050069/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040070 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 */
Trond Myklebust9f958ab2007-07-02 13:58:33 -040072#define open_owner_id_maxsz (1 + 4)
73#define lock_owner_id_maxsz (1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040074#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
76#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77#define op_encode_hdr_maxsz (1)
78#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040079#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
80#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
82#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
84 (NFS4_FHSIZE >> 2))
85#define decode_putfh_maxsz (op_decode_hdr_maxsz)
86#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
87#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
88#define encode_getfh_maxsz (op_encode_hdr_maxsz)
89#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
90 ((3+NFS4_FHSIZE) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000091#define nfs4_fattr_bitmap_maxsz 3
92#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
94#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040095#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
96#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +000097/* This is based on getfattr, which uses the most attributes: */
98#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -040099 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000100#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
101 nfs4_fattr_value_maxsz)
102#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400103#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
104 1 + 2 + 1 + \
105 nfs4_owner_maxsz + \
106 nfs4_group_maxsz + \
107 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#define encode_savefh_maxsz (op_encode_hdr_maxsz)
109#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400110#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
111#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200112#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
114#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
115#define decode_renew_maxsz (op_decode_hdr_maxsz)
116#define encode_setclientid_maxsz \
117 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500118 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
119 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
120 1 /* sc_prog */ + \
121 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
122 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
123 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#define decode_setclientid_maxsz \
125 (op_decode_hdr_maxsz + \
126 2 + \
127 1024) /* large value for CLID_INUSE */
128#define encode_setclientid_confirm_maxsz \
129 (op_encode_hdr_maxsz + \
130 3 + (NFS4_VERIFIER_SIZE >> 2))
131#define decode_setclientid_confirm_maxsz \
132 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400133#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
134#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400135#define encode_share_access_maxsz \
136 (2)
Trond Myklebust9104a552007-07-17 21:52:42 -0400137#define encode_createmode_maxsz (1 + encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400138#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
139#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
140#define encode_open_maxsz (op_encode_hdr_maxsz + \
141 2 + encode_share_access_maxsz + 2 + \
142 open_owner_id_maxsz + \
143 encode_opentype_maxsz + \
144 encode_claim_null_maxsz)
145#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400146#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400147 decode_ace_maxsz)
148#define decode_change_info_maxsz (5)
149#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400150 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400151 decode_change_info_maxsz + 1 + \
152 nfs4_fattr_bitmap_maxsz + \
153 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400154#define encode_open_confirm_maxsz \
155 (op_encode_hdr_maxsz + \
156 encode_stateid_maxsz + 1)
157#define decode_open_confirm_maxsz \
158 (op_decode_hdr_maxsz + \
159 decode_stateid_maxsz)
160#define encode_open_downgrade_maxsz \
161 (op_encode_hdr_maxsz + \
162 encode_stateid_maxsz + 1 + \
163 encode_share_access_maxsz)
164#define decode_open_downgrade_maxsz \
165 (op_decode_hdr_maxsz + \
166 decode_stateid_maxsz)
167#define encode_close_maxsz (op_encode_hdr_maxsz + \
168 1 + encode_stateid_maxsz)
169#define decode_close_maxsz (op_decode_hdr_maxsz + \
170 decode_stateid_maxsz)
171#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
172 encode_stateid_maxsz + \
173 encode_attrs_maxsz)
174#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
175 nfs4_fattr_bitmap_maxsz)
176#define encode_read_maxsz (op_encode_hdr_maxsz + \
177 encode_stateid_maxsz + 3)
178#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
179#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
180 2 + encode_verifier_maxsz + 5)
181#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
182 decode_verifier_maxsz)
183#define encode_readlink_maxsz (op_encode_hdr_maxsz)
184#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
185#define encode_write_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + 4)
187#define decode_write_maxsz (op_decode_hdr_maxsz + \
188 2 + decode_verifier_maxsz)
189#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
190#define decode_commit_maxsz (op_decode_hdr_maxsz + \
191 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192#define encode_remove_maxsz (op_encode_hdr_maxsz + \
193 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400194#define decode_remove_maxsz (op_decode_hdr_maxsz + \
195 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196#define encode_rename_maxsz (op_encode_hdr_maxsz + \
197 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400198#define decode_rename_maxsz (op_decode_hdr_maxsz + \
199 decode_change_info_maxsz + \
200 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201#define encode_link_maxsz (op_encode_hdr_maxsz + \
202 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400203#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400204#define encode_lock_maxsz (op_encode_hdr_maxsz + \
205 7 + \
206 1 + encode_stateid_maxsz + 8)
207#define decode_lock_denied_maxsz \
208 (8 + decode_lockowner_maxsz)
209#define decode_lock_maxsz (op_decode_hdr_maxsz + \
210 decode_lock_denied_maxsz)
211#define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
212#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
213 decode_lock_denied_maxsz)
214#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
215 encode_stateid_maxsz + \
216 4)
217#define decode_locku_maxsz (op_decode_hdr_maxsz + \
218 decode_stateid_maxsz)
219#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
220#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
222 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400223 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000224 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
226#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400227 1 + 2 + nfs4_name_maxsz + \
228 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400229#define decode_create_maxsz (op_decode_hdr_maxsz + \
230 decode_change_info_maxsz + \
231 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400232#define encode_statfs_maxsz (encode_getattr_maxsz)
233#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
235#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400236#define encode_getacl_maxsz (encode_getattr_maxsz)
237#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
238 nfs4_fattr_bitmap_maxsz + 1)
239#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
240 encode_stateid_maxsz + 3)
241#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400242#define encode_fs_locations_maxsz \
243 (encode_getattr_maxsz)
244#define decode_fs_locations_maxsz \
245 (0)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400246
247#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400248#define NFS4_MAX_MACHINE_NAME_LEN (64)
249
Benny Halevy99fe60d2009-04-01 09:22:29 -0400250#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
251 encode_verifier_maxsz + \
252 1 /* co_ownerid.len */ + \
253 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
254 1 /* flags */ + \
255 1 /* spa_how */ + \
256 0 /* SP4_NONE (for now) */ + \
257 1 /* zero implemetation id array */)
258#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
259 2 /* eir_clientid */ + \
260 1 /* eir_sequenceid */ + \
261 1 /* eir_flags */ + \
262 1 /* spr_how */ + \
263 0 /* SP4_NONE (for now) */ + \
264 2 /* eir_server_owner.so_minor_id */ + \
265 /* eir_server_owner.so_major_id<> */ \
266 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
267 /* eir_server_scope<> */ \
268 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
269 1 /* eir_server_impl_id array length */ + \
270 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400271#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
272#define decode_channel_attrs_maxsz (6 + \
273 1 /* ca_rdma_ird.len */ + \
274 1 /* ca_rdma_ird */)
275#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
276 2 /* csa_clientid */ + \
277 1 /* csa_sequence */ + \
278 1 /* csa_flags */ + \
279 encode_channel_attrs_maxsz + \
280 encode_channel_attrs_maxsz + \
281 1 /* csa_cb_program */ + \
282 1 /* csa_sec_parms.len (1) */ + \
283 1 /* cb_secflavor (AUTH_SYS) */ + \
284 1 /* stamp */ + \
285 1 /* machinename.len */ + \
286 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
287 1 /* uid */ + \
288 1 /* gid */ + \
289 1 /* gids.len (0) */)
290#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
291 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
292 1 /* csr_sequence */ + \
293 1 /* csr_flags */ + \
294 decode_channel_attrs_maxsz + \
295 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400296#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
297#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400298#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
299 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
300#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
301 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400302#else /* CONFIG_NFS_V4_1 */
303#define encode_sequence_maxsz 0
304#define decode_sequence_maxsz 0
305#endif /* CONFIG_NFS_V4_1 */
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
308#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
309#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400310 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400312 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400314 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400316 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400318 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400320 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400322 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400324 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400326 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400328 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400330 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400332 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400334 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400336 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400337 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400339 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400341 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400342 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400344 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400346 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400347 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400349 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400351 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400352 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400354 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400355 encode_putfh_maxsz + \
356 encode_savefh_maxsz + \
357 encode_open_maxsz + \
358 encode_getfh_maxsz + \
359 encode_getattr_maxsz + \
360 encode_restorefh_maxsz + \
361 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400363 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400364 decode_putfh_maxsz + \
365 decode_savefh_maxsz + \
366 decode_open_maxsz + \
367 decode_getfh_maxsz + \
368 decode_getattr_maxsz + \
369 decode_restorefh_maxsz + \
370 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400371#define NFS4_enc_open_confirm_sz \
372 (compound_encode_hdr_maxsz + \
373 encode_putfh_maxsz + \
374 encode_open_confirm_maxsz)
375#define NFS4_dec_open_confirm_sz \
376 (compound_decode_hdr_maxsz + \
377 decode_putfh_maxsz + \
378 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400380 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400382 encode_open_maxsz + \
383 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400385 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400387 decode_open_maxsz + \
388 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389#define NFS4_enc_open_downgrade_sz \
390 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400391 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400392 encode_putfh_maxsz + \
393 encode_open_downgrade_maxsz + \
394 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define NFS4_dec_open_downgrade_sz \
396 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400397 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400398 decode_putfh_maxsz + \
399 decode_open_downgrade_maxsz + \
400 decode_getattr_maxsz)
401#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400402 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400403 encode_putfh_maxsz + \
404 encode_close_maxsz + \
405 encode_getattr_maxsz)
406#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400407 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400408 decode_putfh_maxsz + \
409 decode_close_maxsz + \
410 decode_getattr_maxsz)
411#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400412 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400413 encode_putfh_maxsz + \
414 encode_setattr_maxsz + \
415 encode_getattr_maxsz)
416#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400417 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400418 decode_putfh_maxsz + \
419 decode_setattr_maxsz + \
420 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 encode_putfh_maxsz + \
424 encode_fsinfo_maxsz)
425#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400426 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 decode_putfh_maxsz + \
428 decode_fsinfo_maxsz)
429#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
430 encode_renew_maxsz)
431#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
432 decode_renew_maxsz)
433#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
434 encode_setclientid_maxsz)
435#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
436 decode_setclientid_maxsz)
437#define NFS4_enc_setclientid_confirm_sz \
438 (compound_encode_hdr_maxsz + \
439 encode_setclientid_confirm_maxsz + \
440 encode_putrootfh_maxsz + \
441 encode_fsinfo_maxsz)
442#define NFS4_dec_setclientid_confirm_sz \
443 (compound_decode_hdr_maxsz + \
444 decode_setclientid_confirm_maxsz + \
445 decode_putrootfh_maxsz + \
446 decode_fsinfo_maxsz)
447#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400448 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400450 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400452 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400454 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400456 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400458 encode_lockt_maxsz)
459#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400460 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400461 decode_putfh_maxsz + \
462 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400464 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400466 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400468 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400470 decode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471#define NFS4_enc_access_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_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400474 encode_access_maxsz + \
475 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476#define NFS4_dec_access_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_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400479 decode_access_maxsz + \
480 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481#define NFS4_enc_getattr_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 + \
484 encode_getattr_maxsz)
485#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400486 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 decode_putfh_maxsz + \
488 decode_getattr_maxsz)
489#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400490 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 encode_putfh_maxsz + \
492 encode_lookup_maxsz + \
493 encode_getattr_maxsz + \
494 encode_getfh_maxsz)
495#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400498 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 decode_getattr_maxsz + \
500 decode_getfh_maxsz)
501#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400502 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 encode_putrootfh_maxsz + \
504 encode_getattr_maxsz + \
505 encode_getfh_maxsz)
506#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400507 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 decode_putrootfh_maxsz + \
509 decode_getattr_maxsz + \
510 decode_getfh_maxsz)
511#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400512 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400514 encode_remove_maxsz + \
515 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400517 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400519 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400520 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400522 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 encode_putfh_maxsz + \
524 encode_savefh_maxsz + \
525 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400526 encode_rename_maxsz + \
527 encode_getattr_maxsz + \
528 encode_restorefh_maxsz + \
529 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400531 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 decode_putfh_maxsz + \
533 decode_savefh_maxsz + \
534 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400535 decode_rename_maxsz + \
536 decode_getattr_maxsz + \
537 decode_restorefh_maxsz + \
538 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539#define NFS4_enc_link_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 + \
542 encode_savefh_maxsz + \
543 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400544 encode_link_maxsz + \
545 decode_getattr_maxsz + \
546 encode_restorefh_maxsz + \
547 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548#define NFS4_dec_link_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 + \
551 decode_savefh_maxsz + \
552 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400553 decode_link_maxsz + \
554 decode_getattr_maxsz + \
555 decode_restorefh_maxsz + \
556 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#define NFS4_enc_symlink_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_symlink_maxsz + \
561 encode_getattr_maxsz + \
562 encode_getfh_maxsz)
563#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 decode_putfh_maxsz + \
566 decode_symlink_maxsz + \
567 decode_getattr_maxsz + \
568 decode_getfh_maxsz)
569#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400572 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400574 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400576 encode_restorefh_maxsz + \
577 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400579 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400581 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400583 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400585 decode_restorefh_maxsz + \
586 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400588 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 encode_putfh_maxsz + \
590 encode_getattr_maxsz)
591#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400592 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 decode_putfh_maxsz + \
594 decode_getattr_maxsz)
595#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400598 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400600 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400602 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400604 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800605 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 encode_getattr_maxsz)
607#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400608 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800609 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 decode_getattr_maxsz)
611#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400612 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100614 encode_delegreturn_maxsz + \
615 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400617 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100618 decode_delegreturn_maxsz + \
619 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000620#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400621 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000622 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400623 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000624#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400625 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000626 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400627 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000628#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400629 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000630 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400631 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000632#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400633 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000634 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400635 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400636#define NFS4_enc_fs_locations_sz \
637 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400638 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400639 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400640 encode_lookup_maxsz + \
641 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400642#define NFS4_dec_fs_locations_sz \
643 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400644 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400645 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400646 decode_lookup_maxsz + \
647 decode_fs_locations_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400648#if defined(CONFIG_NFS_V4_1)
649#define NFS4_enc_exchange_id_sz \
650 (compound_encode_hdr_maxsz + \
651 encode_exchange_id_maxsz)
652#define NFS4_dec_exchange_id_sz \
653 (compound_decode_hdr_maxsz + \
654 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400655#define NFS4_enc_create_session_sz \
656 (compound_encode_hdr_maxsz + \
657 encode_create_session_maxsz)
658#define NFS4_dec_create_session_sz \
659 (compound_decode_hdr_maxsz + \
660 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400661#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
662 encode_destroy_session_maxsz)
663#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
664 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400665#define NFS4_enc_sequence_sz \
666 (compound_decode_hdr_maxsz + \
667 encode_sequence_maxsz)
668#define NFS4_dec_sequence_sz \
669 (compound_decode_hdr_maxsz + \
670 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400671#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
672 encode_sequence_maxsz + \
673 encode_putrootfh_maxsz + \
674 encode_fsinfo_maxsz)
675#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
676 decode_sequence_maxsz + \
677 decode_putrootfh_maxsz + \
678 decode_fsinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400679#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
Trond Myklebustbca79472009-03-11 14:10:26 -0400681static const umode_t nfs_type2fmt[] = {
682 [NF4BAD] = 0,
683 [NF4REG] = S_IFREG,
684 [NF4DIR] = S_IFDIR,
685 [NF4BLK] = S_IFBLK,
686 [NF4CHR] = S_IFCHR,
687 [NF4LNK] = S_IFLNK,
688 [NF4SOCK] = S_IFSOCK,
689 [NF4FIFO] = S_IFIFO,
690 [NF4ATTRDIR] = 0,
691 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692};
693
694struct compound_hdr {
695 int32_t status;
696 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500697 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 uint32_t taglen;
699 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400700 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400701 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702};
703
Benny Halevy13c65ce2009-08-14 17:19:25 +0300704static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
705{
706 __be32 *p = xdr_reserve_space(xdr, nbytes);
707 BUG_ON(!p);
708 return p;
709}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
711static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
712{
Al Viro8687b632006-10-19 23:28:48 -0700713 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715 p = xdr_reserve_space(xdr, 4 + len);
716 BUG_ON(p == NULL);
717 xdr_encode_opaque(p, str, len);
718}
719
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400720static void encode_compound_hdr(struct xdr_stream *xdr,
721 struct rpc_rqst *req,
722 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723{
Al Viro8687b632006-10-19 23:28:48 -0700724 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400725 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
726
727 /* initialize running count of expected bytes in reply.
728 * NOTE: the replied tag SHOULD be the same is the one sent,
729 * but this is not required as a MUST for the server to do so. */
730 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
732 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
733 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300734 p = reserve_space(xdr, 4 + hdr->taglen + 8);
735 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300736 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500737 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300738 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500739}
740
741static void encode_nops(struct compound_hdr *hdr)
742{
Andy Adamsonfc931582009-04-01 09:22:31 -0400743 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500744 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745}
746
747static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
748{
Al Viro8687b632006-10-19 23:28:48 -0700749 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
751 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
752 BUG_ON(p == NULL);
753 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
754}
755
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500756static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
758 char owner_name[IDMAP_NAMESZ];
759 char owner_group[IDMAP_NAMESZ];
760 int owner_namelen = 0;
761 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700762 __be32 *p;
763 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 int len;
765 uint32_t bmval0 = 0;
766 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
768 /*
769 * We reserve enough space to write the entire attribute buffer at once.
770 * In the worst-case, this would be
771 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
772 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000773 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 */
775 len = 16;
776
777 /* Sigh */
778 if (iap->ia_valid & ATTR_SIZE)
779 len += 8;
780 if (iap->ia_valid & ATTR_MODE)
781 len += 4;
782 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400783 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400785 dprintk("nfs: couldn't resolve uid %d to string\n",
786 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 /* XXX */
788 strcpy(owner_name, "nobody");
789 owner_namelen = sizeof("nobody") - 1;
790 /* goto out; */
791 }
792 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
793 }
794 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400795 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400797 dprintk("nfs: couldn't resolve gid %d to string\n",
798 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 strcpy(owner_group, "nobody");
800 owner_grouplen = sizeof("nobody") - 1;
801 /* goto out; */
802 }
803 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
804 }
805 if (iap->ia_valid & ATTR_ATIME_SET)
806 len += 16;
807 else if (iap->ia_valid & ATTR_ATIME)
808 len += 4;
809 if (iap->ia_valid & ATTR_MTIME_SET)
810 len += 16;
811 else if (iap->ia_valid & ATTR_MTIME)
812 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300813 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 /*
816 * We write the bitmap length now, but leave the bitmap and the attribute
817 * buffer length to be backfilled at the end of this routine.
818 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300819 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 q = p;
821 p += 3;
822
823 if (iap->ia_valid & ATTR_SIZE) {
824 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300825 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 }
827 if (iap->ia_valid & ATTR_MODE) {
828 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300829 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 }
831 if (iap->ia_valid & ATTR_UID) {
832 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300833 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 }
835 if (iap->ia_valid & ATTR_GID) {
836 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300837 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 }
839 if (iap->ia_valid & ATTR_ATIME_SET) {
840 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300841 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
842 *p++ = cpu_to_be32(0);
843 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
844 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 }
846 else if (iap->ia_valid & ATTR_ATIME) {
847 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300848 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 }
850 if (iap->ia_valid & ATTR_MTIME_SET) {
851 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300852 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
853 *p++ = cpu_to_be32(0);
854 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
855 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 }
857 else if (iap->ia_valid & ATTR_MTIME) {
858 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300859 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 /*
863 * Now we backfill the bitmap and the attribute buffer length.
864 */
865 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400866 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 len, ((char *)p - (char *)q) + 4);
868 BUG();
869 }
870 len = (char *)p - (char *)q - 12;
871 *q++ = htonl(bmval0);
872 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300873 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876}
877
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500878static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879{
Al Viro8687b632006-10-19 23:28:48 -0700880 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Benny Halevy13c65ce2009-08-14 17:19:25 +0300882 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300883 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +0300884 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500885 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400886 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887}
888
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500889static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890{
Al Viro8687b632006-10-19 23:28:48 -0700891 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Benny Halevy13c65ce2009-08-14 17:19:25 +0300893 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300894 *p++ = cpu_to_be32(OP_CLOSE);
895 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +0300896 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500897 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400898 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899}
900
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500901static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902{
Al Viro8687b632006-10-19 23:28:48 -0700903 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500904
Benny Halevy13c65ce2009-08-14 17:19:25 +0300905 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300906 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +0300907 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +0300908 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500909 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400910 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911}
912
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500913static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914{
Al Viro8687b632006-10-19 23:28:48 -0700915 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500916
Benny Halevy13c65ce2009-08-14 17:19:25 +0300917 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300918 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +0300919 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
921 switch (create->ftype) {
922 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300923 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +0300924 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -0400925 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 break;
927
928 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300929 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300930 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +0300931 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 break;
933
934 default:
935 break;
936 }
937
Benny Halevy811652b2009-08-14 17:19:34 +0300938 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -0500939 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400940 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500942 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943}
944
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500945static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946{
Andy Adamson05d564f2008-12-23 16:06:15 -0500947 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
Benny Halevy13c65ce2009-08-14 17:19:25 +0300949 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300950 *p++ = cpu_to_be32(OP_GETATTR);
951 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +0300952 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500953 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400954 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955}
956
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500957static 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 -0700958{
Andy Adamson05d564f2008-12-23 16:06:15 -0500959 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
Benny Halevy13c65ce2009-08-14 17:19:25 +0300961 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300962 *p++ = cpu_to_be32(OP_GETATTR);
963 *p++ = cpu_to_be32(2);
964 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +0300965 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -0500966 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400967 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968}
969
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500970static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500972 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
973 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974}
975
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500976static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500978 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
979 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980}
981
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500982static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -0400983{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500984 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
985 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -0400986}
987
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500988static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989{
Al Viro8687b632006-10-19 23:28:48 -0700990 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
Benny Halevy13c65ce2009-08-14 17:19:25 +0300992 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +0300993 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -0500994 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400995 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996}
997
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500998static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999{
Al Viro8687b632006-10-19 23:28:48 -07001000 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
Benny Halevy13c65ce2009-08-14 17:19:25 +03001002 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001003 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001004 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001005 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001006 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007}
1008
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001009static inline int nfs4_lock_type(struct file_lock *fl, int block)
1010{
1011 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1012 return block ? NFS4_READW_LT : NFS4_READ_LT;
1013 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1014}
1015
1016static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1017{
1018 if (fl->fl_end == OFFSET_MAX)
1019 return ~(uint64_t)0;
1020 return fl->fl_end - fl->fl_start + 1;
1021}
1022
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023/*
1024 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1025 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1026 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001027static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028{
Al Viro8687b632006-10-19 23:28:48 -07001029 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
Benny Halevy13c65ce2009-08-14 17:19:25 +03001031 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001032 *p++ = cpu_to_be32(OP_LOCK);
1033 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1034 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001035 p = xdr_encode_hyper(p, args->fl->fl_start);
1036 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001037 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001038 if (args->new_lock_owner){
Benny Halevy13c65ce2009-08-14 17:19:25 +03001039 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001040 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001041 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001042 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001043 p = xdr_encode_hyper(p, args->lock_owner.clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001044 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001045 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001046 xdr_encode_hyper(p, args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 }
1048 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001049 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001050 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001051 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 }
Andy Adamsond0179312008-12-23 16:06:17 -05001053 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001054 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055}
1056
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001057static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058{
Al Viro8687b632006-10-19 23:28:48 -07001059 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Benny Halevy13c65ce2009-08-14 17:19:25 +03001061 p = reserve_space(xdr, 52);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001062 *p++ = cpu_to_be32(OP_LOCKT);
1063 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001064 p = xdr_encode_hyper(p, args->fl->fl_start);
1065 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1066 p = xdr_encode_hyper(p, args->lock_owner.clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001067 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001068 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001069 xdr_encode_hyper(p, args->lock_owner.id);
Andy Adamsond0179312008-12-23 16:06:17 -05001070 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001071 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072}
1073
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001074static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075{
Al Viro8687b632006-10-19 23:28:48 -07001076 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Benny Halevy13c65ce2009-08-14 17:19:25 +03001078 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001079 *p++ = cpu_to_be32(OP_LOCKU);
1080 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1081 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001082 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001083 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001084 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001085 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001086 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087}
1088
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001089static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090{
1091 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001092 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Benny Halevy13c65ce2009-08-14 17:19:25 +03001094 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001095 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001096 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001097 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001098 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099}
1100
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001101static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102{
Al Viro8687b632006-10-19 23:28:48 -07001103 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Benny Halevy13c65ce2009-08-14 17:19:25 +03001105 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001106 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001107 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001108 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001109 break;
1110 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001111 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001112 break;
1113 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001114 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001115 break;
1116 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001117 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 }
Benny Halevy34558512009-08-14 17:19:30 +03001119 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120}
1121
1122static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1123{
Al Viro8687b632006-10-19 23:28:48 -07001124 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 /*
1126 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1127 * owner 4 = 32
1128 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001129 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001130 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001131 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001132 encode_share_access(xdr, arg->fmode);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001133 p = reserve_space(xdr, 28);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001134 p = xdr_encode_hyper(p, arg->clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001135 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001136 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001137 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138}
1139
1140static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1141{
Al Viro8687b632006-10-19 23:28:48 -07001142 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
Benny Halevy13c65ce2009-08-14 17:19:25 +03001144 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001146 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001147 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001148 encode_attrs(xdr, arg->u.attrs, arg->server);
1149 break;
1150 default:
Benny Halevy34558512009-08-14 17:19:30 +03001151 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001152 encode_nfs4_verifier(xdr, &arg->u.verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 }
1154}
1155
1156static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1157{
Al Viro8687b632006-10-19 23:28:48 -07001158 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
Benny Halevy13c65ce2009-08-14 17:19:25 +03001160 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001162 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001163 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001164 break;
1165 default:
1166 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001167 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001168 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 }
1170}
1171
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001172static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173{
Al Viro8687b632006-10-19 23:28:48 -07001174 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Benny Halevy13c65ce2009-08-14 17:19:25 +03001176 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001178 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001179 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001180 break;
1181 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001182 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001183 break;
1184 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001185 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001186 break;
1187 default:
1188 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 }
1190}
1191
1192static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1193{
Al Viro8687b632006-10-19 23:28:48 -07001194 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Benny Halevy13c65ce2009-08-14 17:19:25 +03001196 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001197 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 encode_string(xdr, name->len, name->name);
1199}
1200
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001201static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202{
Al Viro8687b632006-10-19 23:28:48 -07001203 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204
Benny Halevy13c65ce2009-08-14 17:19:25 +03001205 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001206 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 encode_delegation_type(xdr, type);
1208}
1209
1210static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1211{
Al Viro8687b632006-10-19 23:28:48 -07001212 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
Benny Halevy13c65ce2009-08-14 17:19:25 +03001214 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001215 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001216 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 encode_string(xdr, name->len, name->name);
1218}
1219
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001220static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221{
1222 encode_openhdr(xdr, arg);
1223 encode_opentype(xdr, arg);
1224 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001225 case NFS4_OPEN_CLAIM_NULL:
1226 encode_claim_null(xdr, arg->name);
1227 break;
1228 case NFS4_OPEN_CLAIM_PREVIOUS:
1229 encode_claim_previous(xdr, arg->u.delegation_type);
1230 break;
1231 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1232 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1233 break;
1234 default:
1235 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 }
Andy Adamsond0179312008-12-23 16:06:17 -05001237 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001238 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239}
1240
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001241static 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 -07001242{
Al Viro8687b632006-10-19 23:28:48 -07001243 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
Benny Halevy13c65ce2009-08-14 17:19:25 +03001245 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001246 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001247 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001248 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001249 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001250 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251}
1252
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001253static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254{
Al Viro8687b632006-10-19 23:28:48 -07001255 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
Benny Halevy13c65ce2009-08-14 17:19:25 +03001257 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001258 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001259 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001260 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001261 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001262 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001263 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264}
1265
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001266static void
Andy Adamsond0179312008-12-23 16:06:17 -05001267encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268{
1269 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001270 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Benny Halevy13c65ce2009-08-14 17:19:25 +03001272 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001273 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001274 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001275 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001276 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277}
1278
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001279static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280{
Andy Adamson05d564f2008-12-23 16:06:15 -05001281 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001282
Benny Halevy13c65ce2009-08-14 17:19:25 +03001283 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001284 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001285 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001286 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287}
1288
1289static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1290{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001292 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Benny Halevy13c65ce2009-08-14 17:19:25 +03001294 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 if (ctx->state != NULL) {
1296 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
Benny Halevy34558512009-08-14 17:19:30 +03001297 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 } else
Benny Halevy34558512009-08-14 17:19:30 +03001299 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300}
1301
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001302static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303{
Al Viro8687b632006-10-19 23:28:48 -07001304 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
Benny Halevy13c65ce2009-08-14 17:19:25 +03001306 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001307 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
1309 encode_stateid(xdr, args->context);
1310
Benny Halevy13c65ce2009-08-14 17:19:25 +03001311 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001312 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001313 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001314 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001315 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316}
1317
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001318static 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 -07001319{
Manoj Naik97d312d2005-06-22 17:16:39 +00001320 uint32_t attrs[2] = {
1321 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1322 FATTR4_WORD1_MOUNTED_ON_FILEID,
1323 };
Al Viro8687b632006-10-19 23:28:48 -07001324 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
Benny Halevy13c65ce2009-08-14 17:19:25 +03001326 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001327 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001328 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001329 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001330 *p++ = cpu_to_be32(readdir->count >> 1); /* We're not doing readdirplus */
1331 *p++ = cpu_to_be32(readdir->count);
1332 *p++ = cpu_to_be32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001333 /* Switch to mounted_on_fileid if the server supports it */
1334 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1335 attrs[0] &= ~FATTR4_WORD0_FILEID;
1336 else
1337 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001338 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001339 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001340 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001341 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001342 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1343 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001344 (unsigned long long)readdir->cookie,
1345 ((u32 *)readdir->verifier.data)[0],
1346 ((u32 *)readdir->verifier.data)[1],
1347 attrs[0] & readdir->bitmask[0],
1348 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349}
1350
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001351static 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 -07001352{
Al Viro8687b632006-10-19 23:28:48 -07001353 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Benny Halevy13c65ce2009-08-14 17:19:25 +03001355 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001356 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001357 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001358 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359}
1360
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001361static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362{
Al Viro8687b632006-10-19 23:28:48 -07001363 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
Benny Halevy13c65ce2009-08-14 17:19:25 +03001365 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001366 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001367 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001368 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001369 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370}
1371
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001372static 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 -07001373{
Al Viro8687b632006-10-19 23:28:48 -07001374 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
Benny Halevy811652b2009-08-14 17:19:34 +03001376 p = reserve_space(xdr, 4);
1377 *p = cpu_to_be32(OP_RENAME);
1378 encode_string(xdr, oldname->len, oldname->name);
1379 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001380 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001381 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382}
1383
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001384static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385{
Al Viro8687b632006-10-19 23:28:48 -07001386 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Benny Halevy13c65ce2009-08-14 17:19:25 +03001388 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001389 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001390 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001391 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001392 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393}
1394
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001395static void
Andy Adamsond0179312008-12-23 16:06:17 -05001396encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001397{
Al Viro8687b632006-10-19 23:28:48 -07001398 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001399
Benny Halevy13c65ce2009-08-14 17:19:25 +03001400 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001401 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001402 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001403 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001404}
1405
1406static int
Andy Adamsond0179312008-12-23 16:06:17 -05001407encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001408{
Al Viro8687b632006-10-19 23:28:48 -07001409 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001410
Benny Halevy13c65ce2009-08-14 17:19:25 +03001411 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001412 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001413 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001414 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001415 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001416 *p = cpu_to_be32(FATTR4_WORD0_ACL);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001417 if (arg->acl_len % 4)
1418 return -EINVAL;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001419 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001420 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001421 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001422 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001423 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001424 return 0;
1425}
1426
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001427static void
Andy Adamsond0179312008-12-23 16:06:17 -05001428encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429{
Al Viro8687b632006-10-19 23:28:48 -07001430 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
Benny Halevy13c65ce2009-08-14 17:19:25 +03001432 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001433 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001434 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001435 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436}
1437
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001438static 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 -07001439{
Al Viro8687b632006-10-19 23:28:48 -07001440 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001441
Benny Halevy13c65ce2009-08-14 17:19:25 +03001442 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001443 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001444 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001445 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001446 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001447 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448}
1449
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001450static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451{
Al Viro8687b632006-10-19 23:28:48 -07001452 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
Benny Halevy13c65ce2009-08-14 17:19:25 +03001454 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001455 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001456 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
1458 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001459 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001460 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1462 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001463 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001464 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001465 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001466 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467}
1468
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001469static 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 -07001470{
Andy Adamson05d564f2008-12-23 16:06:15 -05001471 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Benny Halevy13c65ce2009-08-14 17:19:25 +03001473 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001474 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001475 p = xdr_encode_hyper(p, client_state->cl_clientid);
Benny Halevy34558512009-08-14 17:19:30 +03001476 xdr_encode_opaque_fixed(p, client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001477 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001478 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001481static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482{
Al Viro8687b632006-10-19 23:28:48 -07001483 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
Benny Halevy13c65ce2009-08-14 17:19:25 +03001485 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001486 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
1488 encode_stateid(xdr, args->context);
1489
Benny Halevy13c65ce2009-08-14 17:19:25 +03001490 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001491 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001492 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001493 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
1495 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001496 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001497 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498}
1499
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001500static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501{
Al Viro8687b632006-10-19 23:28:48 -07001502 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503
Benny Halevy13c65ce2009-08-14 17:19:25 +03001504 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
Benny Halevye75bc1c2009-08-14 17:18:54 +03001506 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001507 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001508 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001509 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001511
Benny Halevy99fe60d2009-04-01 09:22:29 -04001512#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001513/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001514static void encode_exchange_id(struct xdr_stream *xdr,
1515 struct nfs41_exchange_id_args *args,
1516 struct compound_hdr *hdr)
1517{
1518 __be32 *p;
1519
Benny Halevy13c65ce2009-08-14 17:19:25 +03001520 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001521 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001522 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001523
1524 encode_string(xdr, args->id_len, args->id);
1525
Benny Halevy13c65ce2009-08-14 17:19:25 +03001526 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001527 *p++ = cpu_to_be32(args->flags);
1528 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001529 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001530 hdr->nops++;
1531 hdr->replen += decode_exchange_id_maxsz;
1532}
Andy Adamsonfc931582009-04-01 09:22:31 -04001533
1534static void encode_create_session(struct xdr_stream *xdr,
1535 struct nfs41_create_session_args *args,
1536 struct compound_hdr *hdr)
1537{
1538 __be32 *p;
1539 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1540 uint32_t len;
1541 struct nfs_client *clp = args->client;
1542
Andy Adamsonfc931582009-04-01 09:22:31 -04001543 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1544 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001545
Benny Halevy13c65ce2009-08-14 17:19:25 +03001546 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001547 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001548 p = xdr_encode_hyper(p, clp->cl_ex_clid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001549 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1550 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001551
Andy Adamsonfc931582009-04-01 09:22:31 -04001552 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001553 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1554 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1555 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1556 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1557 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1558 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1559 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001560
1561 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001562 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1563 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1564 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1565 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1566 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1567 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1568 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001569
Benny Halevye75bc1c2009-08-14 17:18:54 +03001570 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001571 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001572 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001573
1574 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001575 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001576 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001577 *p++ = cpu_to_be32(0); /* UID */
1578 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001579 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001580 hdr->nops++;
1581 hdr->replen += decode_create_session_maxsz;
1582}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001583
1584static void encode_destroy_session(struct xdr_stream *xdr,
1585 struct nfs4_session *session,
1586 struct compound_hdr *hdr)
1587{
1588 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001589 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001590 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001591 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001592 hdr->nops++;
1593 hdr->replen += decode_destroy_session_maxsz;
1594}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001595#endif /* CONFIG_NFS_V4_1 */
1596
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001597static void encode_sequence(struct xdr_stream *xdr,
1598 const struct nfs4_sequence_args *args,
1599 struct compound_hdr *hdr)
1600{
1601#if defined(CONFIG_NFS_V4_1)
1602 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001603 struct nfs4_slot_table *tp;
1604 struct nfs4_slot *slot;
1605 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001606
1607 if (!session)
1608 return;
1609
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001610 tp = &session->fc_slot_table;
1611
1612 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1613 slot = tp->slots + args->sa_slotid;
1614
Benny Halevy13c65ce2009-08-14 17:19:25 +03001615 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001616 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001617
1618 /*
1619 * Sessionid + seqid + slotid + max slotid + cache_this
1620 */
1621 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1622 "max_slotid=%d cache_this=%d\n",
1623 __func__,
1624 ((u32 *)session->sess_id.data)[0],
1625 ((u32 *)session->sess_id.data)[1],
1626 ((u32 *)session->sess_id.data)[2],
1627 ((u32 *)session->sess_id.data)[3],
1628 slot->seq_nr, args->sa_slotid,
1629 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001630 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001631 *p++ = cpu_to_be32(slot->seq_nr);
1632 *p++ = cpu_to_be32(args->sa_slotid);
1633 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001634 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001635 hdr->nops++;
1636 hdr->replen += decode_sequence_maxsz;
1637#endif /* CONFIG_NFS_V4_1 */
1638}
1639
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640/*
1641 * END OF "GENERIC" ENCODE ROUTINES.
1642 */
1643
Benny Halevy66cc0422009-04-01 09:22:10 -04001644static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1645{
1646#if defined(CONFIG_NFS_V4_1)
1647 if (args->sa_session)
1648 return args->sa_session->clp->cl_minorversion;
1649#endif /* CONFIG_NFS_V4_1 */
1650 return 0;
1651}
1652
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653/*
1654 * Encode an ACCESS request
1655 */
Al Viro8687b632006-10-19 23:28:48 -07001656static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657{
1658 struct xdr_stream xdr;
1659 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001660 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
1663 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001664 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001665 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001666 encode_putfh(&xdr, args->fh, &hdr);
1667 encode_access(&xdr, args->access, &hdr);
1668 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001669 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001670 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671}
1672
1673/*
1674 * Encode LOOKUP request
1675 */
Al Viro8687b632006-10-19 23:28:48 -07001676static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677{
1678 struct xdr_stream xdr;
1679 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001680 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682
1683 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001684 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001685 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001686 encode_putfh(&xdr, args->dir_fh, &hdr);
1687 encode_lookup(&xdr, args->name, &hdr);
1688 encode_getfh(&xdr, &hdr);
1689 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001690 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001691 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692}
1693
1694/*
1695 * Encode LOOKUP_ROOT request
1696 */
Al Viro8687b632006-10-19 23:28:48 -07001697static 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 -07001698{
1699 struct xdr_stream xdr;
1700 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001701 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
1704 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001705 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001706 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001707 encode_putrootfh(&xdr, &hdr);
1708 encode_getfh(&xdr, &hdr);
1709 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001710 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001711 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712}
1713
1714/*
1715 * Encode REMOVE request
1716 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001717static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718{
1719 struct xdr_stream xdr;
1720 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001721 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
1724 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001725 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001726 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001727 encode_putfh(&xdr, args->fh, &hdr);
1728 encode_remove(&xdr, &args->name, &hdr);
1729 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001730 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001731 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732}
1733
1734/*
1735 * Encode RENAME request
1736 */
Al Viro8687b632006-10-19 23:28:48 -07001737static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738{
1739 struct xdr_stream xdr;
1740 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001741 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
1744 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001745 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001746 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001747 encode_putfh(&xdr, args->old_dir, &hdr);
1748 encode_savefh(&xdr, &hdr);
1749 encode_putfh(&xdr, args->new_dir, &hdr);
1750 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1751 encode_getfattr(&xdr, args->bitmask, &hdr);
1752 encode_restorefh(&xdr, &hdr);
1753 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001754 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001755 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756}
1757
1758/*
1759 * Encode LINK request
1760 */
Al Viro8687b632006-10-19 23:28:48 -07001761static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762{
1763 struct xdr_stream xdr;
1764 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001765 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767
1768 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001769 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001770 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001771 encode_putfh(&xdr, args->fh, &hdr);
1772 encode_savefh(&xdr, &hdr);
1773 encode_putfh(&xdr, args->dir_fh, &hdr);
1774 encode_link(&xdr, args->name, &hdr);
1775 encode_getfattr(&xdr, args->bitmask, &hdr);
1776 encode_restorefh(&xdr, &hdr);
1777 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001778 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001779 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780}
1781
1782/*
1783 * Encode CREATE request
1784 */
Al Viro8687b632006-10-19 23:28:48 -07001785static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786{
1787 struct xdr_stream xdr;
1788 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001789 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
1792 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001793 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001794 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001795 encode_putfh(&xdr, args->dir_fh, &hdr);
1796 encode_savefh(&xdr, &hdr);
1797 encode_create(&xdr, args, &hdr);
1798 encode_getfh(&xdr, &hdr);
1799 encode_getfattr(&xdr, args->bitmask, &hdr);
1800 encode_restorefh(&xdr, &hdr);
1801 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001802 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001803 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804}
1805
1806/*
1807 * Encode SYMLINK request
1808 */
Al Viro8687b632006-10-19 23:28:48 -07001809static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810{
1811 return nfs4_xdr_enc_create(req, p, args);
1812}
1813
1814/*
1815 * Encode GETATTR request
1816 */
Al Viro8687b632006-10-19 23:28:48 -07001817static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818{
1819 struct xdr_stream xdr;
1820 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001821 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823
1824 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001825 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001826 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001827 encode_putfh(&xdr, args->fh, &hdr);
1828 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001829 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001830 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831}
1832
1833/*
1834 * Encode a CLOSE request
1835 */
Al Viro8687b632006-10-19 23:28:48 -07001836static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837{
Andy Adamson05d564f2008-12-23 16:06:15 -05001838 struct xdr_stream xdr;
1839 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001840 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05001841 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
Andy Adamson05d564f2008-12-23 16:06:15 -05001843 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001844 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001845 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001846 encode_putfh(&xdr, args->fh, &hdr);
1847 encode_close(&xdr, args, &hdr);
1848 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001849 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001850 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851}
1852
1853/*
1854 * Encode an OPEN request
1855 */
Al Viro8687b632006-10-19 23:28:48 -07001856static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857{
1858 struct xdr_stream xdr;
1859 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001860 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862
1863 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001864 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001865 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001866 encode_putfh(&xdr, args->fh, &hdr);
1867 encode_savefh(&xdr, &hdr);
1868 encode_open(&xdr, args, &hdr);
1869 encode_getfh(&xdr, &hdr);
1870 encode_getfattr(&xdr, args->bitmask, &hdr);
1871 encode_restorefh(&xdr, &hdr);
1872 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001873 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001874 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875}
1876
1877/*
1878 * Encode an OPEN_CONFIRM request
1879 */
Al Viro8687b632006-10-19 23:28:48 -07001880static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881{
1882 struct xdr_stream xdr;
1883 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001884 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
1887 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001888 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001889 encode_putfh(&xdr, args->fh, &hdr);
1890 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001891 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001892 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893}
1894
1895/*
1896 * Encode an OPEN request with no attributes.
1897 */
Al Viro8687b632006-10-19 23:28:48 -07001898static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899{
1900 struct xdr_stream xdr;
1901 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001902 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904
1905 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001906 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001907 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001908 encode_putfh(&xdr, args->fh, &hdr);
1909 encode_open(&xdr, args, &hdr);
1910 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001911 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001912 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913}
1914
1915/*
1916 * Encode an OPEN_DOWNGRADE request
1917 */
Al Viro8687b632006-10-19 23:28:48 -07001918static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919{
1920 struct xdr_stream xdr;
1921 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001922 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924
1925 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001926 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001927 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001928 encode_putfh(&xdr, args->fh, &hdr);
1929 encode_open_downgrade(&xdr, args, &hdr);
1930 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001931 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001932 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933}
1934
1935/*
1936 * Encode a LOCK request
1937 */
Al Viro8687b632006-10-19 23:28:48 -07001938static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939{
1940 struct xdr_stream xdr;
1941 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001942 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944
1945 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001946 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001947 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001948 encode_putfh(&xdr, args->fh, &hdr);
1949 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001950 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001951 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952}
1953
1954/*
1955 * Encode a LOCKT request
1956 */
Al Viro8687b632006-10-19 23:28:48 -07001957static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958{
1959 struct xdr_stream xdr;
1960 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001961 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
1964 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001965 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001966 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001967 encode_putfh(&xdr, args->fh, &hdr);
1968 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001969 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001970 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971}
1972
1973/*
1974 * Encode a LOCKU request
1975 */
Al Viro8687b632006-10-19 23:28:48 -07001976static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977{
1978 struct xdr_stream xdr;
1979 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001980 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982
1983 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001984 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001985 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001986 encode_putfh(&xdr, args->fh, &hdr);
1987 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001988 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001989 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990}
1991
1992/*
1993 * Encode a READLINK request
1994 */
Al Viro8687b632006-10-19 23:28:48 -07001995static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996{
1997 struct xdr_stream xdr;
1998 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001999 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
2002 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002003 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002004 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002005 encode_putfh(&xdr, args->fh, &hdr);
2006 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002007
Benny Halevy28f56692009-04-01 09:22:09 -04002008 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002009 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002010 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002011 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012}
2013
2014/*
2015 * Encode a READDIR request
2016 */
Al Viro8687b632006-10-19 23:28:48 -07002017static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018{
2019 struct xdr_stream xdr;
2020 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002021 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
2024 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002025 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002026 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002027 encode_putfh(&xdr, args->fh, &hdr);
2028 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002029
Benny Halevy28f56692009-04-01 09:22:09 -04002030 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002031 args->pgbase, args->count);
2032 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002033 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002034 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002035 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002036 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037}
2038
2039/*
2040 * Encode a READ request
2041 */
Al Viro8687b632006-10-19 23:28:48 -07002042static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 struct xdr_stream xdr;
2045 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002046 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048
2049 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002050 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002051 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002052 encode_putfh(&xdr, args->fh, &hdr);
2053 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
Benny Halevy28f56692009-04-01 09:22:09 -04002055 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002057 req->rq_rcv_buf.flags |= XDRBUF_READ;
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 * Encode an SETATTR request
2064 */
Al Viro8687b632006-10-19 23:28:48 -07002065static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066{
Andy Adamson05d564f2008-12-23 16:06:15 -05002067 struct xdr_stream xdr;
2068 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002069 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002070 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
Andy Adamson05d564f2008-12-23 16:06:15 -05002072 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_setattr(&xdr, args, args->server, &hdr);
2077 encode_getfattr(&xdr, args->bitmask, &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/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002083 * Encode a GETACL request
2084 */
2085static int
Al Viro8687b632006-10-19 23:28:48 -07002086nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002087 struct nfs_getaclargs *args)
2088{
2089 struct xdr_stream xdr;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002090 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002091 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002092 };
Benny Halevy28f56692009-04-01 09:22:09 -04002093 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002094
2095 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002096 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002097 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002098 encode_putfh(&xdr, args->fh, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002099 replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002100 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2101
Benny Halevy28f56692009-04-01 09:22:09 -04002102 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002103 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002104 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002105 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002106}
2107
2108/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 * Encode a WRITE request
2110 */
Al Viro8687b632006-10-19 23:28:48 -07002111static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112{
2113 struct xdr_stream xdr;
2114 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002115 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
2118 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002119 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002120 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002121 encode_putfh(&xdr, args->fh, &hdr);
2122 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002123 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002124 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002125 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002126 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127}
2128
2129/*
2130 * a COMMIT request
2131 */
Al Viro8687b632006-10-19 23:28:48 -07002132static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
2134 struct xdr_stream xdr;
2135 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002136 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
2139 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002140 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002141 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002142 encode_putfh(&xdr, args->fh, &hdr);
2143 encode_commit(&xdr, args, &hdr);
2144 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002145 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002146 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147}
2148
2149/*
2150 * FSINFO request
2151 */
Al Viro8687b632006-10-19 23:28:48 -07002152static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153{
2154 struct xdr_stream xdr;
2155 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002156 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
2159 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002160 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002161 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002162 encode_putfh(&xdr, args->fh, &hdr);
2163 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002164 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002165 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166}
2167
2168/*
2169 * a PATHCONF request
2170 */
Al Viro8687b632006-10-19 23:28:48 -07002171static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 struct xdr_stream xdr;
2174 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002175 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177
2178 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002179 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002180 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002181 encode_putfh(&xdr, args->fh, &hdr);
2182 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2183 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002184 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002185 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186}
2187
2188/*
2189 * a STATFS request
2190 */
Al Viro8687b632006-10-19 23:28:48 -07002191static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 struct xdr_stream xdr;
2194 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002195 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
2198 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002199 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002200 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002201 encode_putfh(&xdr, args->fh, &hdr);
2202 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2203 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002204 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002205 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206}
2207
2208/*
2209 * GETATTR_BITMAP request
2210 */
Benny Halevy43652ad2009-04-01 09:21:54 -04002211static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2212 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213{
2214 struct xdr_stream xdr;
2215 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002216 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218
2219 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002220 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002221 encode_sequence(&xdr, &args->seq_args, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04002222 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002223 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2224 FATTR4_WORD0_LINK_SUPPORT|
2225 FATTR4_WORD0_SYMLINK_SUPPORT|
2226 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002227 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002228 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229}
2230
2231/*
2232 * a RENEW request
2233 */
Al Viro8687b632006-10-19 23:28:48 -07002234static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235{
2236 struct xdr_stream xdr;
2237 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002238 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 };
2240
2241 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002242 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002243 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002244 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002245 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246}
2247
2248/*
2249 * a SETCLIENTID request
2250 */
Al Viro8687b632006-10-19 23:28:48 -07002251static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252{
2253 struct xdr_stream xdr;
2254 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002255 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 };
2257
2258 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002259 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002260 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002261 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002262 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263}
2264
2265/*
2266 * a SETCLIENTID_CONFIRM request
2267 */
Al Viro8687b632006-10-19 23:28:48 -07002268static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269{
2270 struct xdr_stream xdr;
2271 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002272 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 };
2274 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
2276 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002277 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002278 encode_setclientid_confirm(&xdr, clp, &hdr);
2279 encode_putrootfh(&xdr, &hdr);
2280 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002281 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002282 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283}
2284
2285/*
2286 * DELEGRETURN request
2287 */
Al Viro8687b632006-10-19 23:28:48 -07002288static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289{
2290 struct xdr_stream xdr;
2291 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002292 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
2295 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002296 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002297 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002298 encode_putfh(&xdr, args->fhandle, &hdr);
2299 encode_delegreturn(&xdr, args->stateid, &hdr);
2300 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002301 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002302 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303}
2304
2305/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002306 * Encode FS_LOCATIONS request
2307 */
Al Viro8687b632006-10-19 23:28:48 -07002308static 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 -04002309{
2310 struct xdr_stream xdr;
2311 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002312 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002313 };
Benny Halevy28f56692009-04-01 09:22:09 -04002314 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002315
2316 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002317 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04002318 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002319 encode_putfh(&xdr, args->dir_fh, &hdr);
2320 encode_lookup(&xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002321 replen = hdr.replen; /* get the attribute into args->page */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002322 encode_fs_locations(&xdr, args->bitmask, &hdr);
2323
Benny Halevy28f56692009-04-01 09:22:09 -04002324 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002325 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002326 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002327 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002328}
2329
Benny Halevy99fe60d2009-04-01 09:22:29 -04002330#if defined(CONFIG_NFS_V4_1)
2331/*
2332 * EXCHANGE_ID request
2333 */
2334static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2335 struct nfs41_exchange_id_args *args)
2336{
2337 struct xdr_stream xdr;
2338 struct compound_hdr hdr = {
2339 .minorversion = args->client->cl_minorversion,
2340 };
2341
2342 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2343 encode_compound_hdr(&xdr, req, &hdr);
2344 encode_exchange_id(&xdr, args, &hdr);
2345 encode_nops(&hdr);
2346 return 0;
2347}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002348
2349/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002350 * a CREATE_SESSION request
2351 */
2352static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2353 struct nfs41_create_session_args *args)
2354{
2355 struct xdr_stream xdr;
2356 struct compound_hdr hdr = {
2357 .minorversion = args->client->cl_minorversion,
2358 };
2359
2360 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2361 encode_compound_hdr(&xdr, req, &hdr);
2362 encode_create_session(&xdr, args, &hdr);
2363 encode_nops(&hdr);
2364 return 0;
2365}
2366
2367/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002368 * a DESTROY_SESSION request
2369 */
2370static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2371 struct nfs4_session *session)
2372{
2373 struct xdr_stream xdr;
2374 struct compound_hdr hdr = {
2375 .minorversion = session->clp->cl_minorversion,
2376 };
2377
2378 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2379 encode_compound_hdr(&xdr, req, &hdr);
2380 encode_destroy_session(&xdr, session, &hdr);
2381 encode_nops(&hdr);
2382 return 0;
2383}
2384
2385/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002386 * a SEQUENCE request
2387 */
2388static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p,
2389 struct nfs4_sequence_args *args)
2390{
2391 struct xdr_stream xdr;
2392 struct compound_hdr hdr = {
2393 .minorversion = nfs4_xdr_minorversion(args),
2394 };
2395
2396 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2397 encode_compound_hdr(&xdr, req, &hdr);
2398 encode_sequence(&xdr, args, &hdr);
2399 encode_nops(&hdr);
2400 return 0;
2401}
2402
2403/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002404 * a GET_LEASE_TIME request
2405 */
2406static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2407 struct nfs4_get_lease_time_args *args)
2408{
2409 struct xdr_stream xdr;
2410 struct compound_hdr hdr = {
2411 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2412 };
2413 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2414
2415 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2416 encode_compound_hdr(&xdr, req, &hdr);
2417 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2418 encode_putrootfh(&xdr, &hdr);
2419 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2420 encode_nops(&hdr);
2421 return 0;
2422}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002423#endif /* CONFIG_NFS_V4_1 */
2424
Benny Halevy686841b2009-08-14 17:19:48 +03002425static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2426{
2427 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2428 "Remaining buffer length is %tu words.\n",
2429 func, xdr->end - xdr->p);
2430}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431
Trond Myklebust683b57b2006-06-09 09:34:22 -04002432static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433{
Al Viro8687b632006-10-19 23:28:48 -07002434 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
Benny Halevyc0eae662009-08-14 17:20:14 +03002436 p = xdr_inline_decode(xdr, 4);
2437 if (unlikely(!p))
2438 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002439 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002440 p = xdr_inline_decode(xdr, *len);
2441 if (unlikely(!p))
2442 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 *string = (char *)p;
2444 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002445out_overflow:
2446 print_overflow_msg(__func__, xdr);
2447 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448}
2449
2450static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2451{
Al Viro8687b632006-10-19 23:28:48 -07002452 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453
Benny Halevyc0eae662009-08-14 17:20:14 +03002454 p = xdr_inline_decode(xdr, 8);
2455 if (unlikely(!p))
2456 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002457 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002458 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002459
Benny Halevyc0eae662009-08-14 17:20:14 +03002460 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2461 if (unlikely(!p))
2462 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 hdr->tag = (char *)p;
2464 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002465 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002466 if (unlikely(hdr->nops < 1))
2467 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002469out_overflow:
2470 print_overflow_msg(__func__, xdr);
2471 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472}
2473
2474static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2475{
Al Viro8687b632006-10-19 23:28:48 -07002476 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 uint32_t opnum;
2478 int32_t nfserr;
2479
Benny Halevyc0eae662009-08-14 17:20:14 +03002480 p = xdr_inline_decode(xdr, 8);
2481 if (unlikely(!p))
2482 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002483 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002485 dprintk("nfs: Server returned operation"
2486 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 opnum, expected);
2488 return -EIO;
2489 }
Benny Halevycccddf42009-08-14 17:20:19 +03002490 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002492 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002494out_overflow:
2495 print_overflow_msg(__func__, xdr);
2496 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497}
2498
2499/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002500static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501{
Al Viro8687b632006-10-19 23:28:48 -07002502 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002503 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 char *str;
2505
Benny Halevyc0eae662009-08-14 17:20:14 +03002506 p = xdr_inline_decode(xdr, 12);
2507 if (likely(p))
2508 return decode_opaque_inline(xdr, &strlen, &str);
2509 print_overflow_msg(__func__, xdr);
2510 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511}
2512
2513static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2514{
Al Viro8687b632006-10-19 23:28:48 -07002515 uint32_t bmlen;
2516 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517
Benny Halevyc0eae662009-08-14 17:20:14 +03002518 p = xdr_inline_decode(xdr, 4);
2519 if (unlikely(!p))
2520 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002521 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522
2523 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002524 p = xdr_inline_decode(xdr, (bmlen << 2));
2525 if (unlikely(!p))
2526 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002528 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002530 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 }
2532 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002533out_overflow:
2534 print_overflow_msg(__func__, xdr);
2535 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536}
2537
Al Viro8687b632006-10-19 23:28:48 -07002538static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539{
Al Viro8687b632006-10-19 23:28:48 -07002540 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541
Benny Halevyc0eae662009-08-14 17:20:14 +03002542 p = xdr_inline_decode(xdr, 4);
2543 if (unlikely(!p))
2544 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002545 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 *savep = xdr->p;
2547 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002548out_overflow:
2549 print_overflow_msg(__func__, xdr);
2550 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551}
2552
2553static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2554{
2555 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2556 decode_attr_bitmap(xdr, bitmask);
2557 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2558 } else
2559 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002560 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 return 0;
2562}
2563
2564static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2565{
Al Viro8687b632006-10-19 23:28:48 -07002566 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002567 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568
2569 *type = 0;
2570 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2571 return -EIO;
2572 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002573 p = xdr_inline_decode(xdr, 4);
2574 if (unlikely(!p))
2575 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002576 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002578 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 return -EIO;
2580 }
2581 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002582 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002584 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002585 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002586out_overflow:
2587 print_overflow_msg(__func__, xdr);
2588 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589}
2590
2591static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2592{
Al Viro8687b632006-10-19 23:28:48 -07002593 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002594 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
2596 *change = 0;
2597 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2598 return -EIO;
2599 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002600 p = xdr_inline_decode(xdr, 8);
2601 if (unlikely(!p))
2602 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002603 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002605 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002607 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002609 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002610out_overflow:
2611 print_overflow_msg(__func__, xdr);
2612 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613}
2614
2615static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2616{
Al Viro8687b632006-10-19 23:28:48 -07002617 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002618 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619
2620 *size = 0;
2621 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2622 return -EIO;
2623 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002624 p = xdr_inline_decode(xdr, 8);
2625 if (unlikely(!p))
2626 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002627 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002629 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002631 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002632 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002633out_overflow:
2634 print_overflow_msg(__func__, xdr);
2635 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636}
2637
2638static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2639{
Al Viro8687b632006-10-19 23:28:48 -07002640 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641
2642 *res = 0;
2643 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2644 return -EIO;
2645 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002646 p = xdr_inline_decode(xdr, 4);
2647 if (unlikely(!p))
2648 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002649 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2651 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002652 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002654out_overflow:
2655 print_overflow_msg(__func__, xdr);
2656 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657}
2658
2659static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2660{
Al Viro8687b632006-10-19 23:28:48 -07002661 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662
2663 *res = 0;
2664 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2665 return -EIO;
2666 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002667 p = xdr_inline_decode(xdr, 4);
2668 if (unlikely(!p))
2669 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002670 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2672 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002673 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002675out_overflow:
2676 print_overflow_msg(__func__, xdr);
2677 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678}
2679
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002680static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681{
Al Viro8687b632006-10-19 23:28:48 -07002682 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002683 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
2685 fsid->major = 0;
2686 fsid->minor = 0;
2687 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2688 return -EIO;
2689 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002690 p = xdr_inline_decode(xdr, 16);
2691 if (unlikely(!p))
2692 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03002693 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03002694 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002696 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002698 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 (unsigned long long)fsid->major,
2700 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002701 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002702out_overflow:
2703 print_overflow_msg(__func__, xdr);
2704 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705}
2706
2707static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2708{
Al Viro8687b632006-10-19 23:28:48 -07002709 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710
2711 *res = 60;
2712 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2713 return -EIO;
2714 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002715 p = xdr_inline_decode(xdr, 4);
2716 if (unlikely(!p))
2717 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002718 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2720 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002721 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002723out_overflow:
2724 print_overflow_msg(__func__, xdr);
2725 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726}
2727
2728static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2729{
Al Viro8687b632006-10-19 23:28:48 -07002730 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731
2732 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2733 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2734 return -EIO;
2735 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002736 p = xdr_inline_decode(xdr, 4);
2737 if (unlikely(!p))
2738 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002739 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2741 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002742 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002744out_overflow:
2745 print_overflow_msg(__func__, xdr);
2746 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747}
2748
2749static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2750{
Al Viro8687b632006-10-19 23:28:48 -07002751 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002752 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753
2754 *fileid = 0;
2755 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2756 return -EIO;
2757 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002758 p = xdr_inline_decode(xdr, 8);
2759 if (unlikely(!p))
2760 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002761 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002763 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002765 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002766 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002767out_overflow:
2768 print_overflow_msg(__func__, xdr);
2769 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770}
2771
Manoj Naik99baf622006-06-09 09:34:24 -04002772static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2773{
Al Viro8687b632006-10-19 23:28:48 -07002774 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002775 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002776
2777 *fileid = 0;
2778 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2779 return -EIO;
2780 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002781 p = xdr_inline_decode(xdr, 8);
2782 if (unlikely(!p))
2783 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002784 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04002785 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002786 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002787 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002788 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002789 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002790out_overflow:
2791 print_overflow_msg(__func__, xdr);
2792 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04002793}
2794
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2796{
Al Viro8687b632006-10-19 23:28:48 -07002797 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 int status = 0;
2799
2800 *res = 0;
2801 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2802 return -EIO;
2803 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002804 p = xdr_inline_decode(xdr, 8);
2805 if (unlikely(!p))
2806 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002807 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2809 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002810 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002812out_overflow:
2813 print_overflow_msg(__func__, xdr);
2814 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815}
2816
2817static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2818{
Al Viro8687b632006-10-19 23:28:48 -07002819 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 int status = 0;
2821
2822 *res = 0;
2823 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2824 return -EIO;
2825 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002826 p = xdr_inline_decode(xdr, 8);
2827 if (unlikely(!p))
2828 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002829 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2831 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002832 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002834out_overflow:
2835 print_overflow_msg(__func__, xdr);
2836 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837}
2838
2839static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2840{
Al Viro8687b632006-10-19 23:28:48 -07002841 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 int status = 0;
2843
2844 *res = 0;
2845 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2846 return -EIO;
2847 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002848 p = xdr_inline_decode(xdr, 8);
2849 if (unlikely(!p))
2850 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002851 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2853 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002854 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002856out_overflow:
2857 print_overflow_msg(__func__, xdr);
2858 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859}
2860
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002861static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2862{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002863 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002864 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002865 int status = 0;
2866
Benny Halevyc0eae662009-08-14 17:20:14 +03002867 p = xdr_inline_decode(xdr, 4);
2868 if (unlikely(!p))
2869 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002870 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04002871 if (n == 0)
2872 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002873 dprintk("path ");
2874 path->ncomponents = 0;
2875 while (path->ncomponents < n) {
2876 struct nfs4_string *component = &path->components[path->ncomponents];
2877 status = decode_opaque_inline(xdr, &component->len, &component->data);
2878 if (unlikely(status != 0))
2879 goto out_eio;
2880 if (path->ncomponents != n)
2881 dprintk("/");
2882 dprintk("%s", component->data);
2883 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2884 path->ncomponents++;
2885 else {
2886 dprintk("cannot parse %d components in path\n", n);
2887 goto out_eio;
2888 }
2889 }
2890out:
2891 dprintk("\n");
2892 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002893root_path:
2894/* a root pathname is sent as a zero component4 */
2895 path->ncomponents = 1;
2896 path->components[0].len=0;
2897 path->components[0].data=NULL;
2898 dprintk("path /\n");
2899 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002900out_eio:
2901 dprintk(" status %d", status);
2902 status = -EIO;
2903 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03002904out_overflow:
2905 print_overflow_msg(__func__, xdr);
2906 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002907}
2908
2909static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002910{
2911 int n;
Al Viro8687b632006-10-19 23:28:48 -07002912 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002913 int status = -EIO;
2914
2915 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2916 goto out;
2917 status = 0;
2918 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2919 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002920 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002921 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002922 if (unlikely(status != 0))
2923 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03002924 p = xdr_inline_decode(xdr, 4);
2925 if (unlikely(!p))
2926 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002927 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002928 if (n <= 0)
2929 goto out_eio;
2930 res->nlocations = 0;
2931 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002932 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002933 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04002934
Benny Halevyc0eae662009-08-14 17:20:14 +03002935 p = xdr_inline_decode(xdr, 4);
2936 if (unlikely(!p))
2937 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002938 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002939
2940 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002941 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002942 while (loc->nservers < m) {
2943 struct nfs4_string *server = &loc->servers[loc->nservers];
2944 status = decode_opaque_inline(xdr, &server->len, &server->data);
2945 if (unlikely(status != 0))
2946 goto out_eio;
2947 dprintk("%s ", server->data);
2948 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2949 loc->nservers++;
2950 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002951 unsigned int i;
2952 dprintk("%s: using first %u of %u servers "
2953 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002954 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04002955 NFS4_FS_LOCATION_MAXSERVERS,
2956 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002957 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002958 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002959 char *data;
2960 status = decode_opaque_inline(xdr, &len, &data);
2961 if (unlikely(status != 0))
2962 goto out_eio;
2963 }
2964 }
2965 }
2966 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002967 if (unlikely(status != 0))
2968 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002969 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002970 res->nlocations++;
2971 }
Trond Myklebust409924e2009-03-11 14:10:27 -04002972 if (res->nlocations != 0)
2973 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002974out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002975 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002976 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03002977out_overflow:
2978 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002979out_eio:
2980 status = -EIO;
2981 goto out;
2982}
2983
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2985{
Al Viro8687b632006-10-19 23:28:48 -07002986 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 int status = 0;
2988
2989 *res = 0;
2990 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2991 return -EIO;
2992 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002993 p = xdr_inline_decode(xdr, 8);
2994 if (unlikely(!p))
2995 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002996 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2998 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002999 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003001out_overflow:
3002 print_overflow_msg(__func__, xdr);
3003 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004}
3005
3006static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3007{
Al Viro8687b632006-10-19 23:28:48 -07003008 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 int status = 0;
3010
3011 *maxlink = 1;
3012 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3013 return -EIO;
3014 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003015 p = xdr_inline_decode(xdr, 4);
3016 if (unlikely(!p))
3017 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003018 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3020 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003021 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003023out_overflow:
3024 print_overflow_msg(__func__, xdr);
3025 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026}
3027
3028static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3029{
Al Viro8687b632006-10-19 23:28:48 -07003030 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 int status = 0;
3032
3033 *maxname = 1024;
3034 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3035 return -EIO;
3036 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003037 p = xdr_inline_decode(xdr, 4);
3038 if (unlikely(!p))
3039 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003040 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3042 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003043 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003045out_overflow:
3046 print_overflow_msg(__func__, xdr);
3047 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048}
3049
3050static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3051{
Al Viro8687b632006-10-19 23:28:48 -07003052 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 int status = 0;
3054
3055 *res = 1024;
3056 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3057 return -EIO;
3058 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3059 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003060 p = xdr_inline_decode(xdr, 8);
3061 if (unlikely(!p))
3062 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003063 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 if (maxread > 0x7FFFFFFF)
3065 maxread = 0x7FFFFFFF;
3066 *res = (uint32_t)maxread;
3067 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3068 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003069 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003071out_overflow:
3072 print_overflow_msg(__func__, xdr);
3073 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074}
3075
3076static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3077{
Al Viro8687b632006-10-19 23:28:48 -07003078 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 int status = 0;
3080
3081 *res = 1024;
3082 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3083 return -EIO;
3084 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3085 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003086 p = xdr_inline_decode(xdr, 8);
3087 if (unlikely(!p))
3088 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003089 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 if (maxwrite > 0x7FFFFFFF)
3091 maxwrite = 0x7FFFFFFF;
3092 *res = (uint32_t)maxwrite;
3093 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3094 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003095 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003097out_overflow:
3098 print_overflow_msg(__func__, xdr);
3099 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100}
3101
Trond Myklebustbca79472009-03-11 14:10:26 -04003102static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103{
Trond Myklebustbca79472009-03-11 14:10:26 -04003104 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003105 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003106 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107
3108 *mode = 0;
3109 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3110 return -EIO;
3111 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003112 p = xdr_inline_decode(xdr, 4);
3113 if (unlikely(!p))
3114 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003115 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003116 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003118 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003120 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003121 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003122out_overflow:
3123 print_overflow_msg(__func__, xdr);
3124 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125}
3126
3127static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3128{
Al Viro8687b632006-10-19 23:28:48 -07003129 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003130 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131
3132 *nlink = 1;
3133 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3134 return -EIO;
3135 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003136 p = xdr_inline_decode(xdr, 4);
3137 if (unlikely(!p))
3138 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003139 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003141 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003143 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003144 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003145out_overflow:
3146 print_overflow_msg(__func__, xdr);
3147 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148}
3149
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003150static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3151 struct nfs_client *clp, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152{
Al Viro8687b632006-10-19 23:28:48 -07003153 uint32_t len;
3154 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003155 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156
3157 *uid = -2;
3158 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3159 return -EIO;
3160 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003161 p = xdr_inline_decode(xdr, 4);
3162 if (unlikely(!p))
3163 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003164 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003165 p = xdr_inline_decode(xdr, len);
3166 if (unlikely(!p))
3167 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003168 if (!may_sleep) {
3169 /* do nothing */
3170 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003171 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3172 ret = NFS_ATTR_FATTR_OWNER;
3173 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003175 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003177 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003178 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3180 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003181 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003182 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003183out_overflow:
3184 print_overflow_msg(__func__, xdr);
3185 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186}
3187
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003188static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3189 struct nfs_client *clp, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190{
Al Viro8687b632006-10-19 23:28:48 -07003191 uint32_t len;
3192 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003193 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194
3195 *gid = -2;
3196 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3197 return -EIO;
3198 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003199 p = xdr_inline_decode(xdr, 4);
3200 if (unlikely(!p))
3201 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003202 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003203 p = xdr_inline_decode(xdr, len);
3204 if (unlikely(!p))
3205 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003206 if (!may_sleep) {
3207 /* do nothing */
3208 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003209 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3210 ret = NFS_ATTR_FATTR_GROUP;
3211 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003213 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003215 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003216 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3218 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003219 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003220 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003221out_overflow:
3222 print_overflow_msg(__func__, xdr);
3223 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224}
3225
3226static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3227{
Al Viro8687b632006-10-19 23:28:48 -07003228 uint32_t major = 0, minor = 0;
3229 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003230 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231
3232 *rdev = MKDEV(0,0);
3233 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3234 return -EIO;
3235 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3236 dev_t tmp;
3237
Benny Halevyc0eae662009-08-14 17:20:14 +03003238 p = xdr_inline_decode(xdr, 8);
3239 if (unlikely(!p))
3240 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003241 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003242 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 tmp = MKDEV(major, minor);
3244 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3245 *rdev = tmp;
3246 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003247 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003249 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003250 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003251out_overflow:
3252 print_overflow_msg(__func__, xdr);
3253 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254}
3255
3256static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3257{
Al Viro8687b632006-10-19 23:28:48 -07003258 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 int status = 0;
3260
3261 *res = 0;
3262 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3263 return -EIO;
3264 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003265 p = xdr_inline_decode(xdr, 8);
3266 if (unlikely(!p))
3267 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003268 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3270 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003271 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003273out_overflow:
3274 print_overflow_msg(__func__, xdr);
3275 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276}
3277
3278static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3279{
Al Viro8687b632006-10-19 23:28:48 -07003280 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281 int status = 0;
3282
3283 *res = 0;
3284 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3285 return -EIO;
3286 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003287 p = xdr_inline_decode(xdr, 8);
3288 if (unlikely(!p))
3289 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003290 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3292 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003293 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003295out_overflow:
3296 print_overflow_msg(__func__, xdr);
3297 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298}
3299
3300static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3301{
Al Viro8687b632006-10-19 23:28:48 -07003302 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 int status = 0;
3304
3305 *res = 0;
3306 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3307 return -EIO;
3308 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003309 p = xdr_inline_decode(xdr, 8);
3310 if (unlikely(!p))
3311 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003312 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3314 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003315 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003317out_overflow:
3318 print_overflow_msg(__func__, xdr);
3319 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320}
3321
3322static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3323{
Al Viro8687b632006-10-19 23:28:48 -07003324 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003325 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326
3327 *used = 0;
3328 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3329 return -EIO;
3330 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003331 p = xdr_inline_decode(xdr, 8);
3332 if (unlikely(!p))
3333 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003334 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003336 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003338 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003340 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003341out_overflow:
3342 print_overflow_msg(__func__, xdr);
3343 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344}
3345
3346static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3347{
Al Viro8687b632006-10-19 23:28:48 -07003348 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 uint64_t sec;
3350 uint32_t nsec;
3351
Benny Halevyc0eae662009-08-14 17:20:14 +03003352 p = xdr_inline_decode(xdr, 12);
3353 if (unlikely(!p))
3354 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003355 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003356 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 time->tv_sec = (time_t)sec;
3358 time->tv_nsec = (long)nsec;
3359 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003360out_overflow:
3361 print_overflow_msg(__func__, xdr);
3362 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363}
3364
3365static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3366{
3367 int status = 0;
3368
3369 time->tv_sec = 0;
3370 time->tv_nsec = 0;
3371 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3372 return -EIO;
3373 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3374 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003375 if (status == 0)
3376 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3378 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003379 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 return status;
3381}
3382
3383static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3384{
3385 int status = 0;
3386
3387 time->tv_sec = 0;
3388 time->tv_nsec = 0;
3389 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3390 return -EIO;
3391 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3392 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003393 if (status == 0)
3394 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3396 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003397 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 return status;
3399}
3400
3401static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3402{
3403 int status = 0;
3404
3405 time->tv_sec = 0;
3406 time->tv_nsec = 0;
3407 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3408 return -EIO;
3409 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3410 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003411 if (status == 0)
3412 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3414 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003415 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 return status;
3417}
3418
Al Viro8687b632006-10-19 23:28:48 -07003419static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420{
3421 unsigned int attrwords = XDR_QUADLEN(attrlen);
3422 unsigned int nwords = xdr->p - savep;
3423
3424 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003425 dprintk("%s: server returned incorrect attribute length: "
3426 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003427 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 attrwords << 2,
3429 (attrwords < nwords) ? '<' : '>',
3430 nwords << 2);
3431 return -EIO;
3432 }
3433 return 0;
3434}
3435
3436static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3437{
Al Viro8687b632006-10-19 23:28:48 -07003438 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439
Benny Halevyc0eae662009-08-14 17:20:14 +03003440 p = xdr_inline_decode(xdr, 20);
3441 if (unlikely(!p))
3442 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003443 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003444 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003445 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003447out_overflow:
3448 print_overflow_msg(__func__, xdr);
3449 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450}
3451
3452static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3453{
Al Viro8687b632006-10-19 23:28:48 -07003454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 uint32_t supp, acc;
3456 int status;
3457
3458 status = decode_op_hdr(xdr, OP_ACCESS);
3459 if (status)
3460 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003461 p = xdr_inline_decode(xdr, 8);
3462 if (unlikely(!p))
3463 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003464 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003465 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466 access->supported = supp;
3467 access->access = acc;
3468 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003469out_overflow:
3470 print_overflow_msg(__func__, xdr);
3471 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472}
3473
Benny Halevy07d30432009-08-14 17:19:52 +03003474static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475{
Al Viro8687b632006-10-19 23:28:48 -07003476 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003477
3478 p = xdr_inline_decode(xdr, len);
3479 if (likely(p)) {
3480 memcpy(buf, p, len);
3481 return 0;
3482 }
3483 print_overflow_msg(__func__, xdr);
3484 return -EIO;
3485}
3486
3487static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3488{
3489 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490}
3491
3492static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3493{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 int status;
3495
3496 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003497 if (status != -EIO)
3498 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003499 if (!status)
3500 status = decode_stateid(xdr, &res->stateid);
3501 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502}
3503
Benny Halevydb942bb2009-08-14 17:19:56 +03003504static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3505{
3506 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507}
3508
3509static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3510{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 int status;
3512
3513 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003514 if (!status)
3515 status = decode_verifier(xdr, res->verf->verifier);
3516 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517}
3518
3519static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3520{
Al Viro8687b632006-10-19 23:28:48 -07003521 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 uint32_t bmlen;
3523 int status;
3524
3525 status = decode_op_hdr(xdr, OP_CREATE);
3526 if (status)
3527 return status;
3528 if ((status = decode_change_info(xdr, cinfo)))
3529 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003530 p = xdr_inline_decode(xdr, 4);
3531 if (unlikely(!p))
3532 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003533 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003534 p = xdr_inline_decode(xdr, bmlen << 2);
3535 if (likely(p))
3536 return 0;
3537out_overflow:
3538 print_overflow_msg(__func__, xdr);
3539 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540}
3541
3542static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3543{
Al Viro8687b632006-10-19 23:28:48 -07003544 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003545 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 int status;
3547
3548 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3549 goto xdr_error;
3550 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3551 goto xdr_error;
3552 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3553 goto xdr_error;
3554 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3555 goto xdr_error;
3556 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3557 goto xdr_error;
3558 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3559 goto xdr_error;
3560 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3561 goto xdr_error;
3562 status = verify_attr_len(xdr, savep, attrlen);
3563xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003564 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565 return status;
3566}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003567
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3569{
Al Viro8687b632006-10-19 23:28:48 -07003570 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003571 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003573
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3575 goto xdr_error;
3576 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3577 goto xdr_error;
3578 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3579 goto xdr_error;
3580
3581 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3582 goto xdr_error;
3583 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3584 goto xdr_error;
3585 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3586 goto xdr_error;
3587 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3588 goto xdr_error;
3589 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3590 goto xdr_error;
3591 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3592 goto xdr_error;
3593
3594 status = verify_attr_len(xdr, savep, attrlen);
3595xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003596 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597 return status;
3598}
3599
3600static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3601{
Al Viro8687b632006-10-19 23:28:48 -07003602 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003603 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003605
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3607 goto xdr_error;
3608 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3609 goto xdr_error;
3610 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3611 goto xdr_error;
3612
3613 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3614 goto xdr_error;
3615 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3616 goto xdr_error;
3617
3618 status = verify_attr_len(xdr, savep, attrlen);
3619xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003620 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 return status;
3622}
3623
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003624static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3625 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626{
Al Viro8687b632006-10-19 23:28:48 -07003627 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 uint32_t attrlen,
3629 bitmap[2] = {0},
3630 type;
Trond Myklebustbca79472009-03-11 14:10:26 -04003631 int status;
3632 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003633 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003635 status = decode_op_hdr(xdr, OP_GETATTR);
3636 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 goto xdr_error;
3638
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003639 status = decode_attr_bitmap(xdr, bitmap);
3640 if (status < 0)
3641 goto xdr_error;
3642
3643 status = decode_attr_length(xdr, &attrlen, &savep);
3644 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 goto xdr_error;
3646
3647
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003648 status = decode_attr_type(xdr, bitmap, &type);
3649 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003651 fattr->mode = 0;
3652 if (status != 0) {
3653 fattr->mode |= nfs_type2fmt[type];
3654 fattr->valid |= status;
3655 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003657 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3658 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003660 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003661
3662 status = decode_attr_size(xdr, bitmap, &fattr->size);
3663 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003664 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003665 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003666
3667 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3668 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003670 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003671
3672 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3673 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003675 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003676
3677 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003678 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003679 fattr));
3680 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003681 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003682 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003683
3684 status = decode_attr_mode(xdr, bitmap, &fmode);
3685 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003687 if (status != 0) {
3688 fattr->mode |= fmode;
3689 fattr->valid |= status;
3690 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003691
3692 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3693 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003695 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003696
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003697 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3698 &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003699 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003701 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003702
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003703 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3704 &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003705 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003707 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003708
3709 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3710 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003712 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003713
3714 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3715 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003717 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003718
3719 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3720 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003722 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003723
3724 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3725 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003727 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003728
3729 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3730 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003732 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003733
3734 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3735 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003736 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003737 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003738 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003739 fattr->valid |= status;
3740 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003741
3742 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003744 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 return status;
3746}
3747
3748
3749static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3750{
Al Viro8687b632006-10-19 23:28:48 -07003751 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 uint32_t attrlen, bitmap[2];
3753 int status;
3754
3755 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3756 goto xdr_error;
3757 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3758 goto xdr_error;
3759 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3760 goto xdr_error;
3761
3762 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3763
3764 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3765 goto xdr_error;
3766 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3767 goto xdr_error;
3768 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3769 goto xdr_error;
3770 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3771 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3772 goto xdr_error;
3773 fsinfo->wtpref = fsinfo->wtmax;
3774
3775 status = verify_attr_len(xdr, savep, attrlen);
3776xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003777 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778 return status;
3779}
3780
3781static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3782{
Al Viro8687b632006-10-19 23:28:48 -07003783 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 uint32_t len;
3785 int status;
3786
Trond Myklebust99367812007-07-17 21:52:41 -04003787 /* Zero handle first to allow comparisons */
3788 memset(fh, 0, sizeof(*fh));
3789
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 status = decode_op_hdr(xdr, OP_GETFH);
3791 if (status)
3792 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793
Benny Halevyc0eae662009-08-14 17:20:14 +03003794 p = xdr_inline_decode(xdr, 4);
3795 if (unlikely(!p))
3796 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003797 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798 if (len > NFS4_FHSIZE)
3799 return -EIO;
3800 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03003801 p = xdr_inline_decode(xdr, len);
3802 if (unlikely(!p))
3803 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03003804 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003806out_overflow:
3807 print_overflow_msg(__func__, xdr);
3808 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809}
3810
3811static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3812{
3813 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003814
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 status = decode_op_hdr(xdr, OP_LINK);
3816 if (status)
3817 return status;
3818 return decode_change_info(xdr, cinfo);
3819}
3820
3821/*
3822 * We create the owner, so we know a proper owner.id length is 4.
3823 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003824static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003826 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003827 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003828 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829
Benny Halevyc0eae662009-08-14 17:20:14 +03003830 p = xdr_inline_decode(xdr, 32);
3831 if (unlikely(!p))
3832 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003833 p = xdr_decode_hyper(p, &offset);
3834 p = xdr_decode_hyper(p, &length);
Benny Halevy6f723f72009-08-14 17:19:37 +03003835 type = be32_to_cpup(p++);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003836 if (fl != NULL) {
3837 fl->fl_start = (loff_t)offset;
3838 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3839 if (length == ~(uint64_t)0)
3840 fl->fl_end = OFFSET_MAX;
3841 fl->fl_type = F_WRLCK;
3842 if (type & 1)
3843 fl->fl_type = F_RDLCK;
3844 fl->fl_pid = 0;
3845 }
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003846 p = xdr_decode_hyper(p, &clientid);
Benny Halevycccddf42009-08-14 17:20:19 +03003847 namelen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003848 p = xdr_inline_decode(xdr, namelen);
3849 if (likely(p))
3850 return -NFS4ERR_DENIED;
3851out_overflow:
3852 print_overflow_msg(__func__, xdr);
3853 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854}
3855
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003856static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 int status;
3859
3860 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003861 if (status == -EIO)
3862 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03003864 status = decode_stateid(xdr, &res->stateid);
3865 if (unlikely(status))
3866 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003868 status = decode_lock_denied(xdr, NULL);
3869 if (res->open_seqid != NULL)
3870 nfs_increment_open_seqid(status, res->open_seqid);
3871 nfs_increment_lock_seqid(status, res->lock_seqid);
3872out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 return status;
3874}
3875
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003876static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877{
3878 int status;
3879 status = decode_op_hdr(xdr, OP_LOCKT);
3880 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003881 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882 return status;
3883}
3884
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003885static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 int status;
3888
3889 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003890 if (status != -EIO)
3891 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003892 if (status == 0)
3893 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 return status;
3895}
3896
3897static int decode_lookup(struct xdr_stream *xdr)
3898{
3899 return decode_op_hdr(xdr, OP_LOOKUP);
3900}
3901
3902/* This is too sick! */
3903static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3904{
Andy Adamson05d564f2008-12-23 16:06:15 -05003905 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 uint32_t limit_type, nblocks, blocksize;
3907
Benny Halevyc0eae662009-08-14 17:20:14 +03003908 p = xdr_inline_decode(xdr, 12);
3909 if (unlikely(!p))
3910 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003911 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003913 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03003914 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05003915 break;
3916 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03003917 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003918 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05003919 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920 }
3921 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003922out_overflow:
3923 print_overflow_msg(__func__, xdr);
3924 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925}
3926
3927static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3928{
Andy Adamson05d564f2008-12-23 16:06:15 -05003929 __be32 *p;
3930 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03003931 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932
Benny Halevyc0eae662009-08-14 17:20:14 +03003933 p = xdr_inline_decode(xdr, 4);
3934 if (unlikely(!p))
3935 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003936 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3938 res->delegation_type = 0;
3939 return 0;
3940 }
Benny Halevy07d30432009-08-14 17:19:52 +03003941 status = decode_stateid(xdr, &res->delegation);
3942 if (unlikely(status))
3943 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003944 p = xdr_inline_decode(xdr, 4);
3945 if (unlikely(!p))
3946 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003947 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05003948
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003950 case NFS4_OPEN_DELEGATE_READ:
3951 res->delegation_type = FMODE_READ;
3952 break;
3953 case NFS4_OPEN_DELEGATE_WRITE:
3954 res->delegation_type = FMODE_WRITE|FMODE_READ;
3955 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956 return -EIO;
3957 }
David Howells7539bba2006-08-22 20:06:09 -04003958 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03003959out_overflow:
3960 print_overflow_msg(__func__, xdr);
3961 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962}
3963
3964static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3965{
Andy Adamson05d564f2008-12-23 16:06:15 -05003966 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003967 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05003968 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969
Andy Adamson05d564f2008-12-23 16:06:15 -05003970 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003971 if (status != -EIO)
3972 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003973 if (!status)
3974 status = decode_stateid(xdr, &res->stateid);
3975 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05003976 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977
Andy Adamson05d564f2008-12-23 16:06:15 -05003978 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979
Benny Halevyc0eae662009-08-14 17:20:14 +03003980 p = xdr_inline_decode(xdr, 8);
3981 if (unlikely(!p))
3982 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003983 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003984 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05003985 if (bmlen > 10)
3986 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987
Benny Halevyc0eae662009-08-14 17:20:14 +03003988 p = xdr_inline_decode(xdr, bmlen << 2);
3989 if (unlikely(!p))
3990 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003991 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3992 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03003993 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003994 for (; i < NFS4_BITMAP_SIZE; i++)
3995 res->attrset[i] = 0;
3996
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997 return decode_delegation(xdr, res);
3998xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003999 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004001out_overflow:
4002 print_overflow_msg(__func__, xdr);
4003 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004}
4005
4006static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4007{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 int status;
4009
Andy Adamson05d564f2008-12-23 16:06:15 -05004010 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004011 if (status != -EIO)
4012 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004013 if (!status)
4014 status = decode_stateid(xdr, &res->stateid);
4015 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016}
4017
4018static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4019{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 int status;
4021
4022 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004023 if (status != -EIO)
4024 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004025 if (!status)
4026 status = decode_stateid(xdr, &res->stateid);
4027 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028}
4029
4030static int decode_putfh(struct xdr_stream *xdr)
4031{
4032 return decode_op_hdr(xdr, OP_PUTFH);
4033}
4034
4035static int decode_putrootfh(struct xdr_stream *xdr)
4036{
4037 return decode_op_hdr(xdr, OP_PUTROOTFH);
4038}
4039
4040static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4041{
4042 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004043 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044 uint32_t count, eof, recvd, hdrlen;
4045 int status;
4046
4047 status = decode_op_hdr(xdr, OP_READ);
4048 if (status)
4049 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004050 p = xdr_inline_decode(xdr, 8);
4051 if (unlikely(!p))
4052 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004053 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004054 count = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
4056 recvd = req->rq_rcv_buf.len - hdrlen;
4057 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004058 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059 "count %u > recvd %u\n", count, recvd);
4060 count = recvd;
4061 eof = 0;
4062 }
4063 xdr_read_pages(xdr, count);
4064 res->eof = eof;
4065 res->count = count;
4066 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004067out_overflow:
4068 print_overflow_msg(__func__, xdr);
4069 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070}
4071
4072static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4073{
4074 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4075 struct page *page = *rcvbuf->pages;
4076 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004077 size_t hdrlen;
4078 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07004079 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004080 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04004081 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082
4083 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004084 if (!status)
4085 status = decode_verifier(xdr, readdir->verifier.data);
4086 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004088 dprintk("%s: verifier = %08x:%08x\n",
4089 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004090 ((u32 *)readdir->verifier.data)[0],
4091 ((u32 *)readdir->verifier.data)[1]);
4092
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093
Benny Halevydb942bb2009-08-14 17:19:56 +03004094 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095 recvd = rcvbuf->len - hdrlen;
4096 if (pglen > recvd)
4097 pglen = recvd;
4098 xdr_read_pages(xdr, pglen);
4099
4100 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07004101 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04004102 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004104
4105 /* Make sure the packet actually has a value_follows and EOF entry */
4106 if ((entry + 1) > end)
4107 goto short_pkt;
4108
4109 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004110 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04004111 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00004113 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114 p += 2; /* cookie */
4115 len = ntohl(*p++); /* filename length */
4116 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004117 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
4118 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119 goto err_unmap;
4120 }
David Howellse8896492006-08-24 15:44:19 -04004121 xlen = XDR_QUADLEN(len);
4122 if (end - p < xlen + 1)
4123 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00004124 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04004125 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04004127 if (end - p < len + 1)
4128 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04004131 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04004133 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 entry = p;
4135 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004136 /*
4137 * Apparently some server sends responses that are a valid size, but
4138 * contain no entries, and have value_follows==0 and EOF==0. For
4139 * those, just set the EOF marker.
4140 */
4141 if (!nr && entry[1] == 0) {
4142 dprintk("NFS: readdir reply truncated!\n");
4143 entry[1] = 1;
4144 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05004145out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 kunmap_atomic(kaddr, KM_USER0);
4147 return 0;
4148short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004149 /*
4150 * When we get a short packet there are 2 possibilities. We can
4151 * return an error, or fix up the response to look like a valid
4152 * response and return what we have so far. If there are no
4153 * entries and the packet was short, then return -EIO. If there
4154 * are valid entries in the response, return them and pretend that
4155 * the call was successful, but incomplete. The caller can retry the
4156 * readdir starting at the last cookie.
4157 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07004158 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004160 if (nr)
4161 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162err_unmap:
4163 kunmap_atomic(kaddr, KM_USER0);
4164 return -errno_NFSERR_IO;
4165}
4166
4167static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4168{
4169 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4170 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004171 size_t hdrlen;
4172 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004173 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174 char *kaddr;
4175 int status;
4176
4177 status = decode_op_hdr(xdr, OP_READLINK);
4178 if (status)
4179 return status;
4180
4181 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004182 p = xdr_inline_decode(xdr, 4);
4183 if (unlikely(!p))
4184 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004185 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004187 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188 return -ENAMETOOLONG;
4189 }
4190 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4191 recvd = req->rq_rcv_buf.len - hdrlen;
4192 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004193 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 "count %u > recvd %u\n", len, recvd);
4195 return -EIO;
4196 }
4197 xdr_read_pages(xdr, len);
4198 /*
4199 * The XDR encode routine has set things up so that
4200 * the link text will be copied directly into the
4201 * buffer. We just have to do overflow-checking,
4202 * and and null-terminate the text (the VFS expects
4203 * null-termination).
4204 */
4205 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
4206 kaddr[len+rcvbuf->page_base] = '\0';
4207 kunmap_atomic(kaddr, KM_USER0);
4208 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004209out_overflow:
4210 print_overflow_msg(__func__, xdr);
4211 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212}
4213
4214static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4215{
4216 int status;
4217
4218 status = decode_op_hdr(xdr, OP_REMOVE);
4219 if (status)
4220 goto out;
4221 status = decode_change_info(xdr, cinfo);
4222out:
4223 return status;
4224}
4225
4226static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4227 struct nfs4_change_info *new_cinfo)
4228{
4229 int status;
4230
4231 status = decode_op_hdr(xdr, OP_RENAME);
4232 if (status)
4233 goto out;
4234 if ((status = decode_change_info(xdr, old_cinfo)))
4235 goto out;
4236 status = decode_change_info(xdr, new_cinfo);
4237out:
4238 return status;
4239}
4240
4241static int decode_renew(struct xdr_stream *xdr)
4242{
4243 return decode_op_hdr(xdr, OP_RENEW);
4244}
4245
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004246static int
4247decode_restorefh(struct xdr_stream *xdr)
4248{
4249 return decode_op_hdr(xdr, OP_RESTOREFH);
4250}
4251
J. Bruce Fields029d1052005-06-22 17:16:22 +00004252static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4253 size_t *acl_len)
4254{
Al Viro8687b632006-10-19 23:28:48 -07004255 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004256 uint32_t attrlen,
4257 bitmap[2] = {0};
4258 struct kvec *iov = req->rq_rcv_buf.head;
4259 int status;
4260
4261 *acl_len = 0;
4262 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4263 goto out;
4264 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4265 goto out;
4266 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4267 goto out;
4268
4269 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4270 return -EIO;
4271 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004272 size_t hdrlen;
4273 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004274
4275 /* We ignore &savep and don't do consistency checks on
4276 * the attr length. Let userspace figure it out.... */
4277 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4278 recvd = req->rq_rcv_buf.len - hdrlen;
4279 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004280 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004281 " acl reply: attrlen %u > recvd %u\n",
4282 attrlen, recvd);
4283 return -EINVAL;
4284 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004285 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004286 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004287 } else
4288 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004289
4290out:
4291 return status;
4292}
4293
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294static int
4295decode_savefh(struct xdr_stream *xdr)
4296{
4297 return decode_op_hdr(xdr, OP_SAVEFH);
4298}
4299
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004300static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301{
Al Viro8687b632006-10-19 23:28:48 -07004302 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303 uint32_t bmlen;
4304 int status;
4305
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 status = decode_op_hdr(xdr, OP_SETATTR);
4307 if (status)
4308 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004309 p = xdr_inline_decode(xdr, 4);
4310 if (unlikely(!p))
4311 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004312 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004313 p = xdr_inline_decode(xdr, bmlen << 2);
4314 if (likely(p))
4315 return 0;
4316out_overflow:
4317 print_overflow_msg(__func__, xdr);
4318 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319}
4320
David Howellsadfa6f92006-08-22 20:06:08 -04004321static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322{
Al Viro8687b632006-10-19 23:28:48 -07004323 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324 uint32_t opnum;
4325 int32_t nfserr;
4326
Benny Halevyc0eae662009-08-14 17:20:14 +03004327 p = xdr_inline_decode(xdr, 8);
4328 if (unlikely(!p))
4329 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004330 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004331 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004332 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004333 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334 return -EIO;
4335 }
Benny Halevycccddf42009-08-14 17:20:19 +03004336 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004338 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4339 if (unlikely(!p))
4340 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004341 p = xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevy99398d02009-08-14 17:20:05 +03004342 memcpy(clp->cl_confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 } else if (nfserr == NFSERR_CLID_INUSE) {
4344 uint32_t len;
4345
4346 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004347 p = xdr_inline_decode(xdr, 4);
4348 if (unlikely(!p))
4349 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004350 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004351 p = xdr_inline_decode(xdr, len);
4352 if (unlikely(!p))
4353 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354
4355 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004356 p = xdr_inline_decode(xdr, 4);
4357 if (unlikely(!p))
4358 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004359 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004360 p = xdr_inline_decode(xdr, len);
4361 if (unlikely(!p))
4362 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363 return -NFSERR_CLID_INUSE;
4364 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004365 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366
4367 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004368out_overflow:
4369 print_overflow_msg(__func__, xdr);
4370 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371}
4372
4373static int decode_setclientid_confirm(struct xdr_stream *xdr)
4374{
4375 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4376}
4377
4378static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4379{
Al Viro8687b632006-10-19 23:28:48 -07004380 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004381 int status;
4382
4383 status = decode_op_hdr(xdr, OP_WRITE);
4384 if (status)
4385 return status;
4386
Benny Halevyc0eae662009-08-14 17:20:14 +03004387 p = xdr_inline_decode(xdr, 16);
4388 if (unlikely(!p))
4389 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004390 res->count = be32_to_cpup(p++);
4391 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004392 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004394out_overflow:
4395 print_overflow_msg(__func__, xdr);
4396 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397}
4398
4399static int decode_delegreturn(struct xdr_stream *xdr)
4400{
4401 return decode_op_hdr(xdr, OP_DELEGRETURN);
4402}
4403
Benny Halevy99fe60d2009-04-01 09:22:29 -04004404#if defined(CONFIG_NFS_V4_1)
4405static int decode_exchange_id(struct xdr_stream *xdr,
4406 struct nfs41_exchange_id_res *res)
4407{
4408 __be32 *p;
4409 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004410 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004411 int status;
4412 struct nfs_client *clp = res->client;
4413
4414 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4415 if (status)
4416 return status;
4417
Benny Halevyc0eae662009-08-14 17:20:14 +03004418 p = xdr_inline_decode(xdr, 8);
4419 if (unlikely(!p))
4420 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004421 xdr_decode_hyper(p, &clp->cl_ex_clid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004422 p = xdr_inline_decode(xdr, 12);
4423 if (unlikely(!p))
4424 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004425 clp->cl_seqid = be32_to_cpup(p++);
4426 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004427
4428 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004429 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004430 if (dummy != SP4_NONE)
4431 return -EIO;
4432
4433 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004434 p = xdr_inline_decode(xdr, 8);
4435 if (unlikely(!p))
4436 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004437
4438 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004439 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4440 if (unlikely(status))
4441 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004442
4443 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004444 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4445 if (unlikely(status))
4446 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004447
4448 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004449 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4450 if (unlikely(status))
4451 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004452
4453 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004454out_overflow:
4455 print_overflow_msg(__func__, xdr);
4456 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004457}
Andy Adamsonfc931582009-04-01 09:22:31 -04004458
4459static int decode_chan_attrs(struct xdr_stream *xdr,
4460 struct nfs4_channel_attrs *attrs)
4461{
4462 __be32 *p;
4463 u32 nr_attrs;
4464
Benny Halevyc0eae662009-08-14 17:20:14 +03004465 p = xdr_inline_decode(xdr, 28);
4466 if (unlikely(!p))
4467 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004468 attrs->headerpadsz = be32_to_cpup(p++);
4469 attrs->max_rqst_sz = be32_to_cpup(p++);
4470 attrs->max_resp_sz = be32_to_cpup(p++);
4471 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4472 attrs->max_ops = be32_to_cpup(p++);
4473 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004474 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004475 if (unlikely(nr_attrs > 1)) {
4476 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4477 __func__, nr_attrs);
4478 return -EINVAL;
4479 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004480 if (nr_attrs == 1) {
4481 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4482 if (unlikely(!p))
4483 goto out_overflow;
4484 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004485 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004486out_overflow:
4487 print_overflow_msg(__func__, xdr);
4488 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004489}
4490
Benny Halevye78291e2009-08-14 17:20:00 +03004491static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4492{
4493 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004494}
4495
4496static int decode_create_session(struct xdr_stream *xdr,
4497 struct nfs41_create_session_res *res)
4498{
4499 __be32 *p;
4500 int status;
4501 struct nfs_client *clp = res->client;
4502 struct nfs4_session *session = clp->cl_session;
4503
4504 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004505 if (!status)
4506 status = decode_sessionid(xdr, &session->sess_id);
4507 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004508 return status;
4509
Andy Adamsonfc931582009-04-01 09:22:31 -04004510 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004511 p = xdr_inline_decode(xdr, 8);
4512 if (unlikely(!p))
4513 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004514 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004515 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004516
4517 /* Channel attributes */
4518 status = decode_chan_attrs(xdr, &session->fc_attrs);
4519 if (!status)
4520 status = decode_chan_attrs(xdr, &session->bc_attrs);
4521 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004522out_overflow:
4523 print_overflow_msg(__func__, xdr);
4524 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004525}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004526
4527static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4528{
4529 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4530}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004531#endif /* CONFIG_NFS_V4_1 */
4532
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004533static int decode_sequence(struct xdr_stream *xdr,
4534 struct nfs4_sequence_res *res,
4535 struct rpc_rqst *rqstp)
4536{
4537#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004538 struct nfs4_slot *slot;
4539 struct nfs4_sessionid id;
4540 u32 dummy;
4541 int status;
4542 __be32 *p;
4543
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004544 if (!res->sr_session)
4545 return 0;
4546
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004547 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03004548 if (!status)
4549 status = decode_sessionid(xdr, &id);
4550 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004551 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004552
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004553 /*
4554 * If the server returns different values for sessionID, slotID or
4555 * sequence number, the server is looney tunes.
4556 */
4557 status = -ESERVERFAULT;
4558
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004559 if (memcmp(id.data, res->sr_session->sess_id.data,
4560 NFS4_MAX_SESSIONID_LEN)) {
4561 dprintk("%s Invalid session id\n", __func__);
4562 goto out_err;
4563 }
Benny Halevye78291e2009-08-14 17:20:00 +03004564
Benny Halevyc0eae662009-08-14 17:20:14 +03004565 p = xdr_inline_decode(xdr, 20);
4566 if (unlikely(!p))
4567 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03004568
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004569 /* seqid */
Benny Halevye78291e2009-08-14 17:20:00 +03004570 slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid];
Benny Halevy6f723f72009-08-14 17:19:37 +03004571 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004572 if (dummy != slot->seq_nr) {
4573 dprintk("%s Invalid sequence number\n", __func__);
4574 goto out_err;
4575 }
4576 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03004577 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004578 if (dummy != res->sr_slotid) {
4579 dprintk("%s Invalid slot id\n", __func__);
4580 goto out_err;
4581 }
4582 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004583 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004584 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004585 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004586 /* result flags - currently not processed */
Benny Halevycccddf42009-08-14 17:20:19 +03004587 dummy = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004588 status = 0;
4589out_err:
4590 res->sr_status = status;
4591 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004592out_overflow:
4593 print_overflow_msg(__func__, xdr);
4594 status = -EIO;
4595 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004596#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004597 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004598#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004599}
4600
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601/*
Benny Halevy49c25592008-12-23 16:06:16 -05004602 * END OF "GENERIC" DECODE ROUTINES.
4603 */
4604
4605/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606 * Decode OPEN_DOWNGRADE response
4607 */
Al Viro8687b632006-10-19 23:28:48 -07004608static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004609{
Andy Adamson05d564f2008-12-23 16:06:15 -05004610 struct xdr_stream xdr;
4611 struct compound_hdr hdr;
4612 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613
Andy Adamson05d564f2008-12-23 16:06:15 -05004614 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4615 status = decode_compound_hdr(&xdr, &hdr);
4616 if (status)
4617 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004618 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4619 if (status)
4620 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004621 status = decode_putfh(&xdr);
4622 if (status)
4623 goto out;
4624 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004625 if (status != 0)
4626 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004627 decode_getfattr(&xdr, res->fattr, res->server,
4628 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004630 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631}
4632
4633/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634 * Decode ACCESS response
4635 */
Al Viro8687b632006-10-19 23:28:48 -07004636static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637{
4638 struct xdr_stream xdr;
4639 struct compound_hdr hdr;
4640 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004641
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004643 status = decode_compound_hdr(&xdr, &hdr);
4644 if (status)
4645 goto out;
4646 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4647 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04004649 status = decode_putfh(&xdr);
4650 if (status != 0)
4651 goto out;
4652 status = decode_access(&xdr, res);
4653 if (status != 0)
4654 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004655 decode_getfattr(&xdr, res->fattr, res->server,
4656 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657out:
4658 return status;
4659}
4660
4661/*
4662 * Decode LOOKUP response
4663 */
Al Viro8687b632006-10-19 23:28:48 -07004664static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665{
4666 struct xdr_stream xdr;
4667 struct compound_hdr hdr;
4668 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004669
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004671 status = decode_compound_hdr(&xdr, &hdr);
4672 if (status)
4673 goto out;
4674 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4675 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004676 goto out;
4677 if ((status = decode_putfh(&xdr)) != 0)
4678 goto out;
4679 if ((status = decode_lookup(&xdr)) != 0)
4680 goto out;
4681 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4682 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004683 status = decode_getfattr(&xdr, res->fattr, res->server
4684 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685out:
4686 return status;
4687}
4688
4689/*
4690 * Decode LOOKUP_ROOT response
4691 */
Al Viro8687b632006-10-19 23:28:48 -07004692static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693{
4694 struct xdr_stream xdr;
4695 struct compound_hdr hdr;
4696 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004697
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004699 status = decode_compound_hdr(&xdr, &hdr);
4700 if (status)
4701 goto out;
4702 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4703 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004704 goto out;
4705 if ((status = decode_putrootfh(&xdr)) != 0)
4706 goto out;
4707 if ((status = decode_getfh(&xdr, res->fh)) == 0)
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004708 status = decode_getfattr(&xdr, res->fattr, res->server,
4709 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004710out:
4711 return status;
4712}
4713
4714/*
4715 * Decode REMOVE response
4716 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04004717static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718{
4719 struct xdr_stream xdr;
4720 struct compound_hdr hdr;
4721 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004722
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004724 status = decode_compound_hdr(&xdr, &hdr);
4725 if (status)
4726 goto out;
4727 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4728 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004729 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04004730 if ((status = decode_putfh(&xdr)) != 0)
4731 goto out;
4732 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4733 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004734 decode_getfattr(&xdr, &res->dir_attr, res->server,
4735 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736out:
4737 return status;
4738}
4739
4740/*
4741 * Decode RENAME response
4742 */
Al Viro8687b632006-10-19 23:28:48 -07004743static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744{
4745 struct xdr_stream xdr;
4746 struct compound_hdr hdr;
4747 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004748
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004750 status = decode_compound_hdr(&xdr, &hdr);
4751 if (status)
4752 goto out;
4753 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4754 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755 goto out;
4756 if ((status = decode_putfh(&xdr)) != 0)
4757 goto out;
4758 if ((status = decode_savefh(&xdr)) != 0)
4759 goto out;
4760 if ((status = decode_putfh(&xdr)) != 0)
4761 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004762 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4763 goto out;
4764 /* Current FH is target directory */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004765 if (decode_getfattr(&xdr, res->new_fattr, res->server,
4766 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04004767 goto out;
4768 if ((status = decode_restorefh(&xdr)) != 0)
4769 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004770 decode_getfattr(&xdr, res->old_fattr, res->server,
4771 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772out:
4773 return status;
4774}
4775
4776/*
4777 * Decode LINK response
4778 */
Al Viro8687b632006-10-19 23:28:48 -07004779static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780{
4781 struct xdr_stream xdr;
4782 struct compound_hdr hdr;
4783 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004784
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004786 status = decode_compound_hdr(&xdr, &hdr);
4787 if (status)
4788 goto out;
4789 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4790 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004791 goto out;
4792 if ((status = decode_putfh(&xdr)) != 0)
4793 goto out;
4794 if ((status = decode_savefh(&xdr)) != 0)
4795 goto out;
4796 if ((status = decode_putfh(&xdr)) != 0)
4797 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004798 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4799 goto out;
4800 /*
4801 * Note order: OP_LINK leaves the directory as the current
4802 * filehandle.
4803 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004804 if (decode_getfattr(&xdr, res->dir_attr, res->server,
4805 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04004806 goto out;
4807 if ((status = decode_restorefh(&xdr)) != 0)
4808 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004809 decode_getfattr(&xdr, res->fattr, res->server,
4810 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811out:
4812 return status;
4813}
4814
4815/*
4816 * Decode CREATE response
4817 */
Al Viro8687b632006-10-19 23:28:48 -07004818static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004819{
4820 struct xdr_stream xdr;
4821 struct compound_hdr hdr;
4822 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004823
Linus Torvalds1da177e2005-04-16 15:20:36 -07004824 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004825 status = decode_compound_hdr(&xdr, &hdr);
4826 if (status)
4827 goto out;
4828 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4829 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830 goto out;
4831 if ((status = decode_putfh(&xdr)) != 0)
4832 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004833 if ((status = decode_savefh(&xdr)) != 0)
4834 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4836 goto out;
4837 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4838 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004839 if (decode_getfattr(&xdr, res->fattr, res->server,
4840 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004841 goto out;
4842 if ((status = decode_restorefh(&xdr)) != 0)
4843 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004844 decode_getfattr(&xdr, res->dir_fattr, res->server,
4845 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846out:
4847 return status;
4848}
4849
4850/*
4851 * Decode SYMLINK response
4852 */
Al Viro8687b632006-10-19 23:28:48 -07004853static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854{
4855 return nfs4_xdr_dec_create(rqstp, p, res);
4856}
4857
4858/*
4859 * Decode GETATTR response
4860 */
Al Viro8687b632006-10-19 23:28:48 -07004861static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862{
4863 struct xdr_stream xdr;
4864 struct compound_hdr hdr;
4865 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004866
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4868 status = decode_compound_hdr(&xdr, &hdr);
4869 if (status)
4870 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004871 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4872 if (status)
4873 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874 status = decode_putfh(&xdr);
4875 if (status)
4876 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004877 status = decode_getfattr(&xdr, res->fattr, res->server,
4878 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879out:
4880 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881}
4882
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004883/*
4884 * Encode an SETACL request
4885 */
4886static int
Al Viro8687b632006-10-19 23:28:48 -07004887nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004888{
Andy Adamson05d564f2008-12-23 16:06:15 -05004889 struct xdr_stream xdr;
4890 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04004891 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05004892 };
4893 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004894
Andy Adamson05d564f2008-12-23 16:06:15 -05004895 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04004896 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004897 encode_sequence(&xdr, &args->seq_args, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05004898 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004899 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004900 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004901 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004902}
Andy Adamson05d564f2008-12-23 16:06:15 -05004903
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004904/*
4905 * Decode SETACL response
4906 */
4907static int
Benny Halevy73c403a2009-04-01 09:22:01 -04004908nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4909 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004910{
4911 struct xdr_stream xdr;
4912 struct compound_hdr hdr;
4913 int status;
4914
4915 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4916 status = decode_compound_hdr(&xdr, &hdr);
4917 if (status)
4918 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004919 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4920 if (status)
4921 goto out;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004922 status = decode_putfh(&xdr);
4923 if (status)
4924 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004925 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004926out:
4927 return status;
4928}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004929
4930/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00004931 * Decode GETACL response
4932 */
4933static int
Benny Halevy663c79b2009-04-01 09:21:59 -04004934nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4935 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004936{
4937 struct xdr_stream xdr;
4938 struct compound_hdr hdr;
4939 int status;
4940
4941 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4942 status = decode_compound_hdr(&xdr, &hdr);
4943 if (status)
4944 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004945 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4946 if (status)
4947 goto out;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004948 status = decode_putfh(&xdr);
4949 if (status)
4950 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04004951 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004952
4953out:
4954 return status;
4955}
4956
4957/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 * Decode CLOSE response
4959 */
Al Viro8687b632006-10-19 23:28:48 -07004960static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961{
Andy Adamson05d564f2008-12-23 16:06:15 -05004962 struct xdr_stream xdr;
4963 struct compound_hdr hdr;
4964 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965
Andy Adamson05d564f2008-12-23 16:06:15 -05004966 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4967 status = decode_compound_hdr(&xdr, &hdr);
4968 if (status)
4969 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004970 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4971 if (status)
4972 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004973 status = decode_putfh(&xdr);
4974 if (status)
4975 goto out;
4976 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004977 if (status != 0)
4978 goto out;
4979 /*
4980 * Note: Server may do delete on close for this file
4981 * in which case the getattr call will fail with
4982 * an ESTALE error. Shouldn't be a problem,
4983 * though, since fattr->valid will remain unset.
4984 */
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004985 decode_getfattr(&xdr, res->fattr, res->server,
4986 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004988 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989}
4990
4991/*
4992 * Decode OPEN response
4993 */
Al Viro8687b632006-10-19 23:28:48 -07004994static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995{
Andy Adamson05d564f2008-12-23 16:06:15 -05004996 struct xdr_stream xdr;
4997 struct compound_hdr hdr;
4998 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999
Andy Adamson05d564f2008-12-23 16:06:15 -05005000 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5001 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005002 if (status)
5003 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005004 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5005 if (status)
5006 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005007 status = decode_putfh(&xdr);
5008 if (status)
5009 goto out;
5010 status = decode_savefh(&xdr);
5011 if (status)
5012 goto out;
5013 status = decode_open(&xdr, res);
5014 if (status)
5015 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04005016 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005017 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005018 if (decode_getfattr(&xdr, res->f_attr, res->server,
5019 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005020 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04005021 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005022 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005023 decode_getfattr(&xdr, res->dir_attr, res->server,
5024 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005026 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005027}
5028
5029/*
5030 * Decode OPEN_CONFIRM response
5031 */
Al Viro8687b632006-10-19 23:28:48 -07005032static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005033{
Andy Adamson05d564f2008-12-23 16:06:15 -05005034 struct xdr_stream xdr;
5035 struct compound_hdr hdr;
5036 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005037
Andy Adamson05d564f2008-12-23 16:06:15 -05005038 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5039 status = decode_compound_hdr(&xdr, &hdr);
5040 if (status)
5041 goto out;
5042 status = decode_putfh(&xdr);
5043 if (status)
5044 goto out;
5045 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005047 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048}
5049
5050/*
5051 * Decode OPEN response
5052 */
Al Viro8687b632006-10-19 23:28:48 -07005053static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054{
Andy Adamson05d564f2008-12-23 16:06:15 -05005055 struct xdr_stream xdr;
5056 struct compound_hdr hdr;
5057 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058
Andy Adamson05d564f2008-12-23 16:06:15 -05005059 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5060 status = decode_compound_hdr(&xdr, &hdr);
5061 if (status)
5062 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005063 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5064 if (status)
5065 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005066 status = decode_putfh(&xdr);
5067 if (status)
5068 goto out;
5069 status = decode_open(&xdr, res);
5070 if (status)
5071 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005072 decode_getfattr(&xdr, res->f_attr, res->server,
5073 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005075 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005076}
5077
5078/*
5079 * Decode SETATTR response
5080 */
Al Viro8687b632006-10-19 23:28:48 -07005081static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082{
Andy Adamson05d564f2008-12-23 16:06:15 -05005083 struct xdr_stream xdr;
5084 struct compound_hdr hdr;
5085 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086
Andy Adamson05d564f2008-12-23 16:06:15 -05005087 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5088 status = decode_compound_hdr(&xdr, &hdr);
5089 if (status)
5090 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005091 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5092 if (status)
5093 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05005094 status = decode_putfh(&xdr);
5095 if (status)
5096 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005097 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005098 if (status)
5099 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005100 decode_getfattr(&xdr, res->fattr, res->server,
5101 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005103 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104}
5105
5106/*
5107 * Decode LOCK response
5108 */
Al Viro8687b632006-10-19 23:28:48 -07005109static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005110{
5111 struct xdr_stream xdr;
5112 struct compound_hdr hdr;
5113 int status;
5114
5115 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5116 status = decode_compound_hdr(&xdr, &hdr);
5117 if (status)
5118 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005119 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5120 if (status)
5121 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005122 status = decode_putfh(&xdr);
5123 if (status)
5124 goto out;
5125 status = decode_lock(&xdr, res);
5126out:
5127 return status;
5128}
5129
5130/*
5131 * Decode LOCKT response
5132 */
Al Viro8687b632006-10-19 23:28:48 -07005133static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005134{
5135 struct xdr_stream xdr;
5136 struct compound_hdr hdr;
5137 int status;
5138
5139 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5140 status = decode_compound_hdr(&xdr, &hdr);
5141 if (status)
5142 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005143 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5144 if (status)
5145 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005146 status = decode_putfh(&xdr);
5147 if (status)
5148 goto out;
5149 status = decode_lockt(&xdr, res);
5150out:
5151 return status;
5152}
5153
5154/*
5155 * Decode LOCKU response
5156 */
Al Viro8687b632006-10-19 23:28:48 -07005157static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005158{
5159 struct xdr_stream xdr;
5160 struct compound_hdr hdr;
5161 int status;
5162
5163 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5164 status = decode_compound_hdr(&xdr, &hdr);
5165 if (status)
5166 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005167 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5168 if (status)
5169 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170 status = decode_putfh(&xdr);
5171 if (status)
5172 goto out;
5173 status = decode_locku(&xdr, res);
5174out:
5175 return status;
5176}
5177
5178/*
5179 * Decode READLINK response
5180 */
Benny Halevyf50c7002009-04-01 09:21:55 -04005181static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
5182 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005183{
5184 struct xdr_stream xdr;
5185 struct compound_hdr hdr;
5186 int status;
5187
5188 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5189 status = decode_compound_hdr(&xdr, &hdr);
5190 if (status)
5191 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005192 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5193 if (status)
5194 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005195 status = decode_putfh(&xdr);
5196 if (status)
5197 goto out;
5198 status = decode_readlink(&xdr, rqstp);
5199out:
5200 return status;
5201}
5202
5203/*
5204 * Decode READDIR response
5205 */
Al Viro8687b632006-10-19 23:28:48 -07005206static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207{
5208 struct xdr_stream xdr;
5209 struct compound_hdr hdr;
5210 int status;
5211
5212 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5213 status = decode_compound_hdr(&xdr, &hdr);
5214 if (status)
5215 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005216 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5217 if (status)
5218 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005219 status = decode_putfh(&xdr);
5220 if (status)
5221 goto out;
5222 status = decode_readdir(&xdr, rqstp, res);
5223out:
5224 return status;
5225}
5226
5227/*
5228 * Decode Read response
5229 */
Al Viro8687b632006-10-19 23:28:48 -07005230static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005231{
5232 struct xdr_stream xdr;
5233 struct compound_hdr hdr;
5234 int status;
5235
5236 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5237 status = decode_compound_hdr(&xdr, &hdr);
5238 if (status)
5239 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005240 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5241 if (status)
5242 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005243 status = decode_putfh(&xdr);
5244 if (status)
5245 goto out;
5246 status = decode_read(&xdr, rqstp, res);
5247 if (!status)
5248 status = res->count;
5249out:
5250 return status;
5251}
5252
5253/*
5254 * Decode WRITE response
5255 */
Al Viro8687b632006-10-19 23:28:48 -07005256static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005257{
5258 struct xdr_stream xdr;
5259 struct compound_hdr hdr;
5260 int status;
5261
5262 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5263 status = decode_compound_hdr(&xdr, &hdr);
5264 if (status)
5265 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005266 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5267 if (status)
5268 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269 status = decode_putfh(&xdr);
5270 if (status)
5271 goto out;
5272 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005273 if (status)
5274 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005275 decode_getfattr(&xdr, res->fattr, res->server,
5276 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277 if (!status)
5278 status = res->count;
5279out:
5280 return status;
5281}
5282
5283/*
5284 * Decode COMMIT response
5285 */
Al Viro8687b632006-10-19 23:28:48 -07005286static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005287{
5288 struct xdr_stream xdr;
5289 struct compound_hdr hdr;
5290 int status;
5291
5292 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5293 status = decode_compound_hdr(&xdr, &hdr);
5294 if (status)
5295 goto out;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005296 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5297 if (status)
5298 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299 status = decode_putfh(&xdr);
5300 if (status)
5301 goto out;
5302 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005303 if (status)
5304 goto out;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005305 decode_getfattr(&xdr, res->fattr, res->server,
5306 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005307out:
5308 return status;
5309}
5310
5311/*
5312 * FSINFO request
5313 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04005314static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
5315 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005316{
5317 struct xdr_stream xdr;
5318 struct compound_hdr hdr;
5319 int status;
5320
5321 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5322 status = decode_compound_hdr(&xdr, &hdr);
5323 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005324 status = decode_sequence(&xdr, &res->seq_res, req);
5325 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005326 status = decode_putfh(&xdr);
5327 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04005328 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005329 return status;
5330}
5331
5332/*
5333 * PATHCONF request
5334 */
Benny Halevyd45b2982009-04-01 09:21:58 -04005335static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
5336 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005337{
5338 struct xdr_stream xdr;
5339 struct compound_hdr hdr;
5340 int status;
5341
5342 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5343 status = decode_compound_hdr(&xdr, &hdr);
5344 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005345 status = decode_sequence(&xdr, &res->seq_res, req);
5346 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005347 status = decode_putfh(&xdr);
5348 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04005349 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005350 return status;
5351}
5352
5353/*
5354 * STATFS request
5355 */
Benny Halevy24ad1482009-04-01 09:21:56 -04005356static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
5357 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005358{
5359 struct xdr_stream xdr;
5360 struct compound_hdr hdr;
5361 int status;
5362
5363 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5364 status = decode_compound_hdr(&xdr, &hdr);
5365 if (!status)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005366 status = decode_sequence(&xdr, &res->seq_res, req);
5367 if (!status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005368 status = decode_putfh(&xdr);
5369 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04005370 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005371 return status;
5372}
5373
5374/*
5375 * GETATTR_BITMAP request
5376 */
Al Viro8687b632006-10-19 23:28:48 -07005377static 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 -07005378{
5379 struct xdr_stream xdr;
5380 struct compound_hdr hdr;
5381 int status;
5382
5383 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005384 status = decode_compound_hdr(&xdr, &hdr);
5385 if (status)
5386 goto out;
5387 status = decode_sequence(&xdr, &res->seq_res, req);
5388 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389 goto out;
5390 if ((status = decode_putfh(&xdr)) != 0)
5391 goto out;
5392 status = decode_server_caps(&xdr, res);
5393out:
5394 return status;
5395}
5396
5397/*
5398 * Decode RENEW response
5399 */
Al Viro8687b632006-10-19 23:28:48 -07005400static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005401{
5402 struct xdr_stream xdr;
5403 struct compound_hdr hdr;
5404 int status;
5405
5406 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5407 status = decode_compound_hdr(&xdr, &hdr);
5408 if (!status)
5409 status = decode_renew(&xdr);
5410 return status;
5411}
5412
5413/*
5414 * a SETCLIENTID request
5415 */
Al Viro8687b632006-10-19 23:28:48 -07005416static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04005417 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005418{
5419 struct xdr_stream xdr;
5420 struct compound_hdr hdr;
5421 int status;
5422
5423 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5424 status = decode_compound_hdr(&xdr, &hdr);
5425 if (!status)
5426 status = decode_setclientid(&xdr, clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005427 return status;
5428}
5429
5430/*
5431 * a SETCLIENTID_CONFIRM request
5432 */
Al Viro8687b632006-10-19 23:28:48 -07005433static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005434{
5435 struct xdr_stream xdr;
5436 struct compound_hdr hdr;
5437 int status;
5438
5439 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5440 status = decode_compound_hdr(&xdr, &hdr);
5441 if (!status)
5442 status = decode_setclientid_confirm(&xdr);
5443 if (!status)
5444 status = decode_putrootfh(&xdr);
5445 if (!status)
5446 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005447 return status;
5448}
5449
5450/*
5451 * DELEGRETURN request
5452 */
Al Viro8687b632006-10-19 23:28:48 -07005453static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005454{
5455 struct xdr_stream xdr;
5456 struct compound_hdr hdr;
5457 int status;
5458
5459 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5460 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005461 if (status)
5462 goto out;
5463 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5464 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005465 goto out;
5466 status = decode_putfh(&xdr);
5467 if (status != 0)
5468 goto out;
5469 status = decode_delegreturn(&xdr);
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005470 decode_getfattr(&xdr, res->fattr, res->server,
5471 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01005472out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005473 return status;
5474}
5475
Trond Myklebust683b57b2006-06-09 09:34:22 -04005476/*
5477 * FS_LOCATIONS request
5478 */
Benny Halevy22958462009-04-01 09:22:02 -04005479static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
5480 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005481{
5482 struct xdr_stream xdr;
5483 struct compound_hdr hdr;
5484 int status;
5485
5486 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5487 status = decode_compound_hdr(&xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005488 if (status)
5489 goto out;
5490 status = decode_sequence(&xdr, &res->seq_res, req);
5491 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005492 goto out;
5493 if ((status = decode_putfh(&xdr)) != 0)
5494 goto out;
5495 if ((status = decode_lookup(&xdr)) != 0)
5496 goto out;
5497 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04005498 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005499 res->fs_locations->server,
5500 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04005501out:
5502 return status;
5503}
5504
Benny Halevy99fe60d2009-04-01 09:22:29 -04005505#if defined(CONFIG_NFS_V4_1)
5506/*
5507 * EXCHANGE_ID request
5508 */
5509static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
5510 void *res)
5511{
5512 struct xdr_stream xdr;
5513 struct compound_hdr hdr;
5514 int status;
5515
5516 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5517 status = decode_compound_hdr(&xdr, &hdr);
5518 if (!status)
5519 status = decode_exchange_id(&xdr, res);
5520 return status;
5521}
Andy Adamson2050f0c2009-04-01 09:22:30 -04005522
5523/*
Andy Adamsonfc931582009-04-01 09:22:31 -04005524 * a CREATE_SESSION request
5525 */
5526static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
5527 struct nfs41_create_session_res *res)
5528{
5529 struct xdr_stream xdr;
5530 struct compound_hdr hdr;
5531 int status;
5532
5533 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5534 status = decode_compound_hdr(&xdr, &hdr);
5535 if (!status)
5536 status = decode_create_session(&xdr, res);
5537 return status;
5538}
5539
5540/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005541 * a DESTROY_SESSION request
5542 */
5543static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
5544 void *dummy)
5545{
5546 struct xdr_stream xdr;
5547 struct compound_hdr hdr;
5548 int status;
5549
5550 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5551 status = decode_compound_hdr(&xdr, &hdr);
5552 if (!status)
5553 status = decode_destroy_session(&xdr, dummy);
5554 return status;
5555}
5556
5557/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005558 * a SEQUENCE request
5559 */
5560static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p,
5561 struct nfs4_sequence_res *res)
5562{
5563 struct xdr_stream xdr;
5564 struct compound_hdr hdr;
5565 int status;
5566
5567 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5568 status = decode_compound_hdr(&xdr, &hdr);
5569 if (!status)
5570 status = decode_sequence(&xdr, res, rqstp);
5571 return status;
5572}
5573
5574/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04005575 * a GET_LEASE_TIME request
5576 */
5577static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
5578 struct nfs4_get_lease_time_res *res)
5579{
5580 struct xdr_stream xdr;
5581 struct compound_hdr hdr;
5582 int status;
5583
5584 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5585 status = decode_compound_hdr(&xdr, &hdr);
5586 if (!status)
5587 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
5588 if (!status)
5589 status = decode_putrootfh(&xdr);
5590 if (!status)
5591 status = decode_fsinfo(&xdr, res->lr_fsinfo);
5592 return status;
5593}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005594#endif /* CONFIG_NFS_V4_1 */
5595
Al Viro0dbb4c62006-10-19 23:28:49 -07005596__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005597{
5598 uint32_t bitmap[2] = {0};
5599 uint32_t len;
5600
5601 if (!*p++) {
5602 if (!*p)
5603 return ERR_PTR(-EAGAIN);
5604 entry->eof = 1;
5605 return ERR_PTR(-EBADCOOKIE);
5606 }
5607
5608 entry->prev_cookie = entry->cookie;
5609 p = xdr_decode_hyper(p, &entry->cookie);
5610 entry->len = ntohl(*p++);
5611 entry->name = (const char *) p;
5612 p += XDR_QUADLEN(entry->len);
5613
5614 /*
5615 * In case the server doesn't return an inode number,
5616 * we fake one here. (We don't use inode number 0,
5617 * since glibc seems to choke on it...)
5618 */
5619 entry->ino = 1;
5620
5621 len = ntohl(*p++); /* bitmap length */
5622 if (len-- > 0) {
5623 bitmap[0] = ntohl(*p++);
5624 if (len-- > 0) {
5625 bitmap[1] = ntohl(*p++);
5626 p += len;
5627 }
5628 }
5629 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
5630 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00005631 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
5632 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
5633 /* Ignore the return value of rdattr_error for now */
5634 p++;
5635 len--;
5636 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005637 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
5638 xdr_decode_hyper(p, &entry->ino);
5639 else if (bitmap[0] == FATTR4_WORD0_FILEID)
5640 xdr_decode_hyper(p, &entry->ino);
5641 p += len;
5642 }
5643
5644 entry->eof = !p[0] && p[1];
5645 return p;
5646}
5647
5648/*
5649 * We need to translate between nfs status return values and
5650 * the local errno values which may not be the same.
5651 */
5652static struct {
5653 int stat;
5654 int errno;
5655} nfs_errtbl[] = {
5656 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03005657 { NFS4ERR_PERM, -EPERM },
5658 { NFS4ERR_NOENT, -ENOENT },
5659 { NFS4ERR_IO, -errno_NFSERR_IO},
5660 { NFS4ERR_NXIO, -ENXIO },
5661 { NFS4ERR_ACCESS, -EACCES },
5662 { NFS4ERR_EXIST, -EEXIST },
5663 { NFS4ERR_XDEV, -EXDEV },
5664 { NFS4ERR_NOTDIR, -ENOTDIR },
5665 { NFS4ERR_ISDIR, -EISDIR },
5666 { NFS4ERR_INVAL, -EINVAL },
5667 { NFS4ERR_FBIG, -EFBIG },
5668 { NFS4ERR_NOSPC, -ENOSPC },
5669 { NFS4ERR_ROFS, -EROFS },
5670 { NFS4ERR_MLINK, -EMLINK },
5671 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5672 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5673 { NFS4ERR_DQUOT, -EDQUOT },
5674 { NFS4ERR_STALE, -ESTALE },
5675 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5676 { NFS4ERR_BADOWNER, -EINVAL },
5677 { NFS4ERR_BADNAME, -EINVAL },
5678 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5679 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5680 { NFS4ERR_TOOSMALL, -ETOOSMALL },
5681 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
5682 { NFS4ERR_BADTYPE, -EBADTYPE },
5683 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03005684 { NFS4ERR_SYMLINK, -ELOOP },
5685 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5686 { NFS4ERR_DEADLOCK, -EDEADLK },
5687 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005688 * to be handled by a
5689 * middle-layer.
5690 */
Benny Halevy856dff32008-03-31 17:39:06 +03005691 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005692};
5693
5694/*
5695 * Convert an NFS error code to a local one.
5696 * This one is used jointly by NFSv2 and NFSv3.
5697 */
5698static int
David Howells0a8ea432006-08-22 20:06:08 -04005699nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005700{
5701 int i;
5702 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5703 if (nfs_errtbl[i].stat == stat)
5704 return nfs_errtbl[i].errno;
5705 }
5706 if (stat <= 10000 || stat > 10100) {
5707 /* The server is looney tunes. */
Benny Halevy856dff32008-03-31 17:39:06 +03005708 return -ESERVERFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005709 }
5710 /* If we cannot translate the error, the recovery routines should
5711 * handle it.
5712 * Note: remaining NFSv4 error codes have values > 10000, so should
5713 * not conflict with native Linux error codes.
5714 */
Benny Halevy856dff32008-03-31 17:39:06 +03005715 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005716}
5717
Linus Torvalds1da177e2005-04-16 15:20:36 -07005718#define PROC(proc, argtype, restype) \
5719[NFSPROC4_CLNT_##proc] = { \
5720 .p_proc = NFSPROC4_COMPOUND, \
5721 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5722 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04005723 .p_arglen = NFS4_##argtype##_sz, \
5724 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05005725 .p_statidx = NFSPROC4_CLNT_##proc, \
5726 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05005727}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005728
5729struct rpc_procinfo nfs4_procedures[] = {
5730 PROC(READ, enc_read, dec_read),
5731 PROC(WRITE, enc_write, dec_write),
5732 PROC(COMMIT, enc_commit, dec_commit),
5733 PROC(OPEN, enc_open, dec_open),
5734 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5735 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5736 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5737 PROC(CLOSE, enc_close, dec_close),
5738 PROC(SETATTR, enc_setattr, dec_setattr),
5739 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5740 PROC(RENEW, enc_renew, dec_renew),
5741 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5742 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5743 PROC(LOCK, enc_lock, dec_lock),
5744 PROC(LOCKT, enc_lockt, dec_lockt),
5745 PROC(LOCKU, enc_locku, dec_locku),
5746 PROC(ACCESS, enc_access, dec_access),
5747 PROC(GETATTR, enc_getattr, dec_getattr),
5748 PROC(LOOKUP, enc_lookup, dec_lookup),
5749 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5750 PROC(REMOVE, enc_remove, dec_remove),
5751 PROC(RENAME, enc_rename, dec_rename),
5752 PROC(LINK, enc_link, dec_link),
5753 PROC(SYMLINK, enc_symlink, dec_symlink),
5754 PROC(CREATE, enc_create, dec_create),
5755 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5756 PROC(STATFS, enc_statfs, dec_statfs),
5757 PROC(READLINK, enc_readlink, dec_readlink),
5758 PROC(READDIR, enc_readdir, dec_readdir),
5759 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5760 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00005761 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005762 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04005763 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005764#if defined(CONFIG_NFS_V4_1)
5765 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
Andy Adamsonfc931582009-04-01 09:22:31 -04005766 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005767 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005768 PROC(SEQUENCE, enc_sequence, dec_sequence),
Andy Adamson2050f0c2009-04-01 09:22:30 -04005769 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Benny Halevy99fe60d2009-04-01 09:22:29 -04005770#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005771};
5772
5773struct rpc_version nfs_version4 = {
5774 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08005775 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005776 .procs = nfs4_procedures
5777};
5778
5779/*
5780 * Local variables:
5781 * c-basic-offset: 8
5782 * End:
5783 */