blob: 3e0fe9f92e7cf0c69f5674df49ca90bc2c3c2ead [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 Myklebustd035c362010-12-21 10:45:27 -050077#define open_owner_id_maxsz (1 + 1 + 4)
78#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 + \
434 encode_savefh_maxsz + \
435 encode_open_maxsz + \
436 encode_getfh_maxsz + \
437 encode_getattr_maxsz + \
438 encode_restorefh_maxsz + \
439 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400441 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400442 decode_putfh_maxsz + \
443 decode_savefh_maxsz + \
444 decode_open_maxsz + \
445 decode_getfh_maxsz + \
446 decode_getattr_maxsz + \
447 decode_restorefh_maxsz + \
448 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400449#define NFS4_enc_open_confirm_sz \
450 (compound_encode_hdr_maxsz + \
451 encode_putfh_maxsz + \
452 encode_open_confirm_maxsz)
453#define NFS4_dec_open_confirm_sz \
454 (compound_decode_hdr_maxsz + \
455 decode_putfh_maxsz + \
456 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400460 encode_open_maxsz + \
461 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400465 decode_open_maxsz + \
466 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_enc_open_downgrade_sz \
468 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400470 encode_putfh_maxsz + \
471 encode_open_downgrade_maxsz + \
472 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_dec_open_downgrade_sz \
474 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400475 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400476 decode_putfh_maxsz + \
477 decode_open_downgrade_maxsz + \
478 decode_getattr_maxsz)
479#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400480 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400481 encode_putfh_maxsz + \
482 encode_close_maxsz + \
483 encode_getattr_maxsz)
484#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400486 decode_putfh_maxsz + \
487 decode_close_maxsz + \
488 decode_getattr_maxsz)
489#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400490 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400491 encode_putfh_maxsz + \
492 encode_setattr_maxsz + \
493 encode_getattr_maxsz)
494#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400495 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400496 decode_putfh_maxsz + \
497 decode_setattr_maxsz + \
498 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400500 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 encode_putfh_maxsz + \
502 encode_fsinfo_maxsz)
503#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400504 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 decode_putfh_maxsz + \
506 decode_fsinfo_maxsz)
507#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
508 encode_renew_maxsz)
509#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
510 decode_renew_maxsz)
511#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
512 encode_setclientid_maxsz)
513#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
514 decode_setclientid_maxsz)
515#define NFS4_enc_setclientid_confirm_sz \
516 (compound_encode_hdr_maxsz + \
517 encode_setclientid_confirm_maxsz + \
518 encode_putrootfh_maxsz + \
519 encode_fsinfo_maxsz)
520#define NFS4_dec_setclientid_confirm_sz \
521 (compound_decode_hdr_maxsz + \
522 decode_setclientid_confirm_maxsz + \
523 decode_putrootfh_maxsz + \
524 decode_fsinfo_maxsz)
525#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400526 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400528 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400532 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400536 encode_lockt_maxsz)
537#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400539 decode_putfh_maxsz + \
540 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400544 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400548 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400549#define NFS4_enc_release_lockowner_sz \
550 (compound_encode_hdr_maxsz + \
551 encode_lockowner_maxsz)
552#define NFS4_dec_release_lockowner_sz \
553 (compound_decode_hdr_maxsz + \
554 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400558 encode_access_maxsz + \
559 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400561 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400563 decode_access_maxsz + \
564 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 encode_putfh_maxsz + \
568 encode_getattr_maxsz)
569#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 decode_putfh_maxsz + \
572 decode_getattr_maxsz)
573#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 encode_putfh_maxsz + \
576 encode_lookup_maxsz + \
577 encode_getattr_maxsz + \
578 encode_getfh_maxsz)
579#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400582 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_getattr_maxsz + \
584 decode_getfh_maxsz)
585#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 encode_putrootfh_maxsz + \
588 encode_getattr_maxsz + \
589 encode_getfh_maxsz)
590#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400591 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 decode_putrootfh_maxsz + \
593 decode_getattr_maxsz + \
594 decode_getfh_maxsz)
595#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400598 encode_remove_maxsz + \
599 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400603 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400604 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 encode_putfh_maxsz + \
608 encode_savefh_maxsz + \
609 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400610 encode_rename_maxsz + \
611 encode_getattr_maxsz + \
612 encode_restorefh_maxsz + \
613 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400615 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 decode_putfh_maxsz + \
617 decode_savefh_maxsz + \
618 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400619 decode_rename_maxsz + \
620 decode_getattr_maxsz + \
621 decode_restorefh_maxsz + \
622 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400624 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 encode_putfh_maxsz + \
626 encode_savefh_maxsz + \
627 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400628 encode_link_maxsz + \
629 decode_getattr_maxsz + \
630 encode_restorefh_maxsz + \
631 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400633 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 decode_putfh_maxsz + \
635 decode_savefh_maxsz + \
636 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400637 decode_link_maxsz + \
638 decode_getattr_maxsz + \
639 decode_restorefh_maxsz + \
640 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 encode_putfh_maxsz + \
644 encode_symlink_maxsz + \
645 encode_getattr_maxsz + \
646 encode_getfh_maxsz)
647#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 decode_putfh_maxsz + \
650 decode_symlink_maxsz + \
651 decode_getattr_maxsz + \
652 decode_getfh_maxsz)
653#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400656 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400658 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400660 encode_restorefh_maxsz + \
661 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400663 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400665 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400667 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400669 decode_restorefh_maxsz + \
670 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 encode_putfh_maxsz + \
674 encode_getattr_maxsz)
675#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 decode_putfh_maxsz + \
678 decode_getattr_maxsz)
679#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400682 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400686 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800689 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 encode_getattr_maxsz)
691#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800693 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 decode_getattr_maxsz)
695#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100698 encode_delegreturn_maxsz + \
699 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400701 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100702 decode_delegreturn_maxsz + \
703 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000704#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400705 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000706 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400707 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000708#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400709 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000710 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400711 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000712#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000714 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400715 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000716#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000718 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400719 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400720#define NFS4_enc_fs_locations_sz \
721 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400722 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400723 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400724 encode_lookup_maxsz + \
725 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400726#define NFS4_dec_fs_locations_sz \
727 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400728 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400729 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400730 decode_lookup_maxsz + \
731 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000732#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
733 encode_sequence_maxsz + \
734 encode_putfh_maxsz + \
735 encode_secinfo_maxsz)
736#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
737 decode_sequence_maxsz + \
738 decode_putfh_maxsz + \
739 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400740#if defined(CONFIG_NFS_V4_1)
741#define NFS4_enc_exchange_id_sz \
742 (compound_encode_hdr_maxsz + \
743 encode_exchange_id_maxsz)
744#define NFS4_dec_exchange_id_sz \
745 (compound_decode_hdr_maxsz + \
746 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400747#define NFS4_enc_create_session_sz \
748 (compound_encode_hdr_maxsz + \
749 encode_create_session_maxsz)
750#define NFS4_dec_create_session_sz \
751 (compound_decode_hdr_maxsz + \
752 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400753#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
754 encode_destroy_session_maxsz)
755#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
756 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400757#define NFS4_enc_sequence_sz \
758 (compound_decode_hdr_maxsz + \
759 encode_sequence_maxsz)
760#define NFS4_dec_sequence_sz \
761 (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400763#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
764 encode_sequence_maxsz + \
765 encode_putrootfh_maxsz + \
766 encode_fsinfo_maxsz)
767#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
768 decode_sequence_maxsz + \
769 decode_putrootfh_maxsz + \
770 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500771#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
772 encode_sequence_maxsz + \
773 encode_reclaim_complete_maxsz)
774#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
775 decode_sequence_maxsz + \
776 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400777#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
778 encode_sequence_maxsz + \
779 encode_putfh_maxsz + \
780 encode_getdevicelist_maxsz)
781#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
782 decode_sequence_maxsz + \
783 decode_putfh_maxsz + \
784 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400785#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
786 encode_sequence_maxsz +\
787 encode_getdeviceinfo_maxsz)
788#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
789 decode_sequence_maxsz + \
790 decode_getdeviceinfo_maxsz)
791#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
792 encode_sequence_maxsz + \
793 encode_putfh_maxsz + \
794 encode_layoutget_maxsz)
795#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
796 decode_sequence_maxsz + \
797 decode_putfh_maxsz + \
798 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000799#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
800 encode_sequence_maxsz +\
801 encode_putfh_maxsz + \
802 encode_layoutcommit_maxsz + \
803 encode_getattr_maxsz)
804#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
805 decode_sequence_maxsz + \
806 decode_putfh_maxsz + \
807 decode_layoutcommit_maxsz + \
808 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300809#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz + \
811 encode_putfh_maxsz + \
812 encode_layoutreturn_maxsz)
813#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
814 decode_sequence_maxsz + \
815 decode_putfh_maxsz + \
816 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400817#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
818 encode_sequence_maxsz + \
819 encode_putrootfh_maxsz +\
820 encode_secinfo_no_name_maxsz)
821#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
822 decode_sequence_maxsz + \
823 decode_putrootfh_maxsz + \
824 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400825#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
826 encode_sequence_maxsz + \
827 encode_test_stateid_maxsz)
828#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
829 decode_sequence_maxsz + \
830 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400831#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
832 encode_sequence_maxsz + \
833 encode_free_stateid_maxsz)
834#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
835 decode_sequence_maxsz + \
836 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500837
838const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
839 compound_encode_hdr_maxsz +
840 encode_sequence_maxsz +
841 encode_putfh_maxsz +
842 encode_getattr_maxsz) *
843 XDR_UNIT);
844
845const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
846 compound_decode_hdr_maxsz +
847 decode_sequence_maxsz +
848 decode_putfh_maxsz) *
849 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400850#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500852static unsigned short send_implementation_id = 1;
853
854module_param(send_implementation_id, ushort, 0644);
855MODULE_PARM_DESC(send_implementation_id,
856 "Send implementation ID with NFSv4.1 exchange_id");
857
Trond Myklebustbca79472009-03-11 14:10:26 -0400858static const umode_t nfs_type2fmt[] = {
859 [NF4BAD] = 0,
860 [NF4REG] = S_IFREG,
861 [NF4DIR] = S_IFDIR,
862 [NF4BLK] = S_IFBLK,
863 [NF4CHR] = S_IFCHR,
864 [NF4LNK] = S_IFLNK,
865 [NF4SOCK] = S_IFSOCK,
866 [NF4FIFO] = S_IFIFO,
867 [NF4ATTRDIR] = 0,
868 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869};
870
871struct compound_hdr {
872 int32_t status;
873 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500874 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 uint32_t taglen;
876 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400877 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400878 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879};
880
Benny Halevy13c65ce2009-08-14 17:19:25 +0300881static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
882{
883 __be32 *p = xdr_reserve_space(xdr, nbytes);
884 BUG_ON(!p);
885 return p;
886}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
888static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
889{
Al Viro8687b632006-10-19 23:28:48 -0700890 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
892 p = xdr_reserve_space(xdr, 4 + len);
893 BUG_ON(p == NULL);
894 xdr_encode_opaque(p, str, len);
895}
896
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400897static void encode_compound_hdr(struct xdr_stream *xdr,
898 struct rpc_rqst *req,
899 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900{
Al Viro8687b632006-10-19 23:28:48 -0700901 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400902 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400903
904 /* initialize running count of expected bytes in reply.
905 * NOTE: the replied tag SHOULD be the same is the one sent,
906 * but this is not required as a MUST for the server to do so. */
907 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
909 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
910 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300911 p = reserve_space(xdr, 4 + hdr->taglen + 8);
912 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300913 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500914 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300915 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500916}
917
918static void encode_nops(struct compound_hdr *hdr)
919{
Andy Adamsonfc931582009-04-01 09:22:31 -0400920 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500921 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922}
923
924static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
925{
Al Viro8687b632006-10-19 23:28:48 -0700926 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
929 BUG_ON(p == NULL);
930 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
931}
932
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500933static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
935 char owner_name[IDMAP_NAMESZ];
936 char owner_group[IDMAP_NAMESZ];
937 int owner_namelen = 0;
938 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700939 __be32 *p;
940 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 int len;
942 uint32_t bmval0 = 0;
943 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
945 /*
946 * We reserve enough space to write the entire attribute buffer at once.
947 * In the worst-case, this would be
948 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
949 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000950 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 */
952 len = 16;
953
954 /* Sigh */
955 if (iap->ia_valid & ATTR_SIZE)
956 len += 8;
957 if (iap->ia_valid & ATTR_MODE)
958 len += 4;
959 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800960 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400962 dprintk("nfs: couldn't resolve uid %d to string\n",
963 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 /* XXX */
965 strcpy(owner_name, "nobody");
966 owner_namelen = sizeof("nobody") - 1;
967 /* goto out; */
968 }
969 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
970 }
971 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800972 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400974 dprintk("nfs: couldn't resolve gid %d to string\n",
975 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 strcpy(owner_group, "nobody");
977 owner_grouplen = sizeof("nobody") - 1;
978 /* goto out; */
979 }
980 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
981 }
982 if (iap->ia_valid & ATTR_ATIME_SET)
983 len += 16;
984 else if (iap->ia_valid & ATTR_ATIME)
985 len += 4;
986 if (iap->ia_valid & ATTR_MTIME_SET)
987 len += 16;
988 else if (iap->ia_valid & ATTR_MTIME)
989 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300990 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
992 /*
993 * We write the bitmap length now, but leave the bitmap and the attribute
994 * buffer length to be backfilled at the end of this routine.
995 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300996 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 q = p;
998 p += 3;
999
1000 if (iap->ia_valid & ATTR_SIZE) {
1001 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001002 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 }
1004 if (iap->ia_valid & ATTR_MODE) {
1005 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001006 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 }
1008 if (iap->ia_valid & ATTR_UID) {
1009 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001010 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
1012 if (iap->ia_valid & ATTR_GID) {
1013 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001014 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 }
1016 if (iap->ia_valid & ATTR_ATIME_SET) {
1017 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001018 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1019 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001020 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1021 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 }
1023 else if (iap->ia_valid & ATTR_ATIME) {
1024 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001025 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 }
1027 if (iap->ia_valid & ATTR_MTIME_SET) {
1028 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001029 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1030 *p++ = cpu_to_be32(0);
1031 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1032 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
1034 else if (iap->ia_valid & ATTR_MTIME) {
1035 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001036 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 /*
1040 * Now we backfill the bitmap and the attribute buffer length.
1041 */
1042 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001043 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 len, ((char *)p - (char *)q) + 4);
1045 BUG();
1046 }
1047 len = (char *)p - (char *)q - 12;
1048 *q++ = htonl(bmval0);
1049 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001050 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053}
1054
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001055static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056{
Al Viro8687b632006-10-19 23:28:48 -07001057 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
Benny Halevy13c65ce2009-08-14 17:19:25 +03001059 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001060 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +03001061 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -05001062 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001063 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064}
1065
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001066static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067{
Al Viro8687b632006-10-19 23:28:48 -07001068 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Benny Halevy13c65ce2009-08-14 17:19:25 +03001070 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001071 *p++ = cpu_to_be32(OP_CLOSE);
1072 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +03001073 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001074 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001075 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076}
1077
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001078static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079{
Al Viro8687b632006-10-19 23:28:48 -07001080 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001081
Benny Halevy13c65ce2009-08-14 17:19:25 +03001082 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001083 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001084 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001085 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001086 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001087 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001090static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
Al Viro8687b632006-10-19 23:28:48 -07001092 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001093
Benny Halevy13c65ce2009-08-14 17:19:25 +03001094 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001095 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001096 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
1098 switch (create->ftype) {
1099 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001100 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001101 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001102 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 break;
1104
1105 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001106 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001107 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001108 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 break;
1110
1111 default:
1112 break;
1113 }
1114
Benny Halevy811652b2009-08-14 17:19:34 +03001115 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001116 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001117 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001119 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120}
1121
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001122static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123{
Andy Adamson05d564f2008-12-23 16:06:15 -05001124 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Benny Halevy13c65ce2009-08-14 17:19:25 +03001126 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001127 *p++ = cpu_to_be32(OP_GETATTR);
1128 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001129 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001130 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001131 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132}
1133
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001134static 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 -07001135{
Andy Adamson05d564f2008-12-23 16:06:15 -05001136 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Benny Halevy13c65ce2009-08-14 17:19:25 +03001138 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001139 *p++ = cpu_to_be32(OP_GETATTR);
1140 *p++ = cpu_to_be32(2);
1141 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001142 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001143 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001144 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145}
1146
Fred Isamandae100c2011-07-30 20:52:37 -04001147static void
1148encode_getattr_three(struct xdr_stream *xdr,
1149 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1150 struct compound_hdr *hdr)
1151{
1152 __be32 *p;
1153
1154 p = reserve_space(xdr, 4);
1155 *p = cpu_to_be32(OP_GETATTR);
1156 if (bm2) {
1157 p = reserve_space(xdr, 16);
1158 *p++ = cpu_to_be32(3);
1159 *p++ = cpu_to_be32(bm0);
1160 *p++ = cpu_to_be32(bm1);
1161 *p = cpu_to_be32(bm2);
1162 } else if (bm1) {
1163 p = reserve_space(xdr, 12);
1164 *p++ = cpu_to_be32(2);
1165 *p++ = cpu_to_be32(bm0);
1166 *p = cpu_to_be32(bm1);
1167 } else {
1168 p = reserve_space(xdr, 8);
1169 *p++ = cpu_to_be32(1);
1170 *p = cpu_to_be32(bm0);
1171 }
1172 hdr->nops++;
1173 hdr->replen += decode_getattr_maxsz;
1174}
1175
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001176static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001178 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1179 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180}
1181
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001182static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183{
Fred Isamandae100c2011-07-30 20:52:37 -04001184 encode_getattr_three(xdr,
1185 bitmask[0] & nfs4_fsinfo_bitmap[0],
1186 bitmask[1] & nfs4_fsinfo_bitmap[1],
1187 bitmask[2] & nfs4_fsinfo_bitmap[2],
1188 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189}
1190
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001191static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001192{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001193 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1194 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001195}
1196
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001197static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198{
Al Viro8687b632006-10-19 23:28:48 -07001199 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Benny Halevy13c65ce2009-08-14 17:19:25 +03001201 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001202 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001203 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001204 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205}
1206
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001207static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208{
Al Viro8687b632006-10-19 23:28:48 -07001209 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Benny Halevy13c65ce2009-08-14 17:19:25 +03001211 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001212 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001213 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001214 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001215 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216}
1217
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001218static inline int nfs4_lock_type(struct file_lock *fl, int block)
1219{
1220 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1221 return block ? NFS4_READW_LT : NFS4_READ_LT;
1222 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1223}
1224
1225static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1226{
1227 if (fl->fl_end == OFFSET_MAX)
1228 return ~(uint64_t)0;
1229 return fl->fl_end - fl->fl_start + 1;
1230}
1231
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001232static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1233{
1234 __be32 *p;
1235
Trond Myklebustd035c362010-12-21 10:45:27 -05001236 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001237 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001238 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001239 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001240 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001241 xdr_encode_hyper(p, lowner->id);
1242}
1243
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244/*
1245 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1246 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1247 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001248static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Al Viro8687b632006-10-19 23:28:48 -07001250 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Benny Halevy13c65ce2009-08-14 17:19:25 +03001252 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001253 *p++ = cpu_to_be32(OP_LOCK);
1254 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1255 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001256 p = xdr_encode_hyper(p, args->fl->fl_start);
1257 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001258 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001259 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001260 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001261 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001262 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001263 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001264 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 }
1266 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001267 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001268 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001269 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 }
Andy Adamsond0179312008-12-23 16:06:17 -05001271 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001272 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273}
1274
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001275static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276{
Al Viro8687b632006-10-19 23:28:48 -07001277 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001279 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001280 *p++ = cpu_to_be32(OP_LOCKT);
1281 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001282 p = xdr_encode_hyper(p, args->fl->fl_start);
1283 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001284 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001285 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001286 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287}
1288
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001289static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290{
Al Viro8687b632006-10-19 23:28:48 -07001291 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Benny Halevy13c65ce2009-08-14 17:19:25 +03001293 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001294 *p++ = cpu_to_be32(OP_LOCKU);
1295 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1296 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001297 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001298 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001299 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001300 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001301 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302}
1303
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001304static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1305{
1306 __be32 *p;
1307
1308 p = reserve_space(xdr, 4);
1309 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1310 encode_lockowner(xdr, lowner);
1311 hdr->nops++;
1312 hdr->replen += decode_release_lockowner_maxsz;
1313}
1314
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001315static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316{
1317 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001318 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
Benny Halevy13c65ce2009-08-14 17:19:25 +03001320 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001321 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001322 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001323 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001324 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325}
1326
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001327static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328{
Al Viro8687b632006-10-19 23:28:48 -07001329 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Benny Halevy13c65ce2009-08-14 17:19:25 +03001331 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001332 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001333 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001334 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001335 break;
1336 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001337 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001338 break;
1339 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001340 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001341 break;
1342 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001343 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
Benny Halevy34558512009-08-14 17:19:30 +03001345 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346}
1347
1348static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1349{
Al Viro8687b632006-10-19 23:28:48 -07001350 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 /*
1352 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1353 * owner 4 = 32
1354 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001355 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001356 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001357 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001358 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001359 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001360 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001361 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001362 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001363 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001364 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365}
1366
1367static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1368{
Al Viro8687b632006-10-19 23:28:48 -07001369 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001370 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
Benny Halevy13c65ce2009-08-14 17:19:25 +03001372 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001374 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001375 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001376 encode_attrs(xdr, arg->u.attrs, arg->server);
1377 break;
1378 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001379 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001380 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001381 if (nfs4_has_persistent_session(clp)) {
1382 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1383 encode_attrs(xdr, arg->u.attrs, arg->server);
1384 } else {
1385 struct iattr dummy;
1386
1387 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1388 encode_nfs4_verifier(xdr, &arg->u.verifier);
1389 dummy.ia_valid = 0;
1390 encode_attrs(xdr, &dummy, arg->server);
1391 }
1392 } else {
1393 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1394 encode_nfs4_verifier(xdr, &arg->u.verifier);
1395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 }
1397}
1398
1399static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1400{
Al Viro8687b632006-10-19 23:28:48 -07001401 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Benny Halevy13c65ce2009-08-14 17:19:25 +03001403 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001405 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001406 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001407 break;
1408 default:
1409 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001410 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001411 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 }
1413}
1414
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001415static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416{
Al Viro8687b632006-10-19 23:28:48 -07001417 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Benny Halevy13c65ce2009-08-14 17:19:25 +03001419 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001421 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001422 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001423 break;
1424 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001425 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001426 break;
1427 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001428 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001429 break;
1430 default:
1431 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 }
1433}
1434
1435static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1436{
Al Viro8687b632006-10-19 23:28:48 -07001437 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
Benny Halevy13c65ce2009-08-14 17:19:25 +03001439 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001440 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 encode_string(xdr, name->len, name->name);
1442}
1443
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001444static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445{
Al Viro8687b632006-10-19 23:28:48 -07001446 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
Benny Halevy13c65ce2009-08-14 17:19:25 +03001448 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001449 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 encode_delegation_type(xdr, type);
1451}
1452
1453static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1454{
Al Viro8687b632006-10-19 23:28:48 -07001455 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
Benny Halevy13c65ce2009-08-14 17:19:25 +03001457 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001458 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001459 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 encode_string(xdr, name->len, name->name);
1461}
1462
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001463static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464{
1465 encode_openhdr(xdr, arg);
1466 encode_opentype(xdr, arg);
1467 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001468 case NFS4_OPEN_CLAIM_NULL:
1469 encode_claim_null(xdr, arg->name);
1470 break;
1471 case NFS4_OPEN_CLAIM_PREVIOUS:
1472 encode_claim_previous(xdr, arg->u.delegation_type);
1473 break;
1474 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1475 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1476 break;
1477 default:
1478 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 }
Andy Adamsond0179312008-12-23 16:06:17 -05001480 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001481 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482}
1483
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001484static 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 -07001485{
Al Viro8687b632006-10-19 23:28:48 -07001486 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Benny Halevy13c65ce2009-08-14 17:19:25 +03001488 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001489 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001490 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001491 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001492 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001493 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494}
1495
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001496static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497{
Al Viro8687b632006-10-19 23:28:48 -07001498 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
Benny Halevy13c65ce2009-08-14 17:19:25 +03001500 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001501 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001502 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001503 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001504 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001505 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001506 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507}
1508
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001509static void
Andy Adamsond0179312008-12-23 16:06:17 -05001510encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511{
1512 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001513 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
Benny Halevy13c65ce2009-08-14 17:19:25 +03001515 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001516 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001517 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001518 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001519 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520}
1521
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001522static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
Andy Adamson05d564f2008-12-23 16:06:15 -05001524 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001525
Benny Halevy13c65ce2009-08-14 17:19:25 +03001526 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001527 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001528 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001529 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530}
1531
Andy Adamson89d1ea62011-03-01 01:34:09 +00001532static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001535 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Benny Halevy13c65ce2009-08-14 17:19:25 +03001537 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001539 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001540 if (zero_seqid)
1541 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001542 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 } else
Benny Halevy34558512009-08-14 17:19:30 +03001544 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545}
1546
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001547static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548{
Al Viro8687b632006-10-19 23:28:48 -07001549 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Benny Halevy13c65ce2009-08-14 17:19:25 +03001551 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001552 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
Andy Adamson89d1ea62011-03-01 01:34:09 +00001554 encode_stateid(xdr, args->context, args->lock_context,
1555 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
Benny Halevy13c65ce2009-08-14 17:19:25 +03001557 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001558 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001559 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001560 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001561 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562}
1563
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001564static 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 -07001565{
Trond Myklebust28331a42011-04-27 13:47:52 -04001566 uint32_t attrs[2] = {
1567 FATTR4_WORD0_RDATTR_ERROR,
1568 FATTR4_WORD1_MOUNTED_ON_FILEID,
1569 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001570 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001571 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001573 if (readdir->plus) {
1574 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001575 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001576 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1577 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1578 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1579 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001580 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001581 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001582 /* Use mounted_on_fileid only if the server supports it */
1583 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1584 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001585
Benny Halevy13c65ce2009-08-14 17:19:25 +03001586 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001587 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001588 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001589 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001590 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001591 *p++ = cpu_to_be32(readdir->count);
1592 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001593
Benny Halevye75bc1c2009-08-14 17:18:54 +03001594 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001595 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001596 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001597 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001598 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1599 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001600 (unsigned long long)readdir->cookie,
1601 ((u32 *)readdir->verifier.data)[0],
1602 ((u32 *)readdir->verifier.data)[1],
1603 attrs[0] & readdir->bitmask[0],
1604 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605}
1606
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001607static 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 -07001608{
Al Viro8687b632006-10-19 23:28:48 -07001609 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
Benny Halevy13c65ce2009-08-14 17:19:25 +03001611 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001612 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001613 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001614 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615}
1616
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001617static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618{
Al Viro8687b632006-10-19 23:28:48 -07001619 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
Benny Halevy13c65ce2009-08-14 17:19:25 +03001621 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001622 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001623 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001624 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001625 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626}
1627
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001628static 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 -07001629{
Al Viro8687b632006-10-19 23:28:48 -07001630 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
Benny Halevy811652b2009-08-14 17:19:34 +03001632 p = reserve_space(xdr, 4);
1633 *p = cpu_to_be32(OP_RENAME);
1634 encode_string(xdr, oldname->len, oldname->name);
1635 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001636 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001637 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638}
1639
Chuck Leverbb4dae52012-03-01 17:01:48 -05001640static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1641 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642{
Al Viro8687b632006-10-19 23:28:48 -07001643 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
Benny Halevy13c65ce2009-08-14 17:19:25 +03001645 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001646 *p++ = cpu_to_be32(OP_RENEW);
Chuck Leverbb4dae52012-03-01 17:01:48 -05001647 xdr_encode_hyper(p, clid);
Andy Adamsond0179312008-12-23 16:06:17 -05001648 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001649 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650}
1651
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001652static void
Andy Adamsond0179312008-12-23 16:06:17 -05001653encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001654{
Al Viro8687b632006-10-19 23:28:48 -07001655 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001656
Benny Halevy13c65ce2009-08-14 17:19:25 +03001657 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001658 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001659 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001660 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001661}
1662
Chuck Lever9f06c712010-12-14 14:59:18 +00001663static void
Andy Adamsond0179312008-12-23 16:06:17 -05001664encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001665{
Al Viro8687b632006-10-19 23:28:48 -07001666 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001667
Benny Halevy13c65ce2009-08-14 17:19:25 +03001668 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001669 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001670 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001671 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001672 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001673 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001674 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001675 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001676 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001677 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001678 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001679 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001680}
1681
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001682static void
Andy Adamsond0179312008-12-23 16:06:17 -05001683encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684{
Al Viro8687b632006-10-19 23:28:48 -07001685 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686
Benny Halevy13c65ce2009-08-14 17:19:25 +03001687 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001688 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001689 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001690 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691}
1692
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001693static 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 -07001694{
Al Viro8687b632006-10-19 23:28:48 -07001695 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001696
Benny Halevy13c65ce2009-08-14 17:19:25 +03001697 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001698 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001699 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001700 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001701 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001702 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703}
1704
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001705static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706{
Al Viro8687b632006-10-19 23:28:48 -07001707 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
Benny Halevy13c65ce2009-08-14 17:19:25 +03001709 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001710 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001711 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712
1713 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001714 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001715 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1717 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001718 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001719 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001720 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001721 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722}
1723
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001724static 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 -07001725{
Andy Adamson05d564f2008-12-23 16:06:15 -05001726 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
Benny Halevy13c65ce2009-08-14 17:19:25 +03001728 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001729 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001730 p = xdr_encode_hyper(p, arg->clientid);
1731 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001732 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001733 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734}
1735
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001736static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737{
Al Viro8687b632006-10-19 23:28:48 -07001738 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
Benny Halevy13c65ce2009-08-14 17:19:25 +03001740 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001741 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
Andy Adamson89d1ea62011-03-01 01:34:09 +00001743 encode_stateid(xdr, args->context, args->lock_context,
1744 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
Benny Halevy13c65ce2009-08-14 17:19:25 +03001746 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001747 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001748 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001749 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
1751 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001752 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001753 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754}
1755
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001756static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757{
Al Viro8687b632006-10-19 23:28:48 -07001758 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
Benny Halevy13c65ce2009-08-14 17:19:25 +03001760 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
Benny Halevye75bc1c2009-08-14 17:18:54 +03001762 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001763 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001764 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001765 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001767
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001768static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1769{
1770 int len = name->len;
1771 __be32 *p;
1772
1773 p = reserve_space(xdr, 8 + len);
1774 *p++ = cpu_to_be32(OP_SECINFO);
1775 xdr_encode_opaque(p, name->name, len);
1776 hdr->nops++;
1777 hdr->replen += decode_secinfo_maxsz;
1778}
1779
Benny Halevy99fe60d2009-04-01 09:22:29 -04001780#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001781/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001782static void encode_exchange_id(struct xdr_stream *xdr,
1783 struct nfs41_exchange_id_args *args,
1784 struct compound_hdr *hdr)
1785{
1786 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001787 char impl_name[NFS4_OPAQUE_LIMIT];
1788 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001789
Benny Halevy13c65ce2009-08-14 17:19:25 +03001790 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001791 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001792 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001793
1794 encode_string(xdr, args->id_len, args->id);
1795
Benny Halevy13c65ce2009-08-14 17:19:25 +03001796 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001797 *p++ = cpu_to_be32(args->flags);
1798 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001799
1800 if (send_implementation_id &&
1801 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1802 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1803 <= NFS4_OPAQUE_LIMIT + 1)
1804 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1805 utsname()->sysname, utsname()->release,
1806 utsname()->version, utsname()->machine);
1807
1808 if (len > 0) {
1809 *p = cpu_to_be32(1); /* implementation id array length=1 */
1810
1811 encode_string(xdr,
1812 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1813 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1814 encode_string(xdr, len, impl_name);
1815 /* just send zeros for nii_date - the date is in nii_name */
1816 p = reserve_space(xdr, 12);
1817 p = xdr_encode_hyper(p, 0);
1818 *p = cpu_to_be32(0);
1819 } else
1820 *p = cpu_to_be32(0); /* implementation id array length=0 */
1821
Benny Halevy99fe60d2009-04-01 09:22:29 -04001822 hdr->nops++;
1823 hdr->replen += decode_exchange_id_maxsz;
1824}
Andy Adamsonfc931582009-04-01 09:22:31 -04001825
1826static void encode_create_session(struct xdr_stream *xdr,
1827 struct nfs41_create_session_args *args,
1828 struct compound_hdr *hdr)
1829{
1830 __be32 *p;
1831 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1832 uint32_t len;
1833 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001834 u32 max_resp_sz_cached;
1835
1836 /*
1837 * Assumes OPEN is the biggest non-idempotent compound.
1838 * 2 is the verifier.
1839 */
1840 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1841 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001842
Andy Adamsonfc931582009-04-01 09:22:31 -04001843 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1844 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001845
Benny Halevy13c65ce2009-08-14 17:19:25 +03001846 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001847 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001848 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001849 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1850 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001851
Andy Adamsonfc931582009-04-01 09:22:31 -04001852 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001853 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001854 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1855 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001856 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001857 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1858 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1859 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001860
1861 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001862 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001863 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1864 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1865 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1866 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1867 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1868 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001869
Benny Halevye75bc1c2009-08-14 17:18:54 +03001870 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001871 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001872 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001873
1874 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001875 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001876 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001877 *p++ = cpu_to_be32(0); /* UID */
1878 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001879 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001880 hdr->nops++;
1881 hdr->replen += decode_create_session_maxsz;
1882}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001883
1884static void encode_destroy_session(struct xdr_stream *xdr,
1885 struct nfs4_session *session,
1886 struct compound_hdr *hdr)
1887{
1888 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001889 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001890 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001891 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001892 hdr->nops++;
1893 hdr->replen += decode_destroy_session_maxsz;
1894}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001895
1896static void encode_reclaim_complete(struct xdr_stream *xdr,
1897 struct nfs41_reclaim_complete_args *args,
1898 struct compound_hdr *hdr)
1899{
1900 __be32 *p;
1901
1902 p = reserve_space(xdr, 8);
1903 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1904 *p++ = cpu_to_be32(args->one_fs);
1905 hdr->nops++;
1906 hdr->replen += decode_reclaim_complete_maxsz;
1907}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001908#endif /* CONFIG_NFS_V4_1 */
1909
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001910static void encode_sequence(struct xdr_stream *xdr,
1911 const struct nfs4_sequence_args *args,
1912 struct compound_hdr *hdr)
1913{
1914#if defined(CONFIG_NFS_V4_1)
1915 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001916 struct nfs4_slot_table *tp;
1917 struct nfs4_slot *slot;
1918 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001919
1920 if (!session)
1921 return;
1922
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001923 tp = &session->fc_slot_table;
1924
1925 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1926 slot = tp->slots + args->sa_slotid;
1927
Benny Halevy13c65ce2009-08-14 17:19:25 +03001928 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001929 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001930
1931 /*
1932 * Sessionid + seqid + slotid + max slotid + cache_this
1933 */
1934 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1935 "max_slotid=%d cache_this=%d\n",
1936 __func__,
1937 ((u32 *)session->sess_id.data)[0],
1938 ((u32 *)session->sess_id.data)[1],
1939 ((u32 *)session->sess_id.data)[2],
1940 ((u32 *)session->sess_id.data)[3],
1941 slot->seq_nr, args->sa_slotid,
1942 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001943 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001944 *p++ = cpu_to_be32(slot->seq_nr);
1945 *p++ = cpu_to_be32(args->sa_slotid);
1946 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001947 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001948 hdr->nops++;
1949 hdr->replen += decode_sequence_maxsz;
1950#endif /* CONFIG_NFS_V4_1 */
1951}
1952
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001953#ifdef CONFIG_NFS_V4_1
1954static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001955encode_getdevicelist(struct xdr_stream *xdr,
1956 const struct nfs4_getdevicelist_args *args,
1957 struct compound_hdr *hdr)
1958{
1959 __be32 *p;
1960 nfs4_verifier dummy = {
1961 .data = "dummmmmy",
1962 };
1963
1964 p = reserve_space(xdr, 20);
1965 *p++ = cpu_to_be32(OP_GETDEVICELIST);
1966 *p++ = cpu_to_be32(args->layoutclass);
1967 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1968 xdr_encode_hyper(p, 0ULL); /* cookie */
1969 encode_nfs4_verifier(xdr, &dummy);
1970 hdr->nops++;
1971 hdr->replen += decode_getdevicelist_maxsz;
1972}
1973
1974static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001975encode_getdeviceinfo(struct xdr_stream *xdr,
1976 const struct nfs4_getdeviceinfo_args *args,
1977 struct compound_hdr *hdr)
1978{
1979 __be32 *p;
1980
1981 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1982 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1983 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1984 NFS4_DEVICEID4_SIZE);
1985 *p++ = cpu_to_be32(args->pdev->layout_type);
1986 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1987 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1988 hdr->nops++;
1989 hdr->replen += decode_getdeviceinfo_maxsz;
1990}
1991
1992static void
1993encode_layoutget(struct xdr_stream *xdr,
1994 const struct nfs4_layoutget_args *args,
1995 struct compound_hdr *hdr)
1996{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001997 __be32 *p;
1998
1999 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
2000 *p++ = cpu_to_be32(OP_LAYOUTGET);
2001 *p++ = cpu_to_be32(0); /* Signal layout available */
2002 *p++ = cpu_to_be32(args->type);
2003 *p++ = cpu_to_be32(args->range.iomode);
2004 p = xdr_encode_hyper(p, args->range.offset);
2005 p = xdr_encode_hyper(p, args->range.length);
2006 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00002007 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002008 *p = cpu_to_be32(args->maxcount);
2009
2010 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
2011 __func__,
2012 args->type,
2013 args->range.iomode,
2014 (unsigned long)args->range.offset,
2015 (unsigned long)args->range.length,
2016 args->maxcount);
2017 hdr->nops++;
2018 hdr->replen += decode_layoutget_maxsz;
2019}
Andy Adamson863a3c62011-03-23 13:27:54 +00002020
2021static int
2022encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03002023 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00002024 const struct nfs4_layoutcommit_args *args,
2025 struct compound_hdr *hdr)
2026{
2027 __be32 *p;
2028
2029 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2030 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2031
Benny Halevyac7db722011-05-22 19:53:48 +03002032 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
Andy Adamson863a3c62011-03-23 13:27:54 +00002033 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
2034 /* Only whole file layouts */
2035 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002036 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Andy Adamson863a3c62011-03-23 13:27:54 +00002037 *p++ = cpu_to_be32(0); /* reclaim */
2038 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
2039 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2040 p = xdr_encode_hyper(p, args->lastbytewritten);
2041 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2042 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002043
2044 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2045 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2046 NFS_I(inode)->layout, xdr, args);
2047 else {
2048 p = reserve_space(xdr, 4);
2049 *p = cpu_to_be32(0); /* no layout-type payload */
2050 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002051
2052 hdr->nops++;
2053 hdr->replen += decode_layoutcommit_maxsz;
2054 return 0;
2055}
Benny Halevycbe82602011-05-22 19:52:37 +03002056
2057static void
2058encode_layoutreturn(struct xdr_stream *xdr,
2059 const struct nfs4_layoutreturn_args *args,
2060 struct compound_hdr *hdr)
2061{
2062 __be32 *p;
2063
2064 p = reserve_space(xdr, 20);
2065 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
2066 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2067 *p++ = cpu_to_be32(args->layout_type);
2068 *p++ = cpu_to_be32(IOMODE_ANY);
2069 *p = cpu_to_be32(RETURN_FILE);
2070 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
2071 p = xdr_encode_hyper(p, 0);
2072 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2073 spin_lock(&args->inode->i_lock);
2074 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
2075 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002076 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2077 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2078 NFS_I(args->inode)->layout, xdr, args);
2079 } else {
2080 p = reserve_space(xdr, 4);
2081 *p = cpu_to_be32(0);
2082 }
Benny Halevycbe82602011-05-22 19:52:37 +03002083 hdr->nops++;
2084 hdr->replen += decode_layoutreturn_maxsz;
2085}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002086
2087static int
2088encode_secinfo_no_name(struct xdr_stream *xdr,
2089 const struct nfs41_secinfo_no_name_args *args,
2090 struct compound_hdr *hdr)
2091{
2092 __be32 *p;
2093 p = reserve_space(xdr, 8);
2094 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2095 *p++ = cpu_to_be32(args->style);
2096 hdr->nops++;
2097 hdr->replen += decode_secinfo_no_name_maxsz;
2098 return 0;
2099}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002100
2101static void encode_test_stateid(struct xdr_stream *xdr,
2102 struct nfs41_test_stateid_args *args,
2103 struct compound_hdr *hdr)
2104{
2105 __be32 *p;
2106
2107 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
2108 *p++ = cpu_to_be32(OP_TEST_STATEID);
2109 *p++ = cpu_to_be32(1);
2110 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2111 hdr->nops++;
2112 hdr->replen += decode_test_stateid_maxsz;
2113}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002114
2115static void encode_free_stateid(struct xdr_stream *xdr,
2116 struct nfs41_free_stateid_args *args,
2117 struct compound_hdr *hdr)
2118{
2119 __be32 *p;
2120 p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
2121 *p++ = cpu_to_be32(OP_FREE_STATEID);
2122 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2123 hdr->nops++;
2124 hdr->replen += decode_free_stateid_maxsz;
2125}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002126#endif /* CONFIG_NFS_V4_1 */
2127
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128/*
2129 * END OF "GENERIC" ENCODE ROUTINES.
2130 */
2131
Benny Halevy66cc0422009-04-01 09:22:10 -04002132static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2133{
2134#if defined(CONFIG_NFS_V4_1)
2135 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04002136 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002137#endif /* CONFIG_NFS_V4_1 */
2138 return 0;
2139}
2140
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141/*
2142 * Encode an ACCESS request
2143 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002144static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2145 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002148 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
Chuck Lever9f06c712010-12-14 14:59:18 +00002151 encode_compound_hdr(xdr, req, &hdr);
2152 encode_sequence(xdr, &args->seq_args, &hdr);
2153 encode_putfh(xdr, args->fh, &hdr);
2154 encode_access(xdr, args->access, &hdr);
2155 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002156 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157}
2158
2159/*
2160 * Encode LOOKUP request
2161 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002162static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2163 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002166 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
Chuck Lever9f06c712010-12-14 14:59:18 +00002169 encode_compound_hdr(xdr, req, &hdr);
2170 encode_sequence(xdr, &args->seq_args, &hdr);
2171 encode_putfh(xdr, args->dir_fh, &hdr);
2172 encode_lookup(xdr, args->name, &hdr);
2173 encode_getfh(xdr, &hdr);
2174 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002175 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176}
2177
2178/*
2179 * Encode LOOKUP_ROOT request
2180 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002181static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2182 struct xdr_stream *xdr,
2183 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002186 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
Chuck Lever9f06c712010-12-14 14:59:18 +00002189 encode_compound_hdr(xdr, req, &hdr);
2190 encode_sequence(xdr, &args->seq_args, &hdr);
2191 encode_putrootfh(xdr, &hdr);
2192 encode_getfh(xdr, &hdr);
2193 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002194 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195}
2196
2197/*
2198 * Encode REMOVE request
2199 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002200static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2201 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002204 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206
Chuck Lever9f06c712010-12-14 14:59:18 +00002207 encode_compound_hdr(xdr, req, &hdr);
2208 encode_sequence(xdr, &args->seq_args, &hdr);
2209 encode_putfh(xdr, args->fh, &hdr);
2210 encode_remove(xdr, &args->name, &hdr);
2211 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002212 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213}
2214
2215/*
2216 * Encode RENAME request
2217 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002218static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2219 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002222 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
Chuck Lever9f06c712010-12-14 14:59:18 +00002225 encode_compound_hdr(xdr, req, &hdr);
2226 encode_sequence(xdr, &args->seq_args, &hdr);
2227 encode_putfh(xdr, args->old_dir, &hdr);
2228 encode_savefh(xdr, &hdr);
2229 encode_putfh(xdr, args->new_dir, &hdr);
2230 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2231 encode_getfattr(xdr, args->bitmask, &hdr);
2232 encode_restorefh(xdr, &hdr);
2233 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002234 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235}
2236
2237/*
2238 * Encode LINK request
2239 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002240static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2241 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002244 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246
Chuck Lever9f06c712010-12-14 14:59:18 +00002247 encode_compound_hdr(xdr, req, &hdr);
2248 encode_sequence(xdr, &args->seq_args, &hdr);
2249 encode_putfh(xdr, args->fh, &hdr);
2250 encode_savefh(xdr, &hdr);
2251 encode_putfh(xdr, args->dir_fh, &hdr);
2252 encode_link(xdr, args->name, &hdr);
2253 encode_getfattr(xdr, args->bitmask, &hdr);
2254 encode_restorefh(xdr, &hdr);
2255 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002256 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257}
2258
2259/*
2260 * Encode CREATE request
2261 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002262static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2263 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002266 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
Chuck Lever9f06c712010-12-14 14:59:18 +00002269 encode_compound_hdr(xdr, req, &hdr);
2270 encode_sequence(xdr, &args->seq_args, &hdr);
2271 encode_putfh(xdr, args->dir_fh, &hdr);
2272 encode_savefh(xdr, &hdr);
2273 encode_create(xdr, args, &hdr);
2274 encode_getfh(xdr, &hdr);
2275 encode_getfattr(xdr, args->bitmask, &hdr);
2276 encode_restorefh(xdr, &hdr);
2277 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002278 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279}
2280
2281/*
2282 * Encode SYMLINK request
2283 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002284static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2285 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286{
Chuck Lever9f06c712010-12-14 14:59:18 +00002287 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288}
2289
2290/*
2291 * Encode GETATTR request
2292 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002293static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2294 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002297 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299
Chuck Lever9f06c712010-12-14 14:59:18 +00002300 encode_compound_hdr(xdr, req, &hdr);
2301 encode_sequence(xdr, &args->seq_args, &hdr);
2302 encode_putfh(xdr, args->fh, &hdr);
2303 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002304 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305}
2306
2307/*
2308 * Encode a CLOSE request
2309 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002310static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2311 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312{
Andy Adamson05d564f2008-12-23 16:06:15 -05002313 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002314 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002315 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316
Chuck Lever9f06c712010-12-14 14:59:18 +00002317 encode_compound_hdr(xdr, req, &hdr);
2318 encode_sequence(xdr, &args->seq_args, &hdr);
2319 encode_putfh(xdr, args->fh, &hdr);
2320 encode_close(xdr, args, &hdr);
2321 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002322 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323}
2324
2325/*
2326 * Encode an OPEN request
2327 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002328static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2329 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002332 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334
Chuck Lever9f06c712010-12-14 14:59:18 +00002335 encode_compound_hdr(xdr, req, &hdr);
2336 encode_sequence(xdr, &args->seq_args, &hdr);
2337 encode_putfh(xdr, args->fh, &hdr);
2338 encode_savefh(xdr, &hdr);
2339 encode_open(xdr, args, &hdr);
2340 encode_getfh(xdr, &hdr);
2341 encode_getfattr(xdr, args->bitmask, &hdr);
2342 encode_restorefh(xdr, &hdr);
Trond Myklebust6926afd2012-01-07 13:22:46 -05002343 encode_getfattr(xdr, args->dir_bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002344 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345}
2346
2347/*
2348 * Encode an OPEN_CONFIRM request
2349 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002350static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2351 struct xdr_stream *xdr,
2352 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002355 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
Chuck Lever9f06c712010-12-14 14:59:18 +00002358 encode_compound_hdr(xdr, req, &hdr);
2359 encode_putfh(xdr, args->fh, &hdr);
2360 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002361 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362}
2363
2364/*
2365 * Encode an OPEN request with no attributes.
2366 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002367static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2368 struct xdr_stream *xdr,
2369 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002372 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374
Chuck Lever9f06c712010-12-14 14:59:18 +00002375 encode_compound_hdr(xdr, req, &hdr);
2376 encode_sequence(xdr, &args->seq_args, &hdr);
2377 encode_putfh(xdr, args->fh, &hdr);
2378 encode_open(xdr, args, &hdr);
2379 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002380 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381}
2382
2383/*
2384 * Encode an OPEN_DOWNGRADE request
2385 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002386static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2387 struct xdr_stream *xdr,
2388 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002391 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393
Chuck Lever9f06c712010-12-14 14:59:18 +00002394 encode_compound_hdr(xdr, req, &hdr);
2395 encode_sequence(xdr, &args->seq_args, &hdr);
2396 encode_putfh(xdr, args->fh, &hdr);
2397 encode_open_downgrade(xdr, args, &hdr);
2398 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002399 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400}
2401
2402/*
2403 * Encode a LOCK request
2404 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002405static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2406 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002409 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411
Chuck Lever9f06c712010-12-14 14:59:18 +00002412 encode_compound_hdr(xdr, req, &hdr);
2413 encode_sequence(xdr, &args->seq_args, &hdr);
2414 encode_putfh(xdr, args->fh, &hdr);
2415 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002416 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417}
2418
2419/*
2420 * Encode a LOCKT request
2421 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002422static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2423 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002426 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
Chuck Lever9f06c712010-12-14 14:59:18 +00002429 encode_compound_hdr(xdr, req, &hdr);
2430 encode_sequence(xdr, &args->seq_args, &hdr);
2431 encode_putfh(xdr, args->fh, &hdr);
2432 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002433 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434}
2435
2436/*
2437 * Encode a LOCKU request
2438 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002439static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2440 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002443 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
Chuck Lever9f06c712010-12-14 14:59:18 +00002446 encode_compound_hdr(xdr, req, &hdr);
2447 encode_sequence(xdr, &args->seq_args, &hdr);
2448 encode_putfh(xdr, args->fh, &hdr);
2449 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002450 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451}
2452
Chuck Lever9f06c712010-12-14 14:59:18 +00002453static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2454 struct xdr_stream *xdr,
2455 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002456{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002457 struct compound_hdr hdr = {
2458 .minorversion = 0,
2459 };
2460
Chuck Lever9f06c712010-12-14 14:59:18 +00002461 encode_compound_hdr(xdr, req, &hdr);
2462 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002463 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002464}
2465
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466/*
2467 * Encode a READLINK request
2468 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002469static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2470 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002473 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
Chuck Lever9f06c712010-12-14 14:59:18 +00002476 encode_compound_hdr(xdr, req, &hdr);
2477 encode_sequence(xdr, &args->seq_args, &hdr);
2478 encode_putfh(xdr, args->fh, &hdr);
2479 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002480
Benny Halevy28f56692009-04-01 09:22:09 -04002481 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002482 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002483 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484}
2485
2486/*
2487 * Encode a READDIR request
2488 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002489static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2490 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002493 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495
Chuck Lever9f06c712010-12-14 14:59:18 +00002496 encode_compound_hdr(xdr, req, &hdr);
2497 encode_sequence(xdr, &args->seq_args, &hdr);
2498 encode_putfh(xdr, args->fh, &hdr);
2499 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002500
Benny Halevy28f56692009-04-01 09:22:09 -04002501 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002502 args->pgbase, args->count);
2503 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002504 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002505 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002506 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507}
2508
2509/*
2510 * Encode a READ request
2511 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002512static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2513 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002516 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
Chuck Lever9f06c712010-12-14 14:59:18 +00002519 encode_compound_hdr(xdr, req, &hdr);
2520 encode_sequence(xdr, &args->seq_args, &hdr);
2521 encode_putfh(xdr, args->fh, &hdr);
2522 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523
Benny Halevy28f56692009-04-01 09:22:09 -04002524 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002526 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002527 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528}
2529
2530/*
2531 * Encode an SETATTR request
2532 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002533static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2534 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535{
Andy Adamson05d564f2008-12-23 16:06:15 -05002536 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002537 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002538 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539
Chuck Lever9f06c712010-12-14 14:59:18 +00002540 encode_compound_hdr(xdr, req, &hdr);
2541 encode_sequence(xdr, &args->seq_args, &hdr);
2542 encode_putfh(xdr, args->fh, &hdr);
2543 encode_setattr(xdr, args, args->server, &hdr);
2544 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002545 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546}
2547
2548/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002549 * Encode a GETACL request
2550 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002551static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2552 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002553{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002554 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002555 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002556 };
Benny Halevy28f56692009-04-01 09:22:09 -04002557 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002558
Chuck Lever9f06c712010-12-14 14:59:18 +00002559 encode_compound_hdr(xdr, req, &hdr);
2560 encode_sequence(xdr, &args->seq_args, &hdr);
2561 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002562 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002563 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002564
Benny Halevy28f56692009-04-01 09:22:09 -04002565 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002566 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002567 xdr_set_scratch_buffer(xdr, page_address(args->acl_scratch), PAGE_SIZE);
2568
Andy Adamsond0179312008-12-23 16:06:17 -05002569 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002570}
2571
2572/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 * Encode a WRITE request
2574 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002575static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2576 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002579 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581
Chuck Lever9f06c712010-12-14 14:59:18 +00002582 encode_compound_hdr(xdr, req, &hdr);
2583 encode_sequence(xdr, &args->seq_args, &hdr);
2584 encode_putfh(xdr, args->fh, &hdr);
2585 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002586 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002587 if (args->bitmask)
2588 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002589 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590}
2591
2592/*
2593 * a COMMIT request
2594 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002595static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2596 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002599 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601
Chuck Lever9f06c712010-12-14 14:59:18 +00002602 encode_compound_hdr(xdr, req, &hdr);
2603 encode_sequence(xdr, &args->seq_args, &hdr);
2604 encode_putfh(xdr, args->fh, &hdr);
2605 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002606 if (args->bitmask)
2607 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002608 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609}
2610
2611/*
2612 * FSINFO request
2613 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002614static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2615 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002618 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620
Chuck Lever9f06c712010-12-14 14:59:18 +00002621 encode_compound_hdr(xdr, req, &hdr);
2622 encode_sequence(xdr, &args->seq_args, &hdr);
2623 encode_putfh(xdr, args->fh, &hdr);
2624 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002625 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626}
2627
2628/*
2629 * a PATHCONF request
2630 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002631static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2632 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002635 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637
Chuck Lever9f06c712010-12-14 14:59:18 +00002638 encode_compound_hdr(xdr, req, &hdr);
2639 encode_sequence(xdr, &args->seq_args, &hdr);
2640 encode_putfh(xdr, args->fh, &hdr);
2641 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002642 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002643 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644}
2645
2646/*
2647 * a STATFS request
2648 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002649static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2650 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002653 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
Chuck Lever9f06c712010-12-14 14:59:18 +00002656 encode_compound_hdr(xdr, req, &hdr);
2657 encode_sequence(xdr, &args->seq_args, &hdr);
2658 encode_putfh(xdr, args->fh, &hdr);
2659 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002660 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002661 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662}
2663
2664/*
2665 * GETATTR_BITMAP request
2666 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002667static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2668 struct xdr_stream *xdr,
2669 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002672 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674
Chuck Lever9f06c712010-12-14 14:59:18 +00002675 encode_compound_hdr(xdr, req, &hdr);
2676 encode_sequence(xdr, &args->seq_args, &hdr);
2677 encode_putfh(xdr, args->fhandle, &hdr);
2678 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002679 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002680 FATTR4_WORD0_LINK_SUPPORT|
2681 FATTR4_WORD0_SYMLINK_SUPPORT|
2682 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002683 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684}
2685
2686/*
2687 * a RENEW request
2688 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002689static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2690 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002693 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 };
2695
Chuck Lever9f06c712010-12-14 14:59:18 +00002696 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002697 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002698 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699}
2700
2701/*
2702 * a SETCLIENTID request
2703 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002704static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2705 struct xdr_stream *xdr,
2706 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002709 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 };
2711
Chuck Lever9f06c712010-12-14 14:59:18 +00002712 encode_compound_hdr(xdr, req, &hdr);
2713 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002714 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715}
2716
2717/*
2718 * a SETCLIENTID_CONFIRM request
2719 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002720static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2721 struct xdr_stream *xdr,
2722 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002725 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 };
Fred Isamandae100c2011-07-30 20:52:37 -04002727 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
Chuck Lever9f06c712010-12-14 14:59:18 +00002729 encode_compound_hdr(xdr, req, &hdr);
2730 encode_setclientid_confirm(xdr, arg, &hdr);
2731 encode_putrootfh(xdr, &hdr);
2732 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002733 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734}
2735
2736/*
2737 * DELEGRETURN request
2738 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002739static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2740 struct xdr_stream *xdr,
2741 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002744 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746
Chuck Lever9f06c712010-12-14 14:59:18 +00002747 encode_compound_hdr(xdr, req, &hdr);
2748 encode_sequence(xdr, &args->seq_args, &hdr);
2749 encode_putfh(xdr, args->fhandle, &hdr);
2750 encode_delegreturn(xdr, args->stateid, &hdr);
2751 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002752 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753}
2754
2755/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002756 * Encode FS_LOCATIONS request
2757 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002758static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2759 struct xdr_stream *xdr,
2760 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002761{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002762 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002763 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002764 };
Benny Halevy28f56692009-04-01 09:22:09 -04002765 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002766
Chuck Lever9f06c712010-12-14 14:59:18 +00002767 encode_compound_hdr(xdr, req, &hdr);
2768 encode_sequence(xdr, &args->seq_args, &hdr);
2769 encode_putfh(xdr, args->dir_fh, &hdr);
2770 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002771 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002772 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002773
Benny Halevy28f56692009-04-01 09:22:09 -04002774 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002775 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002776 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002777}
2778
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002779/*
2780 * Encode SECINFO request
2781 */
2782static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2783 struct xdr_stream *xdr,
2784 struct nfs4_secinfo_arg *args)
2785{
2786 struct compound_hdr hdr = {
2787 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2788 };
2789
2790 encode_compound_hdr(xdr, req, &hdr);
2791 encode_sequence(xdr, &args->seq_args, &hdr);
2792 encode_putfh(xdr, args->dir_fh, &hdr);
2793 encode_secinfo(xdr, args->name, &hdr);
2794 encode_nops(&hdr);
2795}
2796
Benny Halevy99fe60d2009-04-01 09:22:29 -04002797#if defined(CONFIG_NFS_V4_1)
2798/*
2799 * EXCHANGE_ID request
2800 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002801static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2802 struct xdr_stream *xdr,
2803 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002804{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002805 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002806 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002807 };
2808
Chuck Lever9f06c712010-12-14 14:59:18 +00002809 encode_compound_hdr(xdr, req, &hdr);
2810 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002811 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002812}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002813
2814/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002815 * a CREATE_SESSION request
2816 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002817static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2818 struct xdr_stream *xdr,
2819 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002820{
Andy Adamsonfc931582009-04-01 09:22:31 -04002821 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002822 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002823 };
2824
Chuck Lever9f06c712010-12-14 14:59:18 +00002825 encode_compound_hdr(xdr, req, &hdr);
2826 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002827 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002828}
2829
2830/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002831 * a DESTROY_SESSION request
2832 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002833static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2834 struct xdr_stream *xdr,
2835 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002836{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002837 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002838 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002839 };
2840
Chuck Lever9f06c712010-12-14 14:59:18 +00002841 encode_compound_hdr(xdr, req, &hdr);
2842 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002843 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002844}
2845
2846/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002847 * a SEQUENCE request
2848 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002849static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2850 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002851{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002852 struct compound_hdr hdr = {
2853 .minorversion = nfs4_xdr_minorversion(args),
2854 };
2855
Chuck Lever9f06c712010-12-14 14:59:18 +00002856 encode_compound_hdr(xdr, req, &hdr);
2857 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002858 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002859}
2860
2861/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002862 * a GET_LEASE_TIME request
2863 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002864static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2865 struct xdr_stream *xdr,
2866 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002867{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002868 struct compound_hdr hdr = {
2869 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2870 };
Fred Isamandae100c2011-07-30 20:52:37 -04002871 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002872
Chuck Lever9f06c712010-12-14 14:59:18 +00002873 encode_compound_hdr(xdr, req, &hdr);
2874 encode_sequence(xdr, &args->la_seq_args, &hdr);
2875 encode_putrootfh(xdr, &hdr);
2876 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002877 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002878}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002879
2880/*
2881 * a RECLAIM_COMPLETE request
2882 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002883static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2884 struct xdr_stream *xdr,
2885 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002886{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002887 struct compound_hdr hdr = {
2888 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2889 };
2890
Chuck Lever9f06c712010-12-14 14:59:18 +00002891 encode_compound_hdr(xdr, req, &hdr);
2892 encode_sequence(xdr, &args->seq_args, &hdr);
2893 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002894 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002895}
2896
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002897/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002898 * Encode GETDEVICELIST request
2899 */
2900static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2901 struct xdr_stream *xdr,
2902 struct nfs4_getdevicelist_args *args)
2903{
2904 struct compound_hdr hdr = {
2905 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2906 };
2907
2908 encode_compound_hdr(xdr, req, &hdr);
2909 encode_sequence(xdr, &args->seq_args, &hdr);
2910 encode_putfh(xdr, args->fh, &hdr);
2911 encode_getdevicelist(xdr, args, &hdr);
2912 encode_nops(&hdr);
2913}
2914
2915/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002916 * Encode GETDEVICEINFO request
2917 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002918static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2919 struct xdr_stream *xdr,
2920 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002921{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002922 struct compound_hdr hdr = {
2923 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2924 };
2925
Chuck Lever9f06c712010-12-14 14:59:18 +00002926 encode_compound_hdr(xdr, req, &hdr);
2927 encode_sequence(xdr, &args->seq_args, &hdr);
2928 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002929
2930 /* set up reply kvec. Subtract notification bitmap max size (2)
2931 * so that notification bitmap is put in xdr_buf tail */
2932 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2933 args->pdev->pages, args->pdev->pgbase,
2934 args->pdev->pglen);
2935
2936 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002937}
2938
2939/*
2940 * Encode LAYOUTGET request
2941 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002942static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2943 struct xdr_stream *xdr,
2944 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002945{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002946 struct compound_hdr hdr = {
2947 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2948 };
2949
Chuck Lever9f06c712010-12-14 14:59:18 +00002950 encode_compound_hdr(xdr, req, &hdr);
2951 encode_sequence(xdr, &args->seq_args, &hdr);
2952 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2953 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002954
2955 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2956 args->layout.pages, 0, args->layout.pglen);
2957
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002958 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002959}
Andy Adamson863a3c62011-03-23 13:27:54 +00002960
2961/*
2962 * Encode LAYOUTCOMMIT request
2963 */
Benny Halevycbe82602011-05-22 19:52:37 +03002964static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2965 struct xdr_stream *xdr,
2966 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002967{
Benny Halevyac7db722011-05-22 19:53:48 +03002968 struct nfs4_layoutcommit_data *data =
2969 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002970 struct compound_hdr hdr = {
2971 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2972 };
2973
2974 encode_compound_hdr(xdr, req, &hdr);
2975 encode_sequence(xdr, &args->seq_args, &hdr);
2976 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002977 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002978 encode_getfattr(xdr, args->bitmask, &hdr);
2979 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002980}
2981
2982/*
2983 * Encode LAYOUTRETURN request
2984 */
2985static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2986 struct xdr_stream *xdr,
2987 struct nfs4_layoutreturn_args *args)
2988{
2989 struct compound_hdr hdr = {
2990 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2991 };
2992
2993 encode_compound_hdr(xdr, req, &hdr);
2994 encode_sequence(xdr, &args->seq_args, &hdr);
2995 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2996 encode_layoutreturn(xdr, args, &hdr);
2997 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002998}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002999
3000/*
3001 * Encode SECINFO_NO_NAME request
3002 */
3003static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3004 struct xdr_stream *xdr,
3005 struct nfs41_secinfo_no_name_args *args)
3006{
3007 struct compound_hdr hdr = {
3008 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3009 };
3010
3011 encode_compound_hdr(xdr, req, &hdr);
3012 encode_sequence(xdr, &args->seq_args, &hdr);
3013 encode_putrootfh(xdr, &hdr);
3014 encode_secinfo_no_name(xdr, args, &hdr);
3015 encode_nops(&hdr);
3016 return 0;
3017}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003018
3019/*
3020 * Encode TEST_STATEID request
3021 */
3022static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3023 struct xdr_stream *xdr,
3024 struct nfs41_test_stateid_args *args)
3025{
3026 struct compound_hdr hdr = {
3027 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3028 };
3029
3030 encode_compound_hdr(xdr, req, &hdr);
3031 encode_sequence(xdr, &args->seq_args, &hdr);
3032 encode_test_stateid(xdr, args, &hdr);
3033 encode_nops(&hdr);
3034}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003035
3036/*
3037 * Encode FREE_STATEID request
3038 */
3039static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3040 struct xdr_stream *xdr,
3041 struct nfs41_free_stateid_args *args)
3042{
3043 struct compound_hdr hdr = {
3044 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3045 };
3046
3047 encode_compound_hdr(xdr, req, &hdr);
3048 encode_sequence(xdr, &args->seq_args, &hdr);
3049 encode_free_stateid(xdr, args, &hdr);
3050 encode_nops(&hdr);
3051}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003052#endif /* CONFIG_NFS_V4_1 */
3053
Benny Halevy686841b2009-08-14 17:19:48 +03003054static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3055{
3056 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3057 "Remaining buffer length is %tu words.\n",
3058 func, xdr->end - xdr->p);
3059}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060
Trond Myklebust683b57b2006-06-09 09:34:22 -04003061static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062{
Al Viro8687b632006-10-19 23:28:48 -07003063 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064
Benny Halevyc0eae662009-08-14 17:20:14 +03003065 p = xdr_inline_decode(xdr, 4);
3066 if (unlikely(!p))
3067 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003068 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003069 p = xdr_inline_decode(xdr, *len);
3070 if (unlikely(!p))
3071 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 *string = (char *)p;
3073 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003074out_overflow:
3075 print_overflow_msg(__func__, xdr);
3076 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077}
3078
3079static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3080{
Al Viro8687b632006-10-19 23:28:48 -07003081 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082
Benny Halevyc0eae662009-08-14 17:20:14 +03003083 p = xdr_inline_decode(xdr, 8);
3084 if (unlikely(!p))
3085 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003086 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003087 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003088
Benny Halevyc0eae662009-08-14 17:20:14 +03003089 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3090 if (unlikely(!p))
3091 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 hdr->tag = (char *)p;
3093 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003094 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003095 if (unlikely(hdr->nops < 1))
3096 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003098out_overflow:
3099 print_overflow_msg(__func__, xdr);
3100 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101}
3102
3103static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3104{
Al Viro8687b632006-10-19 23:28:48 -07003105 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 uint32_t opnum;
3107 int32_t nfserr;
3108
Benny Halevyc0eae662009-08-14 17:20:14 +03003109 p = xdr_inline_decode(xdr, 8);
3110 if (unlikely(!p))
3111 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003112 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003114 dprintk("nfs: Server returned operation"
3115 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 opnum, expected);
3117 return -EIO;
3118 }
Benny Halevycccddf42009-08-14 17:20:19 +03003119 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003121 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003123out_overflow:
3124 print_overflow_msg(__func__, xdr);
3125 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126}
3127
3128/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003129static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130{
Al Viro8687b632006-10-19 23:28:48 -07003131 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003132 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 char *str;
3134
Benny Halevyc0eae662009-08-14 17:20:14 +03003135 p = xdr_inline_decode(xdr, 12);
3136 if (likely(p))
3137 return decode_opaque_inline(xdr, &strlen, &str);
3138 print_overflow_msg(__func__, xdr);
3139 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140}
3141
3142static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3143{
Al Viro8687b632006-10-19 23:28:48 -07003144 uint32_t bmlen;
3145 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146
Benny Halevyc0eae662009-08-14 17:20:14 +03003147 p = xdr_inline_decode(xdr, 4);
3148 if (unlikely(!p))
3149 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003150 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151
Fred Isamandae100c2011-07-30 20:52:37 -04003152 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003153 p = xdr_inline_decode(xdr, (bmlen << 2));
3154 if (unlikely(!p))
3155 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003157 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003158 if (bmlen > 1) {
3159 bitmap[1] = be32_to_cpup(p++);
3160 if (bmlen > 2)
3161 bitmap[2] = be32_to_cpup(p);
3162 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 }
3164 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003165out_overflow:
3166 print_overflow_msg(__func__, xdr);
3167 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168}
3169
Al Viro8687b632006-10-19 23:28:48 -07003170static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171{
Al Viro8687b632006-10-19 23:28:48 -07003172 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173
Benny Halevyc0eae662009-08-14 17:20:14 +03003174 p = xdr_inline_decode(xdr, 4);
3175 if (unlikely(!p))
3176 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003177 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 *savep = xdr->p;
3179 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003180out_overflow:
3181 print_overflow_msg(__func__, xdr);
3182 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183}
3184
3185static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3186{
3187 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003188 int ret;
3189 ret = decode_attr_bitmap(xdr, bitmask);
3190 if (unlikely(ret < 0))
3191 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3193 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003194 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3195 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3196 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 return 0;
3198}
3199
3200static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3201{
Al Viro8687b632006-10-19 23:28:48 -07003202 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003203 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204
3205 *type = 0;
3206 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3207 return -EIO;
3208 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003209 p = xdr_inline_decode(xdr, 4);
3210 if (unlikely(!p))
3211 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003212 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003214 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 return -EIO;
3216 }
3217 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003218 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003220 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003221 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003222out_overflow:
3223 print_overflow_msg(__func__, xdr);
3224 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225}
3226
Chuck Lever264e6352012-03-01 17:02:05 -05003227static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3228 uint32_t *bitmap, uint32_t *type)
3229{
3230 __be32 *p;
3231
3232 *type = 0;
3233 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3234 return -EIO;
3235 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3236 p = xdr_inline_decode(xdr, 4);
3237 if (unlikely(!p))
3238 goto out_overflow;
3239 *type = be32_to_cpup(p);
3240 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3241 }
3242 dprintk("%s: expire type=0x%x\n", __func__, *type);
3243 return 0;
3244out_overflow:
3245 print_overflow_msg(__func__, xdr);
3246 return -EIO;
3247}
3248
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3250{
Al Viro8687b632006-10-19 23:28:48 -07003251 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003252 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253
3254 *change = 0;
3255 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3256 return -EIO;
3257 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003258 p = xdr_inline_decode(xdr, 8);
3259 if (unlikely(!p))
3260 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003261 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003263 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003265 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003267 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003268out_overflow:
3269 print_overflow_msg(__func__, xdr);
3270 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271}
3272
3273static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3274{
Al Viro8687b632006-10-19 23:28:48 -07003275 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003276 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277
3278 *size = 0;
3279 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3280 return -EIO;
3281 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003282 p = xdr_inline_decode(xdr, 8);
3283 if (unlikely(!p))
3284 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003285 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003287 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003289 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003290 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003291out_overflow:
3292 print_overflow_msg(__func__, xdr);
3293 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294}
3295
3296static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3297{
Al Viro8687b632006-10-19 23:28:48 -07003298 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299
3300 *res = 0;
3301 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3302 return -EIO;
3303 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003304 p = xdr_inline_decode(xdr, 4);
3305 if (unlikely(!p))
3306 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003307 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3309 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003310 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003312out_overflow:
3313 print_overflow_msg(__func__, xdr);
3314 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315}
3316
3317static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3318{
Al Viro8687b632006-10-19 23:28:48 -07003319 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320
3321 *res = 0;
3322 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3323 return -EIO;
3324 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003325 p = xdr_inline_decode(xdr, 4);
3326 if (unlikely(!p))
3327 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003328 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3330 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003331 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003333out_overflow:
3334 print_overflow_msg(__func__, xdr);
3335 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336}
3337
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003338static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339{
Al Viro8687b632006-10-19 23:28:48 -07003340 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003341 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342
3343 fsid->major = 0;
3344 fsid->minor = 0;
3345 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3346 return -EIO;
3347 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003348 p = xdr_inline_decode(xdr, 16);
3349 if (unlikely(!p))
3350 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003351 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003352 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003354 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003356 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 (unsigned long long)fsid->major,
3358 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003359 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003360out_overflow:
3361 print_overflow_msg(__func__, xdr);
3362 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363}
3364
3365static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3366{
Al Viro8687b632006-10-19 23:28:48 -07003367 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368
3369 *res = 60;
3370 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3371 return -EIO;
3372 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003373 p = xdr_inline_decode(xdr, 4);
3374 if (unlikely(!p))
3375 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003376 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3378 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003379 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003381out_overflow:
3382 print_overflow_msg(__func__, xdr);
3383 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384}
3385
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003386static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003387{
3388 __be32 *p;
3389
3390 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3391 return -EIO;
3392 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3393 p = xdr_inline_decode(xdr, 4);
3394 if (unlikely(!p))
3395 goto out_overflow;
3396 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003397 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003398 }
3399 return 0;
3400out_overflow:
3401 print_overflow_msg(__func__, xdr);
3402 return -EIO;
3403}
3404
3405static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3406{
3407 __be32 *p;
3408 int len;
3409
Trond Myklebust7ad07352010-10-23 15:34:20 -04003410 if (fh != NULL)
3411 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003412
3413 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3414 return -EIO;
3415 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3416 p = xdr_inline_decode(xdr, 4);
3417 if (unlikely(!p))
3418 goto out_overflow;
3419 len = be32_to_cpup(p);
3420 if (len > NFS4_FHSIZE)
3421 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003422 p = xdr_inline_decode(xdr, len);
3423 if (unlikely(!p))
3424 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003425 if (fh != NULL) {
3426 memcpy(fh->data, p, len);
3427 fh->size = len;
3428 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003429 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3430 }
3431 return 0;
3432out_overflow:
3433 print_overflow_msg(__func__, xdr);
3434 return -EIO;
3435}
3436
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3438{
Al Viro8687b632006-10-19 23:28:48 -07003439 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440
3441 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3442 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3443 return -EIO;
3444 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003445 p = xdr_inline_decode(xdr, 4);
3446 if (unlikely(!p))
3447 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003448 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3450 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003451 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003453out_overflow:
3454 print_overflow_msg(__func__, xdr);
3455 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456}
3457
3458static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3459{
Al Viro8687b632006-10-19 23:28:48 -07003460 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003461 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462
3463 *fileid = 0;
3464 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3465 return -EIO;
3466 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003467 p = xdr_inline_decode(xdr, 8);
3468 if (unlikely(!p))
3469 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003470 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003472 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003474 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003475 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003476out_overflow:
3477 print_overflow_msg(__func__, xdr);
3478 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479}
3480
Manoj Naik99baf622006-06-09 09:34:24 -04003481static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3482{
Al Viro8687b632006-10-19 23:28:48 -07003483 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003484 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003485
3486 *fileid = 0;
3487 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3488 return -EIO;
3489 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003490 p = xdr_inline_decode(xdr, 8);
3491 if (unlikely(!p))
3492 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003493 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003494 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003495 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003496 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003497 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003498 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003499out_overflow:
3500 print_overflow_msg(__func__, xdr);
3501 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003502}
3503
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3505{
Al Viro8687b632006-10-19 23:28:48 -07003506 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 int status = 0;
3508
3509 *res = 0;
3510 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3511 return -EIO;
3512 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003513 p = xdr_inline_decode(xdr, 8);
3514 if (unlikely(!p))
3515 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003516 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3518 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003519 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003521out_overflow:
3522 print_overflow_msg(__func__, xdr);
3523 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524}
3525
3526static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3527{
Al Viro8687b632006-10-19 23:28:48 -07003528 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 int status = 0;
3530
3531 *res = 0;
3532 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3533 return -EIO;
3534 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003535 p = xdr_inline_decode(xdr, 8);
3536 if (unlikely(!p))
3537 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003538 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3540 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003541 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003543out_overflow:
3544 print_overflow_msg(__func__, xdr);
3545 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546}
3547
3548static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3549{
Al Viro8687b632006-10-19 23:28:48 -07003550 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 int status = 0;
3552
3553 *res = 0;
3554 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3555 return -EIO;
3556 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003557 p = xdr_inline_decode(xdr, 8);
3558 if (unlikely(!p))
3559 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003560 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3562 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003563 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003565out_overflow:
3566 print_overflow_msg(__func__, xdr);
3567 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568}
3569
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003570static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3571{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003572 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003573 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003574 int status = 0;
3575
Benny Halevyc0eae662009-08-14 17:20:14 +03003576 p = xdr_inline_decode(xdr, 4);
3577 if (unlikely(!p))
3578 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003579 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003580 if (n == 0)
3581 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003582 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003583 path->ncomponents = 0;
3584 while (path->ncomponents < n) {
3585 struct nfs4_string *component = &path->components[path->ncomponents];
3586 status = decode_opaque_inline(xdr, &component->len, &component->data);
3587 if (unlikely(status != 0))
3588 goto out_eio;
Chuck Lever02a29762012-03-01 17:00:31 -05003589 if (unlikely(nfs_debug & NFSDBG_XDR))
3590 pr_cont("%s%.*s ",
3591 (path->ncomponents != n ? "/ " : ""),
3592 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003593 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3594 path->ncomponents++;
3595 else {
3596 dprintk("cannot parse %d components in path\n", n);
3597 goto out_eio;
3598 }
3599 }
3600out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003601 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003602root_path:
3603/* a root pathname is sent as a zero component4 */
3604 path->ncomponents = 1;
3605 path->components[0].len=0;
3606 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003607 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003608 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003609out_eio:
3610 dprintk(" status %d", status);
3611 status = -EIO;
3612 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003613out_overflow:
3614 print_overflow_msg(__func__, xdr);
3615 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003616}
3617
3618static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003619{
3620 int n;
Al Viro8687b632006-10-19 23:28:48 -07003621 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003622 int status = -EIO;
3623
3624 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3625 goto out;
3626 status = 0;
3627 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3628 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003629 status = -EIO;
3630 /* Ignore borken servers that return unrequested attrs */
3631 if (unlikely(res == NULL))
3632 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003633 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003634 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003635 if (unlikely(status != 0))
3636 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003637 p = xdr_inline_decode(xdr, 4);
3638 if (unlikely(!p))
3639 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003640 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003641 if (n <= 0)
3642 goto out_eio;
3643 res->nlocations = 0;
3644 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003645 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003646 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003647
Benny Halevyc0eae662009-08-14 17:20:14 +03003648 p = xdr_inline_decode(xdr, 4);
3649 if (unlikely(!p))
3650 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003651 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003652
3653 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003654 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003655 while (loc->nservers < m) {
3656 struct nfs4_string *server = &loc->servers[loc->nservers];
3657 status = decode_opaque_inline(xdr, &server->len, &server->data);
3658 if (unlikely(status != 0))
3659 goto out_eio;
3660 dprintk("%s ", server->data);
3661 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3662 loc->nservers++;
3663 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003664 unsigned int i;
3665 dprintk("%s: using first %u of %u servers "
3666 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003667 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003668 NFS4_FS_LOCATION_MAXSERVERS,
3669 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003670 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003671 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003672 char *data;
3673 status = decode_opaque_inline(xdr, &len, &data);
3674 if (unlikely(status != 0))
3675 goto out_eio;
3676 }
3677 }
3678 }
3679 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003680 if (unlikely(status != 0))
3681 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003682 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003683 res->nlocations++;
3684 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003685 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003686 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003687out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003688 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003689 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003690out_overflow:
3691 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003692out_eio:
3693 status = -EIO;
3694 goto out;
3695}
3696
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3698{
Al Viro8687b632006-10-19 23:28:48 -07003699 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 int status = 0;
3701
3702 *res = 0;
3703 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3704 return -EIO;
3705 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003706 p = xdr_inline_decode(xdr, 8);
3707 if (unlikely(!p))
3708 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003709 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3711 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003712 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003714out_overflow:
3715 print_overflow_msg(__func__, xdr);
3716 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717}
3718
3719static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3720{
Al Viro8687b632006-10-19 23:28:48 -07003721 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 int status = 0;
3723
3724 *maxlink = 1;
3725 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3726 return -EIO;
3727 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003728 p = xdr_inline_decode(xdr, 4);
3729 if (unlikely(!p))
3730 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003731 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3733 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003734 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003736out_overflow:
3737 print_overflow_msg(__func__, xdr);
3738 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739}
3740
3741static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3742{
Al Viro8687b632006-10-19 23:28:48 -07003743 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 int status = 0;
3745
3746 *maxname = 1024;
3747 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3748 return -EIO;
3749 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003750 p = xdr_inline_decode(xdr, 4);
3751 if (unlikely(!p))
3752 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003753 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3755 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003756 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003758out_overflow:
3759 print_overflow_msg(__func__, xdr);
3760 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761}
3762
3763static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3764{
Al Viro8687b632006-10-19 23:28:48 -07003765 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 int status = 0;
3767
3768 *res = 1024;
3769 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3770 return -EIO;
3771 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3772 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003773 p = xdr_inline_decode(xdr, 8);
3774 if (unlikely(!p))
3775 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003776 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 if (maxread > 0x7FFFFFFF)
3778 maxread = 0x7FFFFFFF;
3779 *res = (uint32_t)maxread;
3780 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3781 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003782 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003784out_overflow:
3785 print_overflow_msg(__func__, xdr);
3786 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787}
3788
3789static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3790{
Al Viro8687b632006-10-19 23:28:48 -07003791 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 int status = 0;
3793
3794 *res = 1024;
3795 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3796 return -EIO;
3797 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3798 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003799 p = xdr_inline_decode(xdr, 8);
3800 if (unlikely(!p))
3801 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003802 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 if (maxwrite > 0x7FFFFFFF)
3804 maxwrite = 0x7FFFFFFF;
3805 *res = (uint32_t)maxwrite;
3806 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3807 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003808 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003810out_overflow:
3811 print_overflow_msg(__func__, xdr);
3812 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813}
3814
Trond Myklebustbca79472009-03-11 14:10:26 -04003815static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816{
Trond Myklebustbca79472009-03-11 14:10:26 -04003817 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003818 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003819 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820
3821 *mode = 0;
3822 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3823 return -EIO;
3824 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003825 p = xdr_inline_decode(xdr, 4);
3826 if (unlikely(!p))
3827 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003828 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003829 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003831 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003833 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003834 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003835out_overflow:
3836 print_overflow_msg(__func__, xdr);
3837 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838}
3839
3840static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3841{
Al Viro8687b632006-10-19 23:28:48 -07003842 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003843 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844
3845 *nlink = 1;
3846 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3847 return -EIO;
3848 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003849 p = xdr_inline_decode(xdr, 4);
3850 if (unlikely(!p))
3851 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003852 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003854 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003856 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003857 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003858out_overflow:
3859 print_overflow_msg(__func__, xdr);
3860 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861}
3862
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003863static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003864 const struct nfs_server *server, uint32_t *uid,
3865 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866{
Al Viro8687b632006-10-19 23:28:48 -07003867 uint32_t len;
3868 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003869 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870
3871 *uid = -2;
3872 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3873 return -EIO;
3874 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003875 p = xdr_inline_decode(xdr, 4);
3876 if (unlikely(!p))
3877 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003878 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003879 p = xdr_inline_decode(xdr, len);
3880 if (unlikely(!p))
3881 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003882 if (owner_name != NULL) {
3883 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3884 if (owner_name->data != NULL) {
3885 owner_name->len = len;
3886 ret = NFS_ATTR_FATTR_OWNER_NAME;
3887 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003888 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003889 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003890 ret = NFS_ATTR_FATTR_OWNER;
3891 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003893 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003895 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003896 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3898 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003899 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003900 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003901out_overflow:
3902 print_overflow_msg(__func__, xdr);
3903 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904}
3905
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003906static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003907 const struct nfs_server *server, uint32_t *gid,
3908 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909{
Al Viro8687b632006-10-19 23:28:48 -07003910 uint32_t len;
3911 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003912 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913
3914 *gid = -2;
3915 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3916 return -EIO;
3917 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003918 p = xdr_inline_decode(xdr, 4);
3919 if (unlikely(!p))
3920 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003921 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003922 p = xdr_inline_decode(xdr, len);
3923 if (unlikely(!p))
3924 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003925 if (group_name != NULL) {
3926 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3927 if (group_name->data != NULL) {
3928 group_name->len = len;
3929 ret = NFS_ATTR_FATTR_GROUP_NAME;
3930 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003931 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003932 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003933 ret = NFS_ATTR_FATTR_GROUP;
3934 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003936 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003938 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003939 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3941 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003942 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003943 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003944out_overflow:
3945 print_overflow_msg(__func__, xdr);
3946 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947}
3948
3949static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3950{
Al Viro8687b632006-10-19 23:28:48 -07003951 uint32_t major = 0, minor = 0;
3952 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003953 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954
3955 *rdev = MKDEV(0,0);
3956 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3957 return -EIO;
3958 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3959 dev_t tmp;
3960
Benny Halevyc0eae662009-08-14 17:20:14 +03003961 p = xdr_inline_decode(xdr, 8);
3962 if (unlikely(!p))
3963 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003964 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003965 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 tmp = MKDEV(major, minor);
3967 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3968 *rdev = tmp;
3969 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003970 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003972 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003973 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003974out_overflow:
3975 print_overflow_msg(__func__, xdr);
3976 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977}
3978
3979static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3980{
Al Viro8687b632006-10-19 23:28:48 -07003981 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 int status = 0;
3983
3984 *res = 0;
3985 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3986 return -EIO;
3987 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003988 p = xdr_inline_decode(xdr, 8);
3989 if (unlikely(!p))
3990 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003991 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3993 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003994 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003996out_overflow:
3997 print_overflow_msg(__func__, xdr);
3998 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999}
4000
4001static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4002{
Al Viro8687b632006-10-19 23:28:48 -07004003 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004 int status = 0;
4005
4006 *res = 0;
4007 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4008 return -EIO;
4009 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004010 p = xdr_inline_decode(xdr, 8);
4011 if (unlikely(!p))
4012 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004013 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4015 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004016 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004018out_overflow:
4019 print_overflow_msg(__func__, xdr);
4020 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021}
4022
4023static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4024{
Al Viro8687b632006-10-19 23:28:48 -07004025 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026 int status = 0;
4027
4028 *res = 0;
4029 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4030 return -EIO;
4031 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004032 p = xdr_inline_decode(xdr, 8);
4033 if (unlikely(!p))
4034 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004035 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4037 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004038 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004040out_overflow:
4041 print_overflow_msg(__func__, xdr);
4042 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043}
4044
4045static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4046{
Al Viro8687b632006-10-19 23:28:48 -07004047 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004048 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049
4050 *used = 0;
4051 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4052 return -EIO;
4053 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004054 p = xdr_inline_decode(xdr, 8);
4055 if (unlikely(!p))
4056 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004057 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004059 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004061 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004063 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004064out_overflow:
4065 print_overflow_msg(__func__, xdr);
4066 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067}
4068
4069static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4070{
Al Viro8687b632006-10-19 23:28:48 -07004071 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072 uint64_t sec;
4073 uint32_t nsec;
4074
Benny Halevyc0eae662009-08-14 17:20:14 +03004075 p = xdr_inline_decode(xdr, 12);
4076 if (unlikely(!p))
4077 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004078 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004079 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 time->tv_sec = (time_t)sec;
4081 time->tv_nsec = (long)nsec;
4082 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004083out_overflow:
4084 print_overflow_msg(__func__, xdr);
4085 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086}
4087
4088static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4089{
4090 int status = 0;
4091
4092 time->tv_sec = 0;
4093 time->tv_nsec = 0;
4094 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4095 return -EIO;
4096 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4097 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004098 if (status == 0)
4099 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4101 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004102 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 return status;
4104}
4105
4106static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4107{
4108 int status = 0;
4109
4110 time->tv_sec = 0;
4111 time->tv_nsec = 0;
4112 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4113 return -EIO;
4114 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4115 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004116 if (status == 0)
4117 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4119 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004120 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 return status;
4122}
4123
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004124static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4125 struct timespec *time)
4126{
4127 int status = 0;
4128
4129 time->tv_sec = 0;
4130 time->tv_nsec = 0;
4131 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4132 return -EIO;
4133 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4134 status = decode_attr_time(xdr, time);
4135 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4136 }
4137 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4138 (long)time->tv_nsec);
4139 return status;
4140}
4141
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4143{
4144 int status = 0;
4145
4146 time->tv_sec = 0;
4147 time->tv_nsec = 0;
4148 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4149 return -EIO;
4150 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4151 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004152 if (status == 0)
4153 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4155 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004156 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 return status;
4158}
4159
Al Viro8687b632006-10-19 23:28:48 -07004160static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161{
4162 unsigned int attrwords = XDR_QUADLEN(attrlen);
4163 unsigned int nwords = xdr->p - savep;
4164
4165 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004166 dprintk("%s: server returned incorrect attribute length: "
4167 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004168 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 attrwords << 2,
4170 (attrwords < nwords) ? '<' : '>',
4171 nwords << 2);
4172 return -EIO;
4173 }
4174 return 0;
4175}
4176
4177static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4178{
Al Viro8687b632006-10-19 23:28:48 -07004179 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180
Benny Halevyc0eae662009-08-14 17:20:14 +03004181 p = xdr_inline_decode(xdr, 20);
4182 if (unlikely(!p))
4183 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004184 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004185 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004186 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004188out_overflow:
4189 print_overflow_msg(__func__, xdr);
4190 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191}
4192
4193static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4194{
Al Viro8687b632006-10-19 23:28:48 -07004195 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196 uint32_t supp, acc;
4197 int status;
4198
4199 status = decode_op_hdr(xdr, OP_ACCESS);
4200 if (status)
4201 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004202 p = xdr_inline_decode(xdr, 8);
4203 if (unlikely(!p))
4204 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004205 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004206 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 access->supported = supp;
4208 access->access = acc;
4209 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004210out_overflow:
4211 print_overflow_msg(__func__, xdr);
4212 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213}
4214
Benny Halevy07d30432009-08-14 17:19:52 +03004215static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216{
Al Viro8687b632006-10-19 23:28:48 -07004217 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004218
4219 p = xdr_inline_decode(xdr, len);
4220 if (likely(p)) {
4221 memcpy(buf, p, len);
4222 return 0;
4223 }
4224 print_overflow_msg(__func__, xdr);
4225 return -EIO;
4226}
4227
4228static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4229{
4230 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231}
4232
4233static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4234{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 int status;
4236
4237 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004238 if (status != -EIO)
4239 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004240 if (!status)
4241 status = decode_stateid(xdr, &res->stateid);
4242 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243}
4244
Benny Halevydb942bb2009-08-14 17:19:56 +03004245static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4246{
4247 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248}
4249
4250static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4251{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252 int status;
4253
4254 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004255 if (!status)
4256 status = decode_verifier(xdr, res->verf->verifier);
4257 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258}
4259
4260static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4261{
Al Viro8687b632006-10-19 23:28:48 -07004262 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 uint32_t bmlen;
4264 int status;
4265
4266 status = decode_op_hdr(xdr, OP_CREATE);
4267 if (status)
4268 return status;
4269 if ((status = decode_change_info(xdr, cinfo)))
4270 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004271 p = xdr_inline_decode(xdr, 4);
4272 if (unlikely(!p))
4273 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004274 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004275 p = xdr_inline_decode(xdr, bmlen << 2);
4276 if (likely(p))
4277 return 0;
4278out_overflow:
4279 print_overflow_msg(__func__, xdr);
4280 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281}
4282
4283static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4284{
Al Viro8687b632006-10-19 23:28:48 -07004285 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004286 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287 int status;
4288
4289 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4290 goto xdr_error;
4291 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4292 goto xdr_error;
4293 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4294 goto xdr_error;
4295 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4296 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004297 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4298 &res->fh_expire_type)) != 0)
4299 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4301 goto xdr_error;
4302 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4303 goto xdr_error;
4304 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4305 goto xdr_error;
4306 status = verify_attr_len(xdr, savep, attrlen);
4307xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004308 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 return status;
4310}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004311
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4313{
Al Viro8687b632006-10-19 23:28:48 -07004314 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004315 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004317
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4319 goto xdr_error;
4320 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4321 goto xdr_error;
4322 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4323 goto xdr_error;
4324
4325 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4326 goto xdr_error;
4327 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4328 goto xdr_error;
4329 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4330 goto xdr_error;
4331 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4332 goto xdr_error;
4333 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4334 goto xdr_error;
4335 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4336 goto xdr_error;
4337
4338 status = verify_attr_len(xdr, savep, attrlen);
4339xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004340 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004341 return status;
4342}
4343
4344static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4345{
Al Viro8687b632006-10-19 23:28:48 -07004346 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004347 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004349
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4351 goto xdr_error;
4352 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4353 goto xdr_error;
4354 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4355 goto xdr_error;
4356
4357 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4358 goto xdr_error;
4359 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4360 goto xdr_error;
4361
4362 status = verify_attr_len(xdr, savep, attrlen);
4363xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004364 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365 return status;
4366}
4367
Bryan Schumakerae42c702010-10-21 16:33:17 -04004368static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4369 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004370 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004371 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004372{
Trond Myklebustbca79472009-03-11 14:10:26 -04004373 int status;
4374 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004375 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004376 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004378 status = decode_attr_type(xdr, bitmap, &type);
4379 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004381 fattr->mode = 0;
4382 if (status != 0) {
4383 fattr->mode |= nfs_type2fmt[type];
4384 fattr->valid |= status;
4385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004387 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4388 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004390 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004391
4392 status = decode_attr_size(xdr, bitmap, &fattr->size);
4393 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004395 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004396
4397 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4398 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004400 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004401
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004402 err = 0;
4403 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004404 if (status < 0)
4405 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004406 if (err == -NFS4ERR_WRONGSEC)
4407 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004408
4409 status = decode_attr_filehandle(xdr, bitmap, fh);
4410 if (status < 0)
4411 goto xdr_error;
4412
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004413 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4414 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004416 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004417
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004418 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004419 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004420 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004421 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004422
4423 status = decode_attr_mode(xdr, bitmap, &fmode);
4424 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004426 if (status != 0) {
4427 fattr->mode |= fmode;
4428 fattr->valid |= status;
4429 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004430
4431 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4432 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004433 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004434 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004435
Trond Myklebust6926afd2012-01-07 13:22:46 -05004436 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004437 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004439 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004440
Trond Myklebust6926afd2012-01-07 13:22:46 -05004441 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004442 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004444 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004445
4446 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4447 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004449 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004450
4451 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4452 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004454 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004455
4456 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4457 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004459 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004460
4461 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4462 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004464 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004465
4466 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4467 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004469 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004470
Trond Myklebust28331a42011-04-27 13:47:52 -04004471 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004472 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004473 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004474 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004475
Bryan Schumakerae42c702010-10-21 16:33:17 -04004476xdr_error:
4477 dprintk("%s: xdr returned %d\n", __func__, -status);
4478 return status;
4479}
4480
4481static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004482 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4483 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004484{
4485 __be32 *savep;
4486 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004487 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004488 int status;
4489
4490 status = decode_op_hdr(xdr, OP_GETATTR);
4491 if (status < 0)
4492 goto xdr_error;
4493
4494 status = decode_attr_bitmap(xdr, bitmap);
4495 if (status < 0)
4496 goto xdr_error;
4497
4498 status = decode_attr_length(xdr, &attrlen, &savep);
4499 if (status < 0)
4500 goto xdr_error;
4501
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004502 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004503 if (status < 0)
4504 goto xdr_error;
4505
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004506 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004508 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004509 return status;
4510}
4511
Bryan Schumakerae42c702010-10-21 16:33:17 -04004512static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004513 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004514{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004515 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004516}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517
Andy Adamson504913f2010-10-20 00:17:57 -04004518/*
4519 * Decode potentially multiple layout types. Currently we only support
4520 * one layout driver per file system.
4521 */
4522static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4523 uint32_t *layouttype)
4524{
4525 uint32_t *p;
4526 int num;
4527
4528 p = xdr_inline_decode(xdr, 4);
4529 if (unlikely(!p))
4530 goto out_overflow;
4531 num = be32_to_cpup(p);
4532
4533 /* pNFS is not supported by the underlying file system */
4534 if (num == 0) {
4535 *layouttype = 0;
4536 return 0;
4537 }
4538 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004539 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4540 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004541
4542 /* Decode and set first layout type, move xdr->p past unused types */
4543 p = xdr_inline_decode(xdr, num * 4);
4544 if (unlikely(!p))
4545 goto out_overflow;
4546 *layouttype = be32_to_cpup(p);
4547 return 0;
4548out_overflow:
4549 print_overflow_msg(__func__, xdr);
4550 return -EIO;
4551}
4552
4553/*
4554 * The type of file system exported.
4555 * Note we must ensure that layouttype is set in any non-error case.
4556 */
4557static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4558 uint32_t *layouttype)
4559{
4560 int status = 0;
4561
4562 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4563 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4564 return -EIO;
4565 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4566 status = decode_first_pnfs_layout_type(xdr, layouttype);
4567 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4568 } else
4569 *layouttype = 0;
4570 return status;
4571}
4572
Fred Isamandae100c2011-07-30 20:52:37 -04004573/*
4574 * The prefered block size for layout directed io
4575 */
4576static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4577 uint32_t *res)
4578{
4579 __be32 *p;
4580
4581 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4582 *res = 0;
4583 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4584 p = xdr_inline_decode(xdr, 4);
4585 if (unlikely(!p)) {
4586 print_overflow_msg(__func__, xdr);
4587 return -EIO;
4588 }
4589 *res = be32_to_cpup(p);
4590 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4591 }
4592 return 0;
4593}
4594
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4596{
Al Viro8687b632006-10-19 23:28:48 -07004597 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004598 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004599 int status;
4600
4601 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4602 goto xdr_error;
4603 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4604 goto xdr_error;
4605 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4606 goto xdr_error;
4607
4608 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4609
4610 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4611 goto xdr_error;
4612 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4613 goto xdr_error;
4614 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4615 goto xdr_error;
4616 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4617 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4618 goto xdr_error;
4619 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004620 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4621 if (status != 0)
4622 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004623 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4624 if (status != 0)
4625 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004626 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4627 if (status)
4628 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629
4630 status = verify_attr_len(xdr, savep, attrlen);
4631xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004632 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633 return status;
4634}
4635
4636static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4637{
Al Viro8687b632006-10-19 23:28:48 -07004638 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 uint32_t len;
4640 int status;
4641
Trond Myklebust99367812007-07-17 21:52:41 -04004642 /* Zero handle first to allow comparisons */
4643 memset(fh, 0, sizeof(*fh));
4644
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645 status = decode_op_hdr(xdr, OP_GETFH);
4646 if (status)
4647 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648
Benny Halevyc0eae662009-08-14 17:20:14 +03004649 p = xdr_inline_decode(xdr, 4);
4650 if (unlikely(!p))
4651 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004652 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004653 if (len > NFS4_FHSIZE)
4654 return -EIO;
4655 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004656 p = xdr_inline_decode(xdr, len);
4657 if (unlikely(!p))
4658 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004659 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004661out_overflow:
4662 print_overflow_msg(__func__, xdr);
4663 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004664}
4665
4666static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4667{
4668 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004669
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670 status = decode_op_hdr(xdr, OP_LINK);
4671 if (status)
4672 return status;
4673 return decode_change_info(xdr, cinfo);
4674}
4675
4676/*
4677 * We create the owner, so we know a proper owner.id length is 4.
4678 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004679static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004680{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004681 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004682 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004683 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004685 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004686 if (unlikely(!p))
4687 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004688 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004689 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004690 type = be32_to_cpup(p++); /* 4 byte read */
4691 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004692 fl->fl_start = (loff_t)offset;
4693 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4694 if (length == ~(uint64_t)0)
4695 fl->fl_end = OFFSET_MAX;
4696 fl->fl_type = F_WRLCK;
4697 if (type & 1)
4698 fl->fl_type = F_RDLCK;
4699 fl->fl_pid = 0;
4700 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004701 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4702 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4703 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004704 if (likely(p))
4705 return -NFS4ERR_DENIED;
4706out_overflow:
4707 print_overflow_msg(__func__, xdr);
4708 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709}
4710
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004711static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004713 int status;
4714
4715 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004716 if (status == -EIO)
4717 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004719 status = decode_stateid(xdr, &res->stateid);
4720 if (unlikely(status))
4721 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004722 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004723 status = decode_lock_denied(xdr, NULL);
4724 if (res->open_seqid != NULL)
4725 nfs_increment_open_seqid(status, res->open_seqid);
4726 nfs_increment_lock_seqid(status, res->lock_seqid);
4727out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728 return status;
4729}
4730
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004731static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732{
4733 int status;
4734 status = decode_op_hdr(xdr, OP_LOCKT);
4735 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004736 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737 return status;
4738}
4739
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004740static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004742 int status;
4743
4744 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004745 if (status != -EIO)
4746 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004747 if (status == 0)
4748 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 return status;
4750}
4751
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004752static int decode_release_lockowner(struct xdr_stream *xdr)
4753{
4754 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4755}
4756
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757static int decode_lookup(struct xdr_stream *xdr)
4758{
4759 return decode_op_hdr(xdr, OP_LOOKUP);
4760}
4761
4762/* This is too sick! */
4763static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4764{
Andy Adamson05d564f2008-12-23 16:06:15 -05004765 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766 uint32_t limit_type, nblocks, blocksize;
4767
Benny Halevyc0eae662009-08-14 17:20:14 +03004768 p = xdr_inline_decode(xdr, 12);
4769 if (unlikely(!p))
4770 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004771 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004773 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004774 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004775 break;
4776 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004777 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004778 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004779 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780 }
4781 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004782out_overflow:
4783 print_overflow_msg(__func__, xdr);
4784 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785}
4786
4787static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4788{
Andy Adamson05d564f2008-12-23 16:06:15 -05004789 __be32 *p;
4790 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004791 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792
Benny Halevyc0eae662009-08-14 17:20:14 +03004793 p = xdr_inline_decode(xdr, 4);
4794 if (unlikely(!p))
4795 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004796 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4798 res->delegation_type = 0;
4799 return 0;
4800 }
Benny Halevy07d30432009-08-14 17:19:52 +03004801 status = decode_stateid(xdr, &res->delegation);
4802 if (unlikely(status))
4803 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004804 p = xdr_inline_decode(xdr, 4);
4805 if (unlikely(!p))
4806 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004807 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004808
Linus Torvalds1da177e2005-04-16 15:20:36 -07004809 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004810 case NFS4_OPEN_DELEGATE_READ:
4811 res->delegation_type = FMODE_READ;
4812 break;
4813 case NFS4_OPEN_DELEGATE_WRITE:
4814 res->delegation_type = FMODE_WRITE|FMODE_READ;
4815 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816 return -EIO;
4817 }
David Howells7539bba2006-08-22 20:06:09 -04004818 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004819out_overflow:
4820 print_overflow_msg(__func__, xdr);
4821 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822}
4823
4824static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4825{
Andy Adamson05d564f2008-12-23 16:06:15 -05004826 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004827 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004828 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004829
Andy Adamson05d564f2008-12-23 16:06:15 -05004830 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004831 if (status != -EIO)
4832 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004833 if (!status)
4834 status = decode_stateid(xdr, &res->stateid);
4835 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004836 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837
Andy Adamson05d564f2008-12-23 16:06:15 -05004838 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004839
Benny Halevyc0eae662009-08-14 17:20:14 +03004840 p = xdr_inline_decode(xdr, 8);
4841 if (unlikely(!p))
4842 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004843 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004844 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004845 if (bmlen > 10)
4846 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847
Benny Halevyc0eae662009-08-14 17:20:14 +03004848 p = xdr_inline_decode(xdr, bmlen << 2);
4849 if (unlikely(!p))
4850 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004851 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4852 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004853 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004854 for (; i < NFS4_BITMAP_SIZE; i++)
4855 res->attrset[i] = 0;
4856
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857 return decode_delegation(xdr, res);
4858xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004859 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004860 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004861out_overflow:
4862 print_overflow_msg(__func__, xdr);
4863 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864}
4865
4866static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4867{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868 int status;
4869
Andy Adamson05d564f2008-12-23 16:06:15 -05004870 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004871 if (status != -EIO)
4872 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004873 if (!status)
4874 status = decode_stateid(xdr, &res->stateid);
4875 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876}
4877
4878static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4879{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880 int status;
4881
4882 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004883 if (status != -EIO)
4884 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004885 if (!status)
4886 status = decode_stateid(xdr, &res->stateid);
4887 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004888}
4889
4890static int decode_putfh(struct xdr_stream *xdr)
4891{
4892 return decode_op_hdr(xdr, OP_PUTFH);
4893}
4894
4895static int decode_putrootfh(struct xdr_stream *xdr)
4896{
4897 return decode_op_hdr(xdr, OP_PUTROOTFH);
4898}
4899
4900static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4901{
4902 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004903 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904 uint32_t count, eof, recvd, hdrlen;
4905 int status;
4906
4907 status = decode_op_hdr(xdr, OP_READ);
4908 if (status)
4909 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004910 p = xdr_inline_decode(xdr, 8);
4911 if (unlikely(!p))
4912 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004913 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004914 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004915 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916 recvd = req->rq_rcv_buf.len - hdrlen;
4917 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004918 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919 "count %u > recvd %u\n", count, recvd);
4920 count = recvd;
4921 eof = 0;
4922 }
4923 xdr_read_pages(xdr, count);
4924 res->eof = eof;
4925 res->count = count;
4926 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004927out_overflow:
4928 print_overflow_msg(__func__, xdr);
4929 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930}
4931
4932static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4933{
4934 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004936 size_t hdrlen;
4937 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004938 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004939
4940 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004941 if (!status)
4942 status = decode_verifier(xdr, readdir->verifier.data);
4943 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004945 dprintk("%s: verifier = %08x:%08x\n",
4946 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004947 ((u32 *)readdir->verifier.data)[0],
4948 ((u32 *)readdir->verifier.data)[1]);
4949
Linus Torvalds1da177e2005-04-16 15:20:36 -07004950
Benny Halevydb942bb2009-08-14 17:19:56 +03004951 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952 recvd = rcvbuf->len - hdrlen;
4953 if (pglen > recvd)
4954 pglen = recvd;
4955 xdr_read_pages(xdr, pglen);
4956
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004957
Trond Myklebustac396122010-11-15 20:26:22 -05004958 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004959}
4960
4961static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4962{
4963 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4964 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004965 size_t hdrlen;
4966 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004967 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004968 int status;
4969
4970 status = decode_op_hdr(xdr, OP_READLINK);
4971 if (status)
4972 return status;
4973
4974 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004975 p = xdr_inline_decode(xdr, 4);
4976 if (unlikely(!p))
4977 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004978 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004980 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004981 return -ENAMETOOLONG;
4982 }
4983 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4984 recvd = req->rq_rcv_buf.len - hdrlen;
4985 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004986 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987 "count %u > recvd %u\n", len, recvd);
4988 return -EIO;
4989 }
4990 xdr_read_pages(xdr, len);
4991 /*
4992 * The XDR encode routine has set things up so that
4993 * the link text will be copied directly into the
4994 * buffer. We just have to do overflow-checking,
4995 * and and null-terminate the text (the VFS expects
4996 * null-termination).
4997 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004998 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005000out_overflow:
5001 print_overflow_msg(__func__, xdr);
5002 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003}
5004
5005static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5006{
5007 int status;
5008
5009 status = decode_op_hdr(xdr, OP_REMOVE);
5010 if (status)
5011 goto out;
5012 status = decode_change_info(xdr, cinfo);
5013out:
5014 return status;
5015}
5016
5017static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5018 struct nfs4_change_info *new_cinfo)
5019{
5020 int status;
5021
5022 status = decode_op_hdr(xdr, OP_RENAME);
5023 if (status)
5024 goto out;
5025 if ((status = decode_change_info(xdr, old_cinfo)))
5026 goto out;
5027 status = decode_change_info(xdr, new_cinfo);
5028out:
5029 return status;
5030}
5031
5032static int decode_renew(struct xdr_stream *xdr)
5033{
5034 return decode_op_hdr(xdr, OP_RENEW);
5035}
5036
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005037static int
5038decode_restorefh(struct xdr_stream *xdr)
5039{
5040 return decode_op_hdr(xdr, OP_RESTOREFH);
5041}
5042
J. Bruce Fields029d1052005-06-22 17:16:22 +00005043static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005044 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005045{
Andy Adamsonbf118a32011-12-07 11:55:27 -05005046 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005047 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005048 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005049 struct kvec *iov = req->rq_rcv_buf.head;
5050 int status;
5051
Andy Adamsonbf118a32011-12-07 11:55:27 -05005052 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005053 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5054 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005055 bm_p = xdr->p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005056 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5057 goto out;
5058 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5059 goto out;
5060
5061 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5062 return -EIO;
5063 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04005064 size_t hdrlen;
5065 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005066
Andy Adamsonbf118a32011-12-07 11:55:27 -05005067 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5068 * are stored with the acl data to handle the problem of
5069 * variable length bitmaps.*/
5070 xdr->p = bm_p;
5071 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
5072 res->acl_data_offset <<= 2;
5073
J. Bruce Fields029d1052005-06-22 17:16:22 +00005074 /* We ignore &savep and don't do consistency checks on
5075 * the attr length. Let userspace figure it out.... */
5076 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005077 attrlen += res->acl_data_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005078 recvd = req->rq_rcv_buf.len - hdrlen;
5079 if (attrlen > recvd) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05005080 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
5081 /* getxattr interface called with a NULL buf */
5082 res->acl_len = attrlen;
5083 goto out;
5084 }
5085 dprintk("NFS: acl reply: attrlen %u > recvd %u\n",
J. Bruce Fields029d1052005-06-22 17:16:22 +00005086 attrlen, recvd);
5087 return -EINVAL;
5088 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04005089 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05005090 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005091 } else
5092 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005093
5094out:
5095 return status;
5096}
5097
Linus Torvalds1da177e2005-04-16 15:20:36 -07005098static int
5099decode_savefh(struct xdr_stream *xdr)
5100{
5101 return decode_op_hdr(xdr, OP_SAVEFH);
5102}
5103
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005104static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005105{
Al Viro8687b632006-10-19 23:28:48 -07005106 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107 uint32_t bmlen;
5108 int status;
5109
Linus Torvalds1da177e2005-04-16 15:20:36 -07005110 status = decode_op_hdr(xdr, OP_SETATTR);
5111 if (status)
5112 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005113 p = xdr_inline_decode(xdr, 4);
5114 if (unlikely(!p))
5115 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005116 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005117 p = xdr_inline_decode(xdr, bmlen << 2);
5118 if (likely(p))
5119 return 0;
5120out_overflow:
5121 print_overflow_msg(__func__, xdr);
5122 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123}
5124
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005125static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005126{
Al Viro8687b632006-10-19 23:28:48 -07005127 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128 uint32_t opnum;
5129 int32_t nfserr;
5130
Benny Halevyc0eae662009-08-14 17:20:14 +03005131 p = xdr_inline_decode(xdr, 8);
5132 if (unlikely(!p))
5133 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005134 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005135 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005136 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005137 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005138 return -EIO;
5139 }
Benny Halevycccddf42009-08-14 17:20:19 +03005140 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005141 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005142 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5143 if (unlikely(!p))
5144 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005145 p = xdr_decode_hyper(p, &res->clientid);
5146 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147 } else if (nfserr == NFSERR_CLID_INUSE) {
5148 uint32_t len;
5149
5150 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005151 p = xdr_inline_decode(xdr, 4);
5152 if (unlikely(!p))
5153 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005154 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005155 p = xdr_inline_decode(xdr, len);
5156 if (unlikely(!p))
5157 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005158
5159 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005160 p = xdr_inline_decode(xdr, 4);
5161 if (unlikely(!p))
5162 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005163 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005164 p = xdr_inline_decode(xdr, len);
5165 if (unlikely(!p))
5166 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005167 return -NFSERR_CLID_INUSE;
5168 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005169 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170
5171 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005172out_overflow:
5173 print_overflow_msg(__func__, xdr);
5174 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175}
5176
5177static int decode_setclientid_confirm(struct xdr_stream *xdr)
5178{
5179 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5180}
5181
5182static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5183{
Al Viro8687b632006-10-19 23:28:48 -07005184 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185 int status;
5186
5187 status = decode_op_hdr(xdr, OP_WRITE);
5188 if (status)
5189 return status;
5190
Benny Halevyc0eae662009-08-14 17:20:14 +03005191 p = xdr_inline_decode(xdr, 16);
5192 if (unlikely(!p))
5193 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005194 res->count = be32_to_cpup(p++);
5195 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03005196 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005197 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005198out_overflow:
5199 print_overflow_msg(__func__, xdr);
5200 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005201}
5202
5203static int decode_delegreturn(struct xdr_stream *xdr)
5204{
5205 return decode_op_hdr(xdr, OP_DELEGRETURN);
5206}
5207
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005208static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5209{
5210 __be32 *p;
5211
5212 p = xdr_inline_decode(xdr, 4);
5213 if (unlikely(!p))
5214 goto out_overflow;
5215 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5216 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5217 goto out_err;
5218
5219 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5220 if (unlikely(!p))
5221 goto out_overflow;
5222 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5223
5224 p = xdr_inline_decode(xdr, 8);
5225 if (unlikely(!p))
5226 goto out_overflow;
5227 flavor->gss.qop4 = be32_to_cpup(p++);
5228 flavor->gss.service = be32_to_cpup(p);
5229
5230 return 0;
5231
5232out_overflow:
5233 print_overflow_msg(__func__, xdr);
5234 return -EIO;
5235out_err:
5236 return -EINVAL;
5237}
5238
5239static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5240{
5241 struct nfs4_secinfo_flavor *sec_flavor;
5242 int status;
5243 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005244 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005245
5246 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04005247 if (status)
5248 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005249 p = xdr_inline_decode(xdr, 4);
5250 if (unlikely(!p))
5251 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005252
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005253 res->flavors->num_flavors = 0;
5254 num_flavors = be32_to_cpup(p);
5255
5256 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005257 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005258 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005259 break;
5260
5261 p = xdr_inline_decode(xdr, 4);
5262 if (unlikely(!p))
5263 goto out_overflow;
5264 sec_flavor->flavor = be32_to_cpup(p);
5265
5266 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005267 status = decode_secinfo_gss(xdr, sec_flavor);
5268 if (status)
5269 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005270 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005271 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005272 }
5273
Bryan Schumaker613e9012011-04-27 15:28:44 -04005274out:
5275 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005276out_overflow:
5277 print_overflow_msg(__func__, xdr);
5278 return -EIO;
5279}
5280
Benny Halevy99fe60d2009-04-01 09:22:29 -04005281#if defined(CONFIG_NFS_V4_1)
5282static int decode_exchange_id(struct xdr_stream *xdr,
5283 struct nfs41_exchange_id_res *res)
5284{
5285 __be32 *p;
5286 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005287 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005288 int status;
5289 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005290 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005291
5292 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5293 if (status)
5294 return status;
5295
Benny Halevyc0eae662009-08-14 17:20:14 +03005296 p = xdr_inline_decode(xdr, 8);
5297 if (unlikely(!p))
5298 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005299 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005300 p = xdr_inline_decode(xdr, 12);
5301 if (unlikely(!p))
5302 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005303 clp->cl_seqid = be32_to_cpup(p++);
5304 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005305
5306 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005307 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005308 if (dummy != SP4_NONE)
5309 return -EIO;
5310
5311 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005312 p = xdr_inline_decode(xdr, 8);
5313 if (unlikely(!p))
5314 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005315
5316 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005317 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5318 if (unlikely(status))
5319 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005320
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005321 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005322 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5323 if (unlikely(status))
5324 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005325
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005326 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5327 return -EIO;
5328
5329 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5330 res->server_scope->server_scope_sz = dummy;
5331
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005332 /* Implementation Id */
5333 p = xdr_inline_decode(xdr, 4);
5334 if (unlikely(!p))
5335 goto out_overflow;
5336 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005337
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005338 if (impl_id_count) {
5339 /* nii_domain */
5340 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5341 if (unlikely(status))
5342 return status;
5343 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5344 return -EIO;
5345 memcpy(res->impl_id->domain, dummy_str, dummy);
5346
5347 /* nii_name */
5348 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5349 if (unlikely(status))
5350 return status;
5351 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5352 return -EIO;
5353 memcpy(res->impl_id->name, dummy_str, dummy);
5354
5355 /* nii_date */
5356 p = xdr_inline_decode(xdr, 12);
5357 if (unlikely(!p))
5358 goto out_overflow;
5359 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5360 res->impl_id->date.nseconds = be32_to_cpup(p);
5361
5362 /* if there's more than one entry, ignore the rest */
5363 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005364 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005365out_overflow:
5366 print_overflow_msg(__func__, xdr);
5367 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005368}
Andy Adamsonfc931582009-04-01 09:22:31 -04005369
5370static int decode_chan_attrs(struct xdr_stream *xdr,
5371 struct nfs4_channel_attrs *attrs)
5372{
5373 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005374 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005375
Benny Halevyc0eae662009-08-14 17:20:14 +03005376 p = xdr_inline_decode(xdr, 28);
5377 if (unlikely(!p))
5378 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005379 val = be32_to_cpup(p++); /* headerpadsz */
5380 if (val)
5381 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005382 attrs->max_rqst_sz = be32_to_cpup(p++);
5383 attrs->max_resp_sz = be32_to_cpup(p++);
5384 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5385 attrs->max_ops = be32_to_cpup(p++);
5386 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005387 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005388 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005389 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5390 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005391 return -EINVAL;
5392 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005393 if (nr_attrs == 1) {
5394 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5395 if (unlikely(!p))
5396 goto out_overflow;
5397 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005398 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005399out_overflow:
5400 print_overflow_msg(__func__, xdr);
5401 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005402}
5403
Benny Halevye78291e2009-08-14 17:20:00 +03005404static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5405{
5406 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005407}
5408
5409static int decode_create_session(struct xdr_stream *xdr,
5410 struct nfs41_create_session_res *res)
5411{
5412 __be32 *p;
5413 int status;
5414 struct nfs_client *clp = res->client;
5415 struct nfs4_session *session = clp->cl_session;
5416
5417 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005418 if (!status)
5419 status = decode_sessionid(xdr, &session->sess_id);
5420 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005421 return status;
5422
Andy Adamsonfc931582009-04-01 09:22:31 -04005423 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005424 p = xdr_inline_decode(xdr, 8);
5425 if (unlikely(!p))
5426 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005427 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005428 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005429
5430 /* Channel attributes */
5431 status = decode_chan_attrs(xdr, &session->fc_attrs);
5432 if (!status)
5433 status = decode_chan_attrs(xdr, &session->bc_attrs);
5434 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005435out_overflow:
5436 print_overflow_msg(__func__, xdr);
5437 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005438}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005439
5440static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5441{
5442 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5443}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005444
5445static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5446{
5447 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5448}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005449#endif /* CONFIG_NFS_V4_1 */
5450
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005451static int decode_sequence(struct xdr_stream *xdr,
5452 struct nfs4_sequence_res *res,
5453 struct rpc_rqst *rqstp)
5454{
5455#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005456 struct nfs4_sessionid id;
5457 u32 dummy;
5458 int status;
5459 __be32 *p;
5460
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005461 if (!res->sr_session)
5462 return 0;
5463
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005464 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005465 if (!status)
5466 status = decode_sessionid(xdr, &id);
5467 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005468 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005469
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005470 /*
5471 * If the server returns different values for sessionID, slotID or
5472 * sequence number, the server is looney tunes.
5473 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005474 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005475
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005476 if (memcmp(id.data, res->sr_session->sess_id.data,
5477 NFS4_MAX_SESSIONID_LEN)) {
5478 dprintk("%s Invalid session id\n", __func__);
5479 goto out_err;
5480 }
Benny Halevye78291e2009-08-14 17:20:00 +03005481
Benny Halevyc0eae662009-08-14 17:20:14 +03005482 p = xdr_inline_decode(xdr, 20);
5483 if (unlikely(!p))
5484 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005485
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005486 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005487 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005488 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005489 dprintk("%s Invalid sequence number\n", __func__);
5490 goto out_err;
5491 }
5492 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005493 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005494 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005495 dprintk("%s Invalid slot id\n", __func__);
5496 goto out_err;
5497 }
5498 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005499 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005500 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005501 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005502 /* result flags */
5503 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005504 status = 0;
5505out_err:
5506 res->sr_status = status;
5507 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005508out_overflow:
5509 print_overflow_msg(__func__, xdr);
5510 status = -EIO;
5511 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005512#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005513 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005514#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005515}
5516
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005517#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005518/*
5519 * TODO: Need to handle case when EOF != true;
5520 */
5521static int decode_getdevicelist(struct xdr_stream *xdr,
5522 struct pnfs_devicelist *res)
5523{
5524 __be32 *p;
5525 int status, i;
5526 struct nfs_writeverf verftemp;
5527
5528 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5529 if (status)
5530 return status;
5531
5532 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5533 if (unlikely(!p))
5534 goto out_overflow;
5535
5536 /* TODO: Skip cookie for now */
5537 p += 2;
5538
5539 /* Read verifier */
5540 p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8);
5541
5542 res->num_devs = be32_to_cpup(p);
5543
5544 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5545
5546 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005547 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005548 __func__, res->num_devs);
5549 return -EIO;
5550 }
5551
5552 p = xdr_inline_decode(xdr,
5553 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5554 if (unlikely(!p))
5555 goto out_overflow;
5556 for (i = 0; i < res->num_devs; i++)
5557 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5558 NFS4_DEVICEID4_SIZE);
5559 res->eof = be32_to_cpup(p);
5560 return 0;
5561out_overflow:
5562 print_overflow_msg(__func__, xdr);
5563 return -EIO;
5564}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005565
5566static int decode_getdeviceinfo(struct xdr_stream *xdr,
5567 struct pnfs_device *pdev)
5568{
5569 __be32 *p;
5570 uint32_t len, type;
5571 int status;
5572
5573 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5574 if (status) {
5575 if (status == -ETOOSMALL) {
5576 p = xdr_inline_decode(xdr, 4);
5577 if (unlikely(!p))
5578 goto out_overflow;
5579 pdev->mincount = be32_to_cpup(p);
5580 dprintk("%s: Min count too small. mincnt = %u\n",
5581 __func__, pdev->mincount);
5582 }
5583 return status;
5584 }
5585
5586 p = xdr_inline_decode(xdr, 8);
5587 if (unlikely(!p))
5588 goto out_overflow;
5589 type = be32_to_cpup(p++);
5590 if (type != pdev->layout_type) {
5591 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5592 __func__, pdev->layout_type, type);
5593 return -EINVAL;
5594 }
5595 /*
5596 * Get the length of the opaque device_addr4. xdr_read_pages places
5597 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5598 * and places the remaining xdr data in xdr_buf->tail
5599 */
5600 pdev->mincount = be32_to_cpup(p);
5601 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5602
5603 /* Parse notification bitmap, verifying that it is zero. */
5604 p = xdr_inline_decode(xdr, 4);
5605 if (unlikely(!p))
5606 goto out_overflow;
5607 len = be32_to_cpup(p);
5608 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005609 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005610
5611 p = xdr_inline_decode(xdr, 4 * len);
5612 if (unlikely(!p))
5613 goto out_overflow;
5614 for (i = 0; i < len; i++, p++) {
5615 if (be32_to_cpup(p)) {
5616 dprintk("%s: notifications not supported\n",
5617 __func__);
5618 return -EIO;
5619 }
5620 }
5621 }
5622 return 0;
5623out_overflow:
5624 print_overflow_msg(__func__, xdr);
5625 return -EIO;
5626}
5627
5628static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5629 struct nfs4_layoutget_res *res)
5630{
5631 __be32 *p;
5632 int status;
5633 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005634 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5635 struct kvec *iov = rcvbuf->head;
5636 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005637
5638 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5639 if (status)
5640 return status;
5641 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5642 if (unlikely(!p))
5643 goto out_overflow;
5644 res->return_on_close = be32_to_cpup(p++);
5645 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5646 layout_count = be32_to_cpup(p);
5647 if (!layout_count) {
5648 dprintk("%s: server responded with empty layout array\n",
5649 __func__);
5650 return -EINVAL;
5651 }
5652
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005653 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005654 if (unlikely(!p))
5655 goto out_overflow;
5656 p = xdr_decode_hyper(p, &res->range.offset);
5657 p = xdr_decode_hyper(p, &res->range.length);
5658 res->range.iomode = be32_to_cpup(p++);
5659 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005660 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005661
5662 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5663 __func__,
5664 (unsigned long)res->range.offset,
5665 (unsigned long)res->range.length,
5666 res->range.iomode,
5667 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005668 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005669
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005670 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5671 recvd = req->rq_rcv_buf.len - hdrlen;
5672 if (res->layoutp->len > recvd) {
5673 dprintk("NFS: server cheating in layoutget reply: "
5674 "layout len %u > recvd %u\n",
5675 res->layoutp->len, recvd);
5676 return -EINVAL;
5677 }
5678
5679 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005680
5681 if (layout_count > 1) {
5682 /* We only handle a length one array at the moment. Any
5683 * further entries are just ignored. Note that this means
5684 * the client may see a response that is less than the
5685 * minimum it requested.
5686 */
5687 dprintk("%s: server responded with %d layouts, dropping tail\n",
5688 __func__, layout_count);
5689 }
5690
5691 return 0;
5692out_overflow:
5693 print_overflow_msg(__func__, xdr);
5694 return -EIO;
5695}
Andy Adamson863a3c62011-03-23 13:27:54 +00005696
Benny Halevycbe82602011-05-22 19:52:37 +03005697static int decode_layoutreturn(struct xdr_stream *xdr,
5698 struct nfs4_layoutreturn_res *res)
5699{
5700 __be32 *p;
5701 int status;
5702
5703 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5704 if (status)
5705 return status;
5706 p = xdr_inline_decode(xdr, 4);
5707 if (unlikely(!p))
5708 goto out_overflow;
5709 res->lrs_present = be32_to_cpup(p);
5710 if (res->lrs_present)
5711 status = decode_stateid(xdr, &res->stateid);
5712 return status;
5713out_overflow:
5714 print_overflow_msg(__func__, xdr);
5715 return -EIO;
5716}
5717
Andy Adamson863a3c62011-03-23 13:27:54 +00005718static int decode_layoutcommit(struct xdr_stream *xdr,
5719 struct rpc_rqst *req,
5720 struct nfs4_layoutcommit_res *res)
5721{
5722 __be32 *p;
5723 __u32 sizechanged;
5724 int status;
5725
5726 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005727 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005728 if (status)
5729 return status;
5730
5731 p = xdr_inline_decode(xdr, 4);
5732 if (unlikely(!p))
5733 goto out_overflow;
5734 sizechanged = be32_to_cpup(p);
5735
5736 if (sizechanged) {
5737 /* throw away new size */
5738 p = xdr_inline_decode(xdr, 8);
5739 if (unlikely(!p))
5740 goto out_overflow;
5741 }
5742 return 0;
5743out_overflow:
5744 print_overflow_msg(__func__, xdr);
5745 return -EIO;
5746}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005747
5748static int decode_test_stateid(struct xdr_stream *xdr,
5749 struct nfs41_test_stateid_res *res)
5750{
5751 __be32 *p;
5752 int status;
5753 int num_res;
5754
5755 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5756 if (status)
5757 return status;
5758
5759 p = xdr_inline_decode(xdr, 4);
5760 if (unlikely(!p))
5761 goto out_overflow;
5762 num_res = be32_to_cpup(p++);
5763 if (num_res != 1)
5764 goto out;
5765
5766 p = xdr_inline_decode(xdr, 4);
5767 if (unlikely(!p))
5768 goto out_overflow;
5769 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005770
5771 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005772out_overflow:
5773 print_overflow_msg(__func__, xdr);
5774out:
5775 return -EIO;
5776}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005777
5778static int decode_free_stateid(struct xdr_stream *xdr,
5779 struct nfs41_free_stateid_res *res)
5780{
5781 __be32 *p;
5782 int status;
5783
5784 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5785 if (status)
5786 return status;
5787
5788 p = xdr_inline_decode(xdr, 4);
5789 if (unlikely(!p))
5790 goto out_overflow;
5791 res->status = be32_to_cpup(p++);
5792 return res->status;
5793out_overflow:
5794 print_overflow_msg(__func__, xdr);
5795 return -EIO;
5796}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005797#endif /* CONFIG_NFS_V4_1 */
5798
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799/*
Benny Halevy49c25592008-12-23 16:06:16 -05005800 * END OF "GENERIC" DECODE ROUTINES.
5801 */
5802
5803/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005804 * Decode OPEN_DOWNGRADE response
5805 */
Chuck Leverbf269552010-12-14 14:59:29 +00005806static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5807 struct xdr_stream *xdr,
5808 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005809{
Andy Adamson05d564f2008-12-23 16:06:15 -05005810 struct compound_hdr hdr;
5811 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005812
Chuck Leverbf269552010-12-14 14:59:29 +00005813 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005814 if (status)
5815 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005816 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005817 if (status)
5818 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005819 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005820 if (status)
5821 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005822 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005823 if (status != 0)
5824 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005825 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005826out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005827 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005828}
5829
5830/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005831 * Decode ACCESS response
5832 */
Chuck Leverbf269552010-12-14 14:59:29 +00005833static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5834 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005835{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836 struct compound_hdr hdr;
5837 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005838
Chuck Leverbf269552010-12-14 14:59:29 +00005839 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005840 if (status)
5841 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005842 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005843 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005845 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005846 if (status != 0)
5847 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005848 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005849 if (status != 0)
5850 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005851 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005852out:
5853 return status;
5854}
5855
5856/*
5857 * Decode LOOKUP response
5858 */
Chuck Leverbf269552010-12-14 14:59:29 +00005859static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5860 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005861{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862 struct compound_hdr hdr;
5863 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005864
Chuck Leverbf269552010-12-14 14:59:29 +00005865 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005866 if (status)
5867 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005868 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005869 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005870 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005871 status = decode_putfh(xdr);
5872 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005873 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005874 status = decode_lookup(xdr);
5875 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005876 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005877 status = decode_getfh(xdr, res->fh);
5878 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005879 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005880 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005881out:
5882 return status;
5883}
5884
5885/*
5886 * Decode LOOKUP_ROOT response
5887 */
Chuck Leverbf269552010-12-14 14:59:29 +00005888static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5889 struct xdr_stream *xdr,
5890 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005891{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892 struct compound_hdr hdr;
5893 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005894
Chuck Leverbf269552010-12-14 14:59:29 +00005895 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005896 if (status)
5897 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005898 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005899 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005900 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005901 status = decode_putrootfh(xdr);
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 == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005906 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005907out:
5908 return status;
5909}
5910
5911/*
5912 * Decode REMOVE response
5913 */
Chuck Leverbf269552010-12-14 14:59:29 +00005914static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5915 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005916{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005917 struct compound_hdr hdr;
5918 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005919
Chuck Leverbf269552010-12-14 14:59:29 +00005920 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005921 if (status)
5922 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005923 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005924 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005925 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005926 status = decode_putfh(xdr);
5927 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005928 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005929 status = decode_remove(xdr, &res->cinfo);
5930 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005931 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005932 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005933out:
5934 return status;
5935}
5936
5937/*
5938 * Decode RENAME response
5939 */
Chuck Leverbf269552010-12-14 14:59:29 +00005940static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5941 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005942{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005943 struct compound_hdr hdr;
5944 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005945
Chuck Leverbf269552010-12-14 14:59:29 +00005946 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005947 if (status)
5948 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005949 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005950 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005951 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005952 status = decode_putfh(xdr);
5953 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005955 status = decode_savefh(xdr);
5956 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005957 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005958 status = decode_putfh(xdr);
5959 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005960 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005961 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5962 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005963 goto out;
5964 /* Current FH is target directory */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005965 if (decode_getfattr(xdr, res->new_fattr, res->server))
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005966 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005967 status = decode_restorefh(xdr);
5968 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005969 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005970 decode_getfattr(xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005971out:
5972 return status;
5973}
5974
5975/*
5976 * Decode LINK response
5977 */
Chuck Leverbf269552010-12-14 14:59:29 +00005978static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5979 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005980{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005981 struct compound_hdr hdr;
5982 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005983
Chuck Leverbf269552010-12-14 14:59:29 +00005984 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005985 if (status)
5986 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005987 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005988 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005989 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005990 status = decode_putfh(xdr);
5991 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005992 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005993 status = decode_savefh(xdr);
5994 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005995 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005996 status = decode_putfh(xdr);
5997 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005998 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005999 status = decode_link(xdr, &res->cinfo);
6000 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006001 goto out;
6002 /*
6003 * Note order: OP_LINK leaves the directory as the current
6004 * filehandle.
6005 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006006 if (decode_getfattr(xdr, res->dir_attr, res->server))
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006007 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006008 status = decode_restorefh(xdr);
6009 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006010 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006011 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012out:
6013 return status;
6014}
6015
6016/*
6017 * Decode CREATE response
6018 */
Chuck Leverbf269552010-12-14 14:59:29 +00006019static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6020 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006021{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006022 struct compound_hdr hdr;
6023 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006024
Chuck Leverbf269552010-12-14 14:59:29 +00006025 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006026 if (status)
6027 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006028 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006029 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006031 status = decode_putfh(xdr);
6032 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006033 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006034 status = decode_savefh(xdr);
6035 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006036 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006037 status = decode_create(xdr, &res->dir_cinfo);
6038 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006039 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006040 status = decode_getfh(xdr, res->fh);
6041 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006042 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006043 if (decode_getfattr(xdr, res->fattr, res->server))
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006044 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006045 status = decode_restorefh(xdr);
6046 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006047 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006048 decode_getfattr(xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006049out:
6050 return status;
6051}
6052
6053/*
6054 * Decode SYMLINK response
6055 */
Chuck Leverbf269552010-12-14 14:59:29 +00006056static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6057 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006058{
Chuck Leverbf269552010-12-14 14:59:29 +00006059 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006060}
6061
6062/*
6063 * Decode GETATTR response
6064 */
Chuck Leverbf269552010-12-14 14:59:29 +00006065static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6066 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006068 struct compound_hdr hdr;
6069 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006070
Chuck Leverbf269552010-12-14 14:59:29 +00006071 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006072 if (status)
6073 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006074 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006075 if (status)
6076 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006077 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078 if (status)
6079 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006080 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081out:
6082 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083}
6084
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006085/*
6086 * Encode an SETACL request
6087 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006088static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6089 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006090{
Andy Adamson05d564f2008-12-23 16:06:15 -05006091 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006092 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006093 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006094
Chuck Lever9f06c712010-12-14 14:59:18 +00006095 encode_compound_hdr(xdr, req, &hdr);
6096 encode_sequence(xdr, &args->seq_args, &hdr);
6097 encode_putfh(xdr, args->fh, &hdr);
6098 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006099 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006100}
Andy Adamson05d564f2008-12-23 16:06:15 -05006101
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006102/*
6103 * Decode SETACL response
6104 */
6105static int
Chuck Leverbf269552010-12-14 14:59:29 +00006106nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006107 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006108{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006109 struct compound_hdr hdr;
6110 int status;
6111
Chuck Leverbf269552010-12-14 14:59:29 +00006112 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006113 if (status)
6114 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006115 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006116 if (status)
6117 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006118 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006119 if (status)
6120 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006121 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006122out:
6123 return status;
6124}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125
6126/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006127 * Decode GETACL response
6128 */
6129static int
Chuck Leverbf269552010-12-14 14:59:29 +00006130nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006131 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006132{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006133 struct compound_hdr hdr;
6134 int status;
6135
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006137 if (status)
6138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006139 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006140 if (status)
6141 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006142 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006143 if (status)
6144 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006145 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006146
6147out:
6148 return status;
6149}
6150
6151/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152 * Decode CLOSE response
6153 */
Chuck Leverbf269552010-12-14 14:59:29 +00006154static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6155 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006156{
Andy Adamson05d564f2008-12-23 16:06:15 -05006157 struct compound_hdr hdr;
6158 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006159
Chuck Leverbf269552010-12-14 14:59:29 +00006160 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006161 if (status)
6162 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006163 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006164 if (status)
6165 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006166 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006167 if (status)
6168 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006169 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006170 if (status != 0)
6171 goto out;
6172 /*
6173 * Note: Server may do delete on close for this file
6174 * in which case the getattr call will fail with
6175 * an ESTALE error. Shouldn't be a problem,
6176 * though, since fattr->valid will remain unset.
6177 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006178 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006179out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006180 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181}
6182
6183/*
6184 * Decode OPEN response
6185 */
Chuck Leverbf269552010-12-14 14:59:29 +00006186static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6187 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188{
Andy Adamson05d564f2008-12-23 16:06:15 -05006189 struct compound_hdr hdr;
6190 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191
Chuck Leverbf269552010-12-14 14:59:29 +00006192 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006193 if (status)
6194 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006195 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006196 if (status)
6197 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006198 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006199 if (status)
6200 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006202 if (status)
6203 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006204 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006205 if (status)
6206 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006207 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006209 if (decode_getfattr(xdr, res->f_attr, res->server) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006210 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006211 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006212 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006213 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006215 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216}
6217
6218/*
6219 * Decode OPEN_CONFIRM response
6220 */
Chuck Leverbf269552010-12-14 14:59:29 +00006221static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6222 struct xdr_stream *xdr,
6223 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006224{
Andy Adamson05d564f2008-12-23 16:06:15 -05006225 struct compound_hdr hdr;
6226 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227
Chuck Leverbf269552010-12-14 14:59:29 +00006228 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006229 if (status)
6230 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006231 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006232 if (status)
6233 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006234 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006236 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237}
6238
6239/*
6240 * Decode OPEN response
6241 */
Chuck Leverbf269552010-12-14 14:59:29 +00006242static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6243 struct xdr_stream *xdr,
6244 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006245{
Andy Adamson05d564f2008-12-23 16:06:15 -05006246 struct compound_hdr hdr;
6247 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248
Chuck Leverbf269552010-12-14 14:59:29 +00006249 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006250 if (status)
6251 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006252 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006253 if (status)
6254 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006256 if (status)
6257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006258 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006259 if (status)
6260 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006261 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006263 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006264}
6265
6266/*
6267 * Decode SETATTR response
6268 */
Chuck Leverbf269552010-12-14 14:59:29 +00006269static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6270 struct xdr_stream *xdr,
6271 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006272{
Andy Adamson05d564f2008-12-23 16:06:15 -05006273 struct compound_hdr hdr;
6274 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006275
Chuck Leverbf269552010-12-14 14:59:29 +00006276 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006277 if (status)
6278 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006279 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006280 if (status)
6281 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006282 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006283 if (status)
6284 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006285 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006286 if (status)
6287 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006288 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006289out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006290 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006291}
6292
6293/*
6294 * Decode LOCK response
6295 */
Chuck Leverbf269552010-12-14 14:59:29 +00006296static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6297 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299 struct compound_hdr hdr;
6300 int status;
6301
Chuck Leverbf269552010-12-14 14:59:29 +00006302 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006303 if (status)
6304 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006305 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006306 if (status)
6307 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006308 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006309 if (status)
6310 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006311 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006312out:
6313 return status;
6314}
6315
6316/*
6317 * Decode LOCKT response
6318 */
Chuck Leverbf269552010-12-14 14:59:29 +00006319static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6320 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006321{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006322 struct compound_hdr hdr;
6323 int status;
6324
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006326 if (status)
6327 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006328 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006329 if (status)
6330 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006331 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332 if (status)
6333 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006334 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335out:
6336 return status;
6337}
6338
6339/*
6340 * Decode LOCKU response
6341 */
Chuck Leverbf269552010-12-14 14:59:29 +00006342static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6343 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006344{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 struct compound_hdr hdr;
6346 int status;
6347
Chuck Leverbf269552010-12-14 14:59:29 +00006348 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006349 if (status)
6350 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006351 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006352 if (status)
6353 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006354 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006355 if (status)
6356 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006357 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358out:
6359 return status;
6360}
6361
Chuck Leverbf269552010-12-14 14:59:29 +00006362static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6363 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006364{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006365 struct compound_hdr hdr;
6366 int status;
6367
Chuck Leverbf269552010-12-14 14:59:29 +00006368 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006369 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006370 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006371 return status;
6372}
6373
Linus Torvalds1da177e2005-04-16 15:20:36 -07006374/*
6375 * Decode READLINK response
6376 */
Chuck Leverbf269552010-12-14 14:59:29 +00006377static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6378 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006379 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006380{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381 struct compound_hdr hdr;
6382 int status;
6383
Chuck Leverbf269552010-12-14 14:59:29 +00006384 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006385 if (status)
6386 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006387 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006388 if (status)
6389 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006390 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391 if (status)
6392 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006393 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006394out:
6395 return status;
6396}
6397
6398/*
6399 * Decode READDIR response
6400 */
Chuck Leverbf269552010-12-14 14:59:29 +00006401static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6402 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006403{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006404 struct compound_hdr hdr;
6405 int status;
6406
Chuck Leverbf269552010-12-14 14:59:29 +00006407 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006408 if (status)
6409 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006411 if (status)
6412 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006413 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006414 if (status)
6415 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006416 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006417out:
6418 return status;
6419}
6420
6421/*
6422 * Decode Read response
6423 */
Chuck Leverbf269552010-12-14 14:59:29 +00006424static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6425 struct nfs_readres *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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431 if (status)
6432 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006433 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006434 if (status)
6435 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006436 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437 if (status)
6438 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006439 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440 if (!status)
6441 status = res->count;
6442out:
6443 return status;
6444}
6445
6446/*
6447 * Decode WRITE response
6448 */
Chuck Leverbf269552010-12-14 14:59:29 +00006449static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6450 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006451{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006452 struct compound_hdr hdr;
6453 int status;
6454
Chuck Leverbf269552010-12-14 14:59:29 +00006455 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006456 if (status)
6457 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006458 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006459 if (status)
6460 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006461 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006462 if (status)
6463 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006464 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006465 if (status)
6466 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006467 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006468 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006469 if (!status)
6470 status = res->count;
6471out:
6472 return status;
6473}
6474
6475/*
6476 * Decode COMMIT response
6477 */
Chuck Leverbf269552010-12-14 14:59:29 +00006478static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6479 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006481 struct compound_hdr hdr;
6482 int status;
6483
Chuck Leverbf269552010-12-14 14:59:29 +00006484 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485 if (status)
6486 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006487 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006488 if (status)
6489 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006490 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491 if (status)
6492 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006493 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006494 if (status)
6495 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006496 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006497 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006498out:
6499 return status;
6500}
6501
6502/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006503 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006504 */
Chuck Leverbf269552010-12-14 14:59:29 +00006505static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006506 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508 struct compound_hdr hdr;
6509 int status;
6510
Chuck Leverbf269552010-12-14 14:59:29 +00006511 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006512 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006513 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006514 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006515 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006517 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518 return status;
6519}
6520
6521/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006522 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006523 */
Chuck Leverbf269552010-12-14 14:59:29 +00006524static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006525 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006526{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527 struct compound_hdr hdr;
6528 int status;
6529
Chuck Leverbf269552010-12-14 14:59:29 +00006530 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006531 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006532 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006533 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006534 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006536 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006537 return status;
6538}
6539
6540/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006541 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006542 */
Chuck Leverbf269552010-12-14 14:59:29 +00006543static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006544 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006546 struct compound_hdr hdr;
6547 int status;
6548
Chuck Leverbf269552010-12-14 14:59:29 +00006549 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006552 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006553 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006555 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556 return status;
6557}
6558
6559/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006560 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006561 */
Chuck Leverbf269552010-12-14 14:59:29 +00006562static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6563 struct xdr_stream *xdr,
6564 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006565{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006566 struct compound_hdr hdr;
6567 int status;
6568
Chuck Leverbf269552010-12-14 14:59:29 +00006569 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006570 if (status)
6571 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006572 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006573 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006575 status = decode_putfh(xdr);
6576 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006577 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006578 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006579out:
6580 return status;
6581}
6582
6583/*
6584 * Decode RENEW response
6585 */
Chuck Leverbf269552010-12-14 14:59:29 +00006586static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6587 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006588{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006589 struct compound_hdr hdr;
6590 int status;
6591
Chuck Leverbf269552010-12-14 14:59:29 +00006592 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006594 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595 return status;
6596}
6597
6598/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006599 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006600 */
Chuck Leverbf269552010-12-14 14:59:29 +00006601static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6602 struct xdr_stream *xdr,
6603 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006604{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006605 struct compound_hdr hdr;
6606 int status;
6607
Chuck Leverbf269552010-12-14 14:59:29 +00006608 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006609 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006610 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006611 return status;
6612}
6613
6614/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006615 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006616 */
Chuck Leverbf269552010-12-14 14:59:29 +00006617static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6618 struct xdr_stream *xdr,
6619 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006620{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006621 struct compound_hdr hdr;
6622 int status;
6623
Chuck Leverbf269552010-12-14 14:59:29 +00006624 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006625 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006626 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006627 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006628 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006630 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631 return status;
6632}
6633
6634/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006635 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636 */
Chuck Leverbf269552010-12-14 14:59:29 +00006637static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6638 struct xdr_stream *xdr,
6639 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006641 struct compound_hdr hdr;
6642 int status;
6643
Chuck Leverbf269552010-12-14 14:59:29 +00006644 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006645 if (status)
6646 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006647 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006648 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006649 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006650 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006651 if (status != 0)
6652 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006653 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006654 if (status != 0)
6655 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006656 decode_getfattr(xdr, res->fattr, res->server);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006657out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006658 return status;
6659}
6660
Trond Myklebust683b57b2006-06-09 09:34:22 -04006661/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006662 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006663 */
Chuck Leverbf269552010-12-14 14:59:29 +00006664static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6665 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006666 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006667{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006668 struct compound_hdr hdr;
6669 int status;
6670
Chuck Leverbf269552010-12-14 14:59:29 +00006671 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006672 if (status)
6673 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006674 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006675 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006676 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006677 status = decode_putfh(xdr);
6678 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006679 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006680 status = decode_lookup(xdr);
6681 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006682 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006683 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006684 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6685 NULL, res->fs_locations,
6686 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006687out:
6688 return status;
6689}
6690
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006691/*
6692 * Decode SECINFO response
6693 */
6694static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6695 struct xdr_stream *xdr,
6696 struct nfs4_secinfo_res *res)
6697{
6698 struct compound_hdr hdr;
6699 int status;
6700
6701 status = decode_compound_hdr(xdr, &hdr);
6702 if (status)
6703 goto out;
6704 status = decode_sequence(xdr, &res->seq_res, rqstp);
6705 if (status)
6706 goto out;
6707 status = decode_putfh(xdr);
6708 if (status)
6709 goto out;
6710 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006711out:
6712 return status;
6713}
6714
Benny Halevy99fe60d2009-04-01 09:22:29 -04006715#if defined(CONFIG_NFS_V4_1)
6716/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006717 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006718 */
Chuck Leverbf269552010-12-14 14:59:29 +00006719static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6720 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006721 void *res)
6722{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006723 struct compound_hdr hdr;
6724 int status;
6725
Chuck Leverbf269552010-12-14 14:59:29 +00006726 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006727 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006728 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006729 return status;
6730}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006731
6732/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006733 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006734 */
Chuck Leverbf269552010-12-14 14:59:29 +00006735static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6736 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006737 struct nfs41_create_session_res *res)
6738{
Andy Adamsonfc931582009-04-01 09:22:31 -04006739 struct compound_hdr hdr;
6740 int status;
6741
Chuck Leverbf269552010-12-14 14:59:29 +00006742 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006743 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006744 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006745 return status;
6746}
6747
6748/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006749 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006750 */
Chuck Leverbf269552010-12-14 14:59:29 +00006751static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6752 struct xdr_stream *xdr,
6753 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006754{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006755 struct compound_hdr hdr;
6756 int status;
6757
Chuck Leverbf269552010-12-14 14:59:29 +00006758 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006759 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006760 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006761 return status;
6762}
6763
6764/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006765 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006766 */
Chuck Leverbf269552010-12-14 14:59:29 +00006767static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6768 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006769 struct nfs4_sequence_res *res)
6770{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006771 struct compound_hdr hdr;
6772 int status;
6773
Chuck Leverbf269552010-12-14 14:59:29 +00006774 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006775 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006776 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006777 return status;
6778}
6779
6780/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006781 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006782 */
Chuck Leverbf269552010-12-14 14:59:29 +00006783static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6784 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006785 struct nfs4_get_lease_time_res *res)
6786{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006787 struct compound_hdr hdr;
6788 int status;
6789
Chuck Leverbf269552010-12-14 14:59:29 +00006790 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006791 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006792 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006793 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006794 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006795 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006796 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006797 return status;
6798}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006799
6800/*
6801 * Decode RECLAIM_COMPLETE response
6802 */
Chuck Leverbf269552010-12-14 14:59:29 +00006803static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6804 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006805 struct nfs41_reclaim_complete_res *res)
6806{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006807 struct compound_hdr hdr;
6808 int status;
6809
Chuck Leverbf269552010-12-14 14:59:29 +00006810 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006811 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006812 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006813 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006814 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006815 return status;
6816}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006817
6818/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006819 * Decode GETDEVICELIST response
6820 */
6821static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6822 struct xdr_stream *xdr,
6823 struct nfs4_getdevicelist_res *res)
6824{
6825 struct compound_hdr hdr;
6826 int status;
6827
6828 dprintk("encoding getdevicelist!\n");
6829
6830 status = decode_compound_hdr(xdr, &hdr);
6831 if (status != 0)
6832 goto out;
6833 status = decode_sequence(xdr, &res->seq_res, rqstp);
6834 if (status != 0)
6835 goto out;
6836 status = decode_putfh(xdr);
6837 if (status != 0)
6838 goto out;
6839 status = decode_getdevicelist(xdr, res->devlist);
6840out:
6841 return status;
6842}
6843
6844/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006845 * Decode GETDEVINFO response
6846 */
Chuck Leverbf269552010-12-14 14:59:29 +00006847static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6848 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006849 struct nfs4_getdeviceinfo_res *res)
6850{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006851 struct compound_hdr hdr;
6852 int status;
6853
Chuck Leverbf269552010-12-14 14:59:29 +00006854 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006855 if (status != 0)
6856 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006857 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006858 if (status != 0)
6859 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006860 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006861out:
6862 return status;
6863}
6864
6865/*
6866 * Decode LAYOUTGET response
6867 */
Chuck Leverbf269552010-12-14 14:59:29 +00006868static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6869 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006870 struct nfs4_layoutget_res *res)
6871{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006872 struct compound_hdr hdr;
6873 int status;
6874
Chuck Leverbf269552010-12-14 14:59:29 +00006875 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006876 if (status)
6877 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006878 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006879 if (status)
6880 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006881 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006882 if (status)
6883 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006884 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006885out:
6886 return status;
6887}
Andy Adamson863a3c62011-03-23 13:27:54 +00006888
6889/*
Benny Halevycbe82602011-05-22 19:52:37 +03006890 * Decode LAYOUTRETURN response
6891 */
6892static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6893 struct xdr_stream *xdr,
6894 struct nfs4_layoutreturn_res *res)
6895{
6896 struct compound_hdr hdr;
6897 int status;
6898
6899 status = decode_compound_hdr(xdr, &hdr);
6900 if (status)
6901 goto out;
6902 status = decode_sequence(xdr, &res->seq_res, rqstp);
6903 if (status)
6904 goto out;
6905 status = decode_putfh(xdr);
6906 if (status)
6907 goto out;
6908 status = decode_layoutreturn(xdr, res);
6909out:
6910 return status;
6911}
6912
6913/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006914 * Decode LAYOUTCOMMIT response
6915 */
6916static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6917 struct xdr_stream *xdr,
6918 struct nfs4_layoutcommit_res *res)
6919{
6920 struct compound_hdr hdr;
6921 int status;
6922
6923 status = decode_compound_hdr(xdr, &hdr);
6924 if (status)
6925 goto out;
6926 status = decode_sequence(xdr, &res->seq_res, rqstp);
6927 if (status)
6928 goto out;
6929 status = decode_putfh(xdr);
6930 if (status)
6931 goto out;
6932 status = decode_layoutcommit(xdr, rqstp, res);
6933 if (status)
6934 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006935 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006936out:
6937 return status;
6938}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006939
6940/*
6941 * Decode SECINFO_NO_NAME response
6942 */
6943static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6944 struct xdr_stream *xdr,
6945 struct nfs4_secinfo_res *res)
6946{
6947 struct compound_hdr hdr;
6948 int status;
6949
6950 status = decode_compound_hdr(xdr, &hdr);
6951 if (status)
6952 goto out;
6953 status = decode_sequence(xdr, &res->seq_res, rqstp);
6954 if (status)
6955 goto out;
6956 status = decode_putrootfh(xdr);
6957 if (status)
6958 goto out;
6959 status = decode_secinfo(xdr, res);
6960out:
6961 return status;
6962}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006963
6964/*
6965 * Decode TEST_STATEID response
6966 */
6967static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6968 struct xdr_stream *xdr,
6969 struct nfs41_test_stateid_res *res)
6970{
6971 struct compound_hdr hdr;
6972 int status;
6973
6974 status = decode_compound_hdr(xdr, &hdr);
6975 if (status)
6976 goto out;
6977 status = decode_sequence(xdr, &res->seq_res, rqstp);
6978 if (status)
6979 goto out;
6980 status = decode_test_stateid(xdr, res);
6981out:
6982 return status;
6983}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006984
6985/*
6986 * Decode FREE_STATEID response
6987 */
6988static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6989 struct xdr_stream *xdr,
6990 struct nfs41_free_stateid_res *res)
6991{
6992 struct compound_hdr hdr;
6993 int status;
6994
6995 status = decode_compound_hdr(xdr, &hdr);
6996 if (status)
6997 goto out;
6998 status = decode_sequence(xdr, &res->seq_res, rqstp);
6999 if (status)
7000 goto out;
7001 status = decode_free_stateid(xdr, res);
7002out:
7003 return status;
7004}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007005#endif /* CONFIG_NFS_V4_1 */
7006
Chuck Lever573c4e12010-12-14 14:58:11 +00007007/**
7008 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7009 * the local page cache.
7010 * @xdr: XDR stream where entry resides
7011 * @entry: buffer to fill in with entry data
7012 * @plus: boolean indicating whether this should be a readdirplus entry
7013 *
7014 * Returns zero if successful, otherwise a negative errno value is
7015 * returned.
7016 *
7017 * This function is not invoked during READDIR reply decoding, but
7018 * rather whenever an application invokes the getdents(2) system call
7019 * on a directory already in our cache.
7020 */
7021int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7022 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007023{
Fred Isamandae100c2011-07-30 20:52:37 -04007024 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007025 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007026 __be32 *p = xdr_inline_decode(xdr, 4);
7027 if (unlikely(!p))
7028 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007029 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007030 p = xdr_inline_decode(xdr, 4);
7031 if (unlikely(!p))
7032 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007033 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007034 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007035 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007036 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007037 }
7038
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007039 p = xdr_inline_decode(xdr, 12);
7040 if (unlikely(!p))
7041 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007042 entry->prev_cookie = entry->cookie;
7043 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007044 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007045
Trond Myklebust9af8c222010-10-24 11:52:55 -04007046 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007047 if (unlikely(!p))
7048 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007049 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007050
7051 /*
7052 * In case the server doesn't return an inode number,
7053 * we fake one here. (We don't use inode number 0,
7054 * since glibc seems to choke on it...)
7055 */
7056 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007057 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007058
Trond Myklebust9af8c222010-10-24 11:52:55 -04007059 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007060 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007061
7062 if (decode_attr_length(xdr, &len, &p) < 0)
7063 goto out_overflow;
7064
Chuck Lever573c4e12010-12-14 14:58:11 +00007065 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007066 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007067 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007068 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7069 entry->ino = entry->fattr->mounted_on_fileid;
7070 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007071 entry->ino = entry->fattr->fileid;
7072
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007073 entry->d_type = DT_UNKNOWN;
7074 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7075 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7076
Chuck Lever573c4e12010-12-14 14:58:11 +00007077 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007078
7079out_overflow:
7080 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007081 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007082}
7083
7084/*
7085 * We need to translate between nfs status return values and
7086 * the local errno values which may not be the same.
7087 */
7088static struct {
7089 int stat;
7090 int errno;
7091} nfs_errtbl[] = {
7092 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007093 { NFS4ERR_PERM, -EPERM },
7094 { NFS4ERR_NOENT, -ENOENT },
7095 { NFS4ERR_IO, -errno_NFSERR_IO},
7096 { NFS4ERR_NXIO, -ENXIO },
7097 { NFS4ERR_ACCESS, -EACCES },
7098 { NFS4ERR_EXIST, -EEXIST },
7099 { NFS4ERR_XDEV, -EXDEV },
7100 { NFS4ERR_NOTDIR, -ENOTDIR },
7101 { NFS4ERR_ISDIR, -EISDIR },
7102 { NFS4ERR_INVAL, -EINVAL },
7103 { NFS4ERR_FBIG, -EFBIG },
7104 { NFS4ERR_NOSPC, -ENOSPC },
7105 { NFS4ERR_ROFS, -EROFS },
7106 { NFS4ERR_MLINK, -EMLINK },
7107 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7108 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7109 { NFS4ERR_DQUOT, -EDQUOT },
7110 { NFS4ERR_STALE, -ESTALE },
7111 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007112 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7113 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7114 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007115 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007116 { NFS4ERR_BADTYPE, -EBADTYPE },
7117 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007118 { NFS4ERR_SYMLINK, -ELOOP },
7119 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7120 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007121 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007122};
7123
7124/*
7125 * Convert an NFS error code to a local one.
7126 * This one is used jointly by NFSv2 and NFSv3.
7127 */
7128static int
David Howells0a8ea432006-08-22 20:06:08 -04007129nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007130{
7131 int i;
7132 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7133 if (nfs_errtbl[i].stat == stat)
7134 return nfs_errtbl[i].errno;
7135 }
7136 if (stat <= 10000 || stat > 10100) {
7137 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007138 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007139 }
7140 /* If we cannot translate the error, the recovery routines should
7141 * handle it.
7142 * Note: remaining NFSv4 error codes have values > 10000, so should
7143 * not conflict with native Linux error codes.
7144 */
Benny Halevy856dff32008-03-31 17:39:06 +03007145 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007146}
7147
Linus Torvalds1da177e2005-04-16 15:20:36 -07007148#define PROC(proc, argtype, restype) \
7149[NFSPROC4_CLNT_##proc] = { \
7150 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007151 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007152 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007153 .p_arglen = NFS4_##argtype##_sz, \
7154 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007155 .p_statidx = NFSPROC4_CLNT_##proc, \
7156 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007157}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007158
7159struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007160 PROC(READ, enc_read, dec_read),
7161 PROC(WRITE, enc_write, dec_write),
7162 PROC(COMMIT, enc_commit, dec_commit),
7163 PROC(OPEN, enc_open, dec_open),
7164 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7165 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7166 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7167 PROC(CLOSE, enc_close, dec_close),
7168 PROC(SETATTR, enc_setattr, dec_setattr),
7169 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7170 PROC(RENEW, enc_renew, dec_renew),
7171 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7172 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7173 PROC(LOCK, enc_lock, dec_lock),
7174 PROC(LOCKT, enc_lockt, dec_lockt),
7175 PROC(LOCKU, enc_locku, dec_locku),
7176 PROC(ACCESS, enc_access, dec_access),
7177 PROC(GETATTR, enc_getattr, dec_getattr),
7178 PROC(LOOKUP, enc_lookup, dec_lookup),
7179 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7180 PROC(REMOVE, enc_remove, dec_remove),
7181 PROC(RENAME, enc_rename, dec_rename),
7182 PROC(LINK, enc_link, dec_link),
7183 PROC(SYMLINK, enc_symlink, dec_symlink),
7184 PROC(CREATE, enc_create, dec_create),
7185 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7186 PROC(STATFS, enc_statfs, dec_statfs),
7187 PROC(READLINK, enc_readlink, dec_readlink),
7188 PROC(READDIR, enc_readdir, dec_readdir),
7189 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7190 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7191 PROC(GETACL, enc_getacl, dec_getacl),
7192 PROC(SETACL, enc_setacl, dec_setacl),
7193 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7194 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007195 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007196#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007197 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7198 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7199 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7200 PROC(SEQUENCE, enc_sequence, dec_sequence),
7201 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7202 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7203 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7204 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007205 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007206 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007207 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007208 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007209 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007210 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007211#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007212};
7213
Trond Myklebusta613fa12012-01-20 13:53:56 -05007214const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007215 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007216 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007217 .procs = nfs4_procedures
7218};
7219
7220/*
7221 * Local variables:
7222 * c-basic-offset: 8
7223 * End:
7224 */