blob: db040e971932e1ca2fc215494f58a2f5520f1f6b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
55#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000056#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050057#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040058#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#define NFSDBG_FACILITY NFSDBG_XDR
61
62/* Mapping from NFS error code to "errno" error code. */
63#define errno_NFSERR_IO EIO
64
David Howells0a8ea432006-08-22 20:06:08 -040065static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
68#ifdef DEBUG
69#define NFS4_MAXTAGLEN 20
70#else
71#define NFS4_MAXTAGLEN 0
72#endif
73
Andy Adamson6c0195a2008-12-23 16:06:15 -050074/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040075 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040077#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050078#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040079#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
81#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
82#define op_encode_hdr_maxsz (1)
83#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040084#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
85#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
86#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
87#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
89 (NFS4_FHSIZE >> 2))
90#define decode_putfh_maxsz (op_decode_hdr_maxsz)
91#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
92#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
93#define encode_getfh_maxsz (op_encode_hdr_maxsz)
94#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
95 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040096#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000097#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
99#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400100#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
101#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000102/* This is based on getfattr, which uses the most attributes: */
103#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400104 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000105#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
106 nfs4_fattr_value_maxsz)
107#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400108#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 1 + 2 + 1 + \
110 nfs4_owner_maxsz + \
111 nfs4_group_maxsz + \
112 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define encode_savefh_maxsz (op_encode_hdr_maxsz)
114#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400115#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
116#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200117#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400118/* The 5 accounts for the PNFS attributes, and assumes that at most three
119 * layout types will be returned.
120 */
121#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
122 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
124#define decode_renew_maxsz (op_decode_hdr_maxsz)
125#define encode_setclientid_maxsz \
126 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500127 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
128 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
129 1 /* sc_prog */ + \
130 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
131 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
132 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#define decode_setclientid_maxsz \
134 (op_decode_hdr_maxsz + \
135 2 + \
136 1024) /* large value for CLID_INUSE */
137#define encode_setclientid_confirm_maxsz \
138 (op_encode_hdr_maxsz + \
139 3 + (NFS4_VERIFIER_SIZE >> 2))
140#define decode_setclientid_confirm_maxsz \
141 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400142#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
143#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400144#define encode_share_access_maxsz \
145 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500146#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400147#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
148#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
149#define encode_open_maxsz (op_encode_hdr_maxsz + \
150 2 + encode_share_access_maxsz + 2 + \
151 open_owner_id_maxsz + \
152 encode_opentype_maxsz + \
153 encode_claim_null_maxsz)
154#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400155#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400156 decode_ace_maxsz)
157#define decode_change_info_maxsz (5)
158#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400159 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400160 decode_change_info_maxsz + 1 + \
161 nfs4_fattr_bitmap_maxsz + \
162 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400163#define encode_open_confirm_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1)
166#define decode_open_confirm_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169#define encode_open_downgrade_maxsz \
170 (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + 1 + \
172 encode_share_access_maxsz)
173#define decode_open_downgrade_maxsz \
174 (op_decode_hdr_maxsz + \
175 decode_stateid_maxsz)
176#define encode_close_maxsz (op_encode_hdr_maxsz + \
177 1 + encode_stateid_maxsz)
178#define decode_close_maxsz (op_decode_hdr_maxsz + \
179 decode_stateid_maxsz)
180#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
181 encode_stateid_maxsz + \
182 encode_attrs_maxsz)
183#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
184 nfs4_fattr_bitmap_maxsz)
185#define encode_read_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + 3)
187#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
188#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
189 2 + encode_verifier_maxsz + 5)
190#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
191 decode_verifier_maxsz)
192#define encode_readlink_maxsz (op_encode_hdr_maxsz)
193#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
194#define encode_write_maxsz (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + 4)
196#define decode_write_maxsz (op_decode_hdr_maxsz + \
197 2 + decode_verifier_maxsz)
198#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
199#define decode_commit_maxsz (op_decode_hdr_maxsz + \
200 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201#define encode_remove_maxsz (op_encode_hdr_maxsz + \
202 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400203#define decode_remove_maxsz (op_decode_hdr_maxsz + \
204 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#define encode_rename_maxsz (op_encode_hdr_maxsz + \
206 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400207#define decode_rename_maxsz (op_decode_hdr_maxsz + \
208 decode_change_info_maxsz + \
209 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#define encode_link_maxsz (op_encode_hdr_maxsz + \
211 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400212#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400213#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400214#define encode_lock_maxsz (op_encode_hdr_maxsz + \
215 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400216 1 + encode_stateid_maxsz + 1 + \
217 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400218#define decode_lock_denied_maxsz \
219 (8 + decode_lockowner_maxsz)
220#define decode_lock_maxsz (op_decode_hdr_maxsz + \
221 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400222#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
223 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400224#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
225 decode_lock_denied_maxsz)
226#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
227 encode_stateid_maxsz + \
228 4)
229#define decode_locku_maxsz (op_decode_hdr_maxsz + \
230 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400231#define encode_release_lockowner_maxsz \
232 (op_encode_hdr_maxsz + \
233 encode_lockowner_maxsz)
234#define decode_release_lockowner_maxsz \
235 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400236#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
237#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
239 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400240 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000241 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
243#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400244 1 + 2 + nfs4_name_maxsz + \
245 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400246#define decode_create_maxsz (op_decode_hdr_maxsz + \
247 decode_change_info_maxsz + \
248 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400249#define encode_statfs_maxsz (encode_getattr_maxsz)
250#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
252#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400253#define encode_getacl_maxsz (encode_getattr_maxsz)
254#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
255 nfs4_fattr_bitmap_maxsz + 1)
256#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
257 encode_stateid_maxsz + 3)
258#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400259#define encode_fs_locations_maxsz \
260 (encode_getattr_maxsz)
261#define decode_fs_locations_maxsz \
262 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000263#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400264#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400265
266#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400267#define NFS4_MAX_MACHINE_NAME_LEN (64)
268
Benny Halevy99fe60d2009-04-01 09:22:29 -0400269#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
270 encode_verifier_maxsz + \
271 1 /* co_ownerid.len */ + \
272 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
273 1 /* flags */ + \
274 1 /* spa_how */ + \
275 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500276 1 /* implementation id array of size 1 */ + \
277 1 /* nii_domain */ + \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
279 1 /* nii_name */ + \
280 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
281 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400282#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
283 2 /* eir_clientid */ + \
284 1 /* eir_sequenceid */ + \
285 1 /* eir_flags */ + \
286 1 /* spr_how */ + \
287 0 /* SP4_NONE (for now) */ + \
288 2 /* eir_server_owner.so_minor_id */ + \
289 /* eir_server_owner.so_major_id<> */ \
290 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
291 /* eir_server_scope<> */ \
292 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
293 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500294 1 /* nii_domain */ + \
295 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
296 1 /* nii_name */ + \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
298 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400299#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
300#define decode_channel_attrs_maxsz (6 + \
301 1 /* ca_rdma_ird.len */ + \
302 1 /* ca_rdma_ird */)
303#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
304 2 /* csa_clientid */ + \
305 1 /* csa_sequence */ + \
306 1 /* csa_flags */ + \
307 encode_channel_attrs_maxsz + \
308 encode_channel_attrs_maxsz + \
309 1 /* csa_cb_program */ + \
310 1 /* csa_sec_parms.len (1) */ + \
311 1 /* cb_secflavor (AUTH_SYS) */ + \
312 1 /* stamp */ + \
313 1 /* machinename.len */ + \
314 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
315 1 /* uid */ + \
316 1 /* gid */ + \
317 1 /* gids.len (0) */)
318#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
319 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
320 1 /* csr_sequence */ + \
321 1 /* csr_flags */ + \
322 decode_channel_attrs_maxsz + \
323 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400324#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
325#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400326#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
327 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
328#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
329 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500330#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
331#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400332#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
333 encode_verifier_maxsz)
334#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
335 2 /* nfs_cookie4 gdlr_cookie */ + \
336 decode_verifier_maxsz \
337 /* verifier4 gdlr_verifier */ + \
338 1 /* gdlr_deviceid_list count */ + \
339 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
340 NFS4_DEVICEID4_SIZE) \
341 /* gdlr_deviceid_list */ + \
342 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400343#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
344 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
345#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
346 1 /* layout type */ + \
347 1 /* opaque devaddr4 length */ + \
348 /* devaddr4 payload is read into page */ \
349 1 /* notification bitmap length */ + \
350 1 /* notification bitmap */)
351#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
352 encode_stateid_maxsz)
353#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
354 decode_stateid_maxsz + \
355 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000356#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
357 2 /* offset */ + \
358 2 /* length */ + \
359 1 /* reclaim */ + \
360 encode_stateid_maxsz + \
361 1 /* new offset (true) */ + \
362 2 /* last byte written */ + \
363 1 /* nt_timechanged (false) */ + \
364 1 /* layoutupdate4 layout type */ + \
365 1 /* NULL filelayout layoutupdate4 payload */)
366#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300367#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
368 encode_stateid_maxsz + \
369 1 /* FIXME: opaque lrf_body always empty at the moment */)
370#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
371 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400372#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
373#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400374#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
375 XDR_QUADLEN(NFS4_STATEID_SIZE))
376#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400377#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
378 XDR_QUADLEN(NFS4_STATEID_SIZE))
379#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400380#else /* CONFIG_NFS_V4_1 */
381#define encode_sequence_maxsz 0
382#define decode_sequence_maxsz 0
383#endif /* CONFIG_NFS_V4_1 */
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
386#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
387#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400388 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400390 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400392 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400394 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400396 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400398 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400400 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400402 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400404 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400406 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400410 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400412 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400415 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400417 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400420 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421#define NFS4_enc_commit_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 + \
Trond Myklebust85827152012-04-29 10:44:42 -0400424 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425#define NFS4_dec_commit_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 + \
Trond Myklebust85827152012-04-29 10:44:42 -0400428 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400431 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400432 encode_open_maxsz + \
433 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400434 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400436 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400437 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400438 decode_open_maxsz + \
439 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400440 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400441#define NFS4_enc_open_confirm_sz \
442 (compound_encode_hdr_maxsz + \
443 encode_putfh_maxsz + \
444 encode_open_confirm_maxsz)
445#define NFS4_dec_open_confirm_sz \
446 (compound_decode_hdr_maxsz + \
447 decode_putfh_maxsz + \
448 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400450 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400452 encode_open_maxsz + \
453 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400455 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400457 decode_open_maxsz + \
458 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define NFS4_enc_open_downgrade_sz \
460 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400461 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400462 encode_putfh_maxsz + \
463 encode_open_downgrade_maxsz + \
464 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465#define NFS4_dec_open_downgrade_sz \
466 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400467 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400468 decode_putfh_maxsz + \
469 decode_open_downgrade_maxsz + \
470 decode_getattr_maxsz)
471#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400472 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400473 encode_putfh_maxsz + \
474 encode_close_maxsz + \
475 encode_getattr_maxsz)
476#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400477 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400478 decode_putfh_maxsz + \
479 decode_close_maxsz + \
480 decode_getattr_maxsz)
481#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400482 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400483 encode_putfh_maxsz + \
484 encode_setattr_maxsz + \
485 encode_getattr_maxsz)
486#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400487 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400488 decode_putfh_maxsz + \
489 decode_setattr_maxsz + \
490 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 encode_putfh_maxsz + \
494 encode_fsinfo_maxsz)
495#define NFS4_dec_fsinfo_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 + \
498 decode_fsinfo_maxsz)
499#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
500 encode_renew_maxsz)
501#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
502 decode_renew_maxsz)
503#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
504 encode_setclientid_maxsz)
505#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
506 decode_setclientid_maxsz)
507#define NFS4_enc_setclientid_confirm_sz \
508 (compound_encode_hdr_maxsz + \
509 encode_setclientid_confirm_maxsz + \
510 encode_putrootfh_maxsz + \
511 encode_fsinfo_maxsz)
512#define NFS4_dec_setclientid_confirm_sz \
513 (compound_decode_hdr_maxsz + \
514 decode_setclientid_confirm_maxsz + \
515 decode_putrootfh_maxsz + \
516 decode_fsinfo_maxsz)
517#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400518 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400520 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400522 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400524 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400526 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400528 encode_lockt_maxsz)
529#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400531 decode_putfh_maxsz + \
532 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400536 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400540 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400541#define NFS4_enc_release_lockowner_sz \
542 (compound_encode_hdr_maxsz + \
543 encode_lockowner_maxsz)
544#define NFS4_dec_release_lockowner_sz \
545 (compound_decode_hdr_maxsz + \
546 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400548 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400550 encode_access_maxsz + \
551 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400553 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400555 decode_access_maxsz + \
556 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400558 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 encode_putfh_maxsz + \
560 encode_getattr_maxsz)
561#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 decode_putfh_maxsz + \
564 decode_getattr_maxsz)
565#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 encode_putfh_maxsz + \
568 encode_lookup_maxsz + \
569 encode_getattr_maxsz + \
570 encode_getfh_maxsz)
571#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400574 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 decode_getattr_maxsz + \
576 decode_getfh_maxsz)
577#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400578 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 encode_putrootfh_maxsz + \
580 encode_getattr_maxsz + \
581 encode_getfh_maxsz)
582#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400583 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 decode_putrootfh_maxsz + \
585 decode_getattr_maxsz + \
586 decode_getfh_maxsz)
587#define NFS4_enc_remove_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 + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400590 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591#define NFS4_dec_remove_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 + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400594 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595#define NFS4_enc_rename_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 + \
598 encode_savefh_maxsz + \
599 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400600 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400602 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 decode_putfh_maxsz + \
604 decode_savefh_maxsz + \
605 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400606 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400608 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 encode_putfh_maxsz + \
610 encode_savefh_maxsz + \
611 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400612 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400613 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400614 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400616 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 decode_putfh_maxsz + \
618 decode_savefh_maxsz + \
619 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400620 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400621 decode_restorefh_maxsz + \
622 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400624 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 encode_putfh_maxsz + \
626 encode_symlink_maxsz + \
627 encode_getattr_maxsz + \
628 encode_getfh_maxsz)
629#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400630 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 decode_putfh_maxsz + \
632 decode_symlink_maxsz + \
633 decode_getattr_maxsz + \
634 decode_getfh_maxsz)
635#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400636 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 encode_putfh_maxsz + \
638 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400639 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400640 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 decode_putfh_maxsz + \
644 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400645 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400646 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 encode_putfh_maxsz + \
650 encode_getattr_maxsz)
651#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400652 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 decode_putfh_maxsz + \
654 decode_getattr_maxsz)
655#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400656 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400658 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400660 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400662 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400664 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800665 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 encode_getattr_maxsz)
667#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400668 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800669 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 decode_getattr_maxsz)
671#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100674 encode_delegreturn_maxsz + \
675 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400677 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100678 decode_delegreturn_maxsz + \
679 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000680#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400681 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000682 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400683 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000684#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400685 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000686 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400687 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000688#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400689 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000690 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400691 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000692#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400693 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000694 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400695 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400696#define NFS4_enc_fs_locations_sz \
697 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400698 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400699 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400700 encode_lookup_maxsz + \
701 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400702#define NFS4_dec_fs_locations_sz \
703 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400704 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400705 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400706 decode_lookup_maxsz + \
707 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000708#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
709 encode_sequence_maxsz + \
710 encode_putfh_maxsz + \
711 encode_secinfo_maxsz)
712#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
713 decode_sequence_maxsz + \
714 decode_putfh_maxsz + \
715 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400716#if defined(CONFIG_NFS_V4_1)
717#define NFS4_enc_exchange_id_sz \
718 (compound_encode_hdr_maxsz + \
719 encode_exchange_id_maxsz)
720#define NFS4_dec_exchange_id_sz \
721 (compound_decode_hdr_maxsz + \
722 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400723#define NFS4_enc_create_session_sz \
724 (compound_encode_hdr_maxsz + \
725 encode_create_session_maxsz)
726#define NFS4_dec_create_session_sz \
727 (compound_decode_hdr_maxsz + \
728 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400729#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
730 encode_destroy_session_maxsz)
731#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
732 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400733#define NFS4_enc_sequence_sz \
734 (compound_decode_hdr_maxsz + \
735 encode_sequence_maxsz)
736#define NFS4_dec_sequence_sz \
737 (compound_decode_hdr_maxsz + \
738 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400739#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
740 encode_sequence_maxsz + \
741 encode_putrootfh_maxsz + \
742 encode_fsinfo_maxsz)
743#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
744 decode_sequence_maxsz + \
745 decode_putrootfh_maxsz + \
746 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500747#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
748 encode_sequence_maxsz + \
749 encode_reclaim_complete_maxsz)
750#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
751 decode_sequence_maxsz + \
752 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400753#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
754 encode_sequence_maxsz + \
755 encode_putfh_maxsz + \
756 encode_getdevicelist_maxsz)
757#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
758 decode_sequence_maxsz + \
759 decode_putfh_maxsz + \
760 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400761#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
762 encode_sequence_maxsz +\
763 encode_getdeviceinfo_maxsz)
764#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
765 decode_sequence_maxsz + \
766 decode_getdeviceinfo_maxsz)
767#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
768 encode_sequence_maxsz + \
769 encode_putfh_maxsz + \
770 encode_layoutget_maxsz)
771#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
772 decode_sequence_maxsz + \
773 decode_putfh_maxsz + \
774 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000775#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
776 encode_sequence_maxsz +\
777 encode_putfh_maxsz + \
778 encode_layoutcommit_maxsz + \
779 encode_getattr_maxsz)
780#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
781 decode_sequence_maxsz + \
782 decode_putfh_maxsz + \
783 decode_layoutcommit_maxsz + \
784 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300785#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
786 encode_sequence_maxsz + \
787 encode_putfh_maxsz + \
788 encode_layoutreturn_maxsz)
789#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
790 decode_sequence_maxsz + \
791 decode_putfh_maxsz + \
792 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400793#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
794 encode_sequence_maxsz + \
795 encode_putrootfh_maxsz +\
796 encode_secinfo_no_name_maxsz)
797#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
798 decode_sequence_maxsz + \
799 decode_putrootfh_maxsz + \
800 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400801#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
802 encode_sequence_maxsz + \
803 encode_test_stateid_maxsz)
804#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
805 decode_sequence_maxsz + \
806 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400807#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
808 encode_sequence_maxsz + \
809 encode_free_stateid_maxsz)
810#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
811 decode_sequence_maxsz + \
812 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500813
814const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
815 compound_encode_hdr_maxsz +
816 encode_sequence_maxsz +
817 encode_putfh_maxsz +
818 encode_getattr_maxsz) *
819 XDR_UNIT);
820
821const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
822 compound_decode_hdr_maxsz +
823 decode_sequence_maxsz +
824 decode_putfh_maxsz) *
825 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400826#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500828static unsigned short send_implementation_id = 1;
829
830module_param(send_implementation_id, ushort, 0644);
831MODULE_PARM_DESC(send_implementation_id,
832 "Send implementation ID with NFSv4.1 exchange_id");
833
Trond Myklebustbca79472009-03-11 14:10:26 -0400834static const umode_t nfs_type2fmt[] = {
835 [NF4BAD] = 0,
836 [NF4REG] = S_IFREG,
837 [NF4DIR] = S_IFDIR,
838 [NF4BLK] = S_IFBLK,
839 [NF4CHR] = S_IFCHR,
840 [NF4LNK] = S_IFLNK,
841 [NF4SOCK] = S_IFSOCK,
842 [NF4FIFO] = S_IFIFO,
843 [NF4ATTRDIR] = 0,
844 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845};
846
847struct compound_hdr {
848 int32_t status;
849 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500850 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 uint32_t taglen;
852 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400853 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400854 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855};
856
Benny Halevy13c65ce2009-08-14 17:19:25 +0300857static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
858{
859 __be32 *p = xdr_reserve_space(xdr, nbytes);
860 BUG_ON(!p);
861 return p;
862}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
Trond Myklebustcb17e552012-03-04 18:13:56 -0500864static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
865{
866 __be32 *p;
867
868 p = xdr_reserve_space(xdr, len);
869 xdr_encode_opaque_fixed(p, buf, len);
870}
871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
873{
Al Viro8687b632006-10-19 23:28:48 -0700874 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500876 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 xdr_encode_opaque(p, str, len);
878}
879
Trond Myklebust4ade9822012-03-04 18:13:57 -0500880static void encode_uint32(struct xdr_stream *xdr, u32 n)
881{
882 __be32 *p;
883
884 p = reserve_space(xdr, 4);
885 *p = cpu_to_be32(n);
886}
887
Trond Myklebustff2eb682012-03-05 11:40:12 -0500888static void encode_uint64(struct xdr_stream *xdr, u64 n)
889{
890 __be32 *p;
891
892 p = reserve_space(xdr, 8);
893 xdr_encode_hyper(p, n);
894}
895
Trond Myklebust4ade9822012-03-04 18:13:57 -0500896static void encode_nfs4_seqid(struct xdr_stream *xdr,
897 const struct nfs_seqid *seqid)
898{
899 encode_uint32(xdr, seqid->sequence->counter);
900}
901
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400902static void encode_compound_hdr(struct xdr_stream *xdr,
903 struct rpc_rqst *req,
904 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
Al Viro8687b632006-10-19 23:28:48 -0700906 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400907 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400908
909 /* initialize running count of expected bytes in reply.
910 * NOTE: the replied tag SHOULD be the same is the one sent,
911 * but this is not required as a MUST for the server to do so. */
912 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500915 encode_string(xdr, hdr->taglen, hdr->tag);
916 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300917 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500918 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300919 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500920}
921
Trond Myklebustab19b482012-03-04 18:13:57 -0500922static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
923 uint32_t replen,
924 struct compound_hdr *hdr)
925{
926 encode_uint32(xdr, op);
927 hdr->nops++;
928 hdr->replen += replen;
929}
930
Andy Adamsond0179312008-12-23 16:06:17 -0500931static void encode_nops(struct compound_hdr *hdr)
932{
Andy Adamsonfc931582009-04-01 09:22:31 -0400933 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500934 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935}
936
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500937static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
938{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500939 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500940}
941
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
943{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500944 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945}
946
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500947static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948{
949 char owner_name[IDMAP_NAMESZ];
950 char owner_group[IDMAP_NAMESZ];
951 int owner_namelen = 0;
952 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700953 __be32 *p;
954 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 int len;
956 uint32_t bmval0 = 0;
957 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959 /*
960 * We reserve enough space to write the entire attribute buffer at once.
961 * In the worst-case, this would be
962 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
963 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000964 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 */
966 len = 16;
967
968 /* Sigh */
969 if (iap->ia_valid & ATTR_SIZE)
970 len += 8;
971 if (iap->ia_valid & ATTR_MODE)
972 len += 4;
973 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800974 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400976 dprintk("nfs: couldn't resolve uid %d to string\n",
977 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 /* XXX */
979 strcpy(owner_name, "nobody");
980 owner_namelen = sizeof("nobody") - 1;
981 /* goto out; */
982 }
983 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
984 }
985 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800986 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400988 dprintk("nfs: couldn't resolve gid %d to string\n",
989 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 strcpy(owner_group, "nobody");
991 owner_grouplen = sizeof("nobody") - 1;
992 /* goto out; */
993 }
994 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
995 }
996 if (iap->ia_valid & ATTR_ATIME_SET)
997 len += 16;
998 else if (iap->ia_valid & ATTR_ATIME)
999 len += 4;
1000 if (iap->ia_valid & ATTR_MTIME_SET)
1001 len += 16;
1002 else if (iap->ia_valid & ATTR_MTIME)
1003 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001004 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
1006 /*
1007 * We write the bitmap length now, but leave the bitmap and the attribute
1008 * buffer length to be backfilled at the end of this routine.
1009 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001010 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 q = p;
1012 p += 3;
1013
1014 if (iap->ia_valid & ATTR_SIZE) {
1015 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001016 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 }
1018 if (iap->ia_valid & ATTR_MODE) {
1019 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001020 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 }
1022 if (iap->ia_valid & ATTR_UID) {
1023 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001024 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 }
1026 if (iap->ia_valid & ATTR_GID) {
1027 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001028 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 }
1030 if (iap->ia_valid & ATTR_ATIME_SET) {
1031 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001032 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1033 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001034 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1035 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 }
1037 else if (iap->ia_valid & ATTR_ATIME) {
1038 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001039 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 }
1041 if (iap->ia_valid & ATTR_MTIME_SET) {
1042 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001043 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1044 *p++ = cpu_to_be32(0);
1045 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1046 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 }
1048 else if (iap->ia_valid & ATTR_MTIME) {
1049 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001050 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001052
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 /*
1054 * Now we backfill the bitmap and the attribute buffer length.
1055 */
1056 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001057 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 len, ((char *)p - (char *)q) + 4);
1059 BUG();
1060 }
1061 len = (char *)p - (char *)q - 12;
1062 *q++ = htonl(bmval0);
1063 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001064 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067}
1068
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001069static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001071 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1072 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073}
1074
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001075static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076{
Trond Myklebustab19b482012-03-04 18:13:57 -05001077 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001078 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001079 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080}
1081
Fred Isaman0b7c0152012-04-20 14:47:39 -04001082static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083{
Al Viro8687b632006-10-19 23:28:48 -07001084 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001085
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001086 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1087 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001088 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001089 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090}
1091
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001092static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093{
Al Viro8687b632006-10-19 23:28:48 -07001094 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001095
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001096 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1097 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
1099 switch (create->ftype) {
1100 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001101 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001102 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001103 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 break;
1105
1106 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001107 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001108 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001109 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 break;
1111
1112 default:
1113 break;
1114 }
1115
Benny Halevy811652b2009-08-14 17:19:34 +03001116 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001117 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118}
1119
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001120static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121{
Andy Adamson05d564f2008-12-23 16:06:15 -05001122 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001124 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1125 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001126 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001127 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128}
1129
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001130static 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 -07001131{
Andy Adamson05d564f2008-12-23 16:06:15 -05001132 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001134 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1135 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001136 *p++ = cpu_to_be32(2);
1137 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001138 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Fred Isamandae100c2011-07-30 20:52:37 -04001141static void
1142encode_getattr_three(struct xdr_stream *xdr,
1143 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1144 struct compound_hdr *hdr)
1145{
1146 __be32 *p;
1147
Trond Myklebustab19b482012-03-04 18:13:57 -05001148 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001149 if (bm2) {
1150 p = reserve_space(xdr, 16);
1151 *p++ = cpu_to_be32(3);
1152 *p++ = cpu_to_be32(bm0);
1153 *p++ = cpu_to_be32(bm1);
1154 *p = cpu_to_be32(bm2);
1155 } else if (bm1) {
1156 p = reserve_space(xdr, 12);
1157 *p++ = cpu_to_be32(2);
1158 *p++ = cpu_to_be32(bm0);
1159 *p = cpu_to_be32(bm1);
1160 } else {
1161 p = reserve_space(xdr, 8);
1162 *p++ = cpu_to_be32(1);
1163 *p = cpu_to_be32(bm0);
1164 }
Fred Isamandae100c2011-07-30 20:52:37 -04001165}
1166
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001167static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001169 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1170 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171}
1172
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001173static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174{
Fred Isamandae100c2011-07-30 20:52:37 -04001175 encode_getattr_three(xdr,
1176 bitmask[0] & nfs4_fsinfo_bitmap[0],
1177 bitmask[1] & nfs4_fsinfo_bitmap[1],
1178 bitmask[2] & nfs4_fsinfo_bitmap[2],
1179 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180}
1181
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001182static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001183{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001184 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1185 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001186}
1187
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001188static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189{
Trond Myklebustab19b482012-03-04 18:13:57 -05001190 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191}
1192
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001193static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194{
Trond Myklebustab19b482012-03-04 18:13:57 -05001195 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001196 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197}
1198
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001199static inline int nfs4_lock_type(struct file_lock *fl, int block)
1200{
1201 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1202 return block ? NFS4_READW_LT : NFS4_READ_LT;
1203 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1204}
1205
1206static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1207{
1208 if (fl->fl_end == OFFSET_MAX)
1209 return ~(uint64_t)0;
1210 return fl->fl_end - fl->fl_start + 1;
1211}
1212
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001213static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1214{
1215 __be32 *p;
1216
Trond Myklebustd035c362010-12-21 10:45:27 -05001217 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001218 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001219 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001220 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001221 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001222 xdr_encode_hyper(p, lowner->id);
1223}
1224
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225/*
1226 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1227 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1228 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001229static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230{
Al Viro8687b632006-10-19 23:28:48 -07001231 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001233 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1234 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001235 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1236 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001237 p = xdr_encode_hyper(p, args->fl->fl_start);
1238 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001239 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001240 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001241 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001242 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001243 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001244 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 }
1246 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001247 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001248 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250}
1251
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001252static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253{
Al Viro8687b632006-10-19 23:28:48 -07001254 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001256 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1257 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001258 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001259 p = xdr_encode_hyper(p, args->fl->fl_start);
1260 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001261 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262}
1263
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001264static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265{
Al Viro8687b632006-10-19 23:28:48 -07001266 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001268 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1269 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001270 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001271 encode_nfs4_stateid(xdr, args->stateid);
1272 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001273 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001274 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275}
1276
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001277static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1278{
Trond Myklebustab19b482012-03-04 18:13:57 -05001279 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001280 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001281}
1282
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001283static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284{
Trond Myklebustab19b482012-03-04 18:13:57 -05001285 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001286 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287}
1288
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001289static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290{
Al Viro8687b632006-10-19 23:28:48 -07001291 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Benny Halevy13c65ce2009-08-14 17:19:25 +03001293 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001294 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001295 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001296 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001297 break;
1298 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001299 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001300 break;
1301 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001302 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001303 break;
1304 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001305 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 }
Benny Halevy34558512009-08-14 17:19:30 +03001307 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308}
1309
1310static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1311{
Al Viro8687b632006-10-19 23:28:48 -07001312 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 /*
1314 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1315 * owner 4 = 32
1316 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001317 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001318 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001319 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001320 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001321 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001322 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001323 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001324 *p++ = cpu_to_be32(arg->id.uniquifier);
1325 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326}
1327
1328static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1329{
Al Viro8687b632006-10-19 23:28:48 -07001330 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001331 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Benny Halevy13c65ce2009-08-14 17:19:25 +03001333 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001335 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001336 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001337 encode_attrs(xdr, arg->u.attrs, arg->server);
1338 break;
1339 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001340 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001341 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001342 if (nfs4_has_persistent_session(clp)) {
1343 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1344 encode_attrs(xdr, arg->u.attrs, arg->server);
1345 } else {
1346 struct iattr dummy;
1347
1348 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1349 encode_nfs4_verifier(xdr, &arg->u.verifier);
1350 dummy.ia_valid = 0;
1351 encode_attrs(xdr, &dummy, arg->server);
1352 }
1353 } else {
1354 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1355 encode_nfs4_verifier(xdr, &arg->u.verifier);
1356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 }
1358}
1359
1360static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1361{
Al Viro8687b632006-10-19 23:28:48 -07001362 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
Benny Halevy13c65ce2009-08-14 17:19:25 +03001364 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001366 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001367 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001368 break;
1369 default:
1370 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001371 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001372 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 }
1374}
1375
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001376static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377{
Al Viro8687b632006-10-19 23:28:48 -07001378 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
Benny Halevy13c65ce2009-08-14 17:19:25 +03001380 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001382 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001383 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001384 break;
1385 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001386 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001387 break;
1388 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001389 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001390 break;
1391 default:
1392 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 }
1394}
1395
1396static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1397{
Al Viro8687b632006-10-19 23:28:48 -07001398 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
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(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 encode_string(xdr, name->len, name->name);
1403}
1404
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001405static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406{
Al Viro8687b632006-10-19 23:28:48 -07001407 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Benny Halevy13c65ce2009-08-14 17:19:25 +03001409 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001410 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 encode_delegation_type(xdr, type);
1412}
1413
1414static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1415{
Al Viro8687b632006-10-19 23:28:48 -07001416 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001418 p = reserve_space(xdr, 4);
1419 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1420 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 encode_string(xdr, name->len, name->name);
1422}
1423
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001424static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425{
Trond Myklebustab19b482012-03-04 18:13:57 -05001426 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 encode_openhdr(xdr, arg);
1428 encode_opentype(xdr, arg);
1429 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001430 case NFS4_OPEN_CLAIM_NULL:
1431 encode_claim_null(xdr, arg->name);
1432 break;
1433 case NFS4_OPEN_CLAIM_PREVIOUS:
1434 encode_claim_previous(xdr, arg->u.delegation_type);
1435 break;
1436 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1437 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1438 break;
1439 default:
1440 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442}
1443
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001444static 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 -07001445{
Trond Myklebustab19b482012-03-04 18:13:57 -05001446 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001447 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001448 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449}
1450
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001451static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452{
Trond Myklebustab19b482012-03-04 18:13:57 -05001453 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001454 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001455 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001456 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457}
1458
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001459static void
Andy Adamsond0179312008-12-23 16:06:17 -05001460encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461{
Trond Myklebustab19b482012-03-04 18:13:57 -05001462 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001463 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464}
1465
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001466static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
Trond Myklebustab19b482012-03-04 18:13:57 -05001468 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469}
1470
Trond Myklebust4fc87962012-03-08 17:42:01 -05001471static void encode_open_stateid(struct xdr_stream *xdr,
1472 const struct nfs_open_context *ctx,
1473 const struct nfs_lock_context *l_ctx,
1474 fmode_t fmode,
1475 int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 nfs4_stateid stateid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 if (ctx->state != NULL) {
Trond Myklebust4fc87962012-03-08 17:42:01 -05001480 nfs4_select_rw_stateid(&stateid, ctx->state,
1481 fmode, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001482 if (zero_seqid)
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001483 stateid.seqid = 0;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001484 encode_nfs4_stateid(xdr, &stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 } else
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001486 encode_nfs4_stateid(xdr, &zero_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487}
1488
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001489static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490{
Al Viro8687b632006-10-19 23:28:48 -07001491 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
Trond Myklebustab19b482012-03-04 18:13:57 -05001493 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001494 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001495 FMODE_READ, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Benny Halevy13c65ce2009-08-14 17:19:25 +03001497 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001498 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001499 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500}
1501
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001502static 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 -07001503{
Trond Myklebust28331a42011-04-27 13:47:52 -04001504 uint32_t attrs[2] = {
1505 FATTR4_WORD0_RDATTR_ERROR,
1506 FATTR4_WORD1_MOUNTED_ON_FILEID,
1507 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001508 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001509 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001511 if (readdir->plus) {
1512 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001513 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001514 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1515 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1516 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1517 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001518 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001519 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001520 /* Use mounted_on_fileid only if the server supports it */
1521 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1522 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001523
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001524 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001525 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001526 encode_nfs4_verifier(xdr, &readdir->verifier);
1527 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001528 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001529 *p++ = cpu_to_be32(readdir->count);
1530 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001531
Benny Halevye75bc1c2009-08-14 17:18:54 +03001532 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001533 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Chuck Levercd937102012-03-02 17:14:31 -05001534 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001535 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1536 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001537 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001538 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001539 attrs[0] & readdir->bitmask[0],
1540 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541}
1542
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001543static 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 -07001544{
Trond Myklebustab19b482012-03-04 18:13:57 -05001545 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546}
1547
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001548static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549{
Trond Myklebustab19b482012-03-04 18:13:57 -05001550 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001551 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552}
1553
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001554static 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 -07001555{
Trond Myklebustab19b482012-03-04 18:13:57 -05001556 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001557 encode_string(xdr, oldname->len, oldname->name);
1558 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559}
1560
Chuck Leverbb4dae52012-03-01 17:01:48 -05001561static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1562 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001564 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001565 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566}
1567
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001568static void
Andy Adamsond0179312008-12-23 16:06:17 -05001569encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001570{
Trond Myklebustab19b482012-03-04 18:13:57 -05001571 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001572}
1573
Chuck Lever9f06c712010-12-14 14:59:18 +00001574static void
Andy Adamsond0179312008-12-23 16:06:17 -05001575encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001576{
Al Viro8687b632006-10-19 23:28:48 -07001577 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001578
Trond Myklebustab19b482012-03-04 18:13:57 -05001579 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001580 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001581 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001582 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001583 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001584 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001585 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001586 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001587 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001588}
1589
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001590static void
Andy Adamsond0179312008-12-23 16:06:17 -05001591encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592{
Trond Myklebustab19b482012-03-04 18:13:57 -05001593 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594}
1595
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001596static 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 -07001597{
Trond Myklebustab19b482012-03-04 18:13:57 -05001598 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001599 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001600 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601}
1602
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001603static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604{
Al Viro8687b632006-10-19 23:28:48 -07001605 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606
Trond Myklebust70019512012-03-04 20:49:32 -05001607 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001608 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
1610 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001611 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001612 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1614 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001615 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001616 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617}
1618
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001619static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001621 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1622 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001623 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001624 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625}
1626
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001627static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628{
Al Viro8687b632006-10-19 23:28:48 -07001629 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
Trond Myklebustab19b482012-03-04 18:13:57 -05001631 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001632 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001633 FMODE_WRITE, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
Benny Halevy13c65ce2009-08-14 17:19:25 +03001635 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001636 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001637 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001638 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
1640 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641}
1642
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001643static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644{
Trond Myklebustab19b482012-03-04 18:13:57 -05001645 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001646 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001648
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001649static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1650{
Trond Myklebustab19b482012-03-04 18:13:57 -05001651 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001652 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001653}
1654
Benny Halevy99fe60d2009-04-01 09:22:29 -04001655#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001656/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001657static void encode_exchange_id(struct xdr_stream *xdr,
1658 struct nfs41_exchange_id_args *args,
1659 struct compound_hdr *hdr)
1660{
1661 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001662 char impl_name[NFS4_OPAQUE_LIMIT];
1663 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001664
Trond Myklebust70019512012-03-04 20:49:32 -05001665 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001666 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001667
1668 encode_string(xdr, args->id_len, args->id);
1669
Benny Halevy13c65ce2009-08-14 17:19:25 +03001670 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001671 *p++ = cpu_to_be32(args->flags);
1672 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001673
1674 if (send_implementation_id &&
1675 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1676 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1677 <= NFS4_OPAQUE_LIMIT + 1)
1678 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1679 utsname()->sysname, utsname()->release,
1680 utsname()->version, utsname()->machine);
1681
1682 if (len > 0) {
1683 *p = cpu_to_be32(1); /* implementation id array length=1 */
1684
1685 encode_string(xdr,
1686 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1687 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1688 encode_string(xdr, len, impl_name);
1689 /* just send zeros for nii_date - the date is in nii_name */
1690 p = reserve_space(xdr, 12);
1691 p = xdr_encode_hyper(p, 0);
1692 *p = cpu_to_be32(0);
1693 } else
1694 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001695}
Andy Adamsonfc931582009-04-01 09:22:31 -04001696
1697static void encode_create_session(struct xdr_stream *xdr,
1698 struct nfs41_create_session_args *args,
1699 struct compound_hdr *hdr)
1700{
1701 __be32 *p;
1702 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1703 uint32_t len;
1704 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001705 u32 max_resp_sz_cached;
1706
1707 /*
1708 * Assumes OPEN is the biggest non-idempotent compound.
1709 * 2 is the verifier.
1710 */
1711 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1712 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001713
Andy Adamsonfc931582009-04-01 09:22:31 -04001714 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1715 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001716
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001717 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1718 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001719 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001720 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1721 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001722
Andy Adamsonfc931582009-04-01 09:22:31 -04001723 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001724 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001725 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1726 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001727 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001728 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1729 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1730 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001731
1732 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001733 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001734 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1735 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1736 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1737 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1738 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1739 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001740
Benny Halevye75bc1c2009-08-14 17:18:54 +03001741 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001742 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001743 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001744
1745 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001746 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001747 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001748 *p++ = cpu_to_be32(0); /* UID */
1749 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001750 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001751}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001752
1753static void encode_destroy_session(struct xdr_stream *xdr,
1754 struct nfs4_session *session,
1755 struct compound_hdr *hdr)
1756{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001757 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1758 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001759}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001760
1761static void encode_reclaim_complete(struct xdr_stream *xdr,
1762 struct nfs41_reclaim_complete_args *args,
1763 struct compound_hdr *hdr)
1764{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001765 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1766 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001767}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001768#endif /* CONFIG_NFS_V4_1 */
1769
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001770static void encode_sequence(struct xdr_stream *xdr,
1771 const struct nfs4_sequence_args *args,
1772 struct compound_hdr *hdr)
1773{
1774#if defined(CONFIG_NFS_V4_1)
1775 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001776 struct nfs4_slot_table *tp;
1777 struct nfs4_slot *slot;
1778 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001779
1780 if (!session)
1781 return;
1782
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001783 tp = &session->fc_slot_table;
1784
1785 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1786 slot = tp->slots + args->sa_slotid;
1787
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001788 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001789
1790 /*
1791 * Sessionid + seqid + slotid + max slotid + cache_this
1792 */
1793 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1794 "max_slotid=%d cache_this=%d\n",
1795 __func__,
1796 ((u32 *)session->sess_id.data)[0],
1797 ((u32 *)session->sess_id.data)[1],
1798 ((u32 *)session->sess_id.data)[2],
1799 ((u32 *)session->sess_id.data)[3],
1800 slot->seq_nr, args->sa_slotid,
1801 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001802 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001803 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001804 *p++ = cpu_to_be32(slot->seq_nr);
1805 *p++ = cpu_to_be32(args->sa_slotid);
1806 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001807 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001808#endif /* CONFIG_NFS_V4_1 */
1809}
1810
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001811#ifdef CONFIG_NFS_V4_1
1812static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001813encode_getdevicelist(struct xdr_stream *xdr,
1814 const struct nfs4_getdevicelist_args *args,
1815 struct compound_hdr *hdr)
1816{
1817 __be32 *p;
1818 nfs4_verifier dummy = {
1819 .data = "dummmmmy",
1820 };
1821
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001822 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1823 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001824 *p++ = cpu_to_be32(args->layoutclass);
1825 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1826 xdr_encode_hyper(p, 0ULL); /* cookie */
1827 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001828}
1829
1830static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001831encode_getdeviceinfo(struct xdr_stream *xdr,
1832 const struct nfs4_getdeviceinfo_args *args,
1833 struct compound_hdr *hdr)
1834{
1835 __be32 *p;
1836
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001837 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1838 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001839 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1840 NFS4_DEVICEID4_SIZE);
1841 *p++ = cpu_to_be32(args->pdev->layout_type);
1842 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1843 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001844}
1845
1846static void
1847encode_layoutget(struct xdr_stream *xdr,
1848 const struct nfs4_layoutget_args *args,
1849 struct compound_hdr *hdr)
1850{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001851 __be32 *p;
1852
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001853 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1854 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001855 *p++ = cpu_to_be32(0); /* Signal layout available */
1856 *p++ = cpu_to_be32(args->type);
1857 *p++ = cpu_to_be32(args->range.iomode);
1858 p = xdr_encode_hyper(p, args->range.offset);
1859 p = xdr_encode_hyper(p, args->range.length);
1860 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001861 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001862 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001863
1864 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1865 __func__,
1866 args->type,
1867 args->range.iomode,
1868 (unsigned long)args->range.offset,
1869 (unsigned long)args->range.length,
1870 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001871}
Andy Adamson863a3c62011-03-23 13:27:54 +00001872
1873static int
1874encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001875 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001876 const struct nfs4_layoutcommit_args *args,
1877 struct compound_hdr *hdr)
1878{
1879 __be32 *p;
1880
1881 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1882 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1883
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001884 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1885 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001886 /* Only whole file layouts */
1887 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001888 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001889 *p = cpu_to_be32(0); /* reclaim */
1890 encode_nfs4_stateid(xdr, &args->stateid);
1891 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001892 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1893 p = xdr_encode_hyper(p, args->lastbytewritten);
1894 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1895 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001896
1897 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1898 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1899 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001900 else
1901 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001902
Andy Adamson863a3c62011-03-23 13:27:54 +00001903 return 0;
1904}
Benny Halevycbe82602011-05-22 19:52:37 +03001905
1906static void
1907encode_layoutreturn(struct xdr_stream *xdr,
1908 const struct nfs4_layoutreturn_args *args,
1909 struct compound_hdr *hdr)
1910{
1911 __be32 *p;
1912
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001913 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1914 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001915 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1916 *p++ = cpu_to_be32(args->layout_type);
1917 *p++ = cpu_to_be32(IOMODE_ANY);
1918 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001919 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001920 p = xdr_encode_hyper(p, 0);
1921 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1922 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001923 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001924 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001925 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1926 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1927 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001928 } else
1929 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03001930}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001931
1932static int
1933encode_secinfo_no_name(struct xdr_stream *xdr,
1934 const struct nfs41_secinfo_no_name_args *args,
1935 struct compound_hdr *hdr)
1936{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001937 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1938 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001939 return 0;
1940}
Bryan Schumaker7d974792011-06-02 14:59:08 -04001941
1942static void encode_test_stateid(struct xdr_stream *xdr,
1943 struct nfs41_test_stateid_args *args,
1944 struct compound_hdr *hdr)
1945{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001946 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
1947 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001948 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04001949}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001950
1951static void encode_free_stateid(struct xdr_stream *xdr,
1952 struct nfs41_free_stateid_args *args,
1953 struct compound_hdr *hdr)
1954{
Trond Myklebustab19b482012-03-04 18:13:57 -05001955 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001956 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001957}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001958#endif /* CONFIG_NFS_V4_1 */
1959
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960/*
1961 * END OF "GENERIC" ENCODE ROUTINES.
1962 */
1963
Benny Halevy66cc0422009-04-01 09:22:10 -04001964static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1965{
1966#if defined(CONFIG_NFS_V4_1)
1967 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001968 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001969#endif /* CONFIG_NFS_V4_1 */
1970 return 0;
1971}
1972
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973/*
1974 * Encode an ACCESS request
1975 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001976static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1977 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 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
Chuck Lever9f06c712010-12-14 14:59:18 +00001983 encode_compound_hdr(xdr, req, &hdr);
1984 encode_sequence(xdr, &args->seq_args, &hdr);
1985 encode_putfh(xdr, args->fh, &hdr);
1986 encode_access(xdr, args->access, &hdr);
1987 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001988 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989}
1990
1991/*
1992 * Encode LOOKUP request
1993 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001994static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1995 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001998 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
Chuck Lever9f06c712010-12-14 14:59:18 +00002001 encode_compound_hdr(xdr, req, &hdr);
2002 encode_sequence(xdr, &args->seq_args, &hdr);
2003 encode_putfh(xdr, args->dir_fh, &hdr);
2004 encode_lookup(xdr, args->name, &hdr);
2005 encode_getfh(xdr, &hdr);
2006 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002007 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008}
2009
2010/*
2011 * Encode LOOKUP_ROOT request
2012 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002013static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2014 struct xdr_stream *xdr,
2015 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002018 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020
Chuck Lever9f06c712010-12-14 14:59:18 +00002021 encode_compound_hdr(xdr, req, &hdr);
2022 encode_sequence(xdr, &args->seq_args, &hdr);
2023 encode_putrootfh(xdr, &hdr);
2024 encode_getfh(xdr, &hdr);
2025 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002026 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027}
2028
2029/*
2030 * Encode REMOVE request
2031 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002032static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2033 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002036 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038
Chuck Lever9f06c712010-12-14 14:59:18 +00002039 encode_compound_hdr(xdr, req, &hdr);
2040 encode_sequence(xdr, &args->seq_args, &hdr);
2041 encode_putfh(xdr, args->fh, &hdr);
2042 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002043 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044}
2045
2046/*
2047 * Encode RENAME request
2048 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002049static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2050 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002053 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055
Chuck Lever9f06c712010-12-14 14:59:18 +00002056 encode_compound_hdr(xdr, req, &hdr);
2057 encode_sequence(xdr, &args->seq_args, &hdr);
2058 encode_putfh(xdr, args->old_dir, &hdr);
2059 encode_savefh(xdr, &hdr);
2060 encode_putfh(xdr, args->new_dir, &hdr);
2061 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002062 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063}
2064
2065/*
2066 * Encode LINK request
2067 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002068static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2069 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002072 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
Chuck Lever9f06c712010-12-14 14:59:18 +00002075 encode_compound_hdr(xdr, req, &hdr);
2076 encode_sequence(xdr, &args->seq_args, &hdr);
2077 encode_putfh(xdr, args->fh, &hdr);
2078 encode_savefh(xdr, &hdr);
2079 encode_putfh(xdr, args->dir_fh, &hdr);
2080 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002081 encode_restorefh(xdr, &hdr);
2082 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002083 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084}
2085
2086/*
2087 * Encode CREATE request
2088 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002089static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2090 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002093 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095
Chuck Lever9f06c712010-12-14 14:59:18 +00002096 encode_compound_hdr(xdr, req, &hdr);
2097 encode_sequence(xdr, &args->seq_args, &hdr);
2098 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002099 encode_create(xdr, args, &hdr);
2100 encode_getfh(xdr, &hdr);
2101 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002102 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103}
2104
2105/*
2106 * Encode SYMLINK request
2107 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002108static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2109 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110{
Chuck Lever9f06c712010-12-14 14:59:18 +00002111 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112}
2113
2114/*
2115 * Encode GETATTR request
2116 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002117static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2118 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002121 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Chuck Lever9f06c712010-12-14 14:59:18 +00002124 encode_compound_hdr(xdr, req, &hdr);
2125 encode_sequence(xdr, &args->seq_args, &hdr);
2126 encode_putfh(xdr, args->fh, &hdr);
2127 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002128 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129}
2130
2131/*
2132 * Encode a CLOSE request
2133 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002134static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2135 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136{
Andy Adamson05d564f2008-12-23 16:06:15 -05002137 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002138 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002139 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
Chuck Lever9f06c712010-12-14 14:59:18 +00002141 encode_compound_hdr(xdr, req, &hdr);
2142 encode_sequence(xdr, &args->seq_args, &hdr);
2143 encode_putfh(xdr, args->fh, &hdr);
2144 encode_close(xdr, args, &hdr);
2145 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002146 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147}
2148
2149/*
2150 * Encode an OPEN request
2151 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002152static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2153 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 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
Chuck Lever9f06c712010-12-14 14:59:18 +00002159 encode_compound_hdr(xdr, req, &hdr);
2160 encode_sequence(xdr, &args->seq_args, &hdr);
2161 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002162 encode_open(xdr, args, &hdr);
2163 encode_getfh(xdr, &hdr);
2164 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002165 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166}
2167
2168/*
2169 * Encode an OPEN_CONFIRM request
2170 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002171static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2172 struct xdr_stream *xdr,
2173 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002176 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Chuck Lever9f06c712010-12-14 14:59:18 +00002179 encode_compound_hdr(xdr, req, &hdr);
2180 encode_putfh(xdr, args->fh, &hdr);
2181 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002182 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183}
2184
2185/*
2186 * Encode an OPEN request with no attributes.
2187 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002188static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2189 struct xdr_stream *xdr,
2190 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002193 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
Chuck Lever9f06c712010-12-14 14:59:18 +00002196 encode_compound_hdr(xdr, req, &hdr);
2197 encode_sequence(xdr, &args->seq_args, &hdr);
2198 encode_putfh(xdr, args->fh, &hdr);
2199 encode_open(xdr, args, &hdr);
2200 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002201 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202}
2203
2204/*
2205 * Encode an OPEN_DOWNGRADE request
2206 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002207static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2208 struct xdr_stream *xdr,
2209 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002212 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214
Chuck Lever9f06c712010-12-14 14:59:18 +00002215 encode_compound_hdr(xdr, req, &hdr);
2216 encode_sequence(xdr, &args->seq_args, &hdr);
2217 encode_putfh(xdr, args->fh, &hdr);
2218 encode_open_downgrade(xdr, args, &hdr);
2219 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002220 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221}
2222
2223/*
2224 * Encode a LOCK request
2225 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002226static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2227 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002230 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
Chuck Lever9f06c712010-12-14 14:59:18 +00002233 encode_compound_hdr(xdr, req, &hdr);
2234 encode_sequence(xdr, &args->seq_args, &hdr);
2235 encode_putfh(xdr, args->fh, &hdr);
2236 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002237 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238}
2239
2240/*
2241 * Encode a LOCKT request
2242 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002243static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2244 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002247 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249
Chuck Lever9f06c712010-12-14 14:59:18 +00002250 encode_compound_hdr(xdr, req, &hdr);
2251 encode_sequence(xdr, &args->seq_args, &hdr);
2252 encode_putfh(xdr, args->fh, &hdr);
2253 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002254 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255}
2256
2257/*
2258 * Encode a LOCKU request
2259 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002260static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2261 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002264 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
Chuck Lever9f06c712010-12-14 14:59:18 +00002267 encode_compound_hdr(xdr, req, &hdr);
2268 encode_sequence(xdr, &args->seq_args, &hdr);
2269 encode_putfh(xdr, args->fh, &hdr);
2270 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002271 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272}
2273
Chuck Lever9f06c712010-12-14 14:59:18 +00002274static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2275 struct xdr_stream *xdr,
2276 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002277{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002278 struct compound_hdr hdr = {
2279 .minorversion = 0,
2280 };
2281
Chuck Lever9f06c712010-12-14 14:59:18 +00002282 encode_compound_hdr(xdr, req, &hdr);
2283 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002284 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002285}
2286
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287/*
2288 * Encode a READLINK request
2289 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002290static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2291 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002294 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296
Chuck Lever9f06c712010-12-14 14:59:18 +00002297 encode_compound_hdr(xdr, req, &hdr);
2298 encode_sequence(xdr, &args->seq_args, &hdr);
2299 encode_putfh(xdr, args->fh, &hdr);
2300 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002301
Benny Halevy28f56692009-04-01 09:22:09 -04002302 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002303 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002304 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305}
2306
2307/*
2308 * Encode a READDIR request
2309 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002310static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2311 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002314 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316
Chuck Lever9f06c712010-12-14 14:59:18 +00002317 encode_compound_hdr(xdr, req, &hdr);
2318 encode_sequence(xdr, &args->seq_args, &hdr);
2319 encode_putfh(xdr, args->fh, &hdr);
2320 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002321
Benny Halevy28f56692009-04-01 09:22:09 -04002322 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002323 args->pgbase, args->count);
2324 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002325 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002326 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002327 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328}
2329
2330/*
2331 * Encode a READ request
2332 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002333static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2334 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002337 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339
Chuck Lever9f06c712010-12-14 14:59:18 +00002340 encode_compound_hdr(xdr, req, &hdr);
2341 encode_sequence(xdr, &args->seq_args, &hdr);
2342 encode_putfh(xdr, args->fh, &hdr);
2343 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344
Benny Halevy28f56692009-04-01 09:22:09 -04002345 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002347 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002348 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349}
2350
2351/*
2352 * Encode an SETATTR request
2353 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002354static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2355 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356{
Andy Adamson05d564f2008-12-23 16:06:15 -05002357 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002358 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002359 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360
Chuck Lever9f06c712010-12-14 14:59:18 +00002361 encode_compound_hdr(xdr, req, &hdr);
2362 encode_sequence(xdr, &args->seq_args, &hdr);
2363 encode_putfh(xdr, args->fh, &hdr);
2364 encode_setattr(xdr, args, args->server, &hdr);
2365 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002366 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367}
2368
2369/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002370 * Encode a GETACL request
2371 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002372static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2373 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002374{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002375 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002376 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002377 };
Benny Halevy28f56692009-04-01 09:22:09 -04002378 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002379
Chuck Lever9f06c712010-12-14 14:59:18 +00002380 encode_compound_hdr(xdr, req, &hdr);
2381 encode_sequence(xdr, &args->seq_args, &hdr);
2382 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002383 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002384 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002385
Benny Halevy28f56692009-04-01 09:22:09 -04002386 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002387 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002388
Andy Adamsond0179312008-12-23 16:06:17 -05002389 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002390}
2391
2392/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 * Encode a WRITE request
2394 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002395static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2396 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002399 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
Chuck Lever9f06c712010-12-14 14:59:18 +00002402 encode_compound_hdr(xdr, req, &hdr);
2403 encode_sequence(xdr, &args->seq_args, &hdr);
2404 encode_putfh(xdr, args->fh, &hdr);
2405 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002406 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002407 if (args->bitmask)
2408 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002409 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410}
2411
2412/*
2413 * a COMMIT request
2414 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002415static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002416 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002419 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421
Chuck Lever9f06c712010-12-14 14:59:18 +00002422 encode_compound_hdr(xdr, req, &hdr);
2423 encode_sequence(xdr, &args->seq_args, &hdr);
2424 encode_putfh(xdr, args->fh, &hdr);
2425 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002426 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427}
2428
2429/*
2430 * FSINFO request
2431 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002432static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2433 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002436 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438
Chuck Lever9f06c712010-12-14 14:59:18 +00002439 encode_compound_hdr(xdr, req, &hdr);
2440 encode_sequence(xdr, &args->seq_args, &hdr);
2441 encode_putfh(xdr, args->fh, &hdr);
2442 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002443 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444}
2445
2446/*
2447 * a PATHCONF request
2448 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002449static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2450 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002453 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455
Chuck Lever9f06c712010-12-14 14:59:18 +00002456 encode_compound_hdr(xdr, req, &hdr);
2457 encode_sequence(xdr, &args->seq_args, &hdr);
2458 encode_putfh(xdr, args->fh, &hdr);
2459 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002460 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002461 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462}
2463
2464/*
2465 * a STATFS request
2466 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002467static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2468 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002471 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473
Chuck Lever9f06c712010-12-14 14:59:18 +00002474 encode_compound_hdr(xdr, req, &hdr);
2475 encode_sequence(xdr, &args->seq_args, &hdr);
2476 encode_putfh(xdr, args->fh, &hdr);
2477 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002478 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002479 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480}
2481
2482/*
2483 * GETATTR_BITMAP request
2484 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002485static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2486 struct xdr_stream *xdr,
2487 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002490 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492
Chuck Lever9f06c712010-12-14 14:59:18 +00002493 encode_compound_hdr(xdr, req, &hdr);
2494 encode_sequence(xdr, &args->seq_args, &hdr);
2495 encode_putfh(xdr, args->fhandle, &hdr);
2496 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002497 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002498 FATTR4_WORD0_LINK_SUPPORT|
2499 FATTR4_WORD0_SYMLINK_SUPPORT|
2500 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002501 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502}
2503
2504/*
2505 * a RENEW request
2506 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002507static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2508 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002511 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 };
2513
Chuck Lever9f06c712010-12-14 14:59:18 +00002514 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002515 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002516 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517}
2518
2519/*
2520 * a SETCLIENTID request
2521 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002522static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2523 struct xdr_stream *xdr,
2524 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002527 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 };
2529
Chuck Lever9f06c712010-12-14 14:59:18 +00002530 encode_compound_hdr(xdr, req, &hdr);
2531 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002532 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533}
2534
2535/*
2536 * a SETCLIENTID_CONFIRM request
2537 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002538static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2539 struct xdr_stream *xdr,
2540 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002543 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 };
Fred Isamandae100c2011-07-30 20:52:37 -04002545 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546
Chuck Lever9f06c712010-12-14 14:59:18 +00002547 encode_compound_hdr(xdr, req, &hdr);
2548 encode_setclientid_confirm(xdr, arg, &hdr);
2549 encode_putrootfh(xdr, &hdr);
2550 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002551 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552}
2553
2554/*
2555 * DELEGRETURN request
2556 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002557static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2558 struct xdr_stream *xdr,
2559 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002562 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564
Chuck Lever9f06c712010-12-14 14:59:18 +00002565 encode_compound_hdr(xdr, req, &hdr);
2566 encode_sequence(xdr, &args->seq_args, &hdr);
2567 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002568 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002569 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002570 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571}
2572
2573/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002574 * Encode FS_LOCATIONS request
2575 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002576static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2577 struct xdr_stream *xdr,
2578 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002579{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002580 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002581 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002582 };
Benny Halevy28f56692009-04-01 09:22:09 -04002583 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002584
Chuck Lever9f06c712010-12-14 14:59:18 +00002585 encode_compound_hdr(xdr, req, &hdr);
2586 encode_sequence(xdr, &args->seq_args, &hdr);
2587 encode_putfh(xdr, args->dir_fh, &hdr);
2588 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002589 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002590 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002591
Benny Halevy28f56692009-04-01 09:22:09 -04002592 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002593 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002594 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002595}
2596
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002597/*
2598 * Encode SECINFO request
2599 */
2600static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2601 struct xdr_stream *xdr,
2602 struct nfs4_secinfo_arg *args)
2603{
2604 struct compound_hdr hdr = {
2605 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2606 };
2607
2608 encode_compound_hdr(xdr, req, &hdr);
2609 encode_sequence(xdr, &args->seq_args, &hdr);
2610 encode_putfh(xdr, args->dir_fh, &hdr);
2611 encode_secinfo(xdr, args->name, &hdr);
2612 encode_nops(&hdr);
2613}
2614
Benny Halevy99fe60d2009-04-01 09:22:29 -04002615#if defined(CONFIG_NFS_V4_1)
2616/*
2617 * EXCHANGE_ID request
2618 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002619static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2620 struct xdr_stream *xdr,
2621 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002622{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002623 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002624 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002625 };
2626
Chuck Lever9f06c712010-12-14 14:59:18 +00002627 encode_compound_hdr(xdr, req, &hdr);
2628 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002629 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002630}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002631
2632/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002633 * a CREATE_SESSION request
2634 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002635static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2636 struct xdr_stream *xdr,
2637 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002638{
Andy Adamsonfc931582009-04-01 09:22:31 -04002639 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002640 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002641 };
2642
Chuck Lever9f06c712010-12-14 14:59:18 +00002643 encode_compound_hdr(xdr, req, &hdr);
2644 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002645 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002646}
2647
2648/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002649 * a DESTROY_SESSION request
2650 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002651static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2652 struct xdr_stream *xdr,
2653 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002654{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002655 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002656 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002657 };
2658
Chuck Lever9f06c712010-12-14 14:59:18 +00002659 encode_compound_hdr(xdr, req, &hdr);
2660 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002661 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002662}
2663
2664/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002665 * a SEQUENCE request
2666 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002667static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2668 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002669{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002670 struct compound_hdr hdr = {
2671 .minorversion = nfs4_xdr_minorversion(args),
2672 };
2673
Chuck Lever9f06c712010-12-14 14:59:18 +00002674 encode_compound_hdr(xdr, req, &hdr);
2675 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002676 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002677}
2678
2679/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002680 * a GET_LEASE_TIME request
2681 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002682static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2683 struct xdr_stream *xdr,
2684 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002685{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002686 struct compound_hdr hdr = {
2687 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2688 };
Fred Isamandae100c2011-07-30 20:52:37 -04002689 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002690
Chuck Lever9f06c712010-12-14 14:59:18 +00002691 encode_compound_hdr(xdr, req, &hdr);
2692 encode_sequence(xdr, &args->la_seq_args, &hdr);
2693 encode_putrootfh(xdr, &hdr);
2694 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002695 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002696}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002697
2698/*
2699 * a RECLAIM_COMPLETE request
2700 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002701static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2702 struct xdr_stream *xdr,
2703 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002704{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002705 struct compound_hdr hdr = {
2706 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2707 };
2708
Chuck Lever9f06c712010-12-14 14:59:18 +00002709 encode_compound_hdr(xdr, req, &hdr);
2710 encode_sequence(xdr, &args->seq_args, &hdr);
2711 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002712 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002713}
2714
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002715/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002716 * Encode GETDEVICELIST request
2717 */
2718static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2719 struct xdr_stream *xdr,
2720 struct nfs4_getdevicelist_args *args)
2721{
2722 struct compound_hdr hdr = {
2723 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2724 };
2725
2726 encode_compound_hdr(xdr, req, &hdr);
2727 encode_sequence(xdr, &args->seq_args, &hdr);
2728 encode_putfh(xdr, args->fh, &hdr);
2729 encode_getdevicelist(xdr, args, &hdr);
2730 encode_nops(&hdr);
2731}
2732
2733/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002734 * Encode GETDEVICEINFO request
2735 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002736static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2737 struct xdr_stream *xdr,
2738 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002739{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002740 struct compound_hdr hdr = {
2741 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2742 };
2743
Chuck Lever9f06c712010-12-14 14:59:18 +00002744 encode_compound_hdr(xdr, req, &hdr);
2745 encode_sequence(xdr, &args->seq_args, &hdr);
2746 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002747
2748 /* set up reply kvec. Subtract notification bitmap max size (2)
2749 * so that notification bitmap is put in xdr_buf tail */
2750 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2751 args->pdev->pages, args->pdev->pgbase,
2752 args->pdev->pglen);
2753
2754 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002755}
2756
2757/*
2758 * Encode LAYOUTGET request
2759 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002760static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2761 struct xdr_stream *xdr,
2762 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002763{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002764 struct compound_hdr hdr = {
2765 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2766 };
2767
Chuck Lever9f06c712010-12-14 14:59:18 +00002768 encode_compound_hdr(xdr, req, &hdr);
2769 encode_sequence(xdr, &args->seq_args, &hdr);
2770 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2771 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002772
2773 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2774 args->layout.pages, 0, args->layout.pglen);
2775
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002776 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002777}
Andy Adamson863a3c62011-03-23 13:27:54 +00002778
2779/*
2780 * Encode LAYOUTCOMMIT request
2781 */
Benny Halevycbe82602011-05-22 19:52:37 +03002782static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2783 struct xdr_stream *xdr,
2784 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002785{
Benny Halevyac7db722011-05-22 19:53:48 +03002786 struct nfs4_layoutcommit_data *data =
2787 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002788 struct compound_hdr hdr = {
2789 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2790 };
2791
2792 encode_compound_hdr(xdr, req, &hdr);
2793 encode_sequence(xdr, &args->seq_args, &hdr);
2794 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002795 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002796 encode_getfattr(xdr, args->bitmask, &hdr);
2797 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002798}
2799
2800/*
2801 * Encode LAYOUTRETURN request
2802 */
2803static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2804 struct xdr_stream *xdr,
2805 struct nfs4_layoutreturn_args *args)
2806{
2807 struct compound_hdr hdr = {
2808 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2809 };
2810
2811 encode_compound_hdr(xdr, req, &hdr);
2812 encode_sequence(xdr, &args->seq_args, &hdr);
2813 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2814 encode_layoutreturn(xdr, args, &hdr);
2815 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002816}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002817
2818/*
2819 * Encode SECINFO_NO_NAME request
2820 */
2821static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2822 struct xdr_stream *xdr,
2823 struct nfs41_secinfo_no_name_args *args)
2824{
2825 struct compound_hdr hdr = {
2826 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2827 };
2828
2829 encode_compound_hdr(xdr, req, &hdr);
2830 encode_sequence(xdr, &args->seq_args, &hdr);
2831 encode_putrootfh(xdr, &hdr);
2832 encode_secinfo_no_name(xdr, args, &hdr);
2833 encode_nops(&hdr);
2834 return 0;
2835}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002836
2837/*
2838 * Encode TEST_STATEID request
2839 */
2840static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2841 struct xdr_stream *xdr,
2842 struct nfs41_test_stateid_args *args)
2843{
2844 struct compound_hdr hdr = {
2845 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2846 };
2847
2848 encode_compound_hdr(xdr, req, &hdr);
2849 encode_sequence(xdr, &args->seq_args, &hdr);
2850 encode_test_stateid(xdr, args, &hdr);
2851 encode_nops(&hdr);
2852}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002853
2854/*
2855 * Encode FREE_STATEID request
2856 */
2857static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2858 struct xdr_stream *xdr,
2859 struct nfs41_free_stateid_args *args)
2860{
2861 struct compound_hdr hdr = {
2862 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2863 };
2864
2865 encode_compound_hdr(xdr, req, &hdr);
2866 encode_sequence(xdr, &args->seq_args, &hdr);
2867 encode_free_stateid(xdr, args, &hdr);
2868 encode_nops(&hdr);
2869}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002870#endif /* CONFIG_NFS_V4_1 */
2871
Benny Halevy686841b2009-08-14 17:19:48 +03002872static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2873{
2874 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2875 "Remaining buffer length is %tu words.\n",
2876 func, xdr->end - xdr->p);
2877}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878
Trond Myklebust683b57b2006-06-09 09:34:22 -04002879static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880{
Al Viro8687b632006-10-19 23:28:48 -07002881 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882
Benny Halevyc0eae662009-08-14 17:20:14 +03002883 p = xdr_inline_decode(xdr, 4);
2884 if (unlikely(!p))
2885 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002886 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002887 p = xdr_inline_decode(xdr, *len);
2888 if (unlikely(!p))
2889 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 *string = (char *)p;
2891 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002892out_overflow:
2893 print_overflow_msg(__func__, xdr);
2894 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895}
2896
2897static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2898{
Al Viro8687b632006-10-19 23:28:48 -07002899 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900
Benny Halevyc0eae662009-08-14 17:20:14 +03002901 p = xdr_inline_decode(xdr, 8);
2902 if (unlikely(!p))
2903 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002904 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002905 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002906
Benny Halevyc0eae662009-08-14 17:20:14 +03002907 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2908 if (unlikely(!p))
2909 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 hdr->tag = (char *)p;
2911 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002912 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002913 if (unlikely(hdr->nops < 1))
2914 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002916out_overflow:
2917 print_overflow_msg(__func__, xdr);
2918 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919}
2920
2921static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2922{
Al Viro8687b632006-10-19 23:28:48 -07002923 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 uint32_t opnum;
2925 int32_t nfserr;
2926
Benny Halevyc0eae662009-08-14 17:20:14 +03002927 p = xdr_inline_decode(xdr, 8);
2928 if (unlikely(!p))
2929 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002930 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002932 dprintk("nfs: Server returned operation"
2933 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 opnum, expected);
2935 return -EIO;
2936 }
Benny Halevycccddf42009-08-14 17:20:19 +03002937 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002939 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002941out_overflow:
2942 print_overflow_msg(__func__, xdr);
2943 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944}
2945
2946/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002947static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948{
Al Viro8687b632006-10-19 23:28:48 -07002949 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002950 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 char *str;
2952
Benny Halevyc0eae662009-08-14 17:20:14 +03002953 p = xdr_inline_decode(xdr, 12);
2954 if (likely(p))
2955 return decode_opaque_inline(xdr, &strlen, &str);
2956 print_overflow_msg(__func__, xdr);
2957 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958}
2959
2960static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2961{
Al Viro8687b632006-10-19 23:28:48 -07002962 uint32_t bmlen;
2963 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964
Benny Halevyc0eae662009-08-14 17:20:14 +03002965 p = xdr_inline_decode(xdr, 4);
2966 if (unlikely(!p))
2967 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002968 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969
Fred Isamandae100c2011-07-30 20:52:37 -04002970 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002971 p = xdr_inline_decode(xdr, (bmlen << 2));
2972 if (unlikely(!p))
2973 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002975 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04002976 if (bmlen > 1) {
2977 bitmap[1] = be32_to_cpup(p++);
2978 if (bmlen > 2)
2979 bitmap[2] = be32_to_cpup(p);
2980 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 }
2982 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002983out_overflow:
2984 print_overflow_msg(__func__, xdr);
2985 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986}
2987
Al Viro8687b632006-10-19 23:28:48 -07002988static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989{
Al Viro8687b632006-10-19 23:28:48 -07002990 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991
Benny Halevyc0eae662009-08-14 17:20:14 +03002992 p = xdr_inline_decode(xdr, 4);
2993 if (unlikely(!p))
2994 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002995 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 *savep = xdr->p;
2997 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002998out_overflow:
2999 print_overflow_msg(__func__, xdr);
3000 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001}
3002
3003static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3004{
3005 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003006 int ret;
3007 ret = decode_attr_bitmap(xdr, bitmask);
3008 if (unlikely(ret < 0))
3009 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3011 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003012 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3013 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3014 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 return 0;
3016}
3017
3018static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3019{
Al Viro8687b632006-10-19 23:28:48 -07003020 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003021 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022
3023 *type = 0;
3024 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3025 return -EIO;
3026 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003027 p = xdr_inline_decode(xdr, 4);
3028 if (unlikely(!p))
3029 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003030 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003032 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 return -EIO;
3034 }
3035 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003036 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003038 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003039 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003040out_overflow:
3041 print_overflow_msg(__func__, xdr);
3042 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043}
3044
Chuck Lever264e6352012-03-01 17:02:05 -05003045static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3046 uint32_t *bitmap, uint32_t *type)
3047{
3048 __be32 *p;
3049
3050 *type = 0;
3051 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3052 return -EIO;
3053 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3054 p = xdr_inline_decode(xdr, 4);
3055 if (unlikely(!p))
3056 goto out_overflow;
3057 *type = be32_to_cpup(p);
3058 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3059 }
3060 dprintk("%s: expire type=0x%x\n", __func__, *type);
3061 return 0;
3062out_overflow:
3063 print_overflow_msg(__func__, xdr);
3064 return -EIO;
3065}
3066
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3068{
Al Viro8687b632006-10-19 23:28:48 -07003069 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003070 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071
3072 *change = 0;
3073 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3074 return -EIO;
3075 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003076 p = xdr_inline_decode(xdr, 8);
3077 if (unlikely(!p))
3078 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003079 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003081 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003083 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003085 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003086out_overflow:
3087 print_overflow_msg(__func__, xdr);
3088 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089}
3090
3091static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3092{
Al Viro8687b632006-10-19 23:28:48 -07003093 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003094 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095
3096 *size = 0;
3097 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3098 return -EIO;
3099 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003100 p = xdr_inline_decode(xdr, 8);
3101 if (unlikely(!p))
3102 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003103 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003105 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003107 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003108 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003109out_overflow:
3110 print_overflow_msg(__func__, xdr);
3111 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112}
3113
3114static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3115{
Al Viro8687b632006-10-19 23:28:48 -07003116 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117
3118 *res = 0;
3119 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3120 return -EIO;
3121 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003122 p = xdr_inline_decode(xdr, 4);
3123 if (unlikely(!p))
3124 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003125 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3127 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003128 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003130out_overflow:
3131 print_overflow_msg(__func__, xdr);
3132 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133}
3134
3135static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3136{
Al Viro8687b632006-10-19 23:28:48 -07003137 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138
3139 *res = 0;
3140 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3141 return -EIO;
3142 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003143 p = xdr_inline_decode(xdr, 4);
3144 if (unlikely(!p))
3145 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003146 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3148 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003149 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003151out_overflow:
3152 print_overflow_msg(__func__, xdr);
3153 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154}
3155
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003156static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157{
Al Viro8687b632006-10-19 23:28:48 -07003158 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003159 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160
3161 fsid->major = 0;
3162 fsid->minor = 0;
3163 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3164 return -EIO;
3165 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003166 p = xdr_inline_decode(xdr, 16);
3167 if (unlikely(!p))
3168 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003169 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003170 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003172 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003174 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 (unsigned long long)fsid->major,
3176 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003177 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003178out_overflow:
3179 print_overflow_msg(__func__, xdr);
3180 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181}
3182
3183static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3184{
Al Viro8687b632006-10-19 23:28:48 -07003185 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186
3187 *res = 60;
3188 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3189 return -EIO;
3190 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003191 p = xdr_inline_decode(xdr, 4);
3192 if (unlikely(!p))
3193 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003194 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3196 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003197 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003199out_overflow:
3200 print_overflow_msg(__func__, xdr);
3201 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202}
3203
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003204static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003205{
3206 __be32 *p;
3207
3208 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3209 return -EIO;
3210 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3211 p = xdr_inline_decode(xdr, 4);
3212 if (unlikely(!p))
3213 goto out_overflow;
3214 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003215 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003216 }
3217 return 0;
3218out_overflow:
3219 print_overflow_msg(__func__, xdr);
3220 return -EIO;
3221}
3222
3223static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3224{
3225 __be32 *p;
3226 int len;
3227
Trond Myklebust7ad07352010-10-23 15:34:20 -04003228 if (fh != NULL)
3229 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003230
3231 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3232 return -EIO;
3233 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3234 p = xdr_inline_decode(xdr, 4);
3235 if (unlikely(!p))
3236 goto out_overflow;
3237 len = be32_to_cpup(p);
3238 if (len > NFS4_FHSIZE)
3239 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003240 p = xdr_inline_decode(xdr, len);
3241 if (unlikely(!p))
3242 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003243 if (fh != NULL) {
3244 memcpy(fh->data, p, len);
3245 fh->size = len;
3246 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003247 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3248 }
3249 return 0;
3250out_overflow:
3251 print_overflow_msg(__func__, xdr);
3252 return -EIO;
3253}
3254
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3256{
Al Viro8687b632006-10-19 23:28:48 -07003257 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258
3259 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3260 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3261 return -EIO;
3262 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003263 p = xdr_inline_decode(xdr, 4);
3264 if (unlikely(!p))
3265 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003266 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3268 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003269 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003271out_overflow:
3272 print_overflow_msg(__func__, xdr);
3273 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274}
3275
3276static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3277{
Al Viro8687b632006-10-19 23:28:48 -07003278 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003279 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280
3281 *fileid = 0;
3282 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3283 return -EIO;
3284 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003285 p = xdr_inline_decode(xdr, 8);
3286 if (unlikely(!p))
3287 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003288 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003290 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003292 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003293 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003294out_overflow:
3295 print_overflow_msg(__func__, xdr);
3296 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297}
3298
Manoj Naik99baf622006-06-09 09:34:24 -04003299static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3300{
Al Viro8687b632006-10-19 23:28:48 -07003301 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003302 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003303
3304 *fileid = 0;
3305 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3306 return -EIO;
3307 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003308 p = xdr_inline_decode(xdr, 8);
3309 if (unlikely(!p))
3310 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003311 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003312 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003313 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003314 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003315 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003316 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003317out_overflow:
3318 print_overflow_msg(__func__, xdr);
3319 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003320}
3321
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3323{
Al Viro8687b632006-10-19 23:28:48 -07003324 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 int status = 0;
3326
3327 *res = 0;
3328 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3329 return -EIO;
3330 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
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, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3336 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003337 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003339out_overflow:
3340 print_overflow_msg(__func__, xdr);
3341 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342}
3343
3344static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3345{
Al Viro8687b632006-10-19 23:28:48 -07003346 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347 int status = 0;
3348
3349 *res = 0;
3350 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3351 return -EIO;
3352 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003353 p = xdr_inline_decode(xdr, 8);
3354 if (unlikely(!p))
3355 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003356 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3358 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003359 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003361out_overflow:
3362 print_overflow_msg(__func__, xdr);
3363 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364}
3365
3366static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3367{
Al Viro8687b632006-10-19 23:28:48 -07003368 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369 int status = 0;
3370
3371 *res = 0;
3372 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3373 return -EIO;
3374 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003375 p = xdr_inline_decode(xdr, 8);
3376 if (unlikely(!p))
3377 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003378 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3380 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003381 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003383out_overflow:
3384 print_overflow_msg(__func__, xdr);
3385 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386}
3387
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003388static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3389{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003390 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003391 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003392 int status = 0;
3393
Benny Halevyc0eae662009-08-14 17:20:14 +03003394 p = xdr_inline_decode(xdr, 4);
3395 if (unlikely(!p))
3396 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003397 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003398 if (n == 0)
3399 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003400 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003401 path->ncomponents = 0;
3402 while (path->ncomponents < n) {
3403 struct nfs4_string *component = &path->components[path->ncomponents];
3404 status = decode_opaque_inline(xdr, &component->len, &component->data);
3405 if (unlikely(status != 0))
3406 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003407 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003408 pr_cont("%s%.*s ",
3409 (path->ncomponents != n ? "/ " : ""),
3410 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003411 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3412 path->ncomponents++;
3413 else {
3414 dprintk("cannot parse %d components in path\n", n);
3415 goto out_eio;
3416 }
3417 }
3418out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003419 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003420root_path:
3421/* a root pathname is sent as a zero component4 */
3422 path->ncomponents = 1;
3423 path->components[0].len=0;
3424 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003425 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003426 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003427out_eio:
3428 dprintk(" status %d", status);
3429 status = -EIO;
3430 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003431out_overflow:
3432 print_overflow_msg(__func__, xdr);
3433 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003434}
3435
3436static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003437{
3438 int n;
Al Viro8687b632006-10-19 23:28:48 -07003439 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003440 int status = -EIO;
3441
3442 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3443 goto out;
3444 status = 0;
3445 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3446 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003447 status = -EIO;
3448 /* Ignore borken servers that return unrequested attrs */
3449 if (unlikely(res == NULL))
3450 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003451 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003452 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003453 if (unlikely(status != 0))
3454 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003455 p = xdr_inline_decode(xdr, 4);
3456 if (unlikely(!p))
3457 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003458 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003459 if (n <= 0)
3460 goto out_eio;
3461 res->nlocations = 0;
3462 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003463 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003464 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003465
Benny Halevyc0eae662009-08-14 17:20:14 +03003466 p = xdr_inline_decode(xdr, 4);
3467 if (unlikely(!p))
3468 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003469 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003470
3471 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003472 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003473 while (loc->nservers < m) {
3474 struct nfs4_string *server = &loc->servers[loc->nservers];
3475 status = decode_opaque_inline(xdr, &server->len, &server->data);
3476 if (unlikely(status != 0))
3477 goto out_eio;
3478 dprintk("%s ", server->data);
3479 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3480 loc->nservers++;
3481 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003482 unsigned int i;
3483 dprintk("%s: using first %u of %u servers "
3484 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003485 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003486 NFS4_FS_LOCATION_MAXSERVERS,
3487 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003488 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003489 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003490 char *data;
3491 status = decode_opaque_inline(xdr, &len, &data);
3492 if (unlikely(status != 0))
3493 goto out_eio;
3494 }
3495 }
3496 }
3497 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003498 if (unlikely(status != 0))
3499 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003500 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003501 res->nlocations++;
3502 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003503 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003504 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003505out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003506 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003507 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003508out_overflow:
3509 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003510out_eio:
3511 status = -EIO;
3512 goto out;
3513}
3514
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3516{
Al Viro8687b632006-10-19 23:28:48 -07003517 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 int status = 0;
3519
3520 *res = 0;
3521 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3522 return -EIO;
3523 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003524 p = xdr_inline_decode(xdr, 8);
3525 if (unlikely(!p))
3526 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003527 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3529 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003530 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003532out_overflow:
3533 print_overflow_msg(__func__, xdr);
3534 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535}
3536
3537static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3538{
Al Viro8687b632006-10-19 23:28:48 -07003539 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 int status = 0;
3541
3542 *maxlink = 1;
3543 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3544 return -EIO;
3545 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003546 p = xdr_inline_decode(xdr, 4);
3547 if (unlikely(!p))
3548 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003549 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3551 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003552 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003554out_overflow:
3555 print_overflow_msg(__func__, xdr);
3556 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557}
3558
3559static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3560{
Al Viro8687b632006-10-19 23:28:48 -07003561 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 int status = 0;
3563
3564 *maxname = 1024;
3565 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3566 return -EIO;
3567 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003568 p = xdr_inline_decode(xdr, 4);
3569 if (unlikely(!p))
3570 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003571 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3573 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003574 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003576out_overflow:
3577 print_overflow_msg(__func__, xdr);
3578 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579}
3580
3581static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3582{
Al Viro8687b632006-10-19 23:28:48 -07003583 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584 int status = 0;
3585
3586 *res = 1024;
3587 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3588 return -EIO;
3589 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3590 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003591 p = xdr_inline_decode(xdr, 8);
3592 if (unlikely(!p))
3593 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003594 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595 if (maxread > 0x7FFFFFFF)
3596 maxread = 0x7FFFFFFF;
3597 *res = (uint32_t)maxread;
3598 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3599 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003600 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003602out_overflow:
3603 print_overflow_msg(__func__, xdr);
3604 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605}
3606
3607static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3608{
Al Viro8687b632006-10-19 23:28:48 -07003609 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 int status = 0;
3611
3612 *res = 1024;
3613 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3614 return -EIO;
3615 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3616 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003617 p = xdr_inline_decode(xdr, 8);
3618 if (unlikely(!p))
3619 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003620 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 if (maxwrite > 0x7FFFFFFF)
3622 maxwrite = 0x7FFFFFFF;
3623 *res = (uint32_t)maxwrite;
3624 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3625 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003626 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003628out_overflow:
3629 print_overflow_msg(__func__, xdr);
3630 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631}
3632
Trond Myklebustbca79472009-03-11 14:10:26 -04003633static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634{
Trond Myklebustbca79472009-03-11 14:10:26 -04003635 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003636 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003637 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638
3639 *mode = 0;
3640 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3641 return -EIO;
3642 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003643 p = xdr_inline_decode(xdr, 4);
3644 if (unlikely(!p))
3645 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003646 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003647 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003649 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003651 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003652 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003653out_overflow:
3654 print_overflow_msg(__func__, xdr);
3655 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656}
3657
3658static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3659{
Al Viro8687b632006-10-19 23:28:48 -07003660 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003661 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662
3663 *nlink = 1;
3664 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3665 return -EIO;
3666 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003667 p = xdr_inline_decode(xdr, 4);
3668 if (unlikely(!p))
3669 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003670 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003672 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003674 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003675 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003676out_overflow:
3677 print_overflow_msg(__func__, xdr);
3678 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679}
3680
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003681static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003682 const struct nfs_server *server, uint32_t *uid,
3683 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684{
Al Viro8687b632006-10-19 23:28:48 -07003685 uint32_t len;
3686 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003687 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688
3689 *uid = -2;
3690 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3691 return -EIO;
3692 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003693 p = xdr_inline_decode(xdr, 4);
3694 if (unlikely(!p))
3695 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003696 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003697 p = xdr_inline_decode(xdr, len);
3698 if (unlikely(!p))
3699 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003700 if (owner_name != NULL) {
3701 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3702 if (owner_name->data != NULL) {
3703 owner_name->len = len;
3704 ret = NFS_ATTR_FATTR_OWNER_NAME;
3705 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003706 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003707 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003708 ret = NFS_ATTR_FATTR_OWNER;
3709 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003711 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003713 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003714 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3716 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003717 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003718 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003719out_overflow:
3720 print_overflow_msg(__func__, xdr);
3721 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722}
3723
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003724static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003725 const struct nfs_server *server, uint32_t *gid,
3726 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727{
Al Viro8687b632006-10-19 23:28:48 -07003728 uint32_t len;
3729 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003730 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731
3732 *gid = -2;
3733 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3734 return -EIO;
3735 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003736 p = xdr_inline_decode(xdr, 4);
3737 if (unlikely(!p))
3738 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003739 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003740 p = xdr_inline_decode(xdr, len);
3741 if (unlikely(!p))
3742 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003743 if (group_name != NULL) {
3744 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3745 if (group_name->data != NULL) {
3746 group_name->len = len;
3747 ret = NFS_ATTR_FATTR_GROUP_NAME;
3748 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003749 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003750 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003751 ret = NFS_ATTR_FATTR_GROUP;
3752 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003754 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003756 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003757 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3759 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003760 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003761 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003762out_overflow:
3763 print_overflow_msg(__func__, xdr);
3764 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765}
3766
3767static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3768{
Al Viro8687b632006-10-19 23:28:48 -07003769 uint32_t major = 0, minor = 0;
3770 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003771 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772
3773 *rdev = MKDEV(0,0);
3774 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3775 return -EIO;
3776 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3777 dev_t tmp;
3778
Benny Halevyc0eae662009-08-14 17:20:14 +03003779 p = xdr_inline_decode(xdr, 8);
3780 if (unlikely(!p))
3781 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003782 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003783 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 tmp = MKDEV(major, minor);
3785 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3786 *rdev = tmp;
3787 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003788 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003790 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003791 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003792out_overflow:
3793 print_overflow_msg(__func__, xdr);
3794 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795}
3796
3797static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3798{
Al Viro8687b632006-10-19 23:28:48 -07003799 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 int status = 0;
3801
3802 *res = 0;
3803 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3804 return -EIO;
3805 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003806 p = xdr_inline_decode(xdr, 8);
3807 if (unlikely(!p))
3808 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003809 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3811 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003812 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003814out_overflow:
3815 print_overflow_msg(__func__, xdr);
3816 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817}
3818
3819static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3820{
Al Viro8687b632006-10-19 23:28:48 -07003821 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 int status = 0;
3823
3824 *res = 0;
3825 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3826 return -EIO;
3827 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003828 p = xdr_inline_decode(xdr, 8);
3829 if (unlikely(!p))
3830 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003831 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3833 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003834 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003836out_overflow:
3837 print_overflow_msg(__func__, xdr);
3838 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839}
3840
3841static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3842{
Al Viro8687b632006-10-19 23:28:48 -07003843 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 int status = 0;
3845
3846 *res = 0;
3847 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3848 return -EIO;
3849 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003850 p = xdr_inline_decode(xdr, 8);
3851 if (unlikely(!p))
3852 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003853 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3855 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003856 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003858out_overflow:
3859 print_overflow_msg(__func__, xdr);
3860 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861}
3862
3863static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3864{
Al Viro8687b632006-10-19 23:28:48 -07003865 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003866 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867
3868 *used = 0;
3869 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3870 return -EIO;
3871 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003872 p = xdr_inline_decode(xdr, 8);
3873 if (unlikely(!p))
3874 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003875 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003877 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003879 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003881 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003882out_overflow:
3883 print_overflow_msg(__func__, xdr);
3884 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885}
3886
3887static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3888{
Al Viro8687b632006-10-19 23:28:48 -07003889 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 uint64_t sec;
3891 uint32_t nsec;
3892
Benny Halevyc0eae662009-08-14 17:20:14 +03003893 p = xdr_inline_decode(xdr, 12);
3894 if (unlikely(!p))
3895 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003896 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003897 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 time->tv_sec = (time_t)sec;
3899 time->tv_nsec = (long)nsec;
3900 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003901out_overflow:
3902 print_overflow_msg(__func__, xdr);
3903 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904}
3905
3906static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3907{
3908 int status = 0;
3909
3910 time->tv_sec = 0;
3911 time->tv_nsec = 0;
3912 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3913 return -EIO;
3914 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3915 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003916 if (status == 0)
3917 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3919 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003920 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 return status;
3922}
3923
3924static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3925{
3926 int status = 0;
3927
3928 time->tv_sec = 0;
3929 time->tv_nsec = 0;
3930 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3931 return -EIO;
3932 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3933 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003934 if (status == 0)
3935 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3937 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003938 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 return status;
3940}
3941
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003942static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3943 struct timespec *time)
3944{
3945 int status = 0;
3946
3947 time->tv_sec = 0;
3948 time->tv_nsec = 0;
3949 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3950 return -EIO;
3951 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3952 status = decode_attr_time(xdr, time);
3953 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3954 }
3955 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3956 (long)time->tv_nsec);
3957 return status;
3958}
3959
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3961{
3962 int status = 0;
3963
3964 time->tv_sec = 0;
3965 time->tv_nsec = 0;
3966 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3967 return -EIO;
3968 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3969 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003970 if (status == 0)
3971 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3973 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003974 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975 return status;
3976}
3977
Al Viro8687b632006-10-19 23:28:48 -07003978static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979{
3980 unsigned int attrwords = XDR_QUADLEN(attrlen);
3981 unsigned int nwords = xdr->p - savep;
3982
3983 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003984 dprintk("%s: server returned incorrect attribute length: "
3985 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003986 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 attrwords << 2,
3988 (attrwords < nwords) ? '<' : '>',
3989 nwords << 2);
3990 return -EIO;
3991 }
3992 return 0;
3993}
3994
3995static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3996{
Al Viro8687b632006-10-19 23:28:48 -07003997 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998
Benny Halevyc0eae662009-08-14 17:20:14 +03003999 p = xdr_inline_decode(xdr, 20);
4000 if (unlikely(!p))
4001 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004002 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004003 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004004 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004006out_overflow:
4007 print_overflow_msg(__func__, xdr);
4008 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009}
4010
4011static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4012{
Al Viro8687b632006-10-19 23:28:48 -07004013 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 uint32_t supp, acc;
4015 int status;
4016
4017 status = decode_op_hdr(xdr, OP_ACCESS);
4018 if (status)
4019 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004020 p = xdr_inline_decode(xdr, 8);
4021 if (unlikely(!p))
4022 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004023 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004024 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025 access->supported = supp;
4026 access->access = acc;
4027 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004028out_overflow:
4029 print_overflow_msg(__func__, xdr);
4030 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031}
4032
Benny Halevy07d30432009-08-14 17:19:52 +03004033static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034{
Al Viro8687b632006-10-19 23:28:48 -07004035 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004036
4037 p = xdr_inline_decode(xdr, len);
4038 if (likely(p)) {
4039 memcpy(buf, p, len);
4040 return 0;
4041 }
4042 print_overflow_msg(__func__, xdr);
4043 return -EIO;
4044}
4045
4046static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4047{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004048 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049}
4050
4051static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4052{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053 int status;
4054
4055 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004056 if (status != -EIO)
4057 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004058 if (!status)
4059 status = decode_stateid(xdr, &res->stateid);
4060 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061}
4062
Benny Halevydb942bb2009-08-14 17:19:56 +03004063static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4064{
Chuck Levercd937102012-03-02 17:14:31 -05004065 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066}
4067
Fred Isaman0b7c0152012-04-20 14:47:39 -04004068static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 int status;
4071
4072 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004073 if (!status)
4074 status = decode_verifier(xdr, res->verf->verifier);
4075 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076}
4077
4078static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4079{
Al Viro8687b632006-10-19 23:28:48 -07004080 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 uint32_t bmlen;
4082 int status;
4083
4084 status = decode_op_hdr(xdr, OP_CREATE);
4085 if (status)
4086 return status;
4087 if ((status = decode_change_info(xdr, cinfo)))
4088 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004089 p = xdr_inline_decode(xdr, 4);
4090 if (unlikely(!p))
4091 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004092 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004093 p = xdr_inline_decode(xdr, bmlen << 2);
4094 if (likely(p))
4095 return 0;
4096out_overflow:
4097 print_overflow_msg(__func__, xdr);
4098 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099}
4100
4101static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4102{
Al Viro8687b632006-10-19 23:28:48 -07004103 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004104 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105 int status;
4106
4107 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4108 goto xdr_error;
4109 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4110 goto xdr_error;
4111 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4112 goto xdr_error;
4113 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4114 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004115 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4116 &res->fh_expire_type)) != 0)
4117 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4119 goto xdr_error;
4120 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4121 goto xdr_error;
4122 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4123 goto xdr_error;
4124 status = verify_attr_len(xdr, savep, attrlen);
4125xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004126 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127 return status;
4128}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004129
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4131{
Al Viro8687b632006-10-19 23:28:48 -07004132 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004133 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004135
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4137 goto xdr_error;
4138 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4139 goto xdr_error;
4140 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4141 goto xdr_error;
4142
4143 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4144 goto xdr_error;
4145 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4146 goto xdr_error;
4147 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4148 goto xdr_error;
4149 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4150 goto xdr_error;
4151 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4152 goto xdr_error;
4153 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4154 goto xdr_error;
4155
4156 status = verify_attr_len(xdr, savep, attrlen);
4157xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004158 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 return status;
4160}
4161
4162static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4163{
Al Viro8687b632006-10-19 23:28:48 -07004164 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004165 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004167
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4169 goto xdr_error;
4170 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4171 goto xdr_error;
4172 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4173 goto xdr_error;
4174
4175 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4176 goto xdr_error;
4177 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4178 goto xdr_error;
4179
4180 status = verify_attr_len(xdr, savep, attrlen);
4181xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004182 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183 return status;
4184}
4185
Bryan Schumakerae42c702010-10-21 16:33:17 -04004186static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4187 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004188 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004189 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190{
Trond Myklebustbca79472009-03-11 14:10:26 -04004191 int status;
4192 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004193 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004194 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004196 status = decode_attr_type(xdr, bitmap, &type);
4197 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004199 fattr->mode = 0;
4200 if (status != 0) {
4201 fattr->mode |= nfs_type2fmt[type];
4202 fattr->valid |= status;
4203 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004205 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4206 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004208 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004209
4210 status = decode_attr_size(xdr, bitmap, &fattr->size);
4211 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004213 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004214
4215 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4216 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004218 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004219
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004220 err = 0;
4221 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004222 if (status < 0)
4223 goto xdr_error;
4224
4225 status = decode_attr_filehandle(xdr, bitmap, fh);
4226 if (status < 0)
4227 goto xdr_error;
4228
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004229 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4230 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004232 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004233
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004234 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004235 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004236 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004237 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004238
4239 status = decode_attr_mode(xdr, bitmap, &fmode);
4240 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004242 if (status != 0) {
4243 fattr->mode |= fmode;
4244 fattr->valid |= status;
4245 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004246
4247 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4248 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004250 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004251
Trond Myklebust6926afd2012-01-07 13:22:46 -05004252 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004253 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004255 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004256
Trond Myklebust6926afd2012-01-07 13:22:46 -05004257 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004258 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004259 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004260 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004261
4262 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4263 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004265 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004266
4267 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4268 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004270 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004271
4272 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4273 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004275 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004276
4277 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4278 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004280 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004281
4282 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4283 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004284 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004285 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004286
Trond Myklebust28331a42011-04-27 13:47:52 -04004287 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004288 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004289 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004290 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004291
Bryan Schumakerae42c702010-10-21 16:33:17 -04004292xdr_error:
4293 dprintk("%s: xdr returned %d\n", __func__, -status);
4294 return status;
4295}
4296
4297static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004298 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4299 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004300{
4301 __be32 *savep;
4302 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004303 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004304 int status;
4305
4306 status = decode_op_hdr(xdr, OP_GETATTR);
4307 if (status < 0)
4308 goto xdr_error;
4309
4310 status = decode_attr_bitmap(xdr, bitmap);
4311 if (status < 0)
4312 goto xdr_error;
4313
4314 status = decode_attr_length(xdr, &attrlen, &savep);
4315 if (status < 0)
4316 goto xdr_error;
4317
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004318 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004319 if (status < 0)
4320 goto xdr_error;
4321
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004322 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004324 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325 return status;
4326}
4327
Bryan Schumakerae42c702010-10-21 16:33:17 -04004328static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004329 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004330{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004331 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004332}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333
Andy Adamson504913f2010-10-20 00:17:57 -04004334/*
4335 * Decode potentially multiple layout types. Currently we only support
4336 * one layout driver per file system.
4337 */
4338static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4339 uint32_t *layouttype)
4340{
4341 uint32_t *p;
4342 int num;
4343
4344 p = xdr_inline_decode(xdr, 4);
4345 if (unlikely(!p))
4346 goto out_overflow;
4347 num = be32_to_cpup(p);
4348
4349 /* pNFS is not supported by the underlying file system */
4350 if (num == 0) {
4351 *layouttype = 0;
4352 return 0;
4353 }
4354 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004355 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4356 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004357
4358 /* Decode and set first layout type, move xdr->p past unused types */
4359 p = xdr_inline_decode(xdr, num * 4);
4360 if (unlikely(!p))
4361 goto out_overflow;
4362 *layouttype = be32_to_cpup(p);
4363 return 0;
4364out_overflow:
4365 print_overflow_msg(__func__, xdr);
4366 return -EIO;
4367}
4368
4369/*
4370 * The type of file system exported.
4371 * Note we must ensure that layouttype is set in any non-error case.
4372 */
4373static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4374 uint32_t *layouttype)
4375{
4376 int status = 0;
4377
4378 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4379 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4380 return -EIO;
4381 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4382 status = decode_first_pnfs_layout_type(xdr, layouttype);
4383 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4384 } else
4385 *layouttype = 0;
4386 return status;
4387}
4388
Fred Isamandae100c2011-07-30 20:52:37 -04004389/*
4390 * The prefered block size for layout directed io
4391 */
4392static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4393 uint32_t *res)
4394{
4395 __be32 *p;
4396
4397 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4398 *res = 0;
4399 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4400 p = xdr_inline_decode(xdr, 4);
4401 if (unlikely(!p)) {
4402 print_overflow_msg(__func__, xdr);
4403 return -EIO;
4404 }
4405 *res = be32_to_cpup(p);
4406 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4407 }
4408 return 0;
4409}
4410
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4412{
Al Viro8687b632006-10-19 23:28:48 -07004413 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004414 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415 int status;
4416
4417 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4418 goto xdr_error;
4419 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4420 goto xdr_error;
4421 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4422 goto xdr_error;
4423
4424 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4425
4426 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4427 goto xdr_error;
4428 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4429 goto xdr_error;
4430 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4431 goto xdr_error;
4432 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4433 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4434 goto xdr_error;
4435 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004436 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4437 if (status != 0)
4438 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004439 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4440 if (status != 0)
4441 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004442 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4443 if (status)
4444 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445
4446 status = verify_attr_len(xdr, savep, attrlen);
4447xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004448 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449 return status;
4450}
4451
4452static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4453{
Al Viro8687b632006-10-19 23:28:48 -07004454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455 uint32_t len;
4456 int status;
4457
Trond Myklebust99367812007-07-17 21:52:41 -04004458 /* Zero handle first to allow comparisons */
4459 memset(fh, 0, sizeof(*fh));
4460
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461 status = decode_op_hdr(xdr, OP_GETFH);
4462 if (status)
4463 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464
Benny Halevyc0eae662009-08-14 17:20:14 +03004465 p = xdr_inline_decode(xdr, 4);
4466 if (unlikely(!p))
4467 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004468 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 if (len > NFS4_FHSIZE)
4470 return -EIO;
4471 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004472 p = xdr_inline_decode(xdr, len);
4473 if (unlikely(!p))
4474 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004475 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004477out_overflow:
4478 print_overflow_msg(__func__, xdr);
4479 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480}
4481
4482static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4483{
4484 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004485
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486 status = decode_op_hdr(xdr, OP_LINK);
4487 if (status)
4488 return status;
4489 return decode_change_info(xdr, cinfo);
4490}
4491
4492/*
4493 * We create the owner, so we know a proper owner.id length is 4.
4494 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004495static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004497 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004498 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004499 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004500
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004501 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004502 if (unlikely(!p))
4503 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004504 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004505 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004506 type = be32_to_cpup(p++); /* 4 byte read */
4507 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004508 fl->fl_start = (loff_t)offset;
4509 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4510 if (length == ~(uint64_t)0)
4511 fl->fl_end = OFFSET_MAX;
4512 fl->fl_type = F_WRLCK;
4513 if (type & 1)
4514 fl->fl_type = F_RDLCK;
4515 fl->fl_pid = 0;
4516 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004517 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4518 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4519 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004520 if (likely(p))
4521 return -NFS4ERR_DENIED;
4522out_overflow:
4523 print_overflow_msg(__func__, xdr);
4524 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525}
4526
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004527static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529 int status;
4530
4531 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004532 if (status == -EIO)
4533 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004535 status = decode_stateid(xdr, &res->stateid);
4536 if (unlikely(status))
4537 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004539 status = decode_lock_denied(xdr, NULL);
4540 if (res->open_seqid != NULL)
4541 nfs_increment_open_seqid(status, res->open_seqid);
4542 nfs_increment_lock_seqid(status, res->lock_seqid);
4543out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004544 return status;
4545}
4546
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004547static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548{
4549 int status;
4550 status = decode_op_hdr(xdr, OP_LOCKT);
4551 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004552 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553 return status;
4554}
4555
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004556static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004558 int status;
4559
4560 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004561 if (status != -EIO)
4562 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004563 if (status == 0)
4564 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004565 return status;
4566}
4567
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004568static int decode_release_lockowner(struct xdr_stream *xdr)
4569{
4570 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4571}
4572
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573static int decode_lookup(struct xdr_stream *xdr)
4574{
4575 return decode_op_hdr(xdr, OP_LOOKUP);
4576}
4577
4578/* This is too sick! */
4579static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4580{
Andy Adamson05d564f2008-12-23 16:06:15 -05004581 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582 uint32_t limit_type, nblocks, blocksize;
4583
Benny Halevyc0eae662009-08-14 17:20:14 +03004584 p = xdr_inline_decode(xdr, 12);
4585 if (unlikely(!p))
4586 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004587 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004588 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004589 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004590 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004591 break;
4592 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004593 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004594 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004595 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596 }
4597 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004598out_overflow:
4599 print_overflow_msg(__func__, xdr);
4600 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601}
4602
4603static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4604{
Andy Adamson05d564f2008-12-23 16:06:15 -05004605 __be32 *p;
4606 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004607 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608
Benny Halevyc0eae662009-08-14 17:20:14 +03004609 p = xdr_inline_decode(xdr, 4);
4610 if (unlikely(!p))
4611 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004612 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4614 res->delegation_type = 0;
4615 return 0;
4616 }
Benny Halevy07d30432009-08-14 17:19:52 +03004617 status = decode_stateid(xdr, &res->delegation);
4618 if (unlikely(status))
4619 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004620 p = xdr_inline_decode(xdr, 4);
4621 if (unlikely(!p))
4622 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004623 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004624
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004626 case NFS4_OPEN_DELEGATE_READ:
4627 res->delegation_type = FMODE_READ;
4628 break;
4629 case NFS4_OPEN_DELEGATE_WRITE:
4630 res->delegation_type = FMODE_WRITE|FMODE_READ;
4631 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632 return -EIO;
4633 }
David Howells7539bba2006-08-22 20:06:09 -04004634 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004635out_overflow:
4636 print_overflow_msg(__func__, xdr);
4637 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638}
4639
4640static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4641{
Andy Adamson05d564f2008-12-23 16:06:15 -05004642 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004643 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004644 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645
Andy Adamson05d564f2008-12-23 16:06:15 -05004646 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004647 if (status != -EIO)
4648 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004649 if (!status)
4650 status = decode_stateid(xdr, &res->stateid);
4651 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004652 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004653
Andy Adamson05d564f2008-12-23 16:06:15 -05004654 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655
Benny Halevyc0eae662009-08-14 17:20:14 +03004656 p = xdr_inline_decode(xdr, 8);
4657 if (unlikely(!p))
4658 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004659 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004660 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004661 if (bmlen > 10)
4662 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004663
Benny Halevyc0eae662009-08-14 17:20:14 +03004664 p = xdr_inline_decode(xdr, bmlen << 2);
4665 if (unlikely(!p))
4666 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004667 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4668 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004669 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004670 for (; i < NFS4_BITMAP_SIZE; i++)
4671 res->attrset[i] = 0;
4672
Linus Torvalds1da177e2005-04-16 15:20:36 -07004673 return decode_delegation(xdr, res);
4674xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004675 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004676 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004677out_overflow:
4678 print_overflow_msg(__func__, xdr);
4679 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004680}
4681
4682static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4683{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684 int status;
4685
Andy Adamson05d564f2008-12-23 16:06:15 -05004686 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004687 if (status != -EIO)
4688 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004689 if (!status)
4690 status = decode_stateid(xdr, &res->stateid);
4691 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004692}
4693
4694static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4695{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696 int status;
4697
4698 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004699 if (status != -EIO)
4700 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004701 if (!status)
4702 status = decode_stateid(xdr, &res->stateid);
4703 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004704}
4705
4706static int decode_putfh(struct xdr_stream *xdr)
4707{
4708 return decode_op_hdr(xdr, OP_PUTFH);
4709}
4710
4711static int decode_putrootfh(struct xdr_stream *xdr)
4712{
4713 return decode_op_hdr(xdr, OP_PUTROOTFH);
4714}
4715
4716static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4717{
4718 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004719 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720 uint32_t count, eof, recvd, hdrlen;
4721 int status;
4722
4723 status = decode_op_hdr(xdr, OP_READ);
4724 if (status)
4725 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004726 p = xdr_inline_decode(xdr, 8);
4727 if (unlikely(!p))
4728 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004729 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004730 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004731 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732 recvd = req->rq_rcv_buf.len - hdrlen;
4733 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004734 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 "count %u > recvd %u\n", count, recvd);
4736 count = recvd;
4737 eof = 0;
4738 }
4739 xdr_read_pages(xdr, count);
4740 res->eof = eof;
4741 res->count = count;
4742 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004743out_overflow:
4744 print_overflow_msg(__func__, xdr);
4745 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746}
4747
4748static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4749{
4750 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004752 size_t hdrlen;
4753 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004754 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004755 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756
4757 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004758 if (!status)
4759 status = decode_verifier(xdr, readdir->verifier.data);
4760 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004761 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004762 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004763 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004764 __func__, verf[0], verf[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765
Benny Halevydb942bb2009-08-14 17:19:56 +03004766 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 recvd = rcvbuf->len - hdrlen;
4768 if (pglen > recvd)
4769 pglen = recvd;
4770 xdr_read_pages(xdr, pglen);
4771
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004772
Trond Myklebustac396122010-11-15 20:26:22 -05004773 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774}
4775
4776static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4777{
4778 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4779 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004780 size_t hdrlen;
4781 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004782 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 int status;
4784
4785 status = decode_op_hdr(xdr, OP_READLINK);
4786 if (status)
4787 return status;
4788
4789 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004790 p = xdr_inline_decode(xdr, 4);
4791 if (unlikely(!p))
4792 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004793 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004795 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004796 return -ENAMETOOLONG;
4797 }
4798 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4799 recvd = req->rq_rcv_buf.len - hdrlen;
4800 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004801 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802 "count %u > recvd %u\n", len, recvd);
4803 return -EIO;
4804 }
4805 xdr_read_pages(xdr, len);
4806 /*
4807 * The XDR encode routine has set things up so that
4808 * the link text will be copied directly into the
4809 * buffer. We just have to do overflow-checking,
4810 * and and null-terminate the text (the VFS expects
4811 * null-termination).
4812 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004813 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004815out_overflow:
4816 print_overflow_msg(__func__, xdr);
4817 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818}
4819
4820static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4821{
4822 int status;
4823
4824 status = decode_op_hdr(xdr, OP_REMOVE);
4825 if (status)
4826 goto out;
4827 status = decode_change_info(xdr, cinfo);
4828out:
4829 return status;
4830}
4831
4832static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4833 struct nfs4_change_info *new_cinfo)
4834{
4835 int status;
4836
4837 status = decode_op_hdr(xdr, OP_RENAME);
4838 if (status)
4839 goto out;
4840 if ((status = decode_change_info(xdr, old_cinfo)))
4841 goto out;
4842 status = decode_change_info(xdr, new_cinfo);
4843out:
4844 return status;
4845}
4846
4847static int decode_renew(struct xdr_stream *xdr)
4848{
4849 return decode_op_hdr(xdr, OP_RENEW);
4850}
4851
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004852static int
4853decode_restorefh(struct xdr_stream *xdr)
4854{
4855 return decode_op_hdr(xdr, OP_RESTOREFH);
4856}
4857
J. Bruce Fields029d1052005-06-22 17:16:22 +00004858static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05004859 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004860{
Andy Adamsonbf118a32011-12-07 11:55:27 -05004861 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004862 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004863 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00004864 struct kvec *iov = req->rq_rcv_buf.head;
4865 int status;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004866 size_t page_len = xdr->buf->page_len;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004867
Andy Adamsonbf118a32011-12-07 11:55:27 -05004868 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004869 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4870 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004871
Andy Adamsonbf118a32011-12-07 11:55:27 -05004872 bm_p = xdr->p;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004873 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4874 res->acl_data_offset <<= 2;
4875 /* Check if the acl data starts beyond the allocated buffer */
4876 if (res->acl_data_offset > page_len)
4877 return -ERANGE;
4878
J. Bruce Fields029d1052005-06-22 17:16:22 +00004879 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4880 goto out;
4881 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4882 goto out;
4883
4884 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4885 return -EIO;
4886 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004887 size_t hdrlen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004888
Andy Adamsonbf118a32011-12-07 11:55:27 -05004889 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
4890 * are stored with the acl data to handle the problem of
4891 * variable length bitmaps.*/
4892 xdr->p = bm_p;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004893
J. Bruce Fields029d1052005-06-22 17:16:22 +00004894 /* We ignore &savep and don't do consistency checks on
4895 * the attr length. Let userspace figure it out.... */
4896 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004897 attrlen += res->acl_data_offset;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004898 if (attrlen > page_len) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05004899 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
4900 /* getxattr interface called with a NULL buf */
4901 res->acl_len = attrlen;
4902 goto out;
4903 }
Sachin Prabhu5794d212012-04-17 14:36:40 +01004904 dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
Sachin Prabhu5a006892012-04-17 14:35:39 +01004905 attrlen, page_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004906 return -EINVAL;
4907 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004908 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05004909 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004910 } else
4911 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004912
4913out:
4914 return status;
4915}
4916
Linus Torvalds1da177e2005-04-16 15:20:36 -07004917static int
4918decode_savefh(struct xdr_stream *xdr)
4919{
4920 return decode_op_hdr(xdr, OP_SAVEFH);
4921}
4922
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004923static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004924{
Al Viro8687b632006-10-19 23:28:48 -07004925 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926 uint32_t bmlen;
4927 int status;
4928
Linus Torvalds1da177e2005-04-16 15:20:36 -07004929 status = decode_op_hdr(xdr, OP_SETATTR);
4930 if (status)
4931 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004932 p = xdr_inline_decode(xdr, 4);
4933 if (unlikely(!p))
4934 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004935 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004936 p = xdr_inline_decode(xdr, bmlen << 2);
4937 if (likely(p))
4938 return 0;
4939out_overflow:
4940 print_overflow_msg(__func__, xdr);
4941 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942}
4943
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004944static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945{
Al Viro8687b632006-10-19 23:28:48 -07004946 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947 uint32_t opnum;
4948 int32_t nfserr;
4949
Benny Halevyc0eae662009-08-14 17:20:14 +03004950 p = xdr_inline_decode(xdr, 8);
4951 if (unlikely(!p))
4952 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004953 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004955 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004956 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957 return -EIO;
4958 }
Benny Halevycccddf42009-08-14 17:20:19 +03004959 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004961 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4962 if (unlikely(!p))
4963 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004964 p = xdr_decode_hyper(p, &res->clientid);
4965 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004966 } else if (nfserr == NFSERR_CLID_INUSE) {
4967 uint32_t len;
4968
4969 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004970 p = xdr_inline_decode(xdr, 4);
4971 if (unlikely(!p))
4972 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004973 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004974 p = xdr_inline_decode(xdr, len);
4975 if (unlikely(!p))
4976 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977
4978 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004979 p = xdr_inline_decode(xdr, 4);
4980 if (unlikely(!p))
4981 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004982 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004983 p = xdr_inline_decode(xdr, len);
4984 if (unlikely(!p))
4985 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986 return -NFSERR_CLID_INUSE;
4987 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004988 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989
4990 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004991out_overflow:
4992 print_overflow_msg(__func__, xdr);
4993 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994}
4995
4996static int decode_setclientid_confirm(struct xdr_stream *xdr)
4997{
4998 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4999}
5000
5001static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5002{
Al Viro8687b632006-10-19 23:28:48 -07005003 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005004 int status;
5005
5006 status = decode_op_hdr(xdr, OP_WRITE);
5007 if (status)
5008 return status;
5009
Benny Halevyc0eae662009-08-14 17:20:14 +03005010 p = xdr_inline_decode(xdr, 16);
5011 if (unlikely(!p))
5012 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005013 res->count = be32_to_cpup(p++);
5014 res->verf->committed = be32_to_cpup(p++);
Chuck Levercd937102012-03-02 17:14:31 -05005015 memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005017out_overflow:
5018 print_overflow_msg(__func__, xdr);
5019 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005020}
5021
5022static int decode_delegreturn(struct xdr_stream *xdr)
5023{
5024 return decode_op_hdr(xdr, OP_DELEGRETURN);
5025}
5026
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005027static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5028{
5029 __be32 *p;
5030
5031 p = xdr_inline_decode(xdr, 4);
5032 if (unlikely(!p))
5033 goto out_overflow;
5034 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5035 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5036 goto out_err;
5037
5038 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5039 if (unlikely(!p))
5040 goto out_overflow;
5041 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5042
5043 p = xdr_inline_decode(xdr, 8);
5044 if (unlikely(!p))
5045 goto out_overflow;
5046 flavor->gss.qop4 = be32_to_cpup(p++);
5047 flavor->gss.service = be32_to_cpup(p);
5048
5049 return 0;
5050
5051out_overflow:
5052 print_overflow_msg(__func__, xdr);
5053 return -EIO;
5054out_err:
5055 return -EINVAL;
5056}
5057
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005058static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005059{
5060 struct nfs4_secinfo_flavor *sec_flavor;
5061 int status;
5062 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005063 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005064
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005065 p = xdr_inline_decode(xdr, 4);
5066 if (unlikely(!p))
5067 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005068
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005069 res->flavors->num_flavors = 0;
5070 num_flavors = be32_to_cpup(p);
5071
5072 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005073 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005074 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005075 break;
5076
5077 p = xdr_inline_decode(xdr, 4);
5078 if (unlikely(!p))
5079 goto out_overflow;
5080 sec_flavor->flavor = be32_to_cpup(p);
5081
5082 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005083 status = decode_secinfo_gss(xdr, sec_flavor);
5084 if (status)
5085 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005086 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005087 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005088 }
5089
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005090 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005091out:
5092 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005093out_overflow:
5094 print_overflow_msg(__func__, xdr);
5095 return -EIO;
5096}
5097
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005098static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5099{
5100 int status = decode_op_hdr(xdr, OP_SECINFO);
5101 if (status)
5102 return status;
5103 return decode_secinfo_common(xdr, res);
5104}
5105
Benny Halevy99fe60d2009-04-01 09:22:29 -04005106#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005107static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5108{
5109 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5110 if (status)
5111 return status;
5112 return decode_secinfo_common(xdr, res);
5113}
5114
Benny Halevy99fe60d2009-04-01 09:22:29 -04005115static int decode_exchange_id(struct xdr_stream *xdr,
5116 struct nfs41_exchange_id_res *res)
5117{
5118 __be32 *p;
5119 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005120 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005121 int status;
5122 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005123 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005124
5125 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5126 if (status)
5127 return status;
5128
Benny Halevyc0eae662009-08-14 17:20:14 +03005129 p = xdr_inline_decode(xdr, 8);
5130 if (unlikely(!p))
5131 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005132 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005133 p = xdr_inline_decode(xdr, 12);
5134 if (unlikely(!p))
5135 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005136 clp->cl_seqid = be32_to_cpup(p++);
5137 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005138
5139 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005140 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005141 if (dummy != SP4_NONE)
5142 return -EIO;
5143
5144 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005145 p = xdr_inline_decode(xdr, 8);
5146 if (unlikely(!p))
5147 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005148
5149 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005150 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5151 if (unlikely(status))
5152 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005153
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005154 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005155 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5156 if (unlikely(status))
5157 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005158
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005159 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5160 return -EIO;
5161
5162 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5163 res->server_scope->server_scope_sz = dummy;
5164
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005165 /* Implementation Id */
5166 p = xdr_inline_decode(xdr, 4);
5167 if (unlikely(!p))
5168 goto out_overflow;
5169 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005170
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005171 if (impl_id_count) {
5172 /* nii_domain */
5173 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5174 if (unlikely(status))
5175 return status;
5176 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5177 return -EIO;
5178 memcpy(res->impl_id->domain, dummy_str, dummy);
5179
5180 /* nii_name */
5181 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5182 if (unlikely(status))
5183 return status;
5184 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5185 return -EIO;
5186 memcpy(res->impl_id->name, dummy_str, dummy);
5187
5188 /* nii_date */
5189 p = xdr_inline_decode(xdr, 12);
5190 if (unlikely(!p))
5191 goto out_overflow;
5192 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5193 res->impl_id->date.nseconds = be32_to_cpup(p);
5194
5195 /* if there's more than one entry, ignore the rest */
5196 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005197 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005198out_overflow:
5199 print_overflow_msg(__func__, xdr);
5200 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005201}
Andy Adamsonfc931582009-04-01 09:22:31 -04005202
5203static int decode_chan_attrs(struct xdr_stream *xdr,
5204 struct nfs4_channel_attrs *attrs)
5205{
5206 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005207 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005208
Benny Halevyc0eae662009-08-14 17:20:14 +03005209 p = xdr_inline_decode(xdr, 28);
5210 if (unlikely(!p))
5211 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005212 val = be32_to_cpup(p++); /* headerpadsz */
5213 if (val)
5214 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005215 attrs->max_rqst_sz = be32_to_cpup(p++);
5216 attrs->max_resp_sz = be32_to_cpup(p++);
5217 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5218 attrs->max_ops = be32_to_cpup(p++);
5219 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005220 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005221 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005222 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5223 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005224 return -EINVAL;
5225 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005226 if (nr_attrs == 1) {
5227 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5228 if (unlikely(!p))
5229 goto out_overflow;
5230 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005231 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005232out_overflow:
5233 print_overflow_msg(__func__, xdr);
5234 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005235}
5236
Benny Halevye78291e2009-08-14 17:20:00 +03005237static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5238{
5239 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005240}
5241
5242static int decode_create_session(struct xdr_stream *xdr,
5243 struct nfs41_create_session_res *res)
5244{
5245 __be32 *p;
5246 int status;
5247 struct nfs_client *clp = res->client;
5248 struct nfs4_session *session = clp->cl_session;
5249
5250 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005251 if (!status)
5252 status = decode_sessionid(xdr, &session->sess_id);
5253 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005254 return status;
5255
Andy Adamsonfc931582009-04-01 09:22:31 -04005256 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005257 p = xdr_inline_decode(xdr, 8);
5258 if (unlikely(!p))
5259 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005260 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005261 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005262
5263 /* Channel attributes */
5264 status = decode_chan_attrs(xdr, &session->fc_attrs);
5265 if (!status)
5266 status = decode_chan_attrs(xdr, &session->bc_attrs);
5267 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005268out_overflow:
5269 print_overflow_msg(__func__, xdr);
5270 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005271}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005272
5273static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5274{
5275 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5276}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005277
5278static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5279{
5280 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5281}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005282#endif /* CONFIG_NFS_V4_1 */
5283
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005284static int decode_sequence(struct xdr_stream *xdr,
5285 struct nfs4_sequence_res *res,
5286 struct rpc_rqst *rqstp)
5287{
5288#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005289 struct nfs4_sessionid id;
5290 u32 dummy;
5291 int status;
5292 __be32 *p;
5293
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005294 if (!res->sr_session)
5295 return 0;
5296
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005297 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005298 if (!status)
5299 status = decode_sessionid(xdr, &id);
5300 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005301 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005302
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005303 /*
5304 * If the server returns different values for sessionID, slotID or
5305 * sequence number, the server is looney tunes.
5306 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005307 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005308
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005309 if (memcmp(id.data, res->sr_session->sess_id.data,
5310 NFS4_MAX_SESSIONID_LEN)) {
5311 dprintk("%s Invalid session id\n", __func__);
5312 goto out_err;
5313 }
Benny Halevye78291e2009-08-14 17:20:00 +03005314
Benny Halevyc0eae662009-08-14 17:20:14 +03005315 p = xdr_inline_decode(xdr, 20);
5316 if (unlikely(!p))
5317 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005318
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005319 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005320 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005321 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005322 dprintk("%s Invalid sequence number\n", __func__);
5323 goto out_err;
5324 }
5325 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005326 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005327 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005328 dprintk("%s Invalid slot id\n", __func__);
5329 goto out_err;
5330 }
5331 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005332 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005333 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005334 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005335 /* result flags */
5336 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005337 status = 0;
5338out_err:
5339 res->sr_status = status;
5340 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005341out_overflow:
5342 print_overflow_msg(__func__, xdr);
5343 status = -EIO;
5344 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005345#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005346 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005347#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005348}
5349
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005350#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005351/*
5352 * TODO: Need to handle case when EOF != true;
5353 */
5354static int decode_getdevicelist(struct xdr_stream *xdr,
5355 struct pnfs_devicelist *res)
5356{
5357 __be32 *p;
5358 int status, i;
5359 struct nfs_writeverf verftemp;
5360
5361 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5362 if (status)
5363 return status;
5364
5365 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5366 if (unlikely(!p))
5367 goto out_overflow;
5368
5369 /* TODO: Skip cookie for now */
5370 p += 2;
5371
5372 /* Read verifier */
Chuck Levercd937102012-03-02 17:14:31 -05005373 p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005374
5375 res->num_devs = be32_to_cpup(p);
5376
5377 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5378
5379 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005380 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005381 __func__, res->num_devs);
5382 return -EIO;
5383 }
5384
5385 p = xdr_inline_decode(xdr,
5386 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5387 if (unlikely(!p))
5388 goto out_overflow;
5389 for (i = 0; i < res->num_devs; i++)
5390 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5391 NFS4_DEVICEID4_SIZE);
5392 res->eof = be32_to_cpup(p);
5393 return 0;
5394out_overflow:
5395 print_overflow_msg(__func__, xdr);
5396 return -EIO;
5397}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005398
5399static int decode_getdeviceinfo(struct xdr_stream *xdr,
5400 struct pnfs_device *pdev)
5401{
5402 __be32 *p;
5403 uint32_t len, type;
5404 int status;
5405
5406 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5407 if (status) {
5408 if (status == -ETOOSMALL) {
5409 p = xdr_inline_decode(xdr, 4);
5410 if (unlikely(!p))
5411 goto out_overflow;
5412 pdev->mincount = be32_to_cpup(p);
5413 dprintk("%s: Min count too small. mincnt = %u\n",
5414 __func__, pdev->mincount);
5415 }
5416 return status;
5417 }
5418
5419 p = xdr_inline_decode(xdr, 8);
5420 if (unlikely(!p))
5421 goto out_overflow;
5422 type = be32_to_cpup(p++);
5423 if (type != pdev->layout_type) {
5424 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5425 __func__, pdev->layout_type, type);
5426 return -EINVAL;
5427 }
5428 /*
5429 * Get the length of the opaque device_addr4. xdr_read_pages places
5430 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5431 * and places the remaining xdr data in xdr_buf->tail
5432 */
5433 pdev->mincount = be32_to_cpup(p);
5434 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5435
5436 /* Parse notification bitmap, verifying that it is zero. */
5437 p = xdr_inline_decode(xdr, 4);
5438 if (unlikely(!p))
5439 goto out_overflow;
5440 len = be32_to_cpup(p);
5441 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005442 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005443
5444 p = xdr_inline_decode(xdr, 4 * len);
5445 if (unlikely(!p))
5446 goto out_overflow;
5447 for (i = 0; i < len; i++, p++) {
5448 if (be32_to_cpup(p)) {
5449 dprintk("%s: notifications not supported\n",
5450 __func__);
5451 return -EIO;
5452 }
5453 }
5454 }
5455 return 0;
5456out_overflow:
5457 print_overflow_msg(__func__, xdr);
5458 return -EIO;
5459}
5460
5461static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5462 struct nfs4_layoutget_res *res)
5463{
5464 __be32 *p;
5465 int status;
5466 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005467 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5468 struct kvec *iov = rcvbuf->head;
5469 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005470
5471 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5472 if (status)
5473 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005474 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005475 if (unlikely(!p))
5476 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005477 res->return_on_close = be32_to_cpup(p);
5478 decode_stateid(xdr, &res->stateid);
5479 p = xdr_inline_decode(xdr, 4);
5480 if (unlikely(!p))
5481 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005482 layout_count = be32_to_cpup(p);
5483 if (!layout_count) {
5484 dprintk("%s: server responded with empty layout array\n",
5485 __func__);
5486 return -EINVAL;
5487 }
5488
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005489 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005490 if (unlikely(!p))
5491 goto out_overflow;
5492 p = xdr_decode_hyper(p, &res->range.offset);
5493 p = xdr_decode_hyper(p, &res->range.length);
5494 res->range.iomode = be32_to_cpup(p++);
5495 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005496 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005497
5498 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5499 __func__,
5500 (unsigned long)res->range.offset,
5501 (unsigned long)res->range.length,
5502 res->range.iomode,
5503 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005504 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005505
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005506 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5507 recvd = req->rq_rcv_buf.len - hdrlen;
5508 if (res->layoutp->len > recvd) {
5509 dprintk("NFS: server cheating in layoutget reply: "
5510 "layout len %u > recvd %u\n",
5511 res->layoutp->len, recvd);
5512 return -EINVAL;
5513 }
5514
5515 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005516
5517 if (layout_count > 1) {
5518 /* We only handle a length one array at the moment. Any
5519 * further entries are just ignored. Note that this means
5520 * the client may see a response that is less than the
5521 * minimum it requested.
5522 */
5523 dprintk("%s: server responded with %d layouts, dropping tail\n",
5524 __func__, layout_count);
5525 }
5526
5527 return 0;
5528out_overflow:
5529 print_overflow_msg(__func__, xdr);
5530 return -EIO;
5531}
Andy Adamson863a3c62011-03-23 13:27:54 +00005532
Benny Halevycbe82602011-05-22 19:52:37 +03005533static int decode_layoutreturn(struct xdr_stream *xdr,
5534 struct nfs4_layoutreturn_res *res)
5535{
5536 __be32 *p;
5537 int status;
5538
5539 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5540 if (status)
5541 return status;
5542 p = xdr_inline_decode(xdr, 4);
5543 if (unlikely(!p))
5544 goto out_overflow;
5545 res->lrs_present = be32_to_cpup(p);
5546 if (res->lrs_present)
5547 status = decode_stateid(xdr, &res->stateid);
5548 return status;
5549out_overflow:
5550 print_overflow_msg(__func__, xdr);
5551 return -EIO;
5552}
5553
Andy Adamson863a3c62011-03-23 13:27:54 +00005554static int decode_layoutcommit(struct xdr_stream *xdr,
5555 struct rpc_rqst *req,
5556 struct nfs4_layoutcommit_res *res)
5557{
5558 __be32 *p;
5559 __u32 sizechanged;
5560 int status;
5561
5562 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005563 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005564 if (status)
5565 return status;
5566
5567 p = xdr_inline_decode(xdr, 4);
5568 if (unlikely(!p))
5569 goto out_overflow;
5570 sizechanged = be32_to_cpup(p);
5571
5572 if (sizechanged) {
5573 /* throw away new size */
5574 p = xdr_inline_decode(xdr, 8);
5575 if (unlikely(!p))
5576 goto out_overflow;
5577 }
5578 return 0;
5579out_overflow:
5580 print_overflow_msg(__func__, xdr);
5581 return -EIO;
5582}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005583
5584static int decode_test_stateid(struct xdr_stream *xdr,
5585 struct nfs41_test_stateid_res *res)
5586{
5587 __be32 *p;
5588 int status;
5589 int num_res;
5590
5591 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5592 if (status)
5593 return status;
5594
5595 p = xdr_inline_decode(xdr, 4);
5596 if (unlikely(!p))
5597 goto out_overflow;
5598 num_res = be32_to_cpup(p++);
5599 if (num_res != 1)
5600 goto out;
5601
5602 p = xdr_inline_decode(xdr, 4);
5603 if (unlikely(!p))
5604 goto out_overflow;
5605 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005606
5607 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005608out_overflow:
5609 print_overflow_msg(__func__, xdr);
5610out:
5611 return -EIO;
5612}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005613
5614static int decode_free_stateid(struct xdr_stream *xdr,
5615 struct nfs41_free_stateid_res *res)
5616{
5617 __be32 *p;
5618 int status;
5619
5620 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5621 if (status)
5622 return status;
5623
5624 p = xdr_inline_decode(xdr, 4);
5625 if (unlikely(!p))
5626 goto out_overflow;
5627 res->status = be32_to_cpup(p++);
5628 return res->status;
5629out_overflow:
5630 print_overflow_msg(__func__, xdr);
5631 return -EIO;
5632}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005633#endif /* CONFIG_NFS_V4_1 */
5634
Linus Torvalds1da177e2005-04-16 15:20:36 -07005635/*
Benny Halevy49c25592008-12-23 16:06:16 -05005636 * END OF "GENERIC" DECODE ROUTINES.
5637 */
5638
5639/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005640 * Decode OPEN_DOWNGRADE response
5641 */
Chuck Leverbf269552010-12-14 14:59:29 +00005642static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5643 struct xdr_stream *xdr,
5644 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005645{
Andy Adamson05d564f2008-12-23 16:06:15 -05005646 struct compound_hdr hdr;
5647 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005648
Chuck Leverbf269552010-12-14 14:59:29 +00005649 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005650 if (status)
5651 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005652 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005653 if (status)
5654 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005655 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005656 if (status)
5657 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005658 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005659 if (status != 0)
5660 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005661 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005662out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005663 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005664}
5665
5666/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005667 * Decode ACCESS response
5668 */
Chuck Leverbf269552010-12-14 14:59:29 +00005669static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5670 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005671{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005672 struct compound_hdr hdr;
5673 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005674
Chuck Leverbf269552010-12-14 14:59:29 +00005675 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005676 if (status)
5677 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005678 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005679 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005680 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005681 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005682 if (status != 0)
5683 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005684 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005685 if (status != 0)
5686 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005687 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005688out:
5689 return status;
5690}
5691
5692/*
5693 * Decode LOOKUP response
5694 */
Chuck Leverbf269552010-12-14 14:59:29 +00005695static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5696 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005697{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005698 struct compound_hdr hdr;
5699 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005700
Chuck Leverbf269552010-12-14 14:59:29 +00005701 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005702 if (status)
5703 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005704 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005705 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005706 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005707 status = decode_putfh(xdr);
5708 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005709 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005710 status = decode_lookup(xdr);
5711 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005712 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005713 status = decode_getfh(xdr, res->fh);
5714 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005715 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005716 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005717out:
5718 return status;
5719}
5720
5721/*
5722 * Decode LOOKUP_ROOT response
5723 */
Chuck Leverbf269552010-12-14 14:59:29 +00005724static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5725 struct xdr_stream *xdr,
5726 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005727{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005728 struct compound_hdr hdr;
5729 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005730
Chuck Leverbf269552010-12-14 14:59:29 +00005731 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005732 if (status)
5733 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005734 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005735 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005736 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005737 status = decode_putrootfh(xdr);
5738 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005739 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005740 status = decode_getfh(xdr, res->fh);
5741 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005742 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005743out:
5744 return status;
5745}
5746
5747/*
5748 * Decode REMOVE response
5749 */
Chuck Leverbf269552010-12-14 14:59:29 +00005750static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5751 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005752{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005753 struct compound_hdr hdr;
5754 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005755
Chuck Leverbf269552010-12-14 14:59:29 +00005756 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005757 if (status)
5758 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005759 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005760 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005761 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005762 status = decode_putfh(xdr);
5763 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005764 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005765 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005766out:
5767 return status;
5768}
5769
5770/*
5771 * Decode RENAME response
5772 */
Chuck Leverbf269552010-12-14 14:59:29 +00005773static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5774 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005775{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005776 struct compound_hdr hdr;
5777 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005778
Chuck Leverbf269552010-12-14 14:59:29 +00005779 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005780 if (status)
5781 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005782 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005783 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005784 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005785 status = decode_putfh(xdr);
5786 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005787 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005788 status = decode_savefh(xdr);
5789 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005790 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005791 status = decode_putfh(xdr);
5792 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005793 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005794 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005795out:
5796 return status;
5797}
5798
5799/*
5800 * Decode LINK response
5801 */
Chuck Leverbf269552010-12-14 14:59:29 +00005802static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5803 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005804{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005805 struct compound_hdr hdr;
5806 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005807
Chuck Leverbf269552010-12-14 14:59:29 +00005808 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005809 if (status)
5810 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005811 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005812 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005813 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005814 status = decode_putfh(xdr);
5815 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005816 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005817 status = decode_savefh(xdr);
5818 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005819 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005820 status = decode_putfh(xdr);
5821 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005822 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005823 status = decode_link(xdr, &res->cinfo);
5824 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005825 goto out;
5826 /*
5827 * Note order: OP_LINK leaves the directory as the current
5828 * filehandle.
5829 */
Chuck Leverbf269552010-12-14 14:59:29 +00005830 status = decode_restorefh(xdr);
5831 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005832 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005833 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005834out:
5835 return status;
5836}
5837
5838/*
5839 * Decode CREATE response
5840 */
Chuck Leverbf269552010-12-14 14:59:29 +00005841static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5842 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005843{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844 struct compound_hdr hdr;
5845 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005846
Chuck Leverbf269552010-12-14 14:59:29 +00005847 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005848 if (status)
5849 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005850 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005851 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005852 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005853 status = decode_putfh(xdr);
5854 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005855 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005856 status = decode_create(xdr, &res->dir_cinfo);
5857 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005858 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005859 status = decode_getfh(xdr, res->fh);
5860 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005861 goto out;
Trond Myklebust7c317fc2012-04-27 13:48:18 -04005862 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005863out:
5864 return status;
5865}
5866
5867/*
5868 * Decode SYMLINK response
5869 */
Chuck Leverbf269552010-12-14 14:59:29 +00005870static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5871 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005872{
Chuck Leverbf269552010-12-14 14:59:29 +00005873 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005874}
5875
5876/*
5877 * Decode GETATTR response
5878 */
Chuck Leverbf269552010-12-14 14:59:29 +00005879static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5880 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005881{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005882 struct compound_hdr hdr;
5883 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005884
Chuck Leverbf269552010-12-14 14:59:29 +00005885 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005886 if (status)
5887 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005888 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005889 if (status)
5890 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005891 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892 if (status)
5893 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005894 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005895out:
5896 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005897}
5898
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005899/*
5900 * Encode an SETACL request
5901 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005902static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5903 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005904{
Andy Adamson05d564f2008-12-23 16:06:15 -05005905 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005906 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005907 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005908
Chuck Lever9f06c712010-12-14 14:59:18 +00005909 encode_compound_hdr(xdr, req, &hdr);
5910 encode_sequence(xdr, &args->seq_args, &hdr);
5911 encode_putfh(xdr, args->fh, &hdr);
5912 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005913 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005914}
Andy Adamson05d564f2008-12-23 16:06:15 -05005915
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005916/*
5917 * Decode SETACL response
5918 */
5919static int
Chuck Leverbf269552010-12-14 14:59:29 +00005920nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005921 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005922{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005923 struct compound_hdr hdr;
5924 int status;
5925
Chuck Leverbf269552010-12-14 14:59:29 +00005926 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005927 if (status)
5928 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005929 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005930 if (status)
5931 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005932 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005933 if (status)
5934 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005935 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005936out:
5937 return status;
5938}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005939
5940/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005941 * Decode GETACL response
5942 */
5943static int
Chuck Leverbf269552010-12-14 14:59:29 +00005944nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005945 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005946{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005947 struct compound_hdr hdr;
5948 int status;
5949
Trond Myklebust331818f2012-02-03 18:30:53 -05005950 if (res->acl_scratch != NULL) {
5951 void *p = page_address(res->acl_scratch);
5952 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
5953 }
Chuck Leverbf269552010-12-14 14:59:29 +00005954 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005955 if (status)
5956 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005957 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005958 if (status)
5959 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005960 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005961 if (status)
5962 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005963 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005964
5965out:
5966 return status;
5967}
5968
5969/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970 * Decode CLOSE response
5971 */
Chuck Leverbf269552010-12-14 14:59:29 +00005972static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5973 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005974{
Andy Adamson05d564f2008-12-23 16:06:15 -05005975 struct compound_hdr hdr;
5976 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005977
Chuck Leverbf269552010-12-14 14:59:29 +00005978 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005979 if (status)
5980 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005981 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005982 if (status)
5983 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005984 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005985 if (status)
5986 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005987 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005988 if (status != 0)
5989 goto out;
5990 /*
5991 * Note: Server may do delete on close for this file
5992 * in which case the getattr call will fail with
5993 * an ESTALE error. Shouldn't be a problem,
5994 * though, since fattr->valid will remain unset.
5995 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005996 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005998 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005999}
6000
6001/*
6002 * Decode OPEN response
6003 */
Chuck Leverbf269552010-12-14 14:59:29 +00006004static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6005 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006006{
Andy Adamson05d564f2008-12-23 16:06:15 -05006007 struct compound_hdr hdr;
6008 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006009
Chuck Leverbf269552010-12-14 14:59:29 +00006010 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006011 if (status)
6012 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006013 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006014 if (status)
6015 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006016 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006017 if (status)
6018 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006019 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006020 if (status)
6021 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006022 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006023 goto out;
Trond Myklebust90ff0c52012-04-27 13:48:18 -04006024 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006025out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006026 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006027}
6028
6029/*
6030 * Decode OPEN_CONFIRM response
6031 */
Chuck Leverbf269552010-12-14 14:59:29 +00006032static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6033 struct xdr_stream *xdr,
6034 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006035{
Andy Adamson05d564f2008-12-23 16:06:15 -05006036 struct compound_hdr hdr;
6037 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006038
Chuck Leverbf269552010-12-14 14:59:29 +00006039 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006040 if (status)
6041 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006042 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006043 if (status)
6044 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006045 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006046out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006047 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006048}
6049
6050/*
6051 * Decode OPEN response
6052 */
Chuck Leverbf269552010-12-14 14:59:29 +00006053static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6054 struct xdr_stream *xdr,
6055 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056{
Andy Adamson05d564f2008-12-23 16:06:15 -05006057 struct compound_hdr hdr;
6058 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006059
Chuck Leverbf269552010-12-14 14:59:29 +00006060 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006061 if (status)
6062 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006063 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006064 if (status)
6065 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006066 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006067 if (status)
6068 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006069 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006070 if (status)
6071 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006072 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006073out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006074 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006075}
6076
6077/*
6078 * Decode SETATTR response
6079 */
Chuck Leverbf269552010-12-14 14:59:29 +00006080static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6081 struct xdr_stream *xdr,
6082 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083{
Andy Adamson05d564f2008-12-23 16:06:15 -05006084 struct compound_hdr hdr;
6085 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006086
Chuck Leverbf269552010-12-14 14:59:29 +00006087 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006088 if (status)
6089 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006090 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006091 if (status)
6092 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006093 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006094 if (status)
6095 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006096 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006097 if (status)
6098 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006099 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006100out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006101 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006102}
6103
6104/*
6105 * Decode LOCK response
6106 */
Chuck Leverbf269552010-12-14 14:59:29 +00006107static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6108 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006110 struct compound_hdr hdr;
6111 int status;
6112
Chuck Leverbf269552010-12-14 14:59:29 +00006113 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114 if (status)
6115 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006116 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006117 if (status)
6118 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006119 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006120 if (status)
6121 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006122 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006123out:
6124 return status;
6125}
6126
6127/*
6128 * Decode LOCKT response
6129 */
Chuck Leverbf269552010-12-14 14:59:29 +00006130static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6131 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006132{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133 struct compound_hdr hdr;
6134 int status;
6135
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137 if (status)
6138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006139 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006140 if (status)
6141 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006142 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143 if (status)
6144 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006145 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146out:
6147 return status;
6148}
6149
6150/*
6151 * Decode LOCKU response
6152 */
Chuck Leverbf269552010-12-14 14:59:29 +00006153static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6154 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006156 struct compound_hdr hdr;
6157 int status;
6158
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160 if (status)
6161 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006162 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006163 if (status)
6164 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006165 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006166 if (status)
6167 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006168 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169out:
6170 return status;
6171}
6172
Chuck Leverbf269552010-12-14 14:59:29 +00006173static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6174 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006175{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006176 struct compound_hdr hdr;
6177 int status;
6178
Chuck Leverbf269552010-12-14 14:59:29 +00006179 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006180 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006181 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006182 return status;
6183}
6184
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185/*
6186 * Decode READLINK response
6187 */
Chuck Leverbf269552010-12-14 14:59:29 +00006188static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6189 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006190 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192 struct compound_hdr hdr;
6193 int status;
6194
Chuck Leverbf269552010-12-14 14:59:29 +00006195 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196 if (status)
6197 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006198 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006199 if (status)
6200 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202 if (status)
6203 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006204 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205out:
6206 return status;
6207}
6208
6209/*
6210 * Decode READDIR response
6211 */
Chuck Leverbf269552010-12-14 14:59:29 +00006212static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6213 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006215 struct compound_hdr hdr;
6216 int status;
6217
Chuck Leverbf269552010-12-14 14:59:29 +00006218 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219 if (status)
6220 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006221 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006222 if (status)
6223 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006224 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225 if (status)
6226 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006227 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228out:
6229 return status;
6230}
6231
6232/*
6233 * Decode Read response
6234 */
Chuck Leverbf269552010-12-14 14:59:29 +00006235static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6236 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238 struct compound_hdr hdr;
6239 int status;
6240
Chuck Leverbf269552010-12-14 14:59:29 +00006241 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242 if (status)
6243 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006244 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006245 if (status)
6246 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006247 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248 if (status)
6249 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006250 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251 if (!status)
6252 status = res->count;
6253out:
6254 return status;
6255}
6256
6257/*
6258 * Decode WRITE response
6259 */
Chuck Leverbf269552010-12-14 14:59:29 +00006260static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6261 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006263 struct compound_hdr hdr;
6264 int status;
6265
Chuck Leverbf269552010-12-14 14:59:29 +00006266 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006267 if (status)
6268 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006269 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006270 if (status)
6271 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006272 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273 if (status)
6274 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006275 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006276 if (status)
6277 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006278 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006279 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006280 if (!status)
6281 status = res->count;
6282out:
6283 return status;
6284}
6285
6286/*
6287 * Decode COMMIT response
6288 */
Chuck Leverbf269552010-12-14 14:59:29 +00006289static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006290 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006291{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006292 struct compound_hdr hdr;
6293 int status;
6294
Chuck Leverbf269552010-12-14 14:59:29 +00006295 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006296 if (status)
6297 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006298 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006299 if (status)
6300 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006301 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006302 if (status)
6303 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006304 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006305out:
6306 return status;
6307}
6308
6309/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006310 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311 */
Chuck Leverbf269552010-12-14 14:59:29 +00006312static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006313 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006314{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006315 struct compound_hdr hdr;
6316 int status;
6317
Chuck Leverbf269552010-12-14 14:59:29 +00006318 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006319 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006320 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006321 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006322 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006324 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325 return status;
6326}
6327
6328/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006329 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006330 */
Chuck Leverbf269552010-12-14 14:59:29 +00006331static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006332 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006333{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006334 struct compound_hdr hdr;
6335 int status;
6336
Chuck Leverbf269552010-12-14 14:59:29 +00006337 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006338 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006339 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006340 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006341 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006342 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006343 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006344 return status;
6345}
6346
6347/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006348 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006349 */
Chuck Leverbf269552010-12-14 14:59:29 +00006350static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006351 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353 struct compound_hdr hdr;
6354 int status;
6355
Chuck Leverbf269552010-12-14 14:59:29 +00006356 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006358 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006359 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006360 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006361 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006362 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006363 return status;
6364}
6365
6366/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006367 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368 */
Chuck Leverbf269552010-12-14 14:59:29 +00006369static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6370 struct xdr_stream *xdr,
6371 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006373 struct compound_hdr hdr;
6374 int status;
6375
Chuck Leverbf269552010-12-14 14:59:29 +00006376 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006377 if (status)
6378 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006379 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006380 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006382 status = decode_putfh(xdr);
6383 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006384 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006385 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006386out:
6387 return status;
6388}
6389
6390/*
6391 * Decode RENEW response
6392 */
Chuck Leverbf269552010-12-14 14:59:29 +00006393static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6394 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006395{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396 struct compound_hdr hdr;
6397 int status;
6398
Chuck Leverbf269552010-12-14 14:59:29 +00006399 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006401 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006402 return status;
6403}
6404
6405/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006406 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407 */
Chuck Leverbf269552010-12-14 14:59:29 +00006408static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6409 struct xdr_stream *xdr,
6410 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006412 struct compound_hdr hdr;
6413 int status;
6414
Chuck Leverbf269552010-12-14 14:59:29 +00006415 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006417 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006418 return status;
6419}
6420
6421/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006422 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006423 */
Chuck Leverbf269552010-12-14 14:59:29 +00006424static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6425 struct xdr_stream *xdr,
6426 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006428 struct compound_hdr hdr;
6429 int status;
6430
Chuck Leverbf269552010-12-14 14:59:29 +00006431 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006432 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006433 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006434 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006435 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006436 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006437 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006438 return status;
6439}
6440
6441/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006442 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443 */
Chuck Leverbf269552010-12-14 14:59:29 +00006444static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6445 struct xdr_stream *xdr,
6446 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006447{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448 struct compound_hdr hdr;
6449 int status;
6450
Chuck Leverbf269552010-12-14 14:59:29 +00006451 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006452 if (status)
6453 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006454 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006455 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006456 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006457 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006458 if (status != 0)
6459 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006460 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006461 if (status != 0)
6462 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006463 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006464out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465 return status;
6466}
6467
Trond Myklebust683b57b2006-06-09 09:34:22 -04006468/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006469 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006470 */
Chuck Leverbf269552010-12-14 14:59:29 +00006471static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6472 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006473 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006474{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006475 struct compound_hdr hdr;
6476 int status;
6477
Chuck Leverbf269552010-12-14 14:59:29 +00006478 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006479 if (status)
6480 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006481 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006482 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006483 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006484 status = decode_putfh(xdr);
6485 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006486 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006487 status = decode_lookup(xdr);
6488 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006489 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006490 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006491 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6492 NULL, res->fs_locations,
6493 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006494out:
6495 return status;
6496}
6497
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006498/*
6499 * Decode SECINFO response
6500 */
6501static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6502 struct xdr_stream *xdr,
6503 struct nfs4_secinfo_res *res)
6504{
6505 struct compound_hdr hdr;
6506 int status;
6507
6508 status = decode_compound_hdr(xdr, &hdr);
6509 if (status)
6510 goto out;
6511 status = decode_sequence(xdr, &res->seq_res, rqstp);
6512 if (status)
6513 goto out;
6514 status = decode_putfh(xdr);
6515 if (status)
6516 goto out;
6517 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006518out:
6519 return status;
6520}
6521
Benny Halevy99fe60d2009-04-01 09:22:29 -04006522#if defined(CONFIG_NFS_V4_1)
6523/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006524 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006525 */
Chuck Leverbf269552010-12-14 14:59:29 +00006526static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6527 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006528 void *res)
6529{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006530 struct compound_hdr hdr;
6531 int status;
6532
Chuck Leverbf269552010-12-14 14:59:29 +00006533 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006534 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006535 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006536 return status;
6537}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006538
6539/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006540 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006541 */
Chuck Leverbf269552010-12-14 14:59:29 +00006542static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6543 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006544 struct nfs41_create_session_res *res)
6545{
Andy Adamsonfc931582009-04-01 09:22:31 -04006546 struct compound_hdr hdr;
6547 int status;
6548
Chuck Leverbf269552010-12-14 14:59:29 +00006549 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006550 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006552 return status;
6553}
6554
6555/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006556 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006557 */
Chuck Leverbf269552010-12-14 14:59:29 +00006558static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6559 struct xdr_stream *xdr,
6560 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006561{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006562 struct compound_hdr hdr;
6563 int status;
6564
Chuck Leverbf269552010-12-14 14:59:29 +00006565 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006566 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006567 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006568 return status;
6569}
6570
6571/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006572 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006573 */
Chuck Leverbf269552010-12-14 14:59:29 +00006574static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6575 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006576 struct nfs4_sequence_res *res)
6577{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006578 struct compound_hdr hdr;
6579 int status;
6580
Chuck Leverbf269552010-12-14 14:59:29 +00006581 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006582 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006583 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006584 return status;
6585}
6586
6587/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006588 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006589 */
Chuck Leverbf269552010-12-14 14:59:29 +00006590static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6591 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006592 struct nfs4_get_lease_time_res *res)
6593{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006594 struct compound_hdr hdr;
6595 int status;
6596
Chuck Leverbf269552010-12-14 14:59:29 +00006597 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006598 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006599 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006600 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006601 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006602 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006603 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006604 return status;
6605}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006606
6607/*
6608 * Decode RECLAIM_COMPLETE response
6609 */
Chuck Leverbf269552010-12-14 14:59:29 +00006610static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6611 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006612 struct nfs41_reclaim_complete_res *res)
6613{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006614 struct compound_hdr hdr;
6615 int status;
6616
Chuck Leverbf269552010-12-14 14:59:29 +00006617 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006618 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006619 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006620 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006621 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006622 return status;
6623}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006624
6625/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006626 * Decode GETDEVICELIST response
6627 */
6628static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6629 struct xdr_stream *xdr,
6630 struct nfs4_getdevicelist_res *res)
6631{
6632 struct compound_hdr hdr;
6633 int status;
6634
6635 dprintk("encoding getdevicelist!\n");
6636
6637 status = decode_compound_hdr(xdr, &hdr);
6638 if (status != 0)
6639 goto out;
6640 status = decode_sequence(xdr, &res->seq_res, rqstp);
6641 if (status != 0)
6642 goto out;
6643 status = decode_putfh(xdr);
6644 if (status != 0)
6645 goto out;
6646 status = decode_getdevicelist(xdr, res->devlist);
6647out:
6648 return status;
6649}
6650
6651/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006652 * Decode GETDEVINFO response
6653 */
Chuck Leverbf269552010-12-14 14:59:29 +00006654static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6655 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006656 struct nfs4_getdeviceinfo_res *res)
6657{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006658 struct compound_hdr hdr;
6659 int status;
6660
Chuck Leverbf269552010-12-14 14:59:29 +00006661 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006662 if (status != 0)
6663 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006664 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006665 if (status != 0)
6666 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006668out:
6669 return status;
6670}
6671
6672/*
6673 * Decode LAYOUTGET response
6674 */
Chuck Leverbf269552010-12-14 14:59:29 +00006675static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6676 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006677 struct nfs4_layoutget_res *res)
6678{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006679 struct compound_hdr hdr;
6680 int status;
6681
Chuck Leverbf269552010-12-14 14:59:29 +00006682 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006683 if (status)
6684 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006685 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006686 if (status)
6687 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006688 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006689 if (status)
6690 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006691 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006692out:
6693 return status;
6694}
Andy Adamson863a3c62011-03-23 13:27:54 +00006695
6696/*
Benny Halevycbe82602011-05-22 19:52:37 +03006697 * Decode LAYOUTRETURN response
6698 */
6699static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6700 struct xdr_stream *xdr,
6701 struct nfs4_layoutreturn_res *res)
6702{
6703 struct compound_hdr hdr;
6704 int status;
6705
6706 status = decode_compound_hdr(xdr, &hdr);
6707 if (status)
6708 goto out;
6709 status = decode_sequence(xdr, &res->seq_res, rqstp);
6710 if (status)
6711 goto out;
6712 status = decode_putfh(xdr);
6713 if (status)
6714 goto out;
6715 status = decode_layoutreturn(xdr, res);
6716out:
6717 return status;
6718}
6719
6720/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006721 * Decode LAYOUTCOMMIT response
6722 */
6723static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6724 struct xdr_stream *xdr,
6725 struct nfs4_layoutcommit_res *res)
6726{
6727 struct compound_hdr hdr;
6728 int status;
6729
6730 status = decode_compound_hdr(xdr, &hdr);
6731 if (status)
6732 goto out;
6733 status = decode_sequence(xdr, &res->seq_res, rqstp);
6734 if (status)
6735 goto out;
6736 status = decode_putfh(xdr);
6737 if (status)
6738 goto out;
6739 status = decode_layoutcommit(xdr, rqstp, res);
6740 if (status)
6741 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006742 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006743out:
6744 return status;
6745}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006746
6747/*
6748 * Decode SECINFO_NO_NAME response
6749 */
6750static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6751 struct xdr_stream *xdr,
6752 struct nfs4_secinfo_res *res)
6753{
6754 struct compound_hdr hdr;
6755 int status;
6756
6757 status = decode_compound_hdr(xdr, &hdr);
6758 if (status)
6759 goto out;
6760 status = decode_sequence(xdr, &res->seq_res, rqstp);
6761 if (status)
6762 goto out;
6763 status = decode_putrootfh(xdr);
6764 if (status)
6765 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04006766 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006767out:
6768 return status;
6769}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006770
6771/*
6772 * Decode TEST_STATEID response
6773 */
6774static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6775 struct xdr_stream *xdr,
6776 struct nfs41_test_stateid_res *res)
6777{
6778 struct compound_hdr hdr;
6779 int status;
6780
6781 status = decode_compound_hdr(xdr, &hdr);
6782 if (status)
6783 goto out;
6784 status = decode_sequence(xdr, &res->seq_res, rqstp);
6785 if (status)
6786 goto out;
6787 status = decode_test_stateid(xdr, res);
6788out:
6789 return status;
6790}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006791
6792/*
6793 * Decode FREE_STATEID response
6794 */
6795static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6796 struct xdr_stream *xdr,
6797 struct nfs41_free_stateid_res *res)
6798{
6799 struct compound_hdr hdr;
6800 int status;
6801
6802 status = decode_compound_hdr(xdr, &hdr);
6803 if (status)
6804 goto out;
6805 status = decode_sequence(xdr, &res->seq_res, rqstp);
6806 if (status)
6807 goto out;
6808 status = decode_free_stateid(xdr, res);
6809out:
6810 return status;
6811}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006812#endif /* CONFIG_NFS_V4_1 */
6813
Chuck Lever573c4e12010-12-14 14:58:11 +00006814/**
6815 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6816 * the local page cache.
6817 * @xdr: XDR stream where entry resides
6818 * @entry: buffer to fill in with entry data
6819 * @plus: boolean indicating whether this should be a readdirplus entry
6820 *
6821 * Returns zero if successful, otherwise a negative errno value is
6822 * returned.
6823 *
6824 * This function is not invoked during READDIR reply decoding, but
6825 * rather whenever an application invokes the getdents(2) system call
6826 * on a directory already in our cache.
6827 */
6828int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6829 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006830{
Fred Isamandae100c2011-07-30 20:52:37 -04006831 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07006832 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006833 __be32 *p = xdr_inline_decode(xdr, 4);
6834 if (unlikely(!p))
6835 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006836 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006837 p = xdr_inline_decode(xdr, 4);
6838 if (unlikely(!p))
6839 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006840 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006841 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006842 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006843 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006844 }
6845
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006846 p = xdr_inline_decode(xdr, 12);
6847 if (unlikely(!p))
6848 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006849 entry->prev_cookie = entry->cookie;
6850 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006851 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006852
Trond Myklebust9af8c222010-10-24 11:52:55 -04006853 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006854 if (unlikely(!p))
6855 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006856 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006857
6858 /*
6859 * In case the server doesn't return an inode number,
6860 * we fake one here. (We don't use inode number 0,
6861 * since glibc seems to choke on it...)
6862 */
6863 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006864 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006865
Trond Myklebust9af8c222010-10-24 11:52:55 -04006866 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006867 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006868
6869 if (decode_attr_length(xdr, &len, &p) < 0)
6870 goto out_overflow;
6871
Chuck Lever573c4e12010-12-14 14:58:11 +00006872 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006873 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006874 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006875 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6876 entry->ino = entry->fattr->mounted_on_fileid;
6877 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006878 entry->ino = entry->fattr->fileid;
6879
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006880 entry->d_type = DT_UNKNOWN;
6881 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6882 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6883
Chuck Lever573c4e12010-12-14 14:58:11 +00006884 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006885
6886out_overflow:
6887 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006888 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006889}
6890
6891/*
6892 * We need to translate between nfs status return values and
6893 * the local errno values which may not be the same.
6894 */
6895static struct {
6896 int stat;
6897 int errno;
6898} nfs_errtbl[] = {
6899 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006900 { NFS4ERR_PERM, -EPERM },
6901 { NFS4ERR_NOENT, -ENOENT },
6902 { NFS4ERR_IO, -errno_NFSERR_IO},
6903 { NFS4ERR_NXIO, -ENXIO },
6904 { NFS4ERR_ACCESS, -EACCES },
6905 { NFS4ERR_EXIST, -EEXIST },
6906 { NFS4ERR_XDEV, -EXDEV },
6907 { NFS4ERR_NOTDIR, -ENOTDIR },
6908 { NFS4ERR_ISDIR, -EISDIR },
6909 { NFS4ERR_INVAL, -EINVAL },
6910 { NFS4ERR_FBIG, -EFBIG },
6911 { NFS4ERR_NOSPC, -ENOSPC },
6912 { NFS4ERR_ROFS, -EROFS },
6913 { NFS4ERR_MLINK, -EMLINK },
6914 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6915 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6916 { NFS4ERR_DQUOT, -EDQUOT },
6917 { NFS4ERR_STALE, -ESTALE },
6918 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006919 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6920 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6921 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006922 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006923 { NFS4ERR_BADTYPE, -EBADTYPE },
6924 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006925 { NFS4ERR_SYMLINK, -ELOOP },
6926 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6927 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006928 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006929};
6930
6931/*
6932 * Convert an NFS error code to a local one.
6933 * This one is used jointly by NFSv2 and NFSv3.
6934 */
6935static int
David Howells0a8ea432006-08-22 20:06:08 -04006936nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006937{
6938 int i;
6939 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6940 if (nfs_errtbl[i].stat == stat)
6941 return nfs_errtbl[i].errno;
6942 }
6943 if (stat <= 10000 || stat > 10100) {
6944 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006945 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006946 }
6947 /* If we cannot translate the error, the recovery routines should
6948 * handle it.
6949 * Note: remaining NFSv4 error codes have values > 10000, so should
6950 * not conflict with native Linux error codes.
6951 */
Benny Halevy856dff32008-03-31 17:39:06 +03006952 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006953}
6954
Linus Torvalds1da177e2005-04-16 15:20:36 -07006955#define PROC(proc, argtype, restype) \
6956[NFSPROC4_CLNT_##proc] = { \
6957 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006958 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006959 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006960 .p_arglen = NFS4_##argtype##_sz, \
6961 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006962 .p_statidx = NFSPROC4_CLNT_##proc, \
6963 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006964}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006965
6966struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006967 PROC(READ, enc_read, dec_read),
6968 PROC(WRITE, enc_write, dec_write),
6969 PROC(COMMIT, enc_commit, dec_commit),
6970 PROC(OPEN, enc_open, dec_open),
6971 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6972 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6973 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6974 PROC(CLOSE, enc_close, dec_close),
6975 PROC(SETATTR, enc_setattr, dec_setattr),
6976 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6977 PROC(RENEW, enc_renew, dec_renew),
6978 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6979 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6980 PROC(LOCK, enc_lock, dec_lock),
6981 PROC(LOCKT, enc_lockt, dec_lockt),
6982 PROC(LOCKU, enc_locku, dec_locku),
6983 PROC(ACCESS, enc_access, dec_access),
6984 PROC(GETATTR, enc_getattr, dec_getattr),
6985 PROC(LOOKUP, enc_lookup, dec_lookup),
6986 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6987 PROC(REMOVE, enc_remove, dec_remove),
6988 PROC(RENAME, enc_rename, dec_rename),
6989 PROC(LINK, enc_link, dec_link),
6990 PROC(SYMLINK, enc_symlink, dec_symlink),
6991 PROC(CREATE, enc_create, dec_create),
6992 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6993 PROC(STATFS, enc_statfs, dec_statfs),
6994 PROC(READLINK, enc_readlink, dec_readlink),
6995 PROC(READDIR, enc_readdir, dec_readdir),
6996 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6997 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6998 PROC(GETACL, enc_getacl, dec_getacl),
6999 PROC(SETACL, enc_setacl, dec_setacl),
7000 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7001 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007002 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007003#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007004 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7005 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7006 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7007 PROC(SEQUENCE, enc_sequence, dec_sequence),
7008 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7009 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7010 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7011 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007012 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007013 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007014 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007015 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007016 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007017 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007018#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007019};
7020
Trond Myklebusta613fa12012-01-20 13:53:56 -05007021const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007022 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007023 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007024 .procs = nfs4_procedures
7025};
7026
7027/*
7028 * Local variables:
7029 * c-basic-offset: 8
7030 * End:
7031 */