blob: 6e878dcc0d2db23e50628faa97ed85b31a1a019f [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 Myklebust9104a552007-07-17 21:52:42 -0400424 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400425 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400429 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400430 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400433 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400434 encode_open_maxsz + \
435 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400436 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400438 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400439 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400440 decode_open_maxsz + \
441 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400442 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400443#define NFS4_enc_open_confirm_sz \
444 (compound_encode_hdr_maxsz + \
445 encode_putfh_maxsz + \
446 encode_open_confirm_maxsz)
447#define NFS4_dec_open_confirm_sz \
448 (compound_decode_hdr_maxsz + \
449 decode_putfh_maxsz + \
450 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400452 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400454 encode_open_maxsz + \
455 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400457 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400459 decode_open_maxsz + \
460 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461#define NFS4_enc_open_downgrade_sz \
462 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400464 encode_putfh_maxsz + \
465 encode_open_downgrade_maxsz + \
466 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_dec_open_downgrade_sz \
468 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400470 decode_putfh_maxsz + \
471 decode_open_downgrade_maxsz + \
472 decode_getattr_maxsz)
473#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400474 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400475 encode_putfh_maxsz + \
476 encode_close_maxsz + \
477 encode_getattr_maxsz)
478#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400479 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400480 decode_putfh_maxsz + \
481 decode_close_maxsz + \
482 decode_getattr_maxsz)
483#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400484 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400485 encode_putfh_maxsz + \
486 encode_setattr_maxsz + \
487 encode_getattr_maxsz)
488#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400489 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400490 decode_putfh_maxsz + \
491 decode_setattr_maxsz + \
492 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400494 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 encode_putfh_maxsz + \
496 encode_fsinfo_maxsz)
497#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400498 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 decode_putfh_maxsz + \
500 decode_fsinfo_maxsz)
501#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
502 encode_renew_maxsz)
503#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
504 decode_renew_maxsz)
505#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
506 encode_setclientid_maxsz)
507#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
508 decode_setclientid_maxsz)
509#define NFS4_enc_setclientid_confirm_sz \
510 (compound_encode_hdr_maxsz + \
511 encode_setclientid_confirm_maxsz + \
512 encode_putrootfh_maxsz + \
513 encode_fsinfo_maxsz)
514#define NFS4_dec_setclientid_confirm_sz \
515 (compound_decode_hdr_maxsz + \
516 decode_setclientid_confirm_maxsz + \
517 decode_putrootfh_maxsz + \
518 decode_fsinfo_maxsz)
519#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400522 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400524 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400526 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400528 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400530 encode_lockt_maxsz)
531#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400532 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400533 decode_putfh_maxsz + \
534 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400536 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400538 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400540 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400542 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400543#define NFS4_enc_release_lockowner_sz \
544 (compound_encode_hdr_maxsz + \
545 encode_lockowner_maxsz)
546#define NFS4_dec_release_lockowner_sz \
547 (compound_decode_hdr_maxsz + \
548 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400550 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400552 encode_access_maxsz + \
553 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400555 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400557 decode_access_maxsz + \
558 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400560 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 encode_putfh_maxsz + \
562 encode_getattr_maxsz)
563#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 decode_putfh_maxsz + \
566 decode_getattr_maxsz)
567#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 encode_putfh_maxsz + \
570 encode_lookup_maxsz + \
571 encode_getattr_maxsz + \
572 encode_getfh_maxsz)
573#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400576 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 decode_getattr_maxsz + \
578 decode_getfh_maxsz)
579#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 encode_putrootfh_maxsz + \
582 encode_getattr_maxsz + \
583 encode_getfh_maxsz)
584#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400585 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 decode_putrootfh_maxsz + \
587 decode_getattr_maxsz + \
588 decode_getfh_maxsz)
589#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400592 encode_remove_maxsz + \
593 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400595 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400597 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400598 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400600 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 encode_putfh_maxsz + \
602 encode_savefh_maxsz + \
603 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400604 encode_rename_maxsz + \
605 encode_getattr_maxsz + \
606 encode_restorefh_maxsz + \
607 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400609 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 decode_putfh_maxsz + \
611 decode_savefh_maxsz + \
612 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400613 decode_rename_maxsz + \
614 decode_getattr_maxsz + \
615 decode_restorefh_maxsz + \
616 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400618 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 encode_putfh_maxsz + \
620 encode_savefh_maxsz + \
621 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400622 encode_link_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400623 encode_getattr_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400624 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400625 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400627 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 decode_putfh_maxsz + \
629 decode_savefh_maxsz + \
630 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400631 decode_link_maxsz + \
632 decode_getattr_maxsz + \
633 decode_restorefh_maxsz + \
634 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635#define NFS4_enc_symlink_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_symlink_maxsz + \
639 encode_getattr_maxsz + \
640 encode_getfh_maxsz)
641#define NFS4_dec_symlink_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_symlink_maxsz + \
645 decode_getattr_maxsz + \
646 decode_getfh_maxsz)
647#define NFS4_enc_create_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 + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400650 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400652 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400654 encode_restorefh_maxsz + \
655 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400657 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400659 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400661 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400663 decode_restorefh_maxsz + \
664 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400666 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 encode_putfh_maxsz + \
668 encode_getattr_maxsz)
669#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400670 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 decode_putfh_maxsz + \
672 decode_getattr_maxsz)
673#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400674 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400676 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400678 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400680 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400682 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800683 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 encode_getattr_maxsz)
685#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400686 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800687 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 decode_getattr_maxsz)
689#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400690 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100692 encode_delegreturn_maxsz + \
693 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400695 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100696 decode_delegreturn_maxsz + \
697 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000698#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400699 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000700 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400701 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000702#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400703 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000704 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400705 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000706#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400707 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000708 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400709 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000710#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400711 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000712 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400713 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400714#define NFS4_enc_fs_locations_sz \
715 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400716 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400717 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400718 encode_lookup_maxsz + \
719 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400720#define NFS4_dec_fs_locations_sz \
721 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400722 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400723 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400724 decode_lookup_maxsz + \
725 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000726#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
727 encode_sequence_maxsz + \
728 encode_putfh_maxsz + \
729 encode_secinfo_maxsz)
730#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
731 decode_sequence_maxsz + \
732 decode_putfh_maxsz + \
733 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400734#if defined(CONFIG_NFS_V4_1)
735#define NFS4_enc_exchange_id_sz \
736 (compound_encode_hdr_maxsz + \
737 encode_exchange_id_maxsz)
738#define NFS4_dec_exchange_id_sz \
739 (compound_decode_hdr_maxsz + \
740 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400741#define NFS4_enc_create_session_sz \
742 (compound_encode_hdr_maxsz + \
743 encode_create_session_maxsz)
744#define NFS4_dec_create_session_sz \
745 (compound_decode_hdr_maxsz + \
746 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400747#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
748 encode_destroy_session_maxsz)
749#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
750 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400751#define NFS4_enc_sequence_sz \
752 (compound_decode_hdr_maxsz + \
753 encode_sequence_maxsz)
754#define NFS4_dec_sequence_sz \
755 (compound_decode_hdr_maxsz + \
756 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400757#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
758 encode_sequence_maxsz + \
759 encode_putrootfh_maxsz + \
760 encode_fsinfo_maxsz)
761#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz + \
763 decode_putrootfh_maxsz + \
764 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500765#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
766 encode_sequence_maxsz + \
767 encode_reclaim_complete_maxsz)
768#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
769 decode_sequence_maxsz + \
770 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400771#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
772 encode_sequence_maxsz + \
773 encode_putfh_maxsz + \
774 encode_getdevicelist_maxsz)
775#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
776 decode_sequence_maxsz + \
777 decode_putfh_maxsz + \
778 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400779#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
780 encode_sequence_maxsz +\
781 encode_getdeviceinfo_maxsz)
782#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
783 decode_sequence_maxsz + \
784 decode_getdeviceinfo_maxsz)
785#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
786 encode_sequence_maxsz + \
787 encode_putfh_maxsz + \
788 encode_layoutget_maxsz)
789#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
790 decode_sequence_maxsz + \
791 decode_putfh_maxsz + \
792 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000793#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
794 encode_sequence_maxsz +\
795 encode_putfh_maxsz + \
796 encode_layoutcommit_maxsz + \
797 encode_getattr_maxsz)
798#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
799 decode_sequence_maxsz + \
800 decode_putfh_maxsz + \
801 decode_layoutcommit_maxsz + \
802 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300803#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
804 encode_sequence_maxsz + \
805 encode_putfh_maxsz + \
806 encode_layoutreturn_maxsz)
807#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
808 decode_sequence_maxsz + \
809 decode_putfh_maxsz + \
810 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400811#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
812 encode_sequence_maxsz + \
813 encode_putrootfh_maxsz +\
814 encode_secinfo_no_name_maxsz)
815#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
816 decode_sequence_maxsz + \
817 decode_putrootfh_maxsz + \
818 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400819#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
820 encode_sequence_maxsz + \
821 encode_test_stateid_maxsz)
822#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
823 decode_sequence_maxsz + \
824 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400825#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
826 encode_sequence_maxsz + \
827 encode_free_stateid_maxsz)
828#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
829 decode_sequence_maxsz + \
830 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500831
832const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
833 compound_encode_hdr_maxsz +
834 encode_sequence_maxsz +
835 encode_putfh_maxsz +
836 encode_getattr_maxsz) *
837 XDR_UNIT);
838
839const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
840 compound_decode_hdr_maxsz +
841 decode_sequence_maxsz +
842 decode_putfh_maxsz) *
843 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400844#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500846static unsigned short send_implementation_id = 1;
847
848module_param(send_implementation_id, ushort, 0644);
849MODULE_PARM_DESC(send_implementation_id,
850 "Send implementation ID with NFSv4.1 exchange_id");
851
Trond Myklebustbca79472009-03-11 14:10:26 -0400852static const umode_t nfs_type2fmt[] = {
853 [NF4BAD] = 0,
854 [NF4REG] = S_IFREG,
855 [NF4DIR] = S_IFDIR,
856 [NF4BLK] = S_IFBLK,
857 [NF4CHR] = S_IFCHR,
858 [NF4LNK] = S_IFLNK,
859 [NF4SOCK] = S_IFSOCK,
860 [NF4FIFO] = S_IFIFO,
861 [NF4ATTRDIR] = 0,
862 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863};
864
865struct compound_hdr {
866 int32_t status;
867 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500868 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 uint32_t taglen;
870 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400871 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400872 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873};
874
Benny Halevy13c65ce2009-08-14 17:19:25 +0300875static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
876{
877 __be32 *p = xdr_reserve_space(xdr, nbytes);
878 BUG_ON(!p);
879 return p;
880}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Trond Myklebustcb17e552012-03-04 18:13:56 -0500882static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
883{
884 __be32 *p;
885
886 p = xdr_reserve_space(xdr, len);
887 xdr_encode_opaque_fixed(p, buf, len);
888}
889
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
891{
Al Viro8687b632006-10-19 23:28:48 -0700892 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500894 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 xdr_encode_opaque(p, str, len);
896}
897
Trond Myklebust4ade9822012-03-04 18:13:57 -0500898static void encode_uint32(struct xdr_stream *xdr, u32 n)
899{
900 __be32 *p;
901
902 p = reserve_space(xdr, 4);
903 *p = cpu_to_be32(n);
904}
905
Trond Myklebustff2eb682012-03-05 11:40:12 -0500906static void encode_uint64(struct xdr_stream *xdr, u64 n)
907{
908 __be32 *p;
909
910 p = reserve_space(xdr, 8);
911 xdr_encode_hyper(p, n);
912}
913
Trond Myklebust4ade9822012-03-04 18:13:57 -0500914static void encode_nfs4_seqid(struct xdr_stream *xdr,
915 const struct nfs_seqid *seqid)
916{
917 encode_uint32(xdr, seqid->sequence->counter);
918}
919
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400920static void encode_compound_hdr(struct xdr_stream *xdr,
921 struct rpc_rqst *req,
922 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923{
Al Viro8687b632006-10-19 23:28:48 -0700924 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400925 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400926
927 /* initialize running count of expected bytes in reply.
928 * NOTE: the replied tag SHOULD be the same is the one sent,
929 * but this is not required as a MUST for the server to do so. */
930 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500933 encode_string(xdr, hdr->taglen, hdr->tag);
934 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300935 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500936 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300937 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500938}
939
Trond Myklebustab19b482012-03-04 18:13:57 -0500940static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
941 uint32_t replen,
942 struct compound_hdr *hdr)
943{
944 encode_uint32(xdr, op);
945 hdr->nops++;
946 hdr->replen += replen;
947}
948
Andy Adamsond0179312008-12-23 16:06:17 -0500949static void encode_nops(struct compound_hdr *hdr)
950{
Andy Adamsonfc931582009-04-01 09:22:31 -0400951 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500952 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953}
954
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500955static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
956{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500957 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500958}
959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
961{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500962 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963}
964
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500965static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
967 char owner_name[IDMAP_NAMESZ];
968 char owner_group[IDMAP_NAMESZ];
969 int owner_namelen = 0;
970 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700971 __be32 *p;
972 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 int len;
974 uint32_t bmval0 = 0;
975 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 /*
978 * We reserve enough space to write the entire attribute buffer at once.
979 * In the worst-case, this would be
980 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
981 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000982 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 */
984 len = 16;
985
986 /* Sigh */
987 if (iap->ia_valid & ATTR_SIZE)
988 len += 8;
989 if (iap->ia_valid & ATTR_MODE)
990 len += 4;
991 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800992 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400994 dprintk("nfs: couldn't resolve uid %d to string\n",
995 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 /* XXX */
997 strcpy(owner_name, "nobody");
998 owner_namelen = sizeof("nobody") - 1;
999 /* goto out; */
1000 }
1001 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1002 }
1003 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001004 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001006 dprintk("nfs: couldn't resolve gid %d to string\n",
1007 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 strcpy(owner_group, "nobody");
1009 owner_grouplen = sizeof("nobody") - 1;
1010 /* goto out; */
1011 }
1012 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1013 }
1014 if (iap->ia_valid & ATTR_ATIME_SET)
1015 len += 16;
1016 else if (iap->ia_valid & ATTR_ATIME)
1017 len += 4;
1018 if (iap->ia_valid & ATTR_MTIME_SET)
1019 len += 16;
1020 else if (iap->ia_valid & ATTR_MTIME)
1021 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001022 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
1024 /*
1025 * We write the bitmap length now, but leave the bitmap and the attribute
1026 * buffer length to be backfilled at the end of this routine.
1027 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001028 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 q = p;
1030 p += 3;
1031
1032 if (iap->ia_valid & ATTR_SIZE) {
1033 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001034 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 }
1036 if (iap->ia_valid & ATTR_MODE) {
1037 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001038 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 }
1040 if (iap->ia_valid & ATTR_UID) {
1041 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001042 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 }
1044 if (iap->ia_valid & ATTR_GID) {
1045 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001046 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 }
1048 if (iap->ia_valid & ATTR_ATIME_SET) {
1049 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001050 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1051 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001052 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1053 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 }
1055 else if (iap->ia_valid & ATTR_ATIME) {
1056 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001057 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 }
1059 if (iap->ia_valid & ATTR_MTIME_SET) {
1060 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001061 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1062 *p++ = cpu_to_be32(0);
1063 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1064 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 }
1066 else if (iap->ia_valid & ATTR_MTIME) {
1067 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001068 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001070
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 /*
1072 * Now we backfill the bitmap and the attribute buffer length.
1073 */
1074 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001075 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 len, ((char *)p - (char *)q) + 4);
1077 BUG();
1078 }
1079 len = (char *)p - (char *)q - 12;
1080 *q++ = htonl(bmval0);
1081 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001082 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085}
1086
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001087static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001089 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1090 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091}
1092
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001093static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094{
Trond Myklebustab19b482012-03-04 18:13:57 -05001095 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001096 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001097 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098}
1099
Fred Isaman0b7c0152012-04-20 14:47:39 -04001100static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101{
Al Viro8687b632006-10-19 23:28:48 -07001102 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001103
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001104 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1105 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001106 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001107 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108}
1109
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001110static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111{
Al Viro8687b632006-10-19 23:28:48 -07001112 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001113
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001114 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1115 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
1117 switch (create->ftype) {
1118 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001119 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001120 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001121 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 break;
1123
1124 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001125 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001126 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001127 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 break;
1129
1130 default:
1131 break;
1132 }
1133
Benny Halevy811652b2009-08-14 17:19:34 +03001134 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001135 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136}
1137
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001138static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139{
Andy Adamson05d564f2008-12-23 16:06:15 -05001140 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001142 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1143 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001144 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001145 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146}
1147
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001148static 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 -07001149{
Andy Adamson05d564f2008-12-23 16:06:15 -05001150 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001152 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1153 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001154 *p++ = cpu_to_be32(2);
1155 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001156 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157}
1158
Fred Isamandae100c2011-07-30 20:52:37 -04001159static void
1160encode_getattr_three(struct xdr_stream *xdr,
1161 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1162 struct compound_hdr *hdr)
1163{
1164 __be32 *p;
1165
Trond Myklebustab19b482012-03-04 18:13:57 -05001166 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001167 if (bm2) {
1168 p = reserve_space(xdr, 16);
1169 *p++ = cpu_to_be32(3);
1170 *p++ = cpu_to_be32(bm0);
1171 *p++ = cpu_to_be32(bm1);
1172 *p = cpu_to_be32(bm2);
1173 } else if (bm1) {
1174 p = reserve_space(xdr, 12);
1175 *p++ = cpu_to_be32(2);
1176 *p++ = cpu_to_be32(bm0);
1177 *p = cpu_to_be32(bm1);
1178 } else {
1179 p = reserve_space(xdr, 8);
1180 *p++ = cpu_to_be32(1);
1181 *p = cpu_to_be32(bm0);
1182 }
Fred Isamandae100c2011-07-30 20:52:37 -04001183}
1184
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001185static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001187 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1188 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189}
1190
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001191static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192{
Fred Isamandae100c2011-07-30 20:52:37 -04001193 encode_getattr_three(xdr,
1194 bitmask[0] & nfs4_fsinfo_bitmap[0],
1195 bitmask[1] & nfs4_fsinfo_bitmap[1],
1196 bitmask[2] & nfs4_fsinfo_bitmap[2],
1197 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198}
1199
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001200static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001201{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001202 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1203 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001204}
1205
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001206static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207{
Trond Myklebustab19b482012-03-04 18:13:57 -05001208 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209}
1210
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001211static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212{
Trond Myklebustab19b482012-03-04 18:13:57 -05001213 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001214 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215}
1216
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001217static inline int nfs4_lock_type(struct file_lock *fl, int block)
1218{
1219 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1220 return block ? NFS4_READW_LT : NFS4_READ_LT;
1221 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1222}
1223
1224static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1225{
1226 if (fl->fl_end == OFFSET_MAX)
1227 return ~(uint64_t)0;
1228 return fl->fl_end - fl->fl_start + 1;
1229}
1230
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001231static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1232{
1233 __be32 *p;
1234
Trond Myklebustd035c362010-12-21 10:45:27 -05001235 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001236 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001237 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001238 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001239 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001240 xdr_encode_hyper(p, lowner->id);
1241}
1242
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243/*
1244 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1245 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1246 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001247static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248{
Al Viro8687b632006-10-19 23:28:48 -07001249 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001251 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1252 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001253 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1254 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001255 p = xdr_encode_hyper(p, args->fl->fl_start);
1256 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001257 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001258 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001259 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001260 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001261 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001262 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 }
1264 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001265 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001266 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268}
1269
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001270static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271{
Al Viro8687b632006-10-19 23:28:48 -07001272 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001274 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1275 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001276 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001277 p = xdr_encode_hyper(p, args->fl->fl_start);
1278 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001279 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280}
1281
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001282static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283{
Al Viro8687b632006-10-19 23:28:48 -07001284 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001286 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1287 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001288 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001289 encode_nfs4_stateid(xdr, args->stateid);
1290 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001291 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001292 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293}
1294
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001295static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1296{
Trond Myklebustab19b482012-03-04 18:13:57 -05001297 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001298 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001299}
1300
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001301static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302{
Trond Myklebustab19b482012-03-04 18:13:57 -05001303 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001304 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305}
1306
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001307static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308{
Al Viro8687b632006-10-19 23:28:48 -07001309 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
Benny Halevy13c65ce2009-08-14 17:19:25 +03001311 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001312 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001313 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001314 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001315 break;
1316 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001317 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001318 break;
1319 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001320 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001321 break;
1322 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001323 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 }
Benny Halevy34558512009-08-14 17:19:30 +03001325 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326}
1327
1328static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1329{
Al Viro8687b632006-10-19 23:28:48 -07001330 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 /*
1332 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1333 * owner 4 = 32
1334 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001335 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001336 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001337 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001338 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001339 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001340 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001341 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001342 *p++ = cpu_to_be32(arg->id.uniquifier);
1343 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344}
1345
1346static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1347{
Al Viro8687b632006-10-19 23:28:48 -07001348 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001349 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Benny Halevy13c65ce2009-08-14 17:19:25 +03001351 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001353 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001354 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001355 encode_attrs(xdr, arg->u.attrs, arg->server);
1356 break;
1357 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001358 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001359 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001360 if (nfs4_has_persistent_session(clp)) {
1361 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1362 encode_attrs(xdr, arg->u.attrs, arg->server);
1363 } else {
1364 struct iattr dummy;
1365
1366 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1367 encode_nfs4_verifier(xdr, &arg->u.verifier);
1368 dummy.ia_valid = 0;
1369 encode_attrs(xdr, &dummy, arg->server);
1370 }
1371 } else {
1372 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1373 encode_nfs4_verifier(xdr, &arg->u.verifier);
1374 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 }
1376}
1377
1378static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1379{
Al Viro8687b632006-10-19 23:28:48 -07001380 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
Benny Halevy13c65ce2009-08-14 17:19:25 +03001382 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001384 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001385 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001386 break;
1387 default:
1388 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001389 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001390 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 }
1392}
1393
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001394static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395{
Al Viro8687b632006-10-19 23:28:48 -07001396 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
Benny Halevy13c65ce2009-08-14 17:19:25 +03001398 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001400 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001401 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001402 break;
1403 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001404 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001405 break;
1406 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001407 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001408 break;
1409 default:
1410 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 }
1412}
1413
1414static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1415{
Al Viro8687b632006-10-19 23:28:48 -07001416 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Benny Halevy13c65ce2009-08-14 17:19:25 +03001418 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001419 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 encode_string(xdr, name->len, name->name);
1421}
1422
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001423static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424{
Al Viro8687b632006-10-19 23:28:48 -07001425 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
Benny Halevy13c65ce2009-08-14 17:19:25 +03001427 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001428 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 encode_delegation_type(xdr, type);
1430}
1431
1432static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1433{
Al Viro8687b632006-10-19 23:28:48 -07001434 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001436 p = reserve_space(xdr, 4);
1437 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1438 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 encode_string(xdr, name->len, name->name);
1440}
1441
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001442static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443{
Trond Myklebustab19b482012-03-04 18:13:57 -05001444 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 encode_openhdr(xdr, arg);
1446 encode_opentype(xdr, arg);
1447 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001448 case NFS4_OPEN_CLAIM_NULL:
1449 encode_claim_null(xdr, arg->name);
1450 break;
1451 case NFS4_OPEN_CLAIM_PREVIOUS:
1452 encode_claim_previous(xdr, arg->u.delegation_type);
1453 break;
1454 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1455 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1456 break;
1457 default:
1458 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460}
1461
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001462static 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 -07001463{
Trond Myklebustab19b482012-03-04 18:13:57 -05001464 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001465 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001466 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467}
1468
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001469static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470{
Trond Myklebustab19b482012-03-04 18:13:57 -05001471 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001472 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001473 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001474 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475}
1476
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001477static void
Andy Adamsond0179312008-12-23 16:06:17 -05001478encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479{
Trond Myklebustab19b482012-03-04 18:13:57 -05001480 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001481 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482}
1483
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001484static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485{
Trond Myklebustab19b482012-03-04 18:13:57 -05001486 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487}
1488
Trond Myklebust4fc87962012-03-08 17:42:01 -05001489static void encode_open_stateid(struct xdr_stream *xdr,
1490 const struct nfs_open_context *ctx,
1491 const struct nfs_lock_context *l_ctx,
1492 fmode_t fmode,
1493 int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 nfs4_stateid stateid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 if (ctx->state != NULL) {
Trond Myklebust4fc87962012-03-08 17:42:01 -05001498 nfs4_select_rw_stateid(&stateid, ctx->state,
1499 fmode, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001500 if (zero_seqid)
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001501 stateid.seqid = 0;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001502 encode_nfs4_stateid(xdr, &stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 } else
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001504 encode_nfs4_stateid(xdr, &zero_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505}
1506
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001507static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
Al Viro8687b632006-10-19 23:28:48 -07001509 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Trond Myklebustab19b482012-03-04 18:13:57 -05001511 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001512 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001513 FMODE_READ, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
Benny Halevy13c65ce2009-08-14 17:19:25 +03001515 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001516 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001517 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518}
1519
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001520static 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 -07001521{
Trond Myklebust28331a42011-04-27 13:47:52 -04001522 uint32_t attrs[2] = {
1523 FATTR4_WORD0_RDATTR_ERROR,
1524 FATTR4_WORD1_MOUNTED_ON_FILEID,
1525 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001526 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001527 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001529 if (readdir->plus) {
1530 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001531 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001532 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1533 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1534 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1535 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001536 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001537 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001538 /* Use mounted_on_fileid only if the server supports it */
1539 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1540 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001541
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001542 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001543 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001544 encode_nfs4_verifier(xdr, &readdir->verifier);
1545 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001546 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001547 *p++ = cpu_to_be32(readdir->count);
1548 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001549
Benny Halevye75bc1c2009-08-14 17:18:54 +03001550 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001551 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Chuck Levercd937102012-03-02 17:14:31 -05001552 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001553 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1554 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001555 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001556 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001557 attrs[0] & readdir->bitmask[0],
1558 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559}
1560
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001561static 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 -07001562{
Trond Myklebustab19b482012-03-04 18:13:57 -05001563 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564}
1565
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001566static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567{
Trond Myklebustab19b482012-03-04 18:13:57 -05001568 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001569 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570}
1571
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001572static 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 -07001573{
Trond Myklebustab19b482012-03-04 18:13:57 -05001574 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001575 encode_string(xdr, oldname->len, oldname->name);
1576 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577}
1578
Chuck Leverbb4dae52012-03-01 17:01:48 -05001579static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1580 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001582 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001583 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584}
1585
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001586static void
Andy Adamsond0179312008-12-23 16:06:17 -05001587encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001588{
Trond Myklebustab19b482012-03-04 18:13:57 -05001589 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001590}
1591
Chuck Lever9f06c712010-12-14 14:59:18 +00001592static void
Andy Adamsond0179312008-12-23 16:06:17 -05001593encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001594{
Al Viro8687b632006-10-19 23:28:48 -07001595 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001596
Trond Myklebustab19b482012-03-04 18:13:57 -05001597 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001598 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001599 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001600 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001601 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001602 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001603 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001604 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001605 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001606}
1607
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001608static void
Andy Adamsond0179312008-12-23 16:06:17 -05001609encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610{
Trond Myklebustab19b482012-03-04 18:13:57 -05001611 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612}
1613
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001614static 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 -07001615{
Trond Myklebustab19b482012-03-04 18:13:57 -05001616 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001617 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001618 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619}
1620
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001621static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622{
Al Viro8687b632006-10-19 23:28:48 -07001623 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
Trond Myklebust70019512012-03-04 20:49:32 -05001625 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001626 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
1628 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001629 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001630 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1632 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001633 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001634 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635}
1636
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001637static 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 -07001638{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001639 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1640 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001641 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001642 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643}
1644
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001645static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646{
Al Viro8687b632006-10-19 23:28:48 -07001647 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
Trond Myklebustab19b482012-03-04 18:13:57 -05001649 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001650 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001651 FMODE_WRITE, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652
Benny Halevy13c65ce2009-08-14 17:19:25 +03001653 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001654 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001655 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001656 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
1658 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659}
1660
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001661static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662{
Trond Myklebustab19b482012-03-04 18:13:57 -05001663 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001664 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001666
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001667static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1668{
Trond Myklebustab19b482012-03-04 18:13:57 -05001669 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001670 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001671}
1672
Benny Halevy99fe60d2009-04-01 09:22:29 -04001673#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001674/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001675static void encode_exchange_id(struct xdr_stream *xdr,
1676 struct nfs41_exchange_id_args *args,
1677 struct compound_hdr *hdr)
1678{
1679 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001680 char impl_name[NFS4_OPAQUE_LIMIT];
1681 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001682
Trond Myklebust70019512012-03-04 20:49:32 -05001683 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001684 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001685
1686 encode_string(xdr, args->id_len, args->id);
1687
Benny Halevy13c65ce2009-08-14 17:19:25 +03001688 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001689 *p++ = cpu_to_be32(args->flags);
1690 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001691
1692 if (send_implementation_id &&
1693 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1694 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1695 <= NFS4_OPAQUE_LIMIT + 1)
1696 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1697 utsname()->sysname, utsname()->release,
1698 utsname()->version, utsname()->machine);
1699
1700 if (len > 0) {
1701 *p = cpu_to_be32(1); /* implementation id array length=1 */
1702
1703 encode_string(xdr,
1704 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1705 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1706 encode_string(xdr, len, impl_name);
1707 /* just send zeros for nii_date - the date is in nii_name */
1708 p = reserve_space(xdr, 12);
1709 p = xdr_encode_hyper(p, 0);
1710 *p = cpu_to_be32(0);
1711 } else
1712 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001713}
Andy Adamsonfc931582009-04-01 09:22:31 -04001714
1715static void encode_create_session(struct xdr_stream *xdr,
1716 struct nfs41_create_session_args *args,
1717 struct compound_hdr *hdr)
1718{
1719 __be32 *p;
1720 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1721 uint32_t len;
1722 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001723 u32 max_resp_sz_cached;
1724
1725 /*
1726 * Assumes OPEN is the biggest non-idempotent compound.
1727 * 2 is the verifier.
1728 */
1729 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1730 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001731
Andy Adamsonfc931582009-04-01 09:22:31 -04001732 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1733 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001734
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001735 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1736 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001737 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001738 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1739 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001740
Andy Adamsonfc931582009-04-01 09:22:31 -04001741 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001742 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001743 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1744 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001745 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001746 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1747 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1748 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001749
1750 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001751 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001752 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1753 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1754 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1755 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1756 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1757 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001758
Benny Halevye75bc1c2009-08-14 17:18:54 +03001759 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001760 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001761 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001762
1763 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001764 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001765 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001766 *p++ = cpu_to_be32(0); /* UID */
1767 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001768 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001769}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001770
1771static void encode_destroy_session(struct xdr_stream *xdr,
1772 struct nfs4_session *session,
1773 struct compound_hdr *hdr)
1774{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001775 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1776 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001777}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001778
1779static void encode_reclaim_complete(struct xdr_stream *xdr,
1780 struct nfs41_reclaim_complete_args *args,
1781 struct compound_hdr *hdr)
1782{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001783 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1784 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001785}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001786#endif /* CONFIG_NFS_V4_1 */
1787
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001788static void encode_sequence(struct xdr_stream *xdr,
1789 const struct nfs4_sequence_args *args,
1790 struct compound_hdr *hdr)
1791{
1792#if defined(CONFIG_NFS_V4_1)
1793 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001794 struct nfs4_slot_table *tp;
1795 struct nfs4_slot *slot;
1796 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001797
1798 if (!session)
1799 return;
1800
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001801 tp = &session->fc_slot_table;
1802
1803 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1804 slot = tp->slots + args->sa_slotid;
1805
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001806 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001807
1808 /*
1809 * Sessionid + seqid + slotid + max slotid + cache_this
1810 */
1811 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1812 "max_slotid=%d cache_this=%d\n",
1813 __func__,
1814 ((u32 *)session->sess_id.data)[0],
1815 ((u32 *)session->sess_id.data)[1],
1816 ((u32 *)session->sess_id.data)[2],
1817 ((u32 *)session->sess_id.data)[3],
1818 slot->seq_nr, args->sa_slotid,
1819 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001820 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001821 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001822 *p++ = cpu_to_be32(slot->seq_nr);
1823 *p++ = cpu_to_be32(args->sa_slotid);
1824 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001825 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001826#endif /* CONFIG_NFS_V4_1 */
1827}
1828
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001829#ifdef CONFIG_NFS_V4_1
1830static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001831encode_getdevicelist(struct xdr_stream *xdr,
1832 const struct nfs4_getdevicelist_args *args,
1833 struct compound_hdr *hdr)
1834{
1835 __be32 *p;
1836 nfs4_verifier dummy = {
1837 .data = "dummmmmy",
1838 };
1839
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001840 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1841 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001842 *p++ = cpu_to_be32(args->layoutclass);
1843 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1844 xdr_encode_hyper(p, 0ULL); /* cookie */
1845 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001846}
1847
1848static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001849encode_getdeviceinfo(struct xdr_stream *xdr,
1850 const struct nfs4_getdeviceinfo_args *args,
1851 struct compound_hdr *hdr)
1852{
1853 __be32 *p;
1854
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001855 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1856 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001857 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1858 NFS4_DEVICEID4_SIZE);
1859 *p++ = cpu_to_be32(args->pdev->layout_type);
1860 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1861 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001862}
1863
1864static void
1865encode_layoutget(struct xdr_stream *xdr,
1866 const struct nfs4_layoutget_args *args,
1867 struct compound_hdr *hdr)
1868{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001869 __be32 *p;
1870
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001871 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1872 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001873 *p++ = cpu_to_be32(0); /* Signal layout available */
1874 *p++ = cpu_to_be32(args->type);
1875 *p++ = cpu_to_be32(args->range.iomode);
1876 p = xdr_encode_hyper(p, args->range.offset);
1877 p = xdr_encode_hyper(p, args->range.length);
1878 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001879 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001880 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001881
1882 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1883 __func__,
1884 args->type,
1885 args->range.iomode,
1886 (unsigned long)args->range.offset,
1887 (unsigned long)args->range.length,
1888 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001889}
Andy Adamson863a3c62011-03-23 13:27:54 +00001890
1891static int
1892encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001893 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001894 const struct nfs4_layoutcommit_args *args,
1895 struct compound_hdr *hdr)
1896{
1897 __be32 *p;
1898
1899 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1900 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1901
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001902 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1903 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001904 /* Only whole file layouts */
1905 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001906 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001907 *p = cpu_to_be32(0); /* reclaim */
1908 encode_nfs4_stateid(xdr, &args->stateid);
1909 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001910 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1911 p = xdr_encode_hyper(p, args->lastbytewritten);
1912 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1913 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001914
1915 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1916 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1917 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001918 else
1919 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001920
Andy Adamson863a3c62011-03-23 13:27:54 +00001921 return 0;
1922}
Benny Halevycbe82602011-05-22 19:52:37 +03001923
1924static void
1925encode_layoutreturn(struct xdr_stream *xdr,
1926 const struct nfs4_layoutreturn_args *args,
1927 struct compound_hdr *hdr)
1928{
1929 __be32 *p;
1930
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001931 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1932 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001933 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1934 *p++ = cpu_to_be32(args->layout_type);
1935 *p++ = cpu_to_be32(IOMODE_ANY);
1936 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001937 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001938 p = xdr_encode_hyper(p, 0);
1939 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1940 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001941 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001942 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001943 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1944 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1945 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001946 } else
1947 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03001948}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001949
1950static int
1951encode_secinfo_no_name(struct xdr_stream *xdr,
1952 const struct nfs41_secinfo_no_name_args *args,
1953 struct compound_hdr *hdr)
1954{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001955 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1956 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001957 return 0;
1958}
Bryan Schumaker7d974792011-06-02 14:59:08 -04001959
1960static void encode_test_stateid(struct xdr_stream *xdr,
1961 struct nfs41_test_stateid_args *args,
1962 struct compound_hdr *hdr)
1963{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001964 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
1965 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001966 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04001967}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001968
1969static void encode_free_stateid(struct xdr_stream *xdr,
1970 struct nfs41_free_stateid_args *args,
1971 struct compound_hdr *hdr)
1972{
Trond Myklebustab19b482012-03-04 18:13:57 -05001973 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001974 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001975}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001976#endif /* CONFIG_NFS_V4_1 */
1977
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978/*
1979 * END OF "GENERIC" ENCODE ROUTINES.
1980 */
1981
Benny Halevy66cc0422009-04-01 09:22:10 -04001982static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1983{
1984#if defined(CONFIG_NFS_V4_1)
1985 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001986 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001987#endif /* CONFIG_NFS_V4_1 */
1988 return 0;
1989}
1990
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991/*
1992 * Encode an ACCESS request
1993 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001994static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1995 const struct nfs4_accessargs *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->fh, &hdr);
2004 encode_access(xdr, args->access, &hdr);
2005 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002006 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007}
2008
2009/*
2010 * Encode LOOKUP request
2011 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002012static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2013 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002016 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
Chuck Lever9f06c712010-12-14 14:59:18 +00002019 encode_compound_hdr(xdr, req, &hdr);
2020 encode_sequence(xdr, &args->seq_args, &hdr);
2021 encode_putfh(xdr, args->dir_fh, &hdr);
2022 encode_lookup(xdr, args->name, &hdr);
2023 encode_getfh(xdr, &hdr);
2024 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002025 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026}
2027
2028/*
2029 * Encode LOOKUP_ROOT request
2030 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002031static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2032 struct xdr_stream *xdr,
2033 const struct nfs4_lookup_root_arg *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_putrootfh(xdr, &hdr);
2042 encode_getfh(xdr, &hdr);
2043 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002044 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045}
2046
2047/*
2048 * Encode REMOVE request
2049 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002050static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2051 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002054 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056
Chuck Lever9f06c712010-12-14 14:59:18 +00002057 encode_compound_hdr(xdr, req, &hdr);
2058 encode_sequence(xdr, &args->seq_args, &hdr);
2059 encode_putfh(xdr, args->fh, &hdr);
2060 encode_remove(xdr, &args->name, &hdr);
2061 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002062 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063}
2064
2065/*
2066 * Encode RENAME request
2067 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002068static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2069 const struct nfs_renameargs *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->old_dir, &hdr);
2078 encode_savefh(xdr, &hdr);
2079 encode_putfh(xdr, args->new_dir, &hdr);
2080 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2081 encode_getfattr(xdr, args->bitmask, &hdr);
2082 encode_restorefh(xdr, &hdr);
2083 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002084 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085}
2086
2087/*
2088 * Encode LINK request
2089 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002090static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2091 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002094 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096
Chuck Lever9f06c712010-12-14 14:59:18 +00002097 encode_compound_hdr(xdr, req, &hdr);
2098 encode_sequence(xdr, &args->seq_args, &hdr);
2099 encode_putfh(xdr, args->fh, &hdr);
2100 encode_savefh(xdr, &hdr);
2101 encode_putfh(xdr, args->dir_fh, &hdr);
2102 encode_link(xdr, args->name, &hdr);
2103 encode_getfattr(xdr, args->bitmask, &hdr);
2104 encode_restorefh(xdr, &hdr);
2105 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002106 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107}
2108
2109/*
2110 * Encode CREATE request
2111 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002112static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2113 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002116 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
Chuck Lever9f06c712010-12-14 14:59:18 +00002119 encode_compound_hdr(xdr, req, &hdr);
2120 encode_sequence(xdr, &args->seq_args, &hdr);
2121 encode_putfh(xdr, args->dir_fh, &hdr);
2122 encode_savefh(xdr, &hdr);
2123 encode_create(xdr, args, &hdr);
2124 encode_getfh(xdr, &hdr);
2125 encode_getfattr(xdr, args->bitmask, &hdr);
2126 encode_restorefh(xdr, &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 SYMLINK request
2133 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002134static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2135 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136{
Chuck Lever9f06c712010-12-14 14:59:18 +00002137 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138}
2139
2140/*
2141 * Encode GETATTR request
2142 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002143static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2144 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002147 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
Chuck Lever9f06c712010-12-14 14:59:18 +00002150 encode_compound_hdr(xdr, req, &hdr);
2151 encode_sequence(xdr, &args->seq_args, &hdr);
2152 encode_putfh(xdr, args->fh, &hdr);
2153 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002154 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155}
2156
2157/*
2158 * Encode a CLOSE request
2159 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002160static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2161 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162{
Andy Adamson05d564f2008-12-23 16:06:15 -05002163 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002164 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002165 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
Chuck Lever9f06c712010-12-14 14:59:18 +00002167 encode_compound_hdr(xdr, req, &hdr);
2168 encode_sequence(xdr, &args->seq_args, &hdr);
2169 encode_putfh(xdr, args->fh, &hdr);
2170 encode_close(xdr, args, &hdr);
2171 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002172 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173}
2174
2175/*
2176 * Encode an OPEN request
2177 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002178static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2179 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002182 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184
Chuck Lever9f06c712010-12-14 14:59:18 +00002185 encode_compound_hdr(xdr, req, &hdr);
2186 encode_sequence(xdr, &args->seq_args, &hdr);
2187 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002188 encode_open(xdr, args, &hdr);
2189 encode_getfh(xdr, &hdr);
2190 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002191 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192}
2193
2194/*
2195 * Encode an OPEN_CONFIRM request
2196 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002197static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2198 struct xdr_stream *xdr,
2199 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002202 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204
Chuck Lever9f06c712010-12-14 14:59:18 +00002205 encode_compound_hdr(xdr, req, &hdr);
2206 encode_putfh(xdr, args->fh, &hdr);
2207 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002208 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209}
2210
2211/*
2212 * Encode an OPEN request with no attributes.
2213 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002214static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2215 struct xdr_stream *xdr,
2216 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002219 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
Chuck Lever9f06c712010-12-14 14:59:18 +00002222 encode_compound_hdr(xdr, req, &hdr);
2223 encode_sequence(xdr, &args->seq_args, &hdr);
2224 encode_putfh(xdr, args->fh, &hdr);
2225 encode_open(xdr, args, &hdr);
2226 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002227 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228}
2229
2230/*
2231 * Encode an OPEN_DOWNGRADE request
2232 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002233static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2234 struct xdr_stream *xdr,
2235 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002238 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
Chuck Lever9f06c712010-12-14 14:59:18 +00002241 encode_compound_hdr(xdr, req, &hdr);
2242 encode_sequence(xdr, &args->seq_args, &hdr);
2243 encode_putfh(xdr, args->fh, &hdr);
2244 encode_open_downgrade(xdr, args, &hdr);
2245 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002246 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247}
2248
2249/*
2250 * Encode a LOCK request
2251 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002252static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2253 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002256 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258
Chuck Lever9f06c712010-12-14 14:59:18 +00002259 encode_compound_hdr(xdr, req, &hdr);
2260 encode_sequence(xdr, &args->seq_args, &hdr);
2261 encode_putfh(xdr, args->fh, &hdr);
2262 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002263 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264}
2265
2266/*
2267 * Encode a LOCKT request
2268 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002269static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2270 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002273 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
Chuck Lever9f06c712010-12-14 14:59:18 +00002276 encode_compound_hdr(xdr, req, &hdr);
2277 encode_sequence(xdr, &args->seq_args, &hdr);
2278 encode_putfh(xdr, args->fh, &hdr);
2279 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002280 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281}
2282
2283/*
2284 * Encode a LOCKU request
2285 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002286static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2287 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002290 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
Chuck Lever9f06c712010-12-14 14:59:18 +00002293 encode_compound_hdr(xdr, req, &hdr);
2294 encode_sequence(xdr, &args->seq_args, &hdr);
2295 encode_putfh(xdr, args->fh, &hdr);
2296 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002297 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298}
2299
Chuck Lever9f06c712010-12-14 14:59:18 +00002300static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2301 struct xdr_stream *xdr,
2302 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002303{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002304 struct compound_hdr hdr = {
2305 .minorversion = 0,
2306 };
2307
Chuck Lever9f06c712010-12-14 14:59:18 +00002308 encode_compound_hdr(xdr, req, &hdr);
2309 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002310 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002311}
2312
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313/*
2314 * Encode a READLINK request
2315 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002316static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2317 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002320 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322
Chuck Lever9f06c712010-12-14 14:59:18 +00002323 encode_compound_hdr(xdr, req, &hdr);
2324 encode_sequence(xdr, &args->seq_args, &hdr);
2325 encode_putfh(xdr, args->fh, &hdr);
2326 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002327
Benny Halevy28f56692009-04-01 09:22:09 -04002328 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002329 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002330 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331}
2332
2333/*
2334 * Encode a READDIR request
2335 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002336static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2337 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002340 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342
Chuck Lever9f06c712010-12-14 14:59:18 +00002343 encode_compound_hdr(xdr, req, &hdr);
2344 encode_sequence(xdr, &args->seq_args, &hdr);
2345 encode_putfh(xdr, args->fh, &hdr);
2346 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002347
Benny Halevy28f56692009-04-01 09:22:09 -04002348 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002349 args->pgbase, args->count);
2350 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002351 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002352 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002353 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354}
2355
2356/*
2357 * Encode a READ request
2358 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002359static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2360 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002363 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365
Chuck Lever9f06c712010-12-14 14:59:18 +00002366 encode_compound_hdr(xdr, req, &hdr);
2367 encode_sequence(xdr, &args->seq_args, &hdr);
2368 encode_putfh(xdr, args->fh, &hdr);
2369 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370
Benny Halevy28f56692009-04-01 09:22:09 -04002371 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002373 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002374 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375}
2376
2377/*
2378 * Encode an SETATTR request
2379 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002380static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2381 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382{
Andy Adamson05d564f2008-12-23 16:06:15 -05002383 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002384 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002385 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386
Chuck Lever9f06c712010-12-14 14:59:18 +00002387 encode_compound_hdr(xdr, req, &hdr);
2388 encode_sequence(xdr, &args->seq_args, &hdr);
2389 encode_putfh(xdr, args->fh, &hdr);
2390 encode_setattr(xdr, args, args->server, &hdr);
2391 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002392 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393}
2394
2395/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002396 * Encode a GETACL request
2397 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002398static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2399 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002400{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002401 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002402 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002403 };
Benny Halevy28f56692009-04-01 09:22:09 -04002404 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002405
Chuck Lever9f06c712010-12-14 14:59:18 +00002406 encode_compound_hdr(xdr, req, &hdr);
2407 encode_sequence(xdr, &args->seq_args, &hdr);
2408 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002409 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002410 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002411
Benny Halevy28f56692009-04-01 09:22:09 -04002412 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002413 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002414
Andy Adamsond0179312008-12-23 16:06:17 -05002415 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002416}
2417
2418/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 * Encode a WRITE request
2420 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002421static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2422 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002425 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
Chuck Lever9f06c712010-12-14 14:59:18 +00002428 encode_compound_hdr(xdr, req, &hdr);
2429 encode_sequence(xdr, &args->seq_args, &hdr);
2430 encode_putfh(xdr, args->fh, &hdr);
2431 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002432 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002433 if (args->bitmask)
2434 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002435 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436}
2437
2438/*
2439 * a COMMIT request
2440 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002441static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002442 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002445 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447
Chuck Lever9f06c712010-12-14 14:59:18 +00002448 encode_compound_hdr(xdr, req, &hdr);
2449 encode_sequence(xdr, &args->seq_args, &hdr);
2450 encode_putfh(xdr, args->fh, &hdr);
2451 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002452 if (args->bitmask)
2453 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002454 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455}
2456
2457/*
2458 * FSINFO request
2459 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002460static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2461 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002464 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466
Chuck Lever9f06c712010-12-14 14:59:18 +00002467 encode_compound_hdr(xdr, req, &hdr);
2468 encode_sequence(xdr, &args->seq_args, &hdr);
2469 encode_putfh(xdr, args->fh, &hdr);
2470 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002471 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472}
2473
2474/*
2475 * a PATHCONF request
2476 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002477static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2478 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002481 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483
Chuck Lever9f06c712010-12-14 14:59:18 +00002484 encode_compound_hdr(xdr, req, &hdr);
2485 encode_sequence(xdr, &args->seq_args, &hdr);
2486 encode_putfh(xdr, args->fh, &hdr);
2487 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002488 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002489 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490}
2491
2492/*
2493 * a STATFS request
2494 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002495static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2496 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002499 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501
Chuck Lever9f06c712010-12-14 14:59:18 +00002502 encode_compound_hdr(xdr, req, &hdr);
2503 encode_sequence(xdr, &args->seq_args, &hdr);
2504 encode_putfh(xdr, args->fh, &hdr);
2505 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002506 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002507 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508}
2509
2510/*
2511 * GETATTR_BITMAP request
2512 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002513static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2514 struct xdr_stream *xdr,
2515 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002518 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520
Chuck Lever9f06c712010-12-14 14:59:18 +00002521 encode_compound_hdr(xdr, req, &hdr);
2522 encode_sequence(xdr, &args->seq_args, &hdr);
2523 encode_putfh(xdr, args->fhandle, &hdr);
2524 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002525 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002526 FATTR4_WORD0_LINK_SUPPORT|
2527 FATTR4_WORD0_SYMLINK_SUPPORT|
2528 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002529 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530}
2531
2532/*
2533 * a RENEW request
2534 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002535static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2536 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002539 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 };
2541
Chuck Lever9f06c712010-12-14 14:59:18 +00002542 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002543 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002544 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545}
2546
2547/*
2548 * a SETCLIENTID request
2549 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002550static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2551 struct xdr_stream *xdr,
2552 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002555 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 };
2557
Chuck Lever9f06c712010-12-14 14:59:18 +00002558 encode_compound_hdr(xdr, req, &hdr);
2559 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002560 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561}
2562
2563/*
2564 * a SETCLIENTID_CONFIRM request
2565 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002566static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2567 struct xdr_stream *xdr,
2568 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002571 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 };
Fred Isamandae100c2011-07-30 20:52:37 -04002573 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574
Chuck Lever9f06c712010-12-14 14:59:18 +00002575 encode_compound_hdr(xdr, req, &hdr);
2576 encode_setclientid_confirm(xdr, arg, &hdr);
2577 encode_putrootfh(xdr, &hdr);
2578 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002579 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580}
2581
2582/*
2583 * DELEGRETURN request
2584 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002585static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2586 struct xdr_stream *xdr,
2587 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002590 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592
Chuck Lever9f06c712010-12-14 14:59:18 +00002593 encode_compound_hdr(xdr, req, &hdr);
2594 encode_sequence(xdr, &args->seq_args, &hdr);
2595 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002596 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002597 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002598 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599}
2600
2601/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002602 * Encode FS_LOCATIONS request
2603 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002604static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2605 struct xdr_stream *xdr,
2606 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002607{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002608 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002609 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002610 };
Benny Halevy28f56692009-04-01 09:22:09 -04002611 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002612
Chuck Lever9f06c712010-12-14 14:59:18 +00002613 encode_compound_hdr(xdr, req, &hdr);
2614 encode_sequence(xdr, &args->seq_args, &hdr);
2615 encode_putfh(xdr, args->dir_fh, &hdr);
2616 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002617 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002618 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002619
Benny Halevy28f56692009-04-01 09:22:09 -04002620 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002621 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002622 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002623}
2624
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002625/*
2626 * Encode SECINFO request
2627 */
2628static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2629 struct xdr_stream *xdr,
2630 struct nfs4_secinfo_arg *args)
2631{
2632 struct compound_hdr hdr = {
2633 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2634 };
2635
2636 encode_compound_hdr(xdr, req, &hdr);
2637 encode_sequence(xdr, &args->seq_args, &hdr);
2638 encode_putfh(xdr, args->dir_fh, &hdr);
2639 encode_secinfo(xdr, args->name, &hdr);
2640 encode_nops(&hdr);
2641}
2642
Benny Halevy99fe60d2009-04-01 09:22:29 -04002643#if defined(CONFIG_NFS_V4_1)
2644/*
2645 * EXCHANGE_ID request
2646 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002647static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2648 struct xdr_stream *xdr,
2649 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002650{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002651 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002652 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002653 };
2654
Chuck Lever9f06c712010-12-14 14:59:18 +00002655 encode_compound_hdr(xdr, req, &hdr);
2656 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002657 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002658}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002659
2660/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002661 * a CREATE_SESSION request
2662 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002663static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2664 struct xdr_stream *xdr,
2665 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002666{
Andy Adamsonfc931582009-04-01 09:22:31 -04002667 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002668 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002669 };
2670
Chuck Lever9f06c712010-12-14 14:59:18 +00002671 encode_compound_hdr(xdr, req, &hdr);
2672 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002673 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002674}
2675
2676/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002677 * a DESTROY_SESSION request
2678 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002679static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2680 struct xdr_stream *xdr,
2681 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002682{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002683 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002684 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002685 };
2686
Chuck Lever9f06c712010-12-14 14:59:18 +00002687 encode_compound_hdr(xdr, req, &hdr);
2688 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002689 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002690}
2691
2692/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002693 * a SEQUENCE request
2694 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002695static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2696 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002697{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002698 struct compound_hdr hdr = {
2699 .minorversion = nfs4_xdr_minorversion(args),
2700 };
2701
Chuck Lever9f06c712010-12-14 14:59:18 +00002702 encode_compound_hdr(xdr, req, &hdr);
2703 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002704 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002705}
2706
2707/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002708 * a GET_LEASE_TIME request
2709 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002710static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2711 struct xdr_stream *xdr,
2712 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002713{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002714 struct compound_hdr hdr = {
2715 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2716 };
Fred Isamandae100c2011-07-30 20:52:37 -04002717 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002718
Chuck Lever9f06c712010-12-14 14:59:18 +00002719 encode_compound_hdr(xdr, req, &hdr);
2720 encode_sequence(xdr, &args->la_seq_args, &hdr);
2721 encode_putrootfh(xdr, &hdr);
2722 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002723 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002724}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002725
2726/*
2727 * a RECLAIM_COMPLETE request
2728 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002729static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2730 struct xdr_stream *xdr,
2731 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002732{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002733 struct compound_hdr hdr = {
2734 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2735 };
2736
Chuck Lever9f06c712010-12-14 14:59:18 +00002737 encode_compound_hdr(xdr, req, &hdr);
2738 encode_sequence(xdr, &args->seq_args, &hdr);
2739 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002740 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002741}
2742
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002743/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002744 * Encode GETDEVICELIST request
2745 */
2746static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2747 struct xdr_stream *xdr,
2748 struct nfs4_getdevicelist_args *args)
2749{
2750 struct compound_hdr hdr = {
2751 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2752 };
2753
2754 encode_compound_hdr(xdr, req, &hdr);
2755 encode_sequence(xdr, &args->seq_args, &hdr);
2756 encode_putfh(xdr, args->fh, &hdr);
2757 encode_getdevicelist(xdr, args, &hdr);
2758 encode_nops(&hdr);
2759}
2760
2761/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002762 * Encode GETDEVICEINFO request
2763 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002764static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2765 struct xdr_stream *xdr,
2766 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002767{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002768 struct compound_hdr hdr = {
2769 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2770 };
2771
Chuck Lever9f06c712010-12-14 14:59:18 +00002772 encode_compound_hdr(xdr, req, &hdr);
2773 encode_sequence(xdr, &args->seq_args, &hdr);
2774 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002775
2776 /* set up reply kvec. Subtract notification bitmap max size (2)
2777 * so that notification bitmap is put in xdr_buf tail */
2778 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2779 args->pdev->pages, args->pdev->pgbase,
2780 args->pdev->pglen);
2781
2782 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002783}
2784
2785/*
2786 * Encode LAYOUTGET request
2787 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002788static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2789 struct xdr_stream *xdr,
2790 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002791{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002792 struct compound_hdr hdr = {
2793 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2794 };
2795
Chuck Lever9f06c712010-12-14 14:59:18 +00002796 encode_compound_hdr(xdr, req, &hdr);
2797 encode_sequence(xdr, &args->seq_args, &hdr);
2798 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2799 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002800
2801 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2802 args->layout.pages, 0, args->layout.pglen);
2803
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002804 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002805}
Andy Adamson863a3c62011-03-23 13:27:54 +00002806
2807/*
2808 * Encode LAYOUTCOMMIT request
2809 */
Benny Halevycbe82602011-05-22 19:52:37 +03002810static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2811 struct xdr_stream *xdr,
2812 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002813{
Benny Halevyac7db722011-05-22 19:53:48 +03002814 struct nfs4_layoutcommit_data *data =
2815 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002816 struct compound_hdr hdr = {
2817 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2818 };
2819
2820 encode_compound_hdr(xdr, req, &hdr);
2821 encode_sequence(xdr, &args->seq_args, &hdr);
2822 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002823 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002824 encode_getfattr(xdr, args->bitmask, &hdr);
2825 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002826}
2827
2828/*
2829 * Encode LAYOUTRETURN request
2830 */
2831static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2832 struct xdr_stream *xdr,
2833 struct nfs4_layoutreturn_args *args)
2834{
2835 struct compound_hdr hdr = {
2836 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2837 };
2838
2839 encode_compound_hdr(xdr, req, &hdr);
2840 encode_sequence(xdr, &args->seq_args, &hdr);
2841 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2842 encode_layoutreturn(xdr, args, &hdr);
2843 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002844}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002845
2846/*
2847 * Encode SECINFO_NO_NAME request
2848 */
2849static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2850 struct xdr_stream *xdr,
2851 struct nfs41_secinfo_no_name_args *args)
2852{
2853 struct compound_hdr hdr = {
2854 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2855 };
2856
2857 encode_compound_hdr(xdr, req, &hdr);
2858 encode_sequence(xdr, &args->seq_args, &hdr);
2859 encode_putrootfh(xdr, &hdr);
2860 encode_secinfo_no_name(xdr, args, &hdr);
2861 encode_nops(&hdr);
2862 return 0;
2863}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002864
2865/*
2866 * Encode TEST_STATEID request
2867 */
2868static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2869 struct xdr_stream *xdr,
2870 struct nfs41_test_stateid_args *args)
2871{
2872 struct compound_hdr hdr = {
2873 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2874 };
2875
2876 encode_compound_hdr(xdr, req, &hdr);
2877 encode_sequence(xdr, &args->seq_args, &hdr);
2878 encode_test_stateid(xdr, args, &hdr);
2879 encode_nops(&hdr);
2880}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002881
2882/*
2883 * Encode FREE_STATEID request
2884 */
2885static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2886 struct xdr_stream *xdr,
2887 struct nfs41_free_stateid_args *args)
2888{
2889 struct compound_hdr hdr = {
2890 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2891 };
2892
2893 encode_compound_hdr(xdr, req, &hdr);
2894 encode_sequence(xdr, &args->seq_args, &hdr);
2895 encode_free_stateid(xdr, args, &hdr);
2896 encode_nops(&hdr);
2897}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002898#endif /* CONFIG_NFS_V4_1 */
2899
Benny Halevy686841b2009-08-14 17:19:48 +03002900static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2901{
2902 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2903 "Remaining buffer length is %tu words.\n",
2904 func, xdr->end - xdr->p);
2905}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906
Trond Myklebust683b57b2006-06-09 09:34:22 -04002907static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908{
Al Viro8687b632006-10-19 23:28:48 -07002909 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910
Benny Halevyc0eae662009-08-14 17:20:14 +03002911 p = xdr_inline_decode(xdr, 4);
2912 if (unlikely(!p))
2913 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002914 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002915 p = xdr_inline_decode(xdr, *len);
2916 if (unlikely(!p))
2917 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 *string = (char *)p;
2919 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002920out_overflow:
2921 print_overflow_msg(__func__, xdr);
2922 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923}
2924
2925static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2926{
Al Viro8687b632006-10-19 23:28:48 -07002927 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928
Benny Halevyc0eae662009-08-14 17:20:14 +03002929 p = xdr_inline_decode(xdr, 8);
2930 if (unlikely(!p))
2931 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002932 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002933 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002934
Benny Halevyc0eae662009-08-14 17:20:14 +03002935 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2936 if (unlikely(!p))
2937 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 hdr->tag = (char *)p;
2939 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002940 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002941 if (unlikely(hdr->nops < 1))
2942 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002944out_overflow:
2945 print_overflow_msg(__func__, xdr);
2946 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947}
2948
2949static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2950{
Al Viro8687b632006-10-19 23:28:48 -07002951 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 uint32_t opnum;
2953 int32_t nfserr;
2954
Benny Halevyc0eae662009-08-14 17:20:14 +03002955 p = xdr_inline_decode(xdr, 8);
2956 if (unlikely(!p))
2957 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002958 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002960 dprintk("nfs: Server returned operation"
2961 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 opnum, expected);
2963 return -EIO;
2964 }
Benny Halevycccddf42009-08-14 17:20:19 +03002965 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002967 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002969out_overflow:
2970 print_overflow_msg(__func__, xdr);
2971 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972}
2973
2974/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002975static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976{
Al Viro8687b632006-10-19 23:28:48 -07002977 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002978 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 char *str;
2980
Benny Halevyc0eae662009-08-14 17:20:14 +03002981 p = xdr_inline_decode(xdr, 12);
2982 if (likely(p))
2983 return decode_opaque_inline(xdr, &strlen, &str);
2984 print_overflow_msg(__func__, xdr);
2985 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986}
2987
2988static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2989{
Al Viro8687b632006-10-19 23:28:48 -07002990 uint32_t bmlen;
2991 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992
Benny Halevyc0eae662009-08-14 17:20:14 +03002993 p = xdr_inline_decode(xdr, 4);
2994 if (unlikely(!p))
2995 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002996 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997
Fred Isamandae100c2011-07-30 20:52:37 -04002998 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002999 p = xdr_inline_decode(xdr, (bmlen << 2));
3000 if (unlikely(!p))
3001 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003003 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003004 if (bmlen > 1) {
3005 bitmap[1] = be32_to_cpup(p++);
3006 if (bmlen > 2)
3007 bitmap[2] = be32_to_cpup(p);
3008 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 }
3010 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003011out_overflow:
3012 print_overflow_msg(__func__, xdr);
3013 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014}
3015
Al Viro8687b632006-10-19 23:28:48 -07003016static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017{
Al Viro8687b632006-10-19 23:28:48 -07003018 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019
Benny Halevyc0eae662009-08-14 17:20:14 +03003020 p = xdr_inline_decode(xdr, 4);
3021 if (unlikely(!p))
3022 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003023 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 *savep = xdr->p;
3025 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003026out_overflow:
3027 print_overflow_msg(__func__, xdr);
3028 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029}
3030
3031static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3032{
3033 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003034 int ret;
3035 ret = decode_attr_bitmap(xdr, bitmask);
3036 if (unlikely(ret < 0))
3037 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3039 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003040 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3041 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3042 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 return 0;
3044}
3045
3046static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3047{
Al Viro8687b632006-10-19 23:28:48 -07003048 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003049 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050
3051 *type = 0;
3052 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3053 return -EIO;
3054 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003055 p = xdr_inline_decode(xdr, 4);
3056 if (unlikely(!p))
3057 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003058 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003060 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 return -EIO;
3062 }
3063 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003064 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003066 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003067 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003068out_overflow:
3069 print_overflow_msg(__func__, xdr);
3070 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071}
3072
Chuck Lever264e6352012-03-01 17:02:05 -05003073static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3074 uint32_t *bitmap, uint32_t *type)
3075{
3076 __be32 *p;
3077
3078 *type = 0;
3079 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3080 return -EIO;
3081 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3082 p = xdr_inline_decode(xdr, 4);
3083 if (unlikely(!p))
3084 goto out_overflow;
3085 *type = be32_to_cpup(p);
3086 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3087 }
3088 dprintk("%s: expire type=0x%x\n", __func__, *type);
3089 return 0;
3090out_overflow:
3091 print_overflow_msg(__func__, xdr);
3092 return -EIO;
3093}
3094
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3096{
Al Viro8687b632006-10-19 23:28:48 -07003097 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003098 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099
3100 *change = 0;
3101 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3102 return -EIO;
3103 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003104 p = xdr_inline_decode(xdr, 8);
3105 if (unlikely(!p))
3106 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003107 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003109 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003111 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003113 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003114out_overflow:
3115 print_overflow_msg(__func__, xdr);
3116 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117}
3118
3119static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3120{
Al Viro8687b632006-10-19 23:28:48 -07003121 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003122 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123
3124 *size = 0;
3125 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3126 return -EIO;
3127 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003128 p = xdr_inline_decode(xdr, 8);
3129 if (unlikely(!p))
3130 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003131 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003133 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003135 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003136 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003137out_overflow:
3138 print_overflow_msg(__func__, xdr);
3139 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140}
3141
3142static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3143{
Al Viro8687b632006-10-19 23:28:48 -07003144 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145
3146 *res = 0;
3147 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3148 return -EIO;
3149 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003150 p = xdr_inline_decode(xdr, 4);
3151 if (unlikely(!p))
3152 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003153 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3155 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003156 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003158out_overflow:
3159 print_overflow_msg(__func__, xdr);
3160 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161}
3162
3163static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3164{
Al Viro8687b632006-10-19 23:28:48 -07003165 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166
3167 *res = 0;
3168 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3169 return -EIO;
3170 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003171 p = xdr_inline_decode(xdr, 4);
3172 if (unlikely(!p))
3173 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003174 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3176 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003177 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003179out_overflow:
3180 print_overflow_msg(__func__, xdr);
3181 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182}
3183
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003184static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185{
Al Viro8687b632006-10-19 23:28:48 -07003186 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003187 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188
3189 fsid->major = 0;
3190 fsid->minor = 0;
3191 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3192 return -EIO;
3193 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003194 p = xdr_inline_decode(xdr, 16);
3195 if (unlikely(!p))
3196 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003197 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003198 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003200 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003202 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 (unsigned long long)fsid->major,
3204 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003205 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003206out_overflow:
3207 print_overflow_msg(__func__, xdr);
3208 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209}
3210
3211static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3212{
Al Viro8687b632006-10-19 23:28:48 -07003213 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214
3215 *res = 60;
3216 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3217 return -EIO;
3218 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003219 p = xdr_inline_decode(xdr, 4);
3220 if (unlikely(!p))
3221 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003222 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3224 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003225 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003227out_overflow:
3228 print_overflow_msg(__func__, xdr);
3229 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230}
3231
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003232static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003233{
3234 __be32 *p;
3235
3236 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3237 return -EIO;
3238 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3239 p = xdr_inline_decode(xdr, 4);
3240 if (unlikely(!p))
3241 goto out_overflow;
3242 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003243 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003244 }
3245 return 0;
3246out_overflow:
3247 print_overflow_msg(__func__, xdr);
3248 return -EIO;
3249}
3250
3251static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3252{
3253 __be32 *p;
3254 int len;
3255
Trond Myklebust7ad07352010-10-23 15:34:20 -04003256 if (fh != NULL)
3257 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003258
3259 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3260 return -EIO;
3261 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3262 p = xdr_inline_decode(xdr, 4);
3263 if (unlikely(!p))
3264 goto out_overflow;
3265 len = be32_to_cpup(p);
3266 if (len > NFS4_FHSIZE)
3267 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003268 p = xdr_inline_decode(xdr, len);
3269 if (unlikely(!p))
3270 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003271 if (fh != NULL) {
3272 memcpy(fh->data, p, len);
3273 fh->size = len;
3274 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003275 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3276 }
3277 return 0;
3278out_overflow:
3279 print_overflow_msg(__func__, xdr);
3280 return -EIO;
3281}
3282
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3284{
Al Viro8687b632006-10-19 23:28:48 -07003285 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286
3287 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3288 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3289 return -EIO;
3290 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003291 p = xdr_inline_decode(xdr, 4);
3292 if (unlikely(!p))
3293 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003294 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3296 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003297 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003299out_overflow:
3300 print_overflow_msg(__func__, xdr);
3301 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302}
3303
3304static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3305{
Al Viro8687b632006-10-19 23:28:48 -07003306 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003307 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308
3309 *fileid = 0;
3310 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3311 return -EIO;
3312 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003313 p = xdr_inline_decode(xdr, 8);
3314 if (unlikely(!p))
3315 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003316 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003318 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003320 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003321 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003322out_overflow:
3323 print_overflow_msg(__func__, xdr);
3324 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325}
3326
Manoj Naik99baf622006-06-09 09:34:24 -04003327static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3328{
Al Viro8687b632006-10-19 23:28:48 -07003329 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003330 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003331
3332 *fileid = 0;
3333 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3334 return -EIO;
3335 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003336 p = xdr_inline_decode(xdr, 8);
3337 if (unlikely(!p))
3338 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003339 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003340 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003341 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003342 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003343 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003344 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003345out_overflow:
3346 print_overflow_msg(__func__, xdr);
3347 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003348}
3349
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3351{
Al Viro8687b632006-10-19 23:28:48 -07003352 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 int status = 0;
3354
3355 *res = 0;
3356 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3357 return -EIO;
3358 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003359 p = xdr_inline_decode(xdr, 8);
3360 if (unlikely(!p))
3361 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003362 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3364 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003365 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003367out_overflow:
3368 print_overflow_msg(__func__, xdr);
3369 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370}
3371
3372static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3373{
Al Viro8687b632006-10-19 23:28:48 -07003374 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 int status = 0;
3376
3377 *res = 0;
3378 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3379 return -EIO;
3380 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003381 p = xdr_inline_decode(xdr, 8);
3382 if (unlikely(!p))
3383 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003384 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3386 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003387 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003389out_overflow:
3390 print_overflow_msg(__func__, xdr);
3391 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392}
3393
3394static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3395{
Al Viro8687b632006-10-19 23:28:48 -07003396 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397 int status = 0;
3398
3399 *res = 0;
3400 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3401 return -EIO;
3402 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003403 p = xdr_inline_decode(xdr, 8);
3404 if (unlikely(!p))
3405 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003406 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3408 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003409 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003411out_overflow:
3412 print_overflow_msg(__func__, xdr);
3413 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414}
3415
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003416static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3417{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003418 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003419 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003420 int status = 0;
3421
Benny Halevyc0eae662009-08-14 17:20:14 +03003422 p = xdr_inline_decode(xdr, 4);
3423 if (unlikely(!p))
3424 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003425 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003426 if (n == 0)
3427 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003428 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003429 path->ncomponents = 0;
3430 while (path->ncomponents < n) {
3431 struct nfs4_string *component = &path->components[path->ncomponents];
3432 status = decode_opaque_inline(xdr, &component->len, &component->data);
3433 if (unlikely(status != 0))
3434 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003435 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003436 pr_cont("%s%.*s ",
3437 (path->ncomponents != n ? "/ " : ""),
3438 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003439 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3440 path->ncomponents++;
3441 else {
3442 dprintk("cannot parse %d components in path\n", n);
3443 goto out_eio;
3444 }
3445 }
3446out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003447 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003448root_path:
3449/* a root pathname is sent as a zero component4 */
3450 path->ncomponents = 1;
3451 path->components[0].len=0;
3452 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003453 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003454 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003455out_eio:
3456 dprintk(" status %d", status);
3457 status = -EIO;
3458 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003459out_overflow:
3460 print_overflow_msg(__func__, xdr);
3461 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003462}
3463
3464static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003465{
3466 int n;
Al Viro8687b632006-10-19 23:28:48 -07003467 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003468 int status = -EIO;
3469
3470 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3471 goto out;
3472 status = 0;
3473 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3474 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003475 status = -EIO;
3476 /* Ignore borken servers that return unrequested attrs */
3477 if (unlikely(res == NULL))
3478 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003479 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003480 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003481 if (unlikely(status != 0))
3482 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003483 p = xdr_inline_decode(xdr, 4);
3484 if (unlikely(!p))
3485 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003486 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003487 if (n <= 0)
3488 goto out_eio;
3489 res->nlocations = 0;
3490 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003491 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003492 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003493
Benny Halevyc0eae662009-08-14 17:20:14 +03003494 p = xdr_inline_decode(xdr, 4);
3495 if (unlikely(!p))
3496 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003497 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003498
3499 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003500 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003501 while (loc->nservers < m) {
3502 struct nfs4_string *server = &loc->servers[loc->nservers];
3503 status = decode_opaque_inline(xdr, &server->len, &server->data);
3504 if (unlikely(status != 0))
3505 goto out_eio;
3506 dprintk("%s ", server->data);
3507 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3508 loc->nservers++;
3509 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003510 unsigned int i;
3511 dprintk("%s: using first %u of %u servers "
3512 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003513 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003514 NFS4_FS_LOCATION_MAXSERVERS,
3515 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003516 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003517 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003518 char *data;
3519 status = decode_opaque_inline(xdr, &len, &data);
3520 if (unlikely(status != 0))
3521 goto out_eio;
3522 }
3523 }
3524 }
3525 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003526 if (unlikely(status != 0))
3527 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003528 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003529 res->nlocations++;
3530 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003531 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003532 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003533out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003534 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003535 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003536out_overflow:
3537 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003538out_eio:
3539 status = -EIO;
3540 goto out;
3541}
3542
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3544{
Al Viro8687b632006-10-19 23:28:48 -07003545 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 int status = 0;
3547
3548 *res = 0;
3549 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3550 return -EIO;
3551 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003552 p = xdr_inline_decode(xdr, 8);
3553 if (unlikely(!p))
3554 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003555 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3557 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003558 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003560out_overflow:
3561 print_overflow_msg(__func__, xdr);
3562 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563}
3564
3565static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3566{
Al Viro8687b632006-10-19 23:28:48 -07003567 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568 int status = 0;
3569
3570 *maxlink = 1;
3571 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3572 return -EIO;
3573 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003574 p = xdr_inline_decode(xdr, 4);
3575 if (unlikely(!p))
3576 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003577 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3579 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003580 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003582out_overflow:
3583 print_overflow_msg(__func__, xdr);
3584 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585}
3586
3587static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3588{
Al Viro8687b632006-10-19 23:28:48 -07003589 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590 int status = 0;
3591
3592 *maxname = 1024;
3593 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3594 return -EIO;
3595 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003596 p = xdr_inline_decode(xdr, 4);
3597 if (unlikely(!p))
3598 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003599 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3601 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003602 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003604out_overflow:
3605 print_overflow_msg(__func__, xdr);
3606 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607}
3608
3609static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3610{
Al Viro8687b632006-10-19 23:28:48 -07003611 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612 int status = 0;
3613
3614 *res = 1024;
3615 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3616 return -EIO;
3617 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3618 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003619 p = xdr_inline_decode(xdr, 8);
3620 if (unlikely(!p))
3621 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003622 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623 if (maxread > 0x7FFFFFFF)
3624 maxread = 0x7FFFFFFF;
3625 *res = (uint32_t)maxread;
3626 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3627 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003628 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003630out_overflow:
3631 print_overflow_msg(__func__, xdr);
3632 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633}
3634
3635static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3636{
Al Viro8687b632006-10-19 23:28:48 -07003637 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638 int status = 0;
3639
3640 *res = 1024;
3641 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3642 return -EIO;
3643 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3644 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003645 p = xdr_inline_decode(xdr, 8);
3646 if (unlikely(!p))
3647 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003648 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649 if (maxwrite > 0x7FFFFFFF)
3650 maxwrite = 0x7FFFFFFF;
3651 *res = (uint32_t)maxwrite;
3652 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3653 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003654 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003656out_overflow:
3657 print_overflow_msg(__func__, xdr);
3658 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659}
3660
Trond Myklebustbca79472009-03-11 14:10:26 -04003661static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662{
Trond Myklebustbca79472009-03-11 14:10:26 -04003663 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003664 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003665 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666
3667 *mode = 0;
3668 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3669 return -EIO;
3670 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003671 p = xdr_inline_decode(xdr, 4);
3672 if (unlikely(!p))
3673 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003674 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003675 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003677 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003679 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003680 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003681out_overflow:
3682 print_overflow_msg(__func__, xdr);
3683 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684}
3685
3686static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3687{
Al Viro8687b632006-10-19 23:28:48 -07003688 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003689 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690
3691 *nlink = 1;
3692 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3693 return -EIO;
3694 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003695 p = xdr_inline_decode(xdr, 4);
3696 if (unlikely(!p))
3697 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003698 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003700 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003702 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003703 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003704out_overflow:
3705 print_overflow_msg(__func__, xdr);
3706 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707}
3708
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003709static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003710 const struct nfs_server *server, uint32_t *uid,
3711 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712{
Al Viro8687b632006-10-19 23:28:48 -07003713 uint32_t len;
3714 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003715 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716
3717 *uid = -2;
3718 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3719 return -EIO;
3720 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003721 p = xdr_inline_decode(xdr, 4);
3722 if (unlikely(!p))
3723 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003724 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003725 p = xdr_inline_decode(xdr, len);
3726 if (unlikely(!p))
3727 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003728 if (owner_name != NULL) {
3729 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3730 if (owner_name->data != NULL) {
3731 owner_name->len = len;
3732 ret = NFS_ATTR_FATTR_OWNER_NAME;
3733 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003734 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003735 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003736 ret = NFS_ATTR_FATTR_OWNER;
3737 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003739 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003741 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003742 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3744 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003745 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003746 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003747out_overflow:
3748 print_overflow_msg(__func__, xdr);
3749 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750}
3751
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003752static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003753 const struct nfs_server *server, uint32_t *gid,
3754 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755{
Al Viro8687b632006-10-19 23:28:48 -07003756 uint32_t len;
3757 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003758 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759
3760 *gid = -2;
3761 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3762 return -EIO;
3763 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003764 p = xdr_inline_decode(xdr, 4);
3765 if (unlikely(!p))
3766 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003767 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003768 p = xdr_inline_decode(xdr, len);
3769 if (unlikely(!p))
3770 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003771 if (group_name != NULL) {
3772 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3773 if (group_name->data != NULL) {
3774 group_name->len = len;
3775 ret = NFS_ATTR_FATTR_GROUP_NAME;
3776 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003777 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003778 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003779 ret = NFS_ATTR_FATTR_GROUP;
3780 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003782 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003784 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003785 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3787 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003788 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003789 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003790out_overflow:
3791 print_overflow_msg(__func__, xdr);
3792 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793}
3794
3795static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3796{
Al Viro8687b632006-10-19 23:28:48 -07003797 uint32_t major = 0, minor = 0;
3798 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003799 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800
3801 *rdev = MKDEV(0,0);
3802 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3803 return -EIO;
3804 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3805 dev_t tmp;
3806
Benny Halevyc0eae662009-08-14 17:20:14 +03003807 p = xdr_inline_decode(xdr, 8);
3808 if (unlikely(!p))
3809 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003810 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003811 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812 tmp = MKDEV(major, minor);
3813 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3814 *rdev = tmp;
3815 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003816 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003818 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003819 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003820out_overflow:
3821 print_overflow_msg(__func__, xdr);
3822 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823}
3824
3825static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3826{
Al Viro8687b632006-10-19 23:28:48 -07003827 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 int status = 0;
3829
3830 *res = 0;
3831 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3832 return -EIO;
3833 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003834 p = xdr_inline_decode(xdr, 8);
3835 if (unlikely(!p))
3836 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003837 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3839 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003840 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003842out_overflow:
3843 print_overflow_msg(__func__, xdr);
3844 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845}
3846
3847static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3848{
Al Viro8687b632006-10-19 23:28:48 -07003849 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 int status = 0;
3851
3852 *res = 0;
3853 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3854 return -EIO;
3855 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003856 p = xdr_inline_decode(xdr, 8);
3857 if (unlikely(!p))
3858 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003859 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3861 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003862 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003864out_overflow:
3865 print_overflow_msg(__func__, xdr);
3866 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867}
3868
3869static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3870{
Al Viro8687b632006-10-19 23:28:48 -07003871 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 int status = 0;
3873
3874 *res = 0;
3875 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3876 return -EIO;
3877 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003878 p = xdr_inline_decode(xdr, 8);
3879 if (unlikely(!p))
3880 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003881 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3883 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003884 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003886out_overflow:
3887 print_overflow_msg(__func__, xdr);
3888 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889}
3890
3891static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3892{
Al Viro8687b632006-10-19 23:28:48 -07003893 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003894 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895
3896 *used = 0;
3897 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3898 return -EIO;
3899 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003900 p = xdr_inline_decode(xdr, 8);
3901 if (unlikely(!p))
3902 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003903 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003905 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003907 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003909 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003910out_overflow:
3911 print_overflow_msg(__func__, xdr);
3912 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913}
3914
3915static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3916{
Al Viro8687b632006-10-19 23:28:48 -07003917 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 uint64_t sec;
3919 uint32_t nsec;
3920
Benny Halevyc0eae662009-08-14 17:20:14 +03003921 p = xdr_inline_decode(xdr, 12);
3922 if (unlikely(!p))
3923 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003924 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003925 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 time->tv_sec = (time_t)sec;
3927 time->tv_nsec = (long)nsec;
3928 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003929out_overflow:
3930 print_overflow_msg(__func__, xdr);
3931 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932}
3933
3934static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3935{
3936 int status = 0;
3937
3938 time->tv_sec = 0;
3939 time->tv_nsec = 0;
3940 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3941 return -EIO;
3942 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3943 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003944 if (status == 0)
3945 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3947 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003948 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 return status;
3950}
3951
3952static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3953{
3954 int status = 0;
3955
3956 time->tv_sec = 0;
3957 time->tv_nsec = 0;
3958 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3959 return -EIO;
3960 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3961 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003962 if (status == 0)
3963 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3965 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003966 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 return status;
3968}
3969
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003970static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3971 struct timespec *time)
3972{
3973 int status = 0;
3974
3975 time->tv_sec = 0;
3976 time->tv_nsec = 0;
3977 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3978 return -EIO;
3979 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3980 status = decode_attr_time(xdr, time);
3981 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3982 }
3983 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3984 (long)time->tv_nsec);
3985 return status;
3986}
3987
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3989{
3990 int status = 0;
3991
3992 time->tv_sec = 0;
3993 time->tv_nsec = 0;
3994 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3995 return -EIO;
3996 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3997 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003998 if (status == 0)
3999 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4001 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004002 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 return status;
4004}
4005
Al Viro8687b632006-10-19 23:28:48 -07004006static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007{
4008 unsigned int attrwords = XDR_QUADLEN(attrlen);
4009 unsigned int nwords = xdr->p - savep;
4010
4011 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004012 dprintk("%s: server returned incorrect attribute length: "
4013 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004014 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015 attrwords << 2,
4016 (attrwords < nwords) ? '<' : '>',
4017 nwords << 2);
4018 return -EIO;
4019 }
4020 return 0;
4021}
4022
4023static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4024{
Al Viro8687b632006-10-19 23:28:48 -07004025 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026
Benny Halevyc0eae662009-08-14 17:20:14 +03004027 p = xdr_inline_decode(xdr, 20);
4028 if (unlikely(!p))
4029 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004030 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004031 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004032 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004034out_overflow:
4035 print_overflow_msg(__func__, xdr);
4036 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037}
4038
4039static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4040{
Al Viro8687b632006-10-19 23:28:48 -07004041 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 uint32_t supp, acc;
4043 int status;
4044
4045 status = decode_op_hdr(xdr, OP_ACCESS);
4046 if (status)
4047 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004048 p = xdr_inline_decode(xdr, 8);
4049 if (unlikely(!p))
4050 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004051 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004052 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053 access->supported = supp;
4054 access->access = acc;
4055 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004056out_overflow:
4057 print_overflow_msg(__func__, xdr);
4058 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059}
4060
Benny Halevy07d30432009-08-14 17:19:52 +03004061static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062{
Al Viro8687b632006-10-19 23:28:48 -07004063 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004064
4065 p = xdr_inline_decode(xdr, len);
4066 if (likely(p)) {
4067 memcpy(buf, p, len);
4068 return 0;
4069 }
4070 print_overflow_msg(__func__, xdr);
4071 return -EIO;
4072}
4073
4074static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4075{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004076 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077}
4078
4079static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4080{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 int status;
4082
4083 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004084 if (status != -EIO)
4085 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004086 if (!status)
4087 status = decode_stateid(xdr, &res->stateid);
4088 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089}
4090
Benny Halevydb942bb2009-08-14 17:19:56 +03004091static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4092{
Chuck Levercd937102012-03-02 17:14:31 -05004093 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094}
4095
Fred Isaman0b7c0152012-04-20 14:47:39 -04004096static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 int status;
4099
4100 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004101 if (!status)
4102 status = decode_verifier(xdr, res->verf->verifier);
4103 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104}
4105
4106static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4107{
Al Viro8687b632006-10-19 23:28:48 -07004108 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 uint32_t bmlen;
4110 int status;
4111
4112 status = decode_op_hdr(xdr, OP_CREATE);
4113 if (status)
4114 return status;
4115 if ((status = decode_change_info(xdr, cinfo)))
4116 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004117 p = xdr_inline_decode(xdr, 4);
4118 if (unlikely(!p))
4119 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004120 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004121 p = xdr_inline_decode(xdr, bmlen << 2);
4122 if (likely(p))
4123 return 0;
4124out_overflow:
4125 print_overflow_msg(__func__, xdr);
4126 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127}
4128
4129static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4130{
Al Viro8687b632006-10-19 23:28:48 -07004131 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004132 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133 int status;
4134
4135 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4136 goto xdr_error;
4137 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4138 goto xdr_error;
4139 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4140 goto xdr_error;
4141 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4142 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004143 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4144 &res->fh_expire_type)) != 0)
4145 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4147 goto xdr_error;
4148 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4149 goto xdr_error;
4150 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4151 goto xdr_error;
4152 status = verify_attr_len(xdr, savep, attrlen);
4153xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004154 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155 return status;
4156}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004157
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4159{
Al Viro8687b632006-10-19 23:28:48 -07004160 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004161 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004163
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4165 goto xdr_error;
4166 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4167 goto xdr_error;
4168 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4169 goto xdr_error;
4170
4171 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4172 goto xdr_error;
4173 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4174 goto xdr_error;
4175 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4176 goto xdr_error;
4177 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4178 goto xdr_error;
4179 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4180 goto xdr_error;
4181 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4182 goto xdr_error;
4183
4184 status = verify_attr_len(xdr, savep, attrlen);
4185xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004186 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 return status;
4188}
4189
4190static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4191{
Al Viro8687b632006-10-19 23:28:48 -07004192 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004193 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004195
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4197 goto xdr_error;
4198 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4199 goto xdr_error;
4200 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4201 goto xdr_error;
4202
4203 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4204 goto xdr_error;
4205 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4206 goto xdr_error;
4207
4208 status = verify_attr_len(xdr, savep, attrlen);
4209xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004210 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211 return status;
4212}
4213
Bryan Schumakerae42c702010-10-21 16:33:17 -04004214static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4215 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004216 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004217 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218{
Trond Myklebustbca79472009-03-11 14:10:26 -04004219 int status;
4220 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004221 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004222 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004224 status = decode_attr_type(xdr, bitmap, &type);
4225 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004227 fattr->mode = 0;
4228 if (status != 0) {
4229 fattr->mode |= nfs_type2fmt[type];
4230 fattr->valid |= status;
4231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004233 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4234 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004236 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004237
4238 status = decode_attr_size(xdr, bitmap, &fattr->size);
4239 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004241 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004242
4243 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4244 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004246 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004247
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004248 err = 0;
4249 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004250 if (status < 0)
4251 goto xdr_error;
4252
4253 status = decode_attr_filehandle(xdr, bitmap, fh);
4254 if (status < 0)
4255 goto xdr_error;
4256
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004257 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4258 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
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004262 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004263 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004264 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_mode(xdr, bitmap, &fmode);
4268 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004270 if (status != 0) {
4271 fattr->mode |= fmode;
4272 fattr->valid |= status;
4273 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004274
4275 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4276 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004278 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004279
Trond Myklebust6926afd2012-01-07 13:22:46 -05004280 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004281 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004283 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004284
Trond Myklebust6926afd2012-01-07 13:22:46 -05004285 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004286 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004288 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004289
4290 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4291 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004293 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004294
4295 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4296 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004298 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004299
4300 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4301 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004303 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004304
4305 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4306 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004308 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004309
4310 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4311 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004313 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004314
Trond Myklebust28331a42011-04-27 13:47:52 -04004315 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004316 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004317 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004318 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004319
Bryan Schumakerae42c702010-10-21 16:33:17 -04004320xdr_error:
4321 dprintk("%s: xdr returned %d\n", __func__, -status);
4322 return status;
4323}
4324
4325static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004326 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4327 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004328{
4329 __be32 *savep;
4330 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004331 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004332 int status;
4333
4334 status = decode_op_hdr(xdr, OP_GETATTR);
4335 if (status < 0)
4336 goto xdr_error;
4337
4338 status = decode_attr_bitmap(xdr, bitmap);
4339 if (status < 0)
4340 goto xdr_error;
4341
4342 status = decode_attr_length(xdr, &attrlen, &savep);
4343 if (status < 0)
4344 goto xdr_error;
4345
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004346 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004347 if (status < 0)
4348 goto xdr_error;
4349
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004350 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004352 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353 return status;
4354}
4355
Bryan Schumakerae42c702010-10-21 16:33:17 -04004356static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004357 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004358{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004359 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004360}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361
Andy Adamson504913f2010-10-20 00:17:57 -04004362/*
4363 * Decode potentially multiple layout types. Currently we only support
4364 * one layout driver per file system.
4365 */
4366static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4367 uint32_t *layouttype)
4368{
4369 uint32_t *p;
4370 int num;
4371
4372 p = xdr_inline_decode(xdr, 4);
4373 if (unlikely(!p))
4374 goto out_overflow;
4375 num = be32_to_cpup(p);
4376
4377 /* pNFS is not supported by the underlying file system */
4378 if (num == 0) {
4379 *layouttype = 0;
4380 return 0;
4381 }
4382 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004383 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4384 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004385
4386 /* Decode and set first layout type, move xdr->p past unused types */
4387 p = xdr_inline_decode(xdr, num * 4);
4388 if (unlikely(!p))
4389 goto out_overflow;
4390 *layouttype = be32_to_cpup(p);
4391 return 0;
4392out_overflow:
4393 print_overflow_msg(__func__, xdr);
4394 return -EIO;
4395}
4396
4397/*
4398 * The type of file system exported.
4399 * Note we must ensure that layouttype is set in any non-error case.
4400 */
4401static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4402 uint32_t *layouttype)
4403{
4404 int status = 0;
4405
4406 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4407 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4408 return -EIO;
4409 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4410 status = decode_first_pnfs_layout_type(xdr, layouttype);
4411 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4412 } else
4413 *layouttype = 0;
4414 return status;
4415}
4416
Fred Isamandae100c2011-07-30 20:52:37 -04004417/*
4418 * The prefered block size for layout directed io
4419 */
4420static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4421 uint32_t *res)
4422{
4423 __be32 *p;
4424
4425 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4426 *res = 0;
4427 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4428 p = xdr_inline_decode(xdr, 4);
4429 if (unlikely(!p)) {
4430 print_overflow_msg(__func__, xdr);
4431 return -EIO;
4432 }
4433 *res = be32_to_cpup(p);
4434 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4435 }
4436 return 0;
4437}
4438
Linus Torvalds1da177e2005-04-16 15:20:36 -07004439static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4440{
Al Viro8687b632006-10-19 23:28:48 -07004441 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004442 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443 int status;
4444
4445 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4446 goto xdr_error;
4447 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4448 goto xdr_error;
4449 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4450 goto xdr_error;
4451
4452 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4453
4454 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4455 goto xdr_error;
4456 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4457 goto xdr_error;
4458 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4459 goto xdr_error;
4460 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4461 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4462 goto xdr_error;
4463 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004464 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4465 if (status != 0)
4466 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004467 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4468 if (status != 0)
4469 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004470 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4471 if (status)
4472 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473
4474 status = verify_attr_len(xdr, savep, attrlen);
4475xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004476 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004477 return status;
4478}
4479
4480static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4481{
Al Viro8687b632006-10-19 23:28:48 -07004482 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483 uint32_t len;
4484 int status;
4485
Trond Myklebust99367812007-07-17 21:52:41 -04004486 /* Zero handle first to allow comparisons */
4487 memset(fh, 0, sizeof(*fh));
4488
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 status = decode_op_hdr(xdr, OP_GETFH);
4490 if (status)
4491 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004492
Benny Halevyc0eae662009-08-14 17:20:14 +03004493 p = xdr_inline_decode(xdr, 4);
4494 if (unlikely(!p))
4495 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004496 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497 if (len > NFS4_FHSIZE)
4498 return -EIO;
4499 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004500 p = xdr_inline_decode(xdr, len);
4501 if (unlikely(!p))
4502 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004503 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004504 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004505out_overflow:
4506 print_overflow_msg(__func__, xdr);
4507 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508}
4509
4510static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4511{
4512 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004513
Linus Torvalds1da177e2005-04-16 15:20:36 -07004514 status = decode_op_hdr(xdr, OP_LINK);
4515 if (status)
4516 return status;
4517 return decode_change_info(xdr, cinfo);
4518}
4519
4520/*
4521 * We create the owner, so we know a proper owner.id length is 4.
4522 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004523static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004524{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004525 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004526 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004527 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004529 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004530 if (unlikely(!p))
4531 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004532 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004533 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004534 type = be32_to_cpup(p++); /* 4 byte read */
4535 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004536 fl->fl_start = (loff_t)offset;
4537 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4538 if (length == ~(uint64_t)0)
4539 fl->fl_end = OFFSET_MAX;
4540 fl->fl_type = F_WRLCK;
4541 if (type & 1)
4542 fl->fl_type = F_RDLCK;
4543 fl->fl_pid = 0;
4544 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004545 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4546 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4547 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004548 if (likely(p))
4549 return -NFS4ERR_DENIED;
4550out_overflow:
4551 print_overflow_msg(__func__, xdr);
4552 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553}
4554
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004555static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004556{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 int status;
4558
4559 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004560 if (status == -EIO)
4561 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004563 status = decode_stateid(xdr, &res->stateid);
4564 if (unlikely(status))
4565 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004567 status = decode_lock_denied(xdr, NULL);
4568 if (res->open_seqid != NULL)
4569 nfs_increment_open_seqid(status, res->open_seqid);
4570 nfs_increment_lock_seqid(status, res->lock_seqid);
4571out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572 return status;
4573}
4574
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004575static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576{
4577 int status;
4578 status = decode_op_hdr(xdr, OP_LOCKT);
4579 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004580 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581 return status;
4582}
4583
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004584static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586 int status;
4587
4588 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004589 if (status != -EIO)
4590 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004591 if (status == 0)
4592 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593 return status;
4594}
4595
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004596static int decode_release_lockowner(struct xdr_stream *xdr)
4597{
4598 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4599}
4600
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601static int decode_lookup(struct xdr_stream *xdr)
4602{
4603 return decode_op_hdr(xdr, OP_LOOKUP);
4604}
4605
4606/* This is too sick! */
4607static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4608{
Andy Adamson05d564f2008-12-23 16:06:15 -05004609 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610 uint32_t limit_type, nblocks, blocksize;
4611
Benny Halevyc0eae662009-08-14 17:20:14 +03004612 p = xdr_inline_decode(xdr, 12);
4613 if (unlikely(!p))
4614 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004615 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004617 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004618 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004619 break;
4620 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004621 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004622 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004623 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624 }
4625 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004626out_overflow:
4627 print_overflow_msg(__func__, xdr);
4628 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629}
4630
4631static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4632{
Andy Adamson05d564f2008-12-23 16:06:15 -05004633 __be32 *p;
4634 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004635 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004636
Benny Halevyc0eae662009-08-14 17:20:14 +03004637 p = xdr_inline_decode(xdr, 4);
4638 if (unlikely(!p))
4639 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004640 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4642 res->delegation_type = 0;
4643 return 0;
4644 }
Benny Halevy07d30432009-08-14 17:19:52 +03004645 status = decode_stateid(xdr, &res->delegation);
4646 if (unlikely(status))
4647 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004648 p = xdr_inline_decode(xdr, 4);
4649 if (unlikely(!p))
4650 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004651 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004652
Linus Torvalds1da177e2005-04-16 15:20:36 -07004653 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004654 case NFS4_OPEN_DELEGATE_READ:
4655 res->delegation_type = FMODE_READ;
4656 break;
4657 case NFS4_OPEN_DELEGATE_WRITE:
4658 res->delegation_type = FMODE_WRITE|FMODE_READ;
4659 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 return -EIO;
4661 }
David Howells7539bba2006-08-22 20:06:09 -04004662 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004663out_overflow:
4664 print_overflow_msg(__func__, xdr);
4665 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666}
4667
4668static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4669{
Andy Adamson05d564f2008-12-23 16:06:15 -05004670 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004671 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004672 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004673
Andy Adamson05d564f2008-12-23 16:06:15 -05004674 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004675 if (status != -EIO)
4676 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004677 if (!status)
4678 status = decode_stateid(xdr, &res->stateid);
4679 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004680 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004681
Andy Adamson05d564f2008-12-23 16:06:15 -05004682 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004683
Benny Halevyc0eae662009-08-14 17:20:14 +03004684 p = xdr_inline_decode(xdr, 8);
4685 if (unlikely(!p))
4686 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004687 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004688 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004689 if (bmlen > 10)
4690 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691
Benny Halevyc0eae662009-08-14 17:20:14 +03004692 p = xdr_inline_decode(xdr, bmlen << 2);
4693 if (unlikely(!p))
4694 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004695 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4696 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004697 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004698 for (; i < NFS4_BITMAP_SIZE; i++)
4699 res->attrset[i] = 0;
4700
Linus Torvalds1da177e2005-04-16 15:20:36 -07004701 return decode_delegation(xdr, res);
4702xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004703 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004704 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004705out_overflow:
4706 print_overflow_msg(__func__, xdr);
4707 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708}
4709
4710static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4711{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712 int status;
4713
Andy Adamson05d564f2008-12-23 16:06:15 -05004714 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004715 if (status != -EIO)
4716 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004717 if (!status)
4718 status = decode_stateid(xdr, &res->stateid);
4719 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720}
4721
4722static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4723{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724 int status;
4725
4726 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004727 if (status != -EIO)
4728 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004729 if (!status)
4730 status = decode_stateid(xdr, &res->stateid);
4731 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732}
4733
4734static int decode_putfh(struct xdr_stream *xdr)
4735{
4736 return decode_op_hdr(xdr, OP_PUTFH);
4737}
4738
4739static int decode_putrootfh(struct xdr_stream *xdr)
4740{
4741 return decode_op_hdr(xdr, OP_PUTROOTFH);
4742}
4743
4744static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4745{
4746 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004747 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748 uint32_t count, eof, recvd, hdrlen;
4749 int status;
4750
4751 status = decode_op_hdr(xdr, OP_READ);
4752 if (status)
4753 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004754 p = xdr_inline_decode(xdr, 8);
4755 if (unlikely(!p))
4756 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004757 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004758 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004759 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760 recvd = req->rq_rcv_buf.len - hdrlen;
4761 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004762 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004763 "count %u > recvd %u\n", count, recvd);
4764 count = recvd;
4765 eof = 0;
4766 }
4767 xdr_read_pages(xdr, count);
4768 res->eof = eof;
4769 res->count = count;
4770 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004771out_overflow:
4772 print_overflow_msg(__func__, xdr);
4773 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774}
4775
4776static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4777{
4778 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004779 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004780 size_t hdrlen;
4781 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004782 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004783 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784
4785 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004786 if (!status)
4787 status = decode_verifier(xdr, readdir->verifier.data);
4788 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004790 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004791 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004792 __func__, verf[0], verf[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793
Benny Halevydb942bb2009-08-14 17:19:56 +03004794 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795 recvd = rcvbuf->len - hdrlen;
4796 if (pglen > recvd)
4797 pglen = recvd;
4798 xdr_read_pages(xdr, pglen);
4799
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004800
Trond Myklebustac396122010-11-15 20:26:22 -05004801 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802}
4803
4804static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4805{
4806 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4807 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004808 size_t hdrlen;
4809 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004810 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811 int status;
4812
4813 status = decode_op_hdr(xdr, OP_READLINK);
4814 if (status)
4815 return status;
4816
4817 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004818 p = xdr_inline_decode(xdr, 4);
4819 if (unlikely(!p))
4820 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004821 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004823 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004824 return -ENAMETOOLONG;
4825 }
4826 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4827 recvd = req->rq_rcv_buf.len - hdrlen;
4828 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004829 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830 "count %u > recvd %u\n", len, recvd);
4831 return -EIO;
4832 }
4833 xdr_read_pages(xdr, len);
4834 /*
4835 * The XDR encode routine has set things up so that
4836 * the link text will be copied directly into the
4837 * buffer. We just have to do overflow-checking,
4838 * and and null-terminate the text (the VFS expects
4839 * null-termination).
4840 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004841 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004843out_overflow:
4844 print_overflow_msg(__func__, xdr);
4845 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846}
4847
4848static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4849{
4850 int status;
4851
4852 status = decode_op_hdr(xdr, OP_REMOVE);
4853 if (status)
4854 goto out;
4855 status = decode_change_info(xdr, cinfo);
4856out:
4857 return status;
4858}
4859
4860static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4861 struct nfs4_change_info *new_cinfo)
4862{
4863 int status;
4864
4865 status = decode_op_hdr(xdr, OP_RENAME);
4866 if (status)
4867 goto out;
4868 if ((status = decode_change_info(xdr, old_cinfo)))
4869 goto out;
4870 status = decode_change_info(xdr, new_cinfo);
4871out:
4872 return status;
4873}
4874
4875static int decode_renew(struct xdr_stream *xdr)
4876{
4877 return decode_op_hdr(xdr, OP_RENEW);
4878}
4879
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004880static int
4881decode_restorefh(struct xdr_stream *xdr)
4882{
4883 return decode_op_hdr(xdr, OP_RESTOREFH);
4884}
4885
J. Bruce Fields029d1052005-06-22 17:16:22 +00004886static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05004887 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004888{
Andy Adamsonbf118a32011-12-07 11:55:27 -05004889 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004890 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004891 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00004892 struct kvec *iov = req->rq_rcv_buf.head;
4893 int status;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004894 size_t page_len = xdr->buf->page_len;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004895
Andy Adamsonbf118a32011-12-07 11:55:27 -05004896 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004897 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4898 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004899
Andy Adamsonbf118a32011-12-07 11:55:27 -05004900 bm_p = xdr->p;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004901 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4902 res->acl_data_offset <<= 2;
4903 /* Check if the acl data starts beyond the allocated buffer */
4904 if (res->acl_data_offset > page_len)
4905 return -ERANGE;
4906
J. Bruce Fields029d1052005-06-22 17:16:22 +00004907 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4908 goto out;
4909 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4910 goto out;
4911
4912 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4913 return -EIO;
4914 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004915 size_t hdrlen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004916
Andy Adamsonbf118a32011-12-07 11:55:27 -05004917 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
4918 * are stored with the acl data to handle the problem of
4919 * variable length bitmaps.*/
4920 xdr->p = bm_p;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004921
J. Bruce Fields029d1052005-06-22 17:16:22 +00004922 /* We ignore &savep and don't do consistency checks on
4923 * the attr length. Let userspace figure it out.... */
4924 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004925 attrlen += res->acl_data_offset;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004926 if (attrlen > page_len) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05004927 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
4928 /* getxattr interface called with a NULL buf */
4929 res->acl_len = attrlen;
4930 goto out;
4931 }
Sachin Prabhu5794d212012-04-17 14:36:40 +01004932 dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
Sachin Prabhu5a006892012-04-17 14:35:39 +01004933 attrlen, page_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004934 return -EINVAL;
4935 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004936 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05004937 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004938 } else
4939 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004940
4941out:
4942 return status;
4943}
4944
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945static int
4946decode_savefh(struct xdr_stream *xdr)
4947{
4948 return decode_op_hdr(xdr, OP_SAVEFH);
4949}
4950
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004951static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952{
Al Viro8687b632006-10-19 23:28:48 -07004953 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 uint32_t bmlen;
4955 int status;
4956
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957 status = decode_op_hdr(xdr, OP_SETATTR);
4958 if (status)
4959 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004960 p = xdr_inline_decode(xdr, 4);
4961 if (unlikely(!p))
4962 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004963 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004964 p = xdr_inline_decode(xdr, bmlen << 2);
4965 if (likely(p))
4966 return 0;
4967out_overflow:
4968 print_overflow_msg(__func__, xdr);
4969 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970}
4971
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004972static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973{
Al Viro8687b632006-10-19 23:28:48 -07004974 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975 uint32_t opnum;
4976 int32_t nfserr;
4977
Benny Halevyc0eae662009-08-14 17:20:14 +03004978 p = xdr_inline_decode(xdr, 8);
4979 if (unlikely(!p))
4980 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004981 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004983 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004984 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985 return -EIO;
4986 }
Benny Halevycccddf42009-08-14 17:20:19 +03004987 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004989 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4990 if (unlikely(!p))
4991 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004992 p = xdr_decode_hyper(p, &res->clientid);
4993 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994 } else if (nfserr == NFSERR_CLID_INUSE) {
4995 uint32_t len;
4996
4997 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004998 p = xdr_inline_decode(xdr, 4);
4999 if (unlikely(!p))
5000 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005001 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005002 p = xdr_inline_decode(xdr, len);
5003 if (unlikely(!p))
5004 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005
5006 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005007 p = xdr_inline_decode(xdr, 4);
5008 if (unlikely(!p))
5009 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005010 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005011 p = xdr_inline_decode(xdr, len);
5012 if (unlikely(!p))
5013 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005014 return -NFSERR_CLID_INUSE;
5015 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005016 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005017
5018 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005019out_overflow:
5020 print_overflow_msg(__func__, xdr);
5021 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005022}
5023
5024static int decode_setclientid_confirm(struct xdr_stream *xdr)
5025{
5026 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5027}
5028
5029static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5030{
Al Viro8687b632006-10-19 23:28:48 -07005031 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032 int status;
5033
5034 status = decode_op_hdr(xdr, OP_WRITE);
5035 if (status)
5036 return status;
5037
Benny Halevyc0eae662009-08-14 17:20:14 +03005038 p = xdr_inline_decode(xdr, 16);
5039 if (unlikely(!p))
5040 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005041 res->count = be32_to_cpup(p++);
5042 res->verf->committed = be32_to_cpup(p++);
Chuck Levercd937102012-03-02 17:14:31 -05005043 memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005045out_overflow:
5046 print_overflow_msg(__func__, xdr);
5047 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048}
5049
5050static int decode_delegreturn(struct xdr_stream *xdr)
5051{
5052 return decode_op_hdr(xdr, OP_DELEGRETURN);
5053}
5054
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005055static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5056{
5057 __be32 *p;
5058
5059 p = xdr_inline_decode(xdr, 4);
5060 if (unlikely(!p))
5061 goto out_overflow;
5062 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5063 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5064 goto out_err;
5065
5066 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5067 if (unlikely(!p))
5068 goto out_overflow;
5069 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5070
5071 p = xdr_inline_decode(xdr, 8);
5072 if (unlikely(!p))
5073 goto out_overflow;
5074 flavor->gss.qop4 = be32_to_cpup(p++);
5075 flavor->gss.service = be32_to_cpup(p);
5076
5077 return 0;
5078
5079out_overflow:
5080 print_overflow_msg(__func__, xdr);
5081 return -EIO;
5082out_err:
5083 return -EINVAL;
5084}
5085
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005086static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005087{
5088 struct nfs4_secinfo_flavor *sec_flavor;
5089 int status;
5090 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005091 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005092
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005093 p = xdr_inline_decode(xdr, 4);
5094 if (unlikely(!p))
5095 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005096
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005097 res->flavors->num_flavors = 0;
5098 num_flavors = be32_to_cpup(p);
5099
5100 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005101 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005102 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005103 break;
5104
5105 p = xdr_inline_decode(xdr, 4);
5106 if (unlikely(!p))
5107 goto out_overflow;
5108 sec_flavor->flavor = be32_to_cpup(p);
5109
5110 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005111 status = decode_secinfo_gss(xdr, sec_flavor);
5112 if (status)
5113 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005114 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005115 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005116 }
5117
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005118 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005119out:
5120 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005121out_overflow:
5122 print_overflow_msg(__func__, xdr);
5123 return -EIO;
5124}
5125
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005126static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5127{
5128 int status = decode_op_hdr(xdr, OP_SECINFO);
5129 if (status)
5130 return status;
5131 return decode_secinfo_common(xdr, res);
5132}
5133
Benny Halevy99fe60d2009-04-01 09:22:29 -04005134#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005135static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5136{
5137 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5138 if (status)
5139 return status;
5140 return decode_secinfo_common(xdr, res);
5141}
5142
Benny Halevy99fe60d2009-04-01 09:22:29 -04005143static int decode_exchange_id(struct xdr_stream *xdr,
5144 struct nfs41_exchange_id_res *res)
5145{
5146 __be32 *p;
5147 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005148 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005149 int status;
5150 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005151 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005152
5153 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5154 if (status)
5155 return status;
5156
Benny Halevyc0eae662009-08-14 17:20:14 +03005157 p = xdr_inline_decode(xdr, 8);
5158 if (unlikely(!p))
5159 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005160 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005161 p = xdr_inline_decode(xdr, 12);
5162 if (unlikely(!p))
5163 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005164 clp->cl_seqid = be32_to_cpup(p++);
5165 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005166
5167 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005168 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005169 if (dummy != SP4_NONE)
5170 return -EIO;
5171
5172 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005173 p = xdr_inline_decode(xdr, 8);
5174 if (unlikely(!p))
5175 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005176
5177 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005178 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5179 if (unlikely(status))
5180 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005181
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005182 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005183 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5184 if (unlikely(status))
5185 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005186
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005187 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5188 return -EIO;
5189
5190 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5191 res->server_scope->server_scope_sz = dummy;
5192
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005193 /* Implementation Id */
5194 p = xdr_inline_decode(xdr, 4);
5195 if (unlikely(!p))
5196 goto out_overflow;
5197 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005198
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005199 if (impl_id_count) {
5200 /* nii_domain */
5201 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5202 if (unlikely(status))
5203 return status;
5204 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5205 return -EIO;
5206 memcpy(res->impl_id->domain, dummy_str, dummy);
5207
5208 /* nii_name */
5209 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5210 if (unlikely(status))
5211 return status;
5212 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5213 return -EIO;
5214 memcpy(res->impl_id->name, dummy_str, dummy);
5215
5216 /* nii_date */
5217 p = xdr_inline_decode(xdr, 12);
5218 if (unlikely(!p))
5219 goto out_overflow;
5220 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5221 res->impl_id->date.nseconds = be32_to_cpup(p);
5222
5223 /* if there's more than one entry, ignore the rest */
5224 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005225 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005226out_overflow:
5227 print_overflow_msg(__func__, xdr);
5228 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005229}
Andy Adamsonfc931582009-04-01 09:22:31 -04005230
5231static int decode_chan_attrs(struct xdr_stream *xdr,
5232 struct nfs4_channel_attrs *attrs)
5233{
5234 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005235 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005236
Benny Halevyc0eae662009-08-14 17:20:14 +03005237 p = xdr_inline_decode(xdr, 28);
5238 if (unlikely(!p))
5239 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005240 val = be32_to_cpup(p++); /* headerpadsz */
5241 if (val)
5242 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005243 attrs->max_rqst_sz = be32_to_cpup(p++);
5244 attrs->max_resp_sz = be32_to_cpup(p++);
5245 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5246 attrs->max_ops = be32_to_cpup(p++);
5247 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005248 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005249 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005250 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5251 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005252 return -EINVAL;
5253 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005254 if (nr_attrs == 1) {
5255 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5256 if (unlikely(!p))
5257 goto out_overflow;
5258 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005259 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005260out_overflow:
5261 print_overflow_msg(__func__, xdr);
5262 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005263}
5264
Benny Halevye78291e2009-08-14 17:20:00 +03005265static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5266{
5267 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005268}
5269
5270static int decode_create_session(struct xdr_stream *xdr,
5271 struct nfs41_create_session_res *res)
5272{
5273 __be32 *p;
5274 int status;
5275 struct nfs_client *clp = res->client;
5276 struct nfs4_session *session = clp->cl_session;
5277
5278 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005279 if (!status)
5280 status = decode_sessionid(xdr, &session->sess_id);
5281 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005282 return status;
5283
Andy Adamsonfc931582009-04-01 09:22:31 -04005284 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005285 p = xdr_inline_decode(xdr, 8);
5286 if (unlikely(!p))
5287 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005288 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005289 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005290
5291 /* Channel attributes */
5292 status = decode_chan_attrs(xdr, &session->fc_attrs);
5293 if (!status)
5294 status = decode_chan_attrs(xdr, &session->bc_attrs);
5295 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005296out_overflow:
5297 print_overflow_msg(__func__, xdr);
5298 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005299}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005300
5301static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5302{
5303 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5304}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005305
5306static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5307{
5308 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5309}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005310#endif /* CONFIG_NFS_V4_1 */
5311
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005312static int decode_sequence(struct xdr_stream *xdr,
5313 struct nfs4_sequence_res *res,
5314 struct rpc_rqst *rqstp)
5315{
5316#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005317 struct nfs4_sessionid id;
5318 u32 dummy;
5319 int status;
5320 __be32 *p;
5321
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005322 if (!res->sr_session)
5323 return 0;
5324
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005325 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005326 if (!status)
5327 status = decode_sessionid(xdr, &id);
5328 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005329 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005330
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005331 /*
5332 * If the server returns different values for sessionID, slotID or
5333 * sequence number, the server is looney tunes.
5334 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005335 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005336
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005337 if (memcmp(id.data, res->sr_session->sess_id.data,
5338 NFS4_MAX_SESSIONID_LEN)) {
5339 dprintk("%s Invalid session id\n", __func__);
5340 goto out_err;
5341 }
Benny Halevye78291e2009-08-14 17:20:00 +03005342
Benny Halevyc0eae662009-08-14 17:20:14 +03005343 p = xdr_inline_decode(xdr, 20);
5344 if (unlikely(!p))
5345 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005346
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005347 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005348 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005349 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005350 dprintk("%s Invalid sequence number\n", __func__);
5351 goto out_err;
5352 }
5353 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005354 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005355 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005356 dprintk("%s Invalid slot id\n", __func__);
5357 goto out_err;
5358 }
5359 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005360 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005361 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005362 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005363 /* result flags */
5364 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005365 status = 0;
5366out_err:
5367 res->sr_status = status;
5368 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005369out_overflow:
5370 print_overflow_msg(__func__, xdr);
5371 status = -EIO;
5372 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005373#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005374 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005375#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005376}
5377
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005378#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005379/*
5380 * TODO: Need to handle case when EOF != true;
5381 */
5382static int decode_getdevicelist(struct xdr_stream *xdr,
5383 struct pnfs_devicelist *res)
5384{
5385 __be32 *p;
5386 int status, i;
5387 struct nfs_writeverf verftemp;
5388
5389 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5390 if (status)
5391 return status;
5392
5393 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5394 if (unlikely(!p))
5395 goto out_overflow;
5396
5397 /* TODO: Skip cookie for now */
5398 p += 2;
5399
5400 /* Read verifier */
Chuck Levercd937102012-03-02 17:14:31 -05005401 p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005402
5403 res->num_devs = be32_to_cpup(p);
5404
5405 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5406
5407 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005408 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005409 __func__, res->num_devs);
5410 return -EIO;
5411 }
5412
5413 p = xdr_inline_decode(xdr,
5414 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5415 if (unlikely(!p))
5416 goto out_overflow;
5417 for (i = 0; i < res->num_devs; i++)
5418 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5419 NFS4_DEVICEID4_SIZE);
5420 res->eof = be32_to_cpup(p);
5421 return 0;
5422out_overflow:
5423 print_overflow_msg(__func__, xdr);
5424 return -EIO;
5425}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005426
5427static int decode_getdeviceinfo(struct xdr_stream *xdr,
5428 struct pnfs_device *pdev)
5429{
5430 __be32 *p;
5431 uint32_t len, type;
5432 int status;
5433
5434 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5435 if (status) {
5436 if (status == -ETOOSMALL) {
5437 p = xdr_inline_decode(xdr, 4);
5438 if (unlikely(!p))
5439 goto out_overflow;
5440 pdev->mincount = be32_to_cpup(p);
5441 dprintk("%s: Min count too small. mincnt = %u\n",
5442 __func__, pdev->mincount);
5443 }
5444 return status;
5445 }
5446
5447 p = xdr_inline_decode(xdr, 8);
5448 if (unlikely(!p))
5449 goto out_overflow;
5450 type = be32_to_cpup(p++);
5451 if (type != pdev->layout_type) {
5452 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5453 __func__, pdev->layout_type, type);
5454 return -EINVAL;
5455 }
5456 /*
5457 * Get the length of the opaque device_addr4. xdr_read_pages places
5458 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5459 * and places the remaining xdr data in xdr_buf->tail
5460 */
5461 pdev->mincount = be32_to_cpup(p);
5462 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5463
5464 /* Parse notification bitmap, verifying that it is zero. */
5465 p = xdr_inline_decode(xdr, 4);
5466 if (unlikely(!p))
5467 goto out_overflow;
5468 len = be32_to_cpup(p);
5469 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005470 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005471
5472 p = xdr_inline_decode(xdr, 4 * len);
5473 if (unlikely(!p))
5474 goto out_overflow;
5475 for (i = 0; i < len; i++, p++) {
5476 if (be32_to_cpup(p)) {
5477 dprintk("%s: notifications not supported\n",
5478 __func__);
5479 return -EIO;
5480 }
5481 }
5482 }
5483 return 0;
5484out_overflow:
5485 print_overflow_msg(__func__, xdr);
5486 return -EIO;
5487}
5488
5489static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5490 struct nfs4_layoutget_res *res)
5491{
5492 __be32 *p;
5493 int status;
5494 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005495 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5496 struct kvec *iov = rcvbuf->head;
5497 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005498
5499 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5500 if (status)
5501 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005502 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005503 if (unlikely(!p))
5504 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005505 res->return_on_close = be32_to_cpup(p);
5506 decode_stateid(xdr, &res->stateid);
5507 p = xdr_inline_decode(xdr, 4);
5508 if (unlikely(!p))
5509 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005510 layout_count = be32_to_cpup(p);
5511 if (!layout_count) {
5512 dprintk("%s: server responded with empty layout array\n",
5513 __func__);
5514 return -EINVAL;
5515 }
5516
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005517 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005518 if (unlikely(!p))
5519 goto out_overflow;
5520 p = xdr_decode_hyper(p, &res->range.offset);
5521 p = xdr_decode_hyper(p, &res->range.length);
5522 res->range.iomode = be32_to_cpup(p++);
5523 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005524 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005525
5526 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5527 __func__,
5528 (unsigned long)res->range.offset,
5529 (unsigned long)res->range.length,
5530 res->range.iomode,
5531 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005532 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005533
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005534 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5535 recvd = req->rq_rcv_buf.len - hdrlen;
5536 if (res->layoutp->len > recvd) {
5537 dprintk("NFS: server cheating in layoutget reply: "
5538 "layout len %u > recvd %u\n",
5539 res->layoutp->len, recvd);
5540 return -EINVAL;
5541 }
5542
5543 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005544
5545 if (layout_count > 1) {
5546 /* We only handle a length one array at the moment. Any
5547 * further entries are just ignored. Note that this means
5548 * the client may see a response that is less than the
5549 * minimum it requested.
5550 */
5551 dprintk("%s: server responded with %d layouts, dropping tail\n",
5552 __func__, layout_count);
5553 }
5554
5555 return 0;
5556out_overflow:
5557 print_overflow_msg(__func__, xdr);
5558 return -EIO;
5559}
Andy Adamson863a3c62011-03-23 13:27:54 +00005560
Benny Halevycbe82602011-05-22 19:52:37 +03005561static int decode_layoutreturn(struct xdr_stream *xdr,
5562 struct nfs4_layoutreturn_res *res)
5563{
5564 __be32 *p;
5565 int status;
5566
5567 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5568 if (status)
5569 return status;
5570 p = xdr_inline_decode(xdr, 4);
5571 if (unlikely(!p))
5572 goto out_overflow;
5573 res->lrs_present = be32_to_cpup(p);
5574 if (res->lrs_present)
5575 status = decode_stateid(xdr, &res->stateid);
5576 return status;
5577out_overflow:
5578 print_overflow_msg(__func__, xdr);
5579 return -EIO;
5580}
5581
Andy Adamson863a3c62011-03-23 13:27:54 +00005582static int decode_layoutcommit(struct xdr_stream *xdr,
5583 struct rpc_rqst *req,
5584 struct nfs4_layoutcommit_res *res)
5585{
5586 __be32 *p;
5587 __u32 sizechanged;
5588 int status;
5589
5590 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005591 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005592 if (status)
5593 return status;
5594
5595 p = xdr_inline_decode(xdr, 4);
5596 if (unlikely(!p))
5597 goto out_overflow;
5598 sizechanged = be32_to_cpup(p);
5599
5600 if (sizechanged) {
5601 /* throw away new size */
5602 p = xdr_inline_decode(xdr, 8);
5603 if (unlikely(!p))
5604 goto out_overflow;
5605 }
5606 return 0;
5607out_overflow:
5608 print_overflow_msg(__func__, xdr);
5609 return -EIO;
5610}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005611
5612static int decode_test_stateid(struct xdr_stream *xdr,
5613 struct nfs41_test_stateid_res *res)
5614{
5615 __be32 *p;
5616 int status;
5617 int num_res;
5618
5619 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5620 if (status)
5621 return status;
5622
5623 p = xdr_inline_decode(xdr, 4);
5624 if (unlikely(!p))
5625 goto out_overflow;
5626 num_res = be32_to_cpup(p++);
5627 if (num_res != 1)
5628 goto out;
5629
5630 p = xdr_inline_decode(xdr, 4);
5631 if (unlikely(!p))
5632 goto out_overflow;
5633 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005634
5635 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005636out_overflow:
5637 print_overflow_msg(__func__, xdr);
5638out:
5639 return -EIO;
5640}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005641
5642static int decode_free_stateid(struct xdr_stream *xdr,
5643 struct nfs41_free_stateid_res *res)
5644{
5645 __be32 *p;
5646 int status;
5647
5648 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5649 if (status)
5650 return status;
5651
5652 p = xdr_inline_decode(xdr, 4);
5653 if (unlikely(!p))
5654 goto out_overflow;
5655 res->status = be32_to_cpup(p++);
5656 return res->status;
5657out_overflow:
5658 print_overflow_msg(__func__, xdr);
5659 return -EIO;
5660}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005661#endif /* CONFIG_NFS_V4_1 */
5662
Linus Torvalds1da177e2005-04-16 15:20:36 -07005663/*
Benny Halevy49c25592008-12-23 16:06:16 -05005664 * END OF "GENERIC" DECODE ROUTINES.
5665 */
5666
5667/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005668 * Decode OPEN_DOWNGRADE response
5669 */
Chuck Leverbf269552010-12-14 14:59:29 +00005670static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5671 struct xdr_stream *xdr,
5672 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005673{
Andy Adamson05d564f2008-12-23 16:06:15 -05005674 struct compound_hdr hdr;
5675 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005676
Chuck Leverbf269552010-12-14 14:59:29 +00005677 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005678 if (status)
5679 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005680 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005681 if (status)
5682 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005683 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005684 if (status)
5685 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005686 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005687 if (status != 0)
5688 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005689 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005690out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005691 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005692}
5693
5694/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005695 * Decode ACCESS response
5696 */
Chuck Leverbf269552010-12-14 14:59:29 +00005697static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5698 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005699{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005700 struct compound_hdr hdr;
5701 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005702
Chuck Leverbf269552010-12-14 14:59:29 +00005703 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005704 if (status)
5705 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005706 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005707 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005708 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005709 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005710 if (status != 0)
5711 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005712 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005713 if (status != 0)
5714 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005715 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005716out:
5717 return status;
5718}
5719
5720/*
5721 * Decode LOOKUP response
5722 */
Chuck Leverbf269552010-12-14 14:59:29 +00005723static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5724 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005725{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005726 struct compound_hdr hdr;
5727 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005728
Chuck Leverbf269552010-12-14 14:59:29 +00005729 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005730 if (status)
5731 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005732 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005733 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005734 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005735 status = decode_putfh(xdr);
5736 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005737 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005738 status = decode_lookup(xdr);
5739 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005740 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005741 status = decode_getfh(xdr, res->fh);
5742 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005743 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005744 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745out:
5746 return status;
5747}
5748
5749/*
5750 * Decode LOOKUP_ROOT response
5751 */
Chuck Leverbf269552010-12-14 14:59:29 +00005752static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5753 struct xdr_stream *xdr,
5754 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005756 struct compound_hdr hdr;
5757 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005758
Chuck Leverbf269552010-12-14 14:59:29 +00005759 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005760 if (status)
5761 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005762 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005763 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005764 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005765 status = decode_putrootfh(xdr);
5766 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005768 status = decode_getfh(xdr, res->fh);
5769 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005770 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005771out:
5772 return status;
5773}
5774
5775/*
5776 * Decode REMOVE response
5777 */
Chuck Leverbf269552010-12-14 14:59:29 +00005778static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5779 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005780{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005781 struct compound_hdr hdr;
5782 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005783
Chuck Leverbf269552010-12-14 14:59:29 +00005784 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005785 if (status)
5786 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005787 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005788 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005789 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005790 status = decode_putfh(xdr);
5791 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005792 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005793 status = decode_remove(xdr, &res->cinfo);
5794 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005795 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005796 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005797out:
5798 return status;
5799}
5800
5801/*
5802 * Decode RENAME response
5803 */
Chuck Leverbf269552010-12-14 14:59:29 +00005804static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5805 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005806{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005807 struct compound_hdr hdr;
5808 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005809
Chuck Leverbf269552010-12-14 14:59:29 +00005810 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005811 if (status)
5812 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005813 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005814 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005815 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005816 status = decode_putfh(xdr);
5817 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005818 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005819 status = decode_savefh(xdr);
5820 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005821 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005822 status = decode_putfh(xdr);
5823 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005824 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005825 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5826 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005827 goto out;
5828 /* Current FH is target directory */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005829 if (decode_getfattr(xdr, res->new_fattr, res->server))
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005830 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005831 status = decode_restorefh(xdr);
5832 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005833 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005834 decode_getfattr(xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005835out:
5836 return status;
5837}
5838
5839/*
5840 * Decode LINK response
5841 */
Chuck Leverbf269552010-12-14 14:59:29 +00005842static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5843 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845 struct compound_hdr hdr;
5846 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005847
Chuck Leverbf269552010-12-14 14:59:29 +00005848 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005849 if (status)
5850 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005851 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005852 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005853 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005854 status = decode_putfh(xdr);
5855 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005856 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005857 status = decode_savefh(xdr);
5858 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005859 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005860 status = decode_putfh(xdr);
5861 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005863 status = decode_link(xdr, &res->cinfo);
5864 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005865 goto out;
5866 /*
5867 * Note order: OP_LINK leaves the directory as the current
5868 * filehandle.
5869 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005870 if (decode_getfattr(xdr, res->dir_attr, res->server))
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005871 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005872 status = decode_restorefh(xdr);
5873 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005874 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005875 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005876out:
5877 return status;
5878}
5879
5880/*
5881 * Decode CREATE response
5882 */
Chuck Leverbf269552010-12-14 14:59:29 +00005883static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5884 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005885{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005886 struct compound_hdr hdr;
5887 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005888
Chuck Leverbf269552010-12-14 14:59:29 +00005889 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005890 if (status)
5891 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005892 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005893 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005894 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005895 status = decode_putfh(xdr);
5896 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005897 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005898 status = decode_savefh(xdr);
5899 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005900 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005901 status = decode_create(xdr, &res->dir_cinfo);
5902 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005903 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005904 status = decode_getfh(xdr, res->fh);
5905 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005906 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005907 if (decode_getfattr(xdr, res->fattr, res->server))
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005908 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005909 status = decode_restorefh(xdr);
5910 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005911 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005912 decode_getfattr(xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005913out:
5914 return status;
5915}
5916
5917/*
5918 * Decode SYMLINK response
5919 */
Chuck Leverbf269552010-12-14 14:59:29 +00005920static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5921 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005922{
Chuck Leverbf269552010-12-14 14:59:29 +00005923 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005924}
5925
5926/*
5927 * Decode GETATTR response
5928 */
Chuck Leverbf269552010-12-14 14:59:29 +00005929static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5930 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005932 struct compound_hdr hdr;
5933 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005934
Chuck Leverbf269552010-12-14 14:59:29 +00005935 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005936 if (status)
5937 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005938 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005939 if (status)
5940 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005941 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005942 if (status)
5943 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005944 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005945out:
5946 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005947}
5948
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005949/*
5950 * Encode an SETACL request
5951 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005952static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5953 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005954{
Andy Adamson05d564f2008-12-23 16:06:15 -05005955 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005956 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005957 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005958
Chuck Lever9f06c712010-12-14 14:59:18 +00005959 encode_compound_hdr(xdr, req, &hdr);
5960 encode_sequence(xdr, &args->seq_args, &hdr);
5961 encode_putfh(xdr, args->fh, &hdr);
5962 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005963 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005964}
Andy Adamson05d564f2008-12-23 16:06:15 -05005965
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005966/*
5967 * Decode SETACL response
5968 */
5969static int
Chuck Leverbf269552010-12-14 14:59:29 +00005970nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005971 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005972{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005973 struct compound_hdr hdr;
5974 int status;
5975
Chuck Leverbf269552010-12-14 14:59:29 +00005976 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005977 if (status)
5978 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005979 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005980 if (status)
5981 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005982 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005983 if (status)
5984 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005985 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005986out:
5987 return status;
5988}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005989
5990/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005991 * Decode GETACL response
5992 */
5993static int
Chuck Leverbf269552010-12-14 14:59:29 +00005994nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005995 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005996{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005997 struct compound_hdr hdr;
5998 int status;
5999
Trond Myklebust331818f2012-02-03 18:30:53 -05006000 if (res->acl_scratch != NULL) {
6001 void *p = page_address(res->acl_scratch);
6002 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6003 }
Chuck Leverbf269552010-12-14 14:59:29 +00006004 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006005 if (status)
6006 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006007 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006008 if (status)
6009 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006010 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006011 if (status)
6012 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006013 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006014
6015out:
6016 return status;
6017}
6018
6019/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006020 * Decode CLOSE response
6021 */
Chuck Leverbf269552010-12-14 14:59:29 +00006022static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6023 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024{
Andy Adamson05d564f2008-12-23 16:06:15 -05006025 struct compound_hdr hdr;
6026 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006027
Chuck Leverbf269552010-12-14 14:59:29 +00006028 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006029 if (status)
6030 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006031 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006032 if (status)
6033 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006034 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006035 if (status)
6036 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006037 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006038 if (status != 0)
6039 goto out;
6040 /*
6041 * Note: Server may do delete on close for this file
6042 * in which case the getattr call will fail with
6043 * an ESTALE error. Shouldn't be a problem,
6044 * though, since fattr->valid will remain unset.
6045 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006046 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006047out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006048 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006049}
6050
6051/*
6052 * Decode OPEN response
6053 */
Chuck Leverbf269552010-12-14 14:59:29 +00006054static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, 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);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006061 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;
Chuck Leverbf269552010-12-14 14:59:29 +00006072 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006073 goto out;
Trond Myklebust90ff0c52012-04-27 13:48:18 -04006074 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006075out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006076 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077}
6078
6079/*
6080 * Decode OPEN_CONFIRM response
6081 */
Chuck Leverbf269552010-12-14 14:59:29 +00006082static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6083 struct xdr_stream *xdr,
6084 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006085{
Andy Adamson05d564f2008-12-23 16:06:15 -05006086 struct compound_hdr hdr;
6087 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006088
Chuck Leverbf269552010-12-14 14:59:29 +00006089 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006090 if (status)
6091 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006092 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006093 if (status)
6094 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006095 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006097 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098}
6099
6100/*
6101 * Decode OPEN response
6102 */
Chuck Leverbf269552010-12-14 14:59:29 +00006103static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6104 struct xdr_stream *xdr,
6105 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106{
Andy Adamson05d564f2008-12-23 16:06:15 -05006107 struct compound_hdr hdr;
6108 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109
Chuck Leverbf269552010-12-14 14:59:29 +00006110 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006111 if (status)
6112 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006113 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006114 if (status)
6115 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006116 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006117 if (status)
6118 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006119 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006120 if (status)
6121 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006122 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006123out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006124 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125}
6126
6127/*
6128 * Decode SETATTR response
6129 */
Chuck Leverbf269552010-12-14 14:59:29 +00006130static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6131 struct xdr_stream *xdr,
6132 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133{
Andy Adamson05d564f2008-12-23 16:06:15 -05006134 struct compound_hdr hdr;
6135 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006136
Chuck Leverbf269552010-12-14 14:59:29 +00006137 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006138 if (status)
6139 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006140 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006141 if (status)
6142 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006143 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006144 if (status)
6145 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006146 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006147 if (status)
6148 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006149 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006150out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006151 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152}
6153
6154/*
6155 * Decode LOCK response
6156 */
Chuck Leverbf269552010-12-14 14:59:29 +00006157static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6158 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006159{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160 struct compound_hdr hdr;
6161 int status;
6162
Chuck Leverbf269552010-12-14 14:59:29 +00006163 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164 if (status)
6165 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006166 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006167 if (status)
6168 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006169 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170 if (status)
6171 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006172 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173out:
6174 return status;
6175}
6176
6177/*
6178 * Decode LOCKT response
6179 */
Chuck Leverbf269552010-12-14 14:59:29 +00006180static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6181 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183 struct compound_hdr hdr;
6184 int status;
6185
Chuck Leverbf269552010-12-14 14:59:29 +00006186 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187 if (status)
6188 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006189 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006190 if (status)
6191 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006192 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193 if (status)
6194 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006195 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196out:
6197 return status;
6198}
6199
6200/*
6201 * Decode LOCKU response
6202 */
Chuck Leverbf269552010-12-14 14:59:29 +00006203static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6204 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206 struct compound_hdr hdr;
6207 int status;
6208
Chuck Leverbf269552010-12-14 14:59:29 +00006209 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210 if (status)
6211 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006212 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006213 if (status)
6214 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006215 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216 if (status)
6217 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006218 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219out:
6220 return status;
6221}
6222
Chuck Leverbf269552010-12-14 14:59:29 +00006223static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6224 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006225{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006226 struct compound_hdr hdr;
6227 int status;
6228
Chuck Leverbf269552010-12-14 14:59:29 +00006229 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006230 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006231 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006232 return status;
6233}
6234
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235/*
6236 * Decode READLINK response
6237 */
Chuck Leverbf269552010-12-14 14:59:29 +00006238static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6239 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006240 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006241{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242 struct compound_hdr hdr;
6243 int status;
6244
Chuck Leverbf269552010-12-14 14:59:29 +00006245 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246 if (status)
6247 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006248 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006249 if (status)
6250 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006251 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006252 if (status)
6253 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006254 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006255out:
6256 return status;
6257}
6258
6259/*
6260 * Decode READDIR response
6261 */
Chuck Leverbf269552010-12-14 14:59:29 +00006262static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6263 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006264{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006265 struct compound_hdr hdr;
6266 int status;
6267
Chuck Leverbf269552010-12-14 14:59:29 +00006268 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006269 if (status)
6270 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006271 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006272 if (status)
6273 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006274 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006275 if (status)
6276 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006277 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006278out:
6279 return status;
6280}
6281
6282/*
6283 * Decode Read response
6284 */
Chuck Leverbf269552010-12-14 14:59:29 +00006285static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6286 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006287{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006288 struct compound_hdr hdr;
6289 int status;
6290
Chuck Leverbf269552010-12-14 14:59:29 +00006291 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006292 if (status)
6293 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006294 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006295 if (status)
6296 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006297 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298 if (status)
6299 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006300 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006301 if (!status)
6302 status = res->count;
6303out:
6304 return status;
6305}
6306
6307/*
6308 * Decode WRITE response
6309 */
Chuck Leverbf269552010-12-14 14:59:29 +00006310static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6311 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006312{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006313 struct compound_hdr hdr;
6314 int status;
6315
Chuck Leverbf269552010-12-14 14:59:29 +00006316 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006317 if (status)
6318 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006319 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006320 if (status)
6321 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006322 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323 if (status)
6324 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006326 if (status)
6327 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006328 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006329 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006330 if (!status)
6331 status = res->count;
6332out:
6333 return status;
6334}
6335
6336/*
6337 * Decode COMMIT response
6338 */
Chuck Leverbf269552010-12-14 14:59:29 +00006339static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006340 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006341{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006342 struct compound_hdr hdr;
6343 int status;
6344
Chuck Leverbf269552010-12-14 14:59:29 +00006345 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006346 if (status)
6347 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006348 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006349 if (status)
6350 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006351 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352 if (status)
6353 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006354 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006355 if (status)
6356 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006357 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006358 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359out:
6360 return status;
6361}
6362
6363/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006364 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006365 */
Chuck Leverbf269552010-12-14 14:59:29 +00006366static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006367 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006369 struct compound_hdr hdr;
6370 int status;
6371
Chuck Leverbf269552010-12-14 14:59:29 +00006372 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006373 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006374 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006375 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006376 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006378 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006379 return status;
6380}
6381
6382/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006383 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006384 */
Chuck Leverbf269552010-12-14 14:59:29 +00006385static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006386 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006387{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006388 struct compound_hdr hdr;
6389 int status;
6390
Chuck Leverbf269552010-12-14 14:59:29 +00006391 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006392 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006393 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006394 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006395 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006397 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006398 return status;
6399}
6400
6401/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006402 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006403 */
Chuck Leverbf269552010-12-14 14:59:29 +00006404static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006405 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006406{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407 struct compound_hdr hdr;
6408 int status;
6409
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006412 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006413 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006414 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006415 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006416 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006417 return status;
6418}
6419
6420/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006421 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006422 */
Chuck Leverbf269552010-12-14 14:59:29 +00006423static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6424 struct xdr_stream *xdr,
6425 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427 struct compound_hdr hdr;
6428 int status;
6429
Chuck Leverbf269552010-12-14 14:59:29 +00006430 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006431 if (status)
6432 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006433 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006434 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006436 status = decode_putfh(xdr);
6437 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006438 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006439 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440out:
6441 return status;
6442}
6443
6444/*
6445 * Decode RENEW response
6446 */
Chuck Leverbf269552010-12-14 14:59:29 +00006447static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6448 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006449{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450 struct compound_hdr hdr;
6451 int status;
6452
Chuck Leverbf269552010-12-14 14:59:29 +00006453 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006455 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006456 return status;
6457}
6458
6459/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006460 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461 */
Chuck Leverbf269552010-12-14 14:59:29 +00006462static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6463 struct xdr_stream *xdr,
6464 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466 struct compound_hdr hdr;
6467 int status;
6468
Chuck Leverbf269552010-12-14 14:59:29 +00006469 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006470 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006471 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472 return status;
6473}
6474
6475/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006476 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006477 */
Chuck Leverbf269552010-12-14 14:59:29 +00006478static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6479 struct xdr_stream *xdr,
6480 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006481{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482 struct compound_hdr hdr;
6483 int status;
6484
Chuck Leverbf269552010-12-14 14:59:29 +00006485 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006486 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006487 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006488 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006489 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006491 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006492 return status;
6493}
6494
6495/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006496 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497 */
Chuck Leverbf269552010-12-14 14:59:29 +00006498static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6499 struct xdr_stream *xdr,
6500 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006501{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502 struct compound_hdr hdr;
6503 int status;
6504
Chuck Leverbf269552010-12-14 14:59:29 +00006505 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006506 if (status)
6507 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006508 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006509 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006510 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006511 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006512 if (status != 0)
6513 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006514 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006515 if (status != 0)
6516 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006517 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006518out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006519 return status;
6520}
6521
Trond Myklebust683b57b2006-06-09 09:34:22 -04006522/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006523 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006524 */
Chuck Leverbf269552010-12-14 14:59:29 +00006525static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6526 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006527 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006528{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006529 struct compound_hdr hdr;
6530 int status;
6531
Chuck Leverbf269552010-12-14 14:59:29 +00006532 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006533 if (status)
6534 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006535 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006536 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006537 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006538 status = decode_putfh(xdr);
6539 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006540 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006541 status = decode_lookup(xdr);
6542 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006543 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006544 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006545 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6546 NULL, res->fs_locations,
6547 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006548out:
6549 return status;
6550}
6551
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006552/*
6553 * Decode SECINFO response
6554 */
6555static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6556 struct xdr_stream *xdr,
6557 struct nfs4_secinfo_res *res)
6558{
6559 struct compound_hdr hdr;
6560 int status;
6561
6562 status = decode_compound_hdr(xdr, &hdr);
6563 if (status)
6564 goto out;
6565 status = decode_sequence(xdr, &res->seq_res, rqstp);
6566 if (status)
6567 goto out;
6568 status = decode_putfh(xdr);
6569 if (status)
6570 goto out;
6571 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006572out:
6573 return status;
6574}
6575
Benny Halevy99fe60d2009-04-01 09:22:29 -04006576#if defined(CONFIG_NFS_V4_1)
6577/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006578 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006579 */
Chuck Leverbf269552010-12-14 14:59:29 +00006580static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6581 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006582 void *res)
6583{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006584 struct compound_hdr hdr;
6585 int status;
6586
Chuck Leverbf269552010-12-14 14:59:29 +00006587 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006588 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006589 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006590 return status;
6591}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006592
6593/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006594 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006595 */
Chuck Leverbf269552010-12-14 14:59:29 +00006596static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6597 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006598 struct nfs41_create_session_res *res)
6599{
Andy Adamsonfc931582009-04-01 09:22:31 -04006600 struct compound_hdr hdr;
6601 int status;
6602
Chuck Leverbf269552010-12-14 14:59:29 +00006603 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006604 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006605 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006606 return status;
6607}
6608
6609/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006610 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006611 */
Chuck Leverbf269552010-12-14 14:59:29 +00006612static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6613 struct xdr_stream *xdr,
6614 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006615{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006616 struct compound_hdr hdr;
6617 int status;
6618
Chuck Leverbf269552010-12-14 14:59:29 +00006619 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006620 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006621 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006622 return status;
6623}
6624
6625/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006626 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006627 */
Chuck Leverbf269552010-12-14 14:59:29 +00006628static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6629 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006630 struct nfs4_sequence_res *res)
6631{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006632 struct compound_hdr hdr;
6633 int status;
6634
Chuck Leverbf269552010-12-14 14:59:29 +00006635 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006636 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006637 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006638 return status;
6639}
6640
6641/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006642 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006643 */
Chuck Leverbf269552010-12-14 14:59:29 +00006644static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6645 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006646 struct nfs4_get_lease_time_res *res)
6647{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006648 struct compound_hdr hdr;
6649 int status;
6650
Chuck Leverbf269552010-12-14 14:59:29 +00006651 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006652 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006653 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006654 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006655 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006656 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006657 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006658 return status;
6659}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006660
6661/*
6662 * Decode RECLAIM_COMPLETE response
6663 */
Chuck Leverbf269552010-12-14 14:59:29 +00006664static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6665 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006666 struct nfs41_reclaim_complete_res *res)
6667{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006668 struct compound_hdr hdr;
6669 int status;
6670
Chuck Leverbf269552010-12-14 14:59:29 +00006671 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006672 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006673 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006674 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006675 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006676 return status;
6677}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006678
6679/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006680 * Decode GETDEVICELIST response
6681 */
6682static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6683 struct xdr_stream *xdr,
6684 struct nfs4_getdevicelist_res *res)
6685{
6686 struct compound_hdr hdr;
6687 int status;
6688
6689 dprintk("encoding getdevicelist!\n");
6690
6691 status = decode_compound_hdr(xdr, &hdr);
6692 if (status != 0)
6693 goto out;
6694 status = decode_sequence(xdr, &res->seq_res, rqstp);
6695 if (status != 0)
6696 goto out;
6697 status = decode_putfh(xdr);
6698 if (status != 0)
6699 goto out;
6700 status = decode_getdevicelist(xdr, res->devlist);
6701out:
6702 return status;
6703}
6704
6705/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006706 * Decode GETDEVINFO response
6707 */
Chuck Leverbf269552010-12-14 14:59:29 +00006708static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6709 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006710 struct nfs4_getdeviceinfo_res *res)
6711{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006712 struct compound_hdr hdr;
6713 int status;
6714
Chuck Leverbf269552010-12-14 14:59:29 +00006715 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006716 if (status != 0)
6717 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006718 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006719 if (status != 0)
6720 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006721 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006722out:
6723 return status;
6724}
6725
6726/*
6727 * Decode LAYOUTGET response
6728 */
Chuck Leverbf269552010-12-14 14:59:29 +00006729static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6730 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006731 struct nfs4_layoutget_res *res)
6732{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006733 struct compound_hdr hdr;
6734 int status;
6735
Chuck Leverbf269552010-12-14 14:59:29 +00006736 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006737 if (status)
6738 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006739 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006740 if (status)
6741 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006742 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006743 if (status)
6744 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006745 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006746out:
6747 return status;
6748}
Andy Adamson863a3c62011-03-23 13:27:54 +00006749
6750/*
Benny Halevycbe82602011-05-22 19:52:37 +03006751 * Decode LAYOUTRETURN response
6752 */
6753static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6754 struct xdr_stream *xdr,
6755 struct nfs4_layoutreturn_res *res)
6756{
6757 struct compound_hdr hdr;
6758 int status;
6759
6760 status = decode_compound_hdr(xdr, &hdr);
6761 if (status)
6762 goto out;
6763 status = decode_sequence(xdr, &res->seq_res, rqstp);
6764 if (status)
6765 goto out;
6766 status = decode_putfh(xdr);
6767 if (status)
6768 goto out;
6769 status = decode_layoutreturn(xdr, res);
6770out:
6771 return status;
6772}
6773
6774/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006775 * Decode LAYOUTCOMMIT response
6776 */
6777static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6778 struct xdr_stream *xdr,
6779 struct nfs4_layoutcommit_res *res)
6780{
6781 struct compound_hdr hdr;
6782 int status;
6783
6784 status = decode_compound_hdr(xdr, &hdr);
6785 if (status)
6786 goto out;
6787 status = decode_sequence(xdr, &res->seq_res, rqstp);
6788 if (status)
6789 goto out;
6790 status = decode_putfh(xdr);
6791 if (status)
6792 goto out;
6793 status = decode_layoutcommit(xdr, rqstp, res);
6794 if (status)
6795 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006796 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006797out:
6798 return status;
6799}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006800
6801/*
6802 * Decode SECINFO_NO_NAME response
6803 */
6804static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6805 struct xdr_stream *xdr,
6806 struct nfs4_secinfo_res *res)
6807{
6808 struct compound_hdr hdr;
6809 int status;
6810
6811 status = decode_compound_hdr(xdr, &hdr);
6812 if (status)
6813 goto out;
6814 status = decode_sequence(xdr, &res->seq_res, rqstp);
6815 if (status)
6816 goto out;
6817 status = decode_putrootfh(xdr);
6818 if (status)
6819 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04006820 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006821out:
6822 return status;
6823}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006824
6825/*
6826 * Decode TEST_STATEID response
6827 */
6828static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6829 struct xdr_stream *xdr,
6830 struct nfs41_test_stateid_res *res)
6831{
6832 struct compound_hdr hdr;
6833 int status;
6834
6835 status = decode_compound_hdr(xdr, &hdr);
6836 if (status)
6837 goto out;
6838 status = decode_sequence(xdr, &res->seq_res, rqstp);
6839 if (status)
6840 goto out;
6841 status = decode_test_stateid(xdr, res);
6842out:
6843 return status;
6844}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006845
6846/*
6847 * Decode FREE_STATEID response
6848 */
6849static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6850 struct xdr_stream *xdr,
6851 struct nfs41_free_stateid_res *res)
6852{
6853 struct compound_hdr hdr;
6854 int status;
6855
6856 status = decode_compound_hdr(xdr, &hdr);
6857 if (status)
6858 goto out;
6859 status = decode_sequence(xdr, &res->seq_res, rqstp);
6860 if (status)
6861 goto out;
6862 status = decode_free_stateid(xdr, res);
6863out:
6864 return status;
6865}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006866#endif /* CONFIG_NFS_V4_1 */
6867
Chuck Lever573c4e12010-12-14 14:58:11 +00006868/**
6869 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6870 * the local page cache.
6871 * @xdr: XDR stream where entry resides
6872 * @entry: buffer to fill in with entry data
6873 * @plus: boolean indicating whether this should be a readdirplus entry
6874 *
6875 * Returns zero if successful, otherwise a negative errno value is
6876 * returned.
6877 *
6878 * This function is not invoked during READDIR reply decoding, but
6879 * rather whenever an application invokes the getdents(2) system call
6880 * on a directory already in our cache.
6881 */
6882int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6883 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006884{
Fred Isamandae100c2011-07-30 20:52:37 -04006885 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07006886 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006887 __be32 *p = xdr_inline_decode(xdr, 4);
6888 if (unlikely(!p))
6889 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006890 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006891 p = xdr_inline_decode(xdr, 4);
6892 if (unlikely(!p))
6893 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006894 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006895 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006896 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006897 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006898 }
6899
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006900 p = xdr_inline_decode(xdr, 12);
6901 if (unlikely(!p))
6902 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006903 entry->prev_cookie = entry->cookie;
6904 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006905 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006906
Trond Myklebust9af8c222010-10-24 11:52:55 -04006907 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006908 if (unlikely(!p))
6909 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006910 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006911
6912 /*
6913 * In case the server doesn't return an inode number,
6914 * we fake one here. (We don't use inode number 0,
6915 * since glibc seems to choke on it...)
6916 */
6917 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006918 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006919
Trond Myklebust9af8c222010-10-24 11:52:55 -04006920 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006921 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006922
6923 if (decode_attr_length(xdr, &len, &p) < 0)
6924 goto out_overflow;
6925
Chuck Lever573c4e12010-12-14 14:58:11 +00006926 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006927 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006928 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006929 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6930 entry->ino = entry->fattr->mounted_on_fileid;
6931 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006932 entry->ino = entry->fattr->fileid;
6933
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006934 entry->d_type = DT_UNKNOWN;
6935 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6936 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6937
Chuck Lever573c4e12010-12-14 14:58:11 +00006938 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006939
6940out_overflow:
6941 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006942 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006943}
6944
6945/*
6946 * We need to translate between nfs status return values and
6947 * the local errno values which may not be the same.
6948 */
6949static struct {
6950 int stat;
6951 int errno;
6952} nfs_errtbl[] = {
6953 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006954 { NFS4ERR_PERM, -EPERM },
6955 { NFS4ERR_NOENT, -ENOENT },
6956 { NFS4ERR_IO, -errno_NFSERR_IO},
6957 { NFS4ERR_NXIO, -ENXIO },
6958 { NFS4ERR_ACCESS, -EACCES },
6959 { NFS4ERR_EXIST, -EEXIST },
6960 { NFS4ERR_XDEV, -EXDEV },
6961 { NFS4ERR_NOTDIR, -ENOTDIR },
6962 { NFS4ERR_ISDIR, -EISDIR },
6963 { NFS4ERR_INVAL, -EINVAL },
6964 { NFS4ERR_FBIG, -EFBIG },
6965 { NFS4ERR_NOSPC, -ENOSPC },
6966 { NFS4ERR_ROFS, -EROFS },
6967 { NFS4ERR_MLINK, -EMLINK },
6968 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6969 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6970 { NFS4ERR_DQUOT, -EDQUOT },
6971 { NFS4ERR_STALE, -ESTALE },
6972 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006973 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6974 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6975 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006976 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006977 { NFS4ERR_BADTYPE, -EBADTYPE },
6978 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006979 { NFS4ERR_SYMLINK, -ELOOP },
6980 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6981 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006982 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006983};
6984
6985/*
6986 * Convert an NFS error code to a local one.
6987 * This one is used jointly by NFSv2 and NFSv3.
6988 */
6989static int
David Howells0a8ea432006-08-22 20:06:08 -04006990nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006991{
6992 int i;
6993 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6994 if (nfs_errtbl[i].stat == stat)
6995 return nfs_errtbl[i].errno;
6996 }
6997 if (stat <= 10000 || stat > 10100) {
6998 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006999 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007000 }
7001 /* If we cannot translate the error, the recovery routines should
7002 * handle it.
7003 * Note: remaining NFSv4 error codes have values > 10000, so should
7004 * not conflict with native Linux error codes.
7005 */
Benny Halevy856dff32008-03-31 17:39:06 +03007006 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007007}
7008
Linus Torvalds1da177e2005-04-16 15:20:36 -07007009#define PROC(proc, argtype, restype) \
7010[NFSPROC4_CLNT_##proc] = { \
7011 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007012 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007013 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007014 .p_arglen = NFS4_##argtype##_sz, \
7015 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007016 .p_statidx = NFSPROC4_CLNT_##proc, \
7017 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007018}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007019
7020struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007021 PROC(READ, enc_read, dec_read),
7022 PROC(WRITE, enc_write, dec_write),
7023 PROC(COMMIT, enc_commit, dec_commit),
7024 PROC(OPEN, enc_open, dec_open),
7025 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7026 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7027 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7028 PROC(CLOSE, enc_close, dec_close),
7029 PROC(SETATTR, enc_setattr, dec_setattr),
7030 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7031 PROC(RENEW, enc_renew, dec_renew),
7032 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7033 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7034 PROC(LOCK, enc_lock, dec_lock),
7035 PROC(LOCKT, enc_lockt, dec_lockt),
7036 PROC(LOCKU, enc_locku, dec_locku),
7037 PROC(ACCESS, enc_access, dec_access),
7038 PROC(GETATTR, enc_getattr, dec_getattr),
7039 PROC(LOOKUP, enc_lookup, dec_lookup),
7040 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7041 PROC(REMOVE, enc_remove, dec_remove),
7042 PROC(RENAME, enc_rename, dec_rename),
7043 PROC(LINK, enc_link, dec_link),
7044 PROC(SYMLINK, enc_symlink, dec_symlink),
7045 PROC(CREATE, enc_create, dec_create),
7046 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7047 PROC(STATFS, enc_statfs, dec_statfs),
7048 PROC(READLINK, enc_readlink, dec_readlink),
7049 PROC(READDIR, enc_readdir, dec_readdir),
7050 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7051 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7052 PROC(GETACL, enc_getacl, dec_getacl),
7053 PROC(SETACL, enc_setacl, dec_setacl),
7054 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7055 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007056 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007057#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007058 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7059 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7060 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7061 PROC(SEQUENCE, enc_sequence, dec_sequence),
7062 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7063 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7064 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7065 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007066 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007067 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007068 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007069 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007070 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007071 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007072#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007073};
7074
Trond Myklebusta613fa12012-01-20 13:53:56 -05007075const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007076 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007077 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007078 .procs = nfs4_procedures
7079};
7080
7081/*
7082 * Local variables:
7083 * c-basic-offset: 8
7084 * End:
7085 */