blob: 8cf722f2e2ebc892f555bf85822a040c250f88df [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
55#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000056#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050057#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040058#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#define NFSDBG_FACILITY NFSDBG_XDR
61
62/* Mapping from NFS error code to "errno" error code. */
63#define errno_NFSERR_IO EIO
64
David Howells0a8ea432006-08-22 20:06:08 -040065static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
68#ifdef DEBUG
69#define NFS4_MAXTAGLEN 20
70#else
71#define NFS4_MAXTAGLEN 0
72#endif
73
Andy Adamson6c0195a2008-12-23 16:06:15 -050074/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040075 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040077#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050078#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040079#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
81#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
82#define op_encode_hdr_maxsz (1)
83#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040084#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
85#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
86#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
87#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
89 (NFS4_FHSIZE >> 2))
90#define decode_putfh_maxsz (op_decode_hdr_maxsz)
91#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
92#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
93#define encode_getfh_maxsz (op_encode_hdr_maxsz)
94#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
95 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040096#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000097#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
99#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400100#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
101#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000102/* This is based on getfattr, which uses the most attributes: */
103#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400104 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000105#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
106 nfs4_fattr_value_maxsz)
107#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400108#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 1 + 2 + 1 + \
110 nfs4_owner_maxsz + \
111 nfs4_group_maxsz + \
112 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define encode_savefh_maxsz (op_encode_hdr_maxsz)
114#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400115#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
116#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200117#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400118/* The 5 accounts for the PNFS attributes, and assumes that at most three
119 * layout types will be returned.
120 */
121#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
122 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
124#define decode_renew_maxsz (op_decode_hdr_maxsz)
125#define encode_setclientid_maxsz \
126 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500127 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
128 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
129 1 /* sc_prog */ + \
130 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
131 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
132 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#define decode_setclientid_maxsz \
134 (op_decode_hdr_maxsz + \
135 2 + \
136 1024) /* large value for CLID_INUSE */
137#define encode_setclientid_confirm_maxsz \
138 (op_encode_hdr_maxsz + \
139 3 + (NFS4_VERIFIER_SIZE >> 2))
140#define decode_setclientid_confirm_maxsz \
141 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400142#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
143#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400144#define encode_share_access_maxsz \
145 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500146#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400147#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
148#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
149#define encode_open_maxsz (op_encode_hdr_maxsz + \
150 2 + encode_share_access_maxsz + 2 + \
151 open_owner_id_maxsz + \
152 encode_opentype_maxsz + \
153 encode_claim_null_maxsz)
154#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400155#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400156 decode_ace_maxsz)
157#define decode_change_info_maxsz (5)
158#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400159 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400160 decode_change_info_maxsz + 1 + \
161 nfs4_fattr_bitmap_maxsz + \
162 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400163#define encode_open_confirm_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1)
166#define decode_open_confirm_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169#define encode_open_downgrade_maxsz \
170 (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + 1 + \
172 encode_share_access_maxsz)
173#define decode_open_downgrade_maxsz \
174 (op_decode_hdr_maxsz + \
175 decode_stateid_maxsz)
176#define encode_close_maxsz (op_encode_hdr_maxsz + \
177 1 + encode_stateid_maxsz)
178#define decode_close_maxsz (op_decode_hdr_maxsz + \
179 decode_stateid_maxsz)
180#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
181 encode_stateid_maxsz + \
182 encode_attrs_maxsz)
183#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
184 nfs4_fattr_bitmap_maxsz)
185#define encode_read_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + 3)
187#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
188#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
189 2 + encode_verifier_maxsz + 5)
190#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
191 decode_verifier_maxsz)
192#define encode_readlink_maxsz (op_encode_hdr_maxsz)
193#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
194#define encode_write_maxsz (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + 4)
196#define decode_write_maxsz (op_decode_hdr_maxsz + \
197 2 + decode_verifier_maxsz)
198#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
199#define decode_commit_maxsz (op_decode_hdr_maxsz + \
200 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201#define encode_remove_maxsz (op_encode_hdr_maxsz + \
202 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400203#define decode_remove_maxsz (op_decode_hdr_maxsz + \
204 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#define encode_rename_maxsz (op_encode_hdr_maxsz + \
206 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400207#define decode_rename_maxsz (op_decode_hdr_maxsz + \
208 decode_change_info_maxsz + \
209 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#define encode_link_maxsz (op_encode_hdr_maxsz + \
211 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400212#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400213#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400214#define encode_lock_maxsz (op_encode_hdr_maxsz + \
215 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400216 1 + encode_stateid_maxsz + 1 + \
217 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400218#define decode_lock_denied_maxsz \
219 (8 + decode_lockowner_maxsz)
220#define decode_lock_maxsz (op_decode_hdr_maxsz + \
221 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400222#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
223 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400224#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
225 decode_lock_denied_maxsz)
226#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
227 encode_stateid_maxsz + \
228 4)
229#define decode_locku_maxsz (op_decode_hdr_maxsz + \
230 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400231#define encode_release_lockowner_maxsz \
232 (op_encode_hdr_maxsz + \
233 encode_lockowner_maxsz)
234#define decode_release_lockowner_maxsz \
235 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400236#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
237#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
239 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400240 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000241 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
243#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400244 1 + 2 + nfs4_name_maxsz + \
245 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400246#define decode_create_maxsz (op_decode_hdr_maxsz + \
247 decode_change_info_maxsz + \
248 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400249#define encode_statfs_maxsz (encode_getattr_maxsz)
250#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
252#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400253#define encode_getacl_maxsz (encode_getattr_maxsz)
254#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
255 nfs4_fattr_bitmap_maxsz + 1)
256#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
257 encode_stateid_maxsz + 3)
258#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400259#define encode_fs_locations_maxsz \
260 (encode_getattr_maxsz)
261#define decode_fs_locations_maxsz \
262 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000263#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400264#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400265
266#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400267#define NFS4_MAX_MACHINE_NAME_LEN (64)
268
Benny Halevy99fe60d2009-04-01 09:22:29 -0400269#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
270 encode_verifier_maxsz + \
271 1 /* co_ownerid.len */ + \
272 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
273 1 /* flags */ + \
274 1 /* spa_how */ + \
275 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500276 1 /* implementation id array of size 1 */ + \
277 1 /* nii_domain */ + \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
279 1 /* nii_name */ + \
280 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
281 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400282#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
283 2 /* eir_clientid */ + \
284 1 /* eir_sequenceid */ + \
285 1 /* eir_flags */ + \
286 1 /* spr_how */ + \
287 0 /* SP4_NONE (for now) */ + \
288 2 /* eir_server_owner.so_minor_id */ + \
289 /* eir_server_owner.so_major_id<> */ \
290 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
291 /* eir_server_scope<> */ \
292 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
293 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500294 1 /* nii_domain */ + \
295 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
296 1 /* nii_name */ + \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
298 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400299#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
300#define decode_channel_attrs_maxsz (6 + \
301 1 /* ca_rdma_ird.len */ + \
302 1 /* ca_rdma_ird */)
303#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
304 2 /* csa_clientid */ + \
305 1 /* csa_sequence */ + \
306 1 /* csa_flags */ + \
307 encode_channel_attrs_maxsz + \
308 encode_channel_attrs_maxsz + \
309 1 /* csa_cb_program */ + \
310 1 /* csa_sec_parms.len (1) */ + \
311 1 /* cb_secflavor (AUTH_SYS) */ + \
312 1 /* stamp */ + \
313 1 /* machinename.len */ + \
314 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
315 1 /* uid */ + \
316 1 /* gid */ + \
317 1 /* gids.len (0) */)
318#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
319 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
320 1 /* csr_sequence */ + \
321 1 /* csr_flags */ + \
322 decode_channel_attrs_maxsz + \
323 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400324#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
325#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400326#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
327 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
328#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
329 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga18019752009-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 Labiaga18019752009-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
Trond Myklebustcb17e552012-03-04 18:13:56 -0500888static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
889{
890 __be32 *p;
891
892 p = xdr_reserve_space(xdr, len);
893 xdr_encode_opaque_fixed(p, buf, len);
894}
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
897{
Al Viro8687b632006-10-19 23:28:48 -0700898 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500900 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 xdr_encode_opaque(p, str, len);
902}
903
Trond Myklebust4ade9822012-03-04 18:13:57 -0500904static void encode_uint32(struct xdr_stream *xdr, u32 n)
905{
906 __be32 *p;
907
908 p = reserve_space(xdr, 4);
909 *p = cpu_to_be32(n);
910}
911
Trond Myklebustff2eb682012-03-05 11:40:12 -0500912static void encode_uint64(struct xdr_stream *xdr, u64 n)
913{
914 __be32 *p;
915
916 p = reserve_space(xdr, 8);
917 xdr_encode_hyper(p, n);
918}
919
Trond Myklebust4ade9822012-03-04 18:13:57 -0500920static void encode_nfs4_seqid(struct xdr_stream *xdr,
921 const struct nfs_seqid *seqid)
922{
923 encode_uint32(xdr, seqid->sequence->counter);
924}
925
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400926static void encode_compound_hdr(struct xdr_stream *xdr,
927 struct rpc_rqst *req,
928 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929{
Al Viro8687b632006-10-19 23:28:48 -0700930 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400931 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400932
933 /* initialize running count of expected bytes in reply.
934 * NOTE: the replied tag SHOULD be the same is the one sent,
935 * but this is not required as a MUST for the server to do so. */
936 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500939 encode_string(xdr, hdr->taglen, hdr->tag);
940 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300941 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500942 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300943 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500944}
945
Trond Myklebustab19b482012-03-04 18:13:57 -0500946static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
947 uint32_t replen,
948 struct compound_hdr *hdr)
949{
950 encode_uint32(xdr, op);
951 hdr->nops++;
952 hdr->replen += replen;
953}
954
Andy Adamsond0179312008-12-23 16:06:17 -0500955static void encode_nops(struct compound_hdr *hdr)
956{
Andy Adamsonfc931582009-04-01 09:22:31 -0400957 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500958 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959}
960
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500961static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
962{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500963 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500964}
965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
967{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500968 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969}
970
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500971static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972{
973 char owner_name[IDMAP_NAMESZ];
974 char owner_group[IDMAP_NAMESZ];
975 int owner_namelen = 0;
976 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700977 __be32 *p;
978 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 int len;
980 uint32_t bmval0 = 0;
981 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983 /*
984 * We reserve enough space to write the entire attribute buffer at once.
985 * In the worst-case, this would be
986 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
987 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000988 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 */
990 len = 16;
991
992 /* Sigh */
993 if (iap->ia_valid & ATTR_SIZE)
994 len += 8;
995 if (iap->ia_valid & ATTR_MODE)
996 len += 4;
997 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800998 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001000 dprintk("nfs: couldn't resolve uid %d to string\n",
1001 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 /* XXX */
1003 strcpy(owner_name, "nobody");
1004 owner_namelen = sizeof("nobody") - 1;
1005 /* goto out; */
1006 }
1007 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1008 }
1009 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001010 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001012 dprintk("nfs: couldn't resolve gid %d to string\n",
1013 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 strcpy(owner_group, "nobody");
1015 owner_grouplen = sizeof("nobody") - 1;
1016 /* goto out; */
1017 }
1018 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1019 }
1020 if (iap->ia_valid & ATTR_ATIME_SET)
1021 len += 16;
1022 else if (iap->ia_valid & ATTR_ATIME)
1023 len += 4;
1024 if (iap->ia_valid & ATTR_MTIME_SET)
1025 len += 16;
1026 else if (iap->ia_valid & ATTR_MTIME)
1027 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001028 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
1030 /*
1031 * We write the bitmap length now, but leave the bitmap and the attribute
1032 * buffer length to be backfilled at the end of this routine.
1033 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001034 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 q = p;
1036 p += 3;
1037
1038 if (iap->ia_valid & ATTR_SIZE) {
1039 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001040 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 }
1042 if (iap->ia_valid & ATTR_MODE) {
1043 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001044 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 }
1046 if (iap->ia_valid & ATTR_UID) {
1047 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001048 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 }
1050 if (iap->ia_valid & ATTR_GID) {
1051 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001052 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
1054 if (iap->ia_valid & ATTR_ATIME_SET) {
1055 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001056 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1057 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001058 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1059 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 }
1061 else if (iap->ia_valid & ATTR_ATIME) {
1062 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001063 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 }
1065 if (iap->ia_valid & ATTR_MTIME_SET) {
1066 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001067 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1068 *p++ = cpu_to_be32(0);
1069 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1070 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 }
1072 else if (iap->ia_valid & ATTR_MTIME) {
1073 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001074 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001076
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 /*
1078 * Now we backfill the bitmap and the attribute buffer length.
1079 */
1080 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001081 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 len, ((char *)p - (char *)q) + 4);
1083 BUG();
1084 }
1085 len = (char *)p - (char *)q - 12;
1086 *q++ = htonl(bmval0);
1087 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001088 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091}
1092
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001093static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001095 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1096 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097}
1098
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001099static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100{
Trond Myklebustab19b482012-03-04 18:13:57 -05001101 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001102 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001103 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104}
1105
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001106static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107{
Al Viro8687b632006-10-19 23:28:48 -07001108 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001109
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001110 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1111 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001112 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001113 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114}
1115
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001116static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117{
Al Viro8687b632006-10-19 23:28:48 -07001118 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001119
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001120 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1121 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
1123 switch (create->ftype) {
1124 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001125 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001126 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001127 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 break;
1129
1130 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001131 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001132 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001133 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 break;
1135
1136 default:
1137 break;
1138 }
1139
Benny Halevy811652b2009-08-14 17:19:34 +03001140 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001141 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
1143
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001144static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
Andy Adamson05d564f2008-12-23 16:06:15 -05001146 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001148 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1149 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001150 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001151 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152}
1153
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001154static 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 -07001155{
Andy Adamson05d564f2008-12-23 16:06:15 -05001156 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001158 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1159 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001160 *p++ = cpu_to_be32(2);
1161 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001162 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163}
1164
Fred Isamandae100c2011-07-30 20:52:37 -04001165static void
1166encode_getattr_three(struct xdr_stream *xdr,
1167 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1168 struct compound_hdr *hdr)
1169{
1170 __be32 *p;
1171
Trond Myklebustab19b482012-03-04 18:13:57 -05001172 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001173 if (bm2) {
1174 p = reserve_space(xdr, 16);
1175 *p++ = cpu_to_be32(3);
1176 *p++ = cpu_to_be32(bm0);
1177 *p++ = cpu_to_be32(bm1);
1178 *p = cpu_to_be32(bm2);
1179 } else if (bm1) {
1180 p = reserve_space(xdr, 12);
1181 *p++ = cpu_to_be32(2);
1182 *p++ = cpu_to_be32(bm0);
1183 *p = cpu_to_be32(bm1);
1184 } else {
1185 p = reserve_space(xdr, 8);
1186 *p++ = cpu_to_be32(1);
1187 *p = cpu_to_be32(bm0);
1188 }
Fred Isamandae100c2011-07-30 20:52:37 -04001189}
1190
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001191static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001193 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1194 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195}
1196
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001197static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198{
Fred Isamandae100c2011-07-30 20:52:37 -04001199 encode_getattr_three(xdr,
1200 bitmask[0] & nfs4_fsinfo_bitmap[0],
1201 bitmask[1] & nfs4_fsinfo_bitmap[1],
1202 bitmask[2] & nfs4_fsinfo_bitmap[2],
1203 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204}
1205
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001206static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001207{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001208 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1209 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001210}
1211
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001212static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
Trond Myklebustab19b482012-03-04 18:13:57 -05001214 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215}
1216
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001217static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218{
Trond Myklebustab19b482012-03-04 18:13:57 -05001219 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001220 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221}
1222
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001223static inline int nfs4_lock_type(struct file_lock *fl, int block)
1224{
1225 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1226 return block ? NFS4_READW_LT : NFS4_READ_LT;
1227 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1228}
1229
1230static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1231{
1232 if (fl->fl_end == OFFSET_MAX)
1233 return ~(uint64_t)0;
1234 return fl->fl_end - fl->fl_start + 1;
1235}
1236
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001237static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1238{
1239 __be32 *p;
1240
Trond Myklebustd035c362010-12-21 10:45:27 -05001241 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001242 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001243 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001244 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001245 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001246 xdr_encode_hyper(p, lowner->id);
1247}
1248
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249/*
1250 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1251 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1252 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001253static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254{
Al Viro8687b632006-10-19 23:28:48 -07001255 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001257 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1258 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001259 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1260 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001261 p = xdr_encode_hyper(p, args->fl->fl_start);
1262 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001263 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001264 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001265 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001266 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001267 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001268 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 }
1270 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001271 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001272 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274}
1275
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001276static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277{
Al Viro8687b632006-10-19 23:28:48 -07001278 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001280 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1281 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001282 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001283 p = xdr_encode_hyper(p, args->fl->fl_start);
1284 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001285 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286}
1287
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001288static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
Al Viro8687b632006-10-19 23:28:48 -07001290 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001292 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1293 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001294 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001295 encode_nfs4_stateid(xdr, args->stateid);
1296 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001297 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001298 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299}
1300
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001301static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1302{
Trond Myklebustab19b482012-03-04 18:13:57 -05001303 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001304 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001305}
1306
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001307static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308{
Trond Myklebustab19b482012-03-04 18:13:57 -05001309 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001310 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311}
1312
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001313static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314{
Al Viro8687b632006-10-19 23:28:48 -07001315 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316
Benny Halevy13c65ce2009-08-14 17:19:25 +03001317 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001318 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001319 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001320 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001321 break;
1322 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001323 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001324 break;
1325 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001326 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001327 break;
1328 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001329 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 }
Benny Halevy34558512009-08-14 17:19:30 +03001331 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332}
1333
1334static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1335{
Al Viro8687b632006-10-19 23:28:48 -07001336 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 /*
1338 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1339 * owner 4 = 32
1340 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001341 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001342 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001343 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001344 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001345 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001346 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001347 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001348 *p++ = cpu_to_be32(arg->id.uniquifier);
1349 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350}
1351
1352static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1353{
Al Viro8687b632006-10-19 23:28:48 -07001354 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001355 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
Benny Halevy13c65ce2009-08-14 17:19:25 +03001357 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001359 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001360 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001361 encode_attrs(xdr, arg->u.attrs, arg->server);
1362 break;
1363 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001364 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001365 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001366 if (nfs4_has_persistent_session(clp)) {
1367 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1368 encode_attrs(xdr, arg->u.attrs, arg->server);
1369 } else {
1370 struct iattr dummy;
1371
1372 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1373 encode_nfs4_verifier(xdr, &arg->u.verifier);
1374 dummy.ia_valid = 0;
1375 encode_attrs(xdr, &dummy, arg->server);
1376 }
1377 } else {
1378 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1379 encode_nfs4_verifier(xdr, &arg->u.verifier);
1380 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 }
1382}
1383
1384static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1385{
Al Viro8687b632006-10-19 23:28:48 -07001386 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Benny Halevy13c65ce2009-08-14 17:19:25 +03001388 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001390 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001391 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001392 break;
1393 default:
1394 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001395 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001396 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 }
1398}
1399
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001400static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401{
Al Viro8687b632006-10-19 23:28:48 -07001402 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Benny Halevy13c65ce2009-08-14 17:19:25 +03001404 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001406 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001407 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001408 break;
1409 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001410 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001411 break;
1412 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001413 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001414 break;
1415 default:
1416 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 }
1418}
1419
1420static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1421{
Al Viro8687b632006-10-19 23:28:48 -07001422 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
Benny Halevy13c65ce2009-08-14 17:19:25 +03001424 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001425 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 encode_string(xdr, name->len, name->name);
1427}
1428
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001429static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430{
Al Viro8687b632006-10-19 23:28:48 -07001431 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
Benny Halevy13c65ce2009-08-14 17:19:25 +03001433 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001434 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 encode_delegation_type(xdr, type);
1436}
1437
1438static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1439{
Al Viro8687b632006-10-19 23:28:48 -07001440 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001442 p = reserve_space(xdr, 4);
1443 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1444 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 encode_string(xdr, name->len, name->name);
1446}
1447
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001448static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449{
Trond Myklebustab19b482012-03-04 18:13:57 -05001450 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 encode_openhdr(xdr, arg);
1452 encode_opentype(xdr, arg);
1453 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001454 case NFS4_OPEN_CLAIM_NULL:
1455 encode_claim_null(xdr, arg->name);
1456 break;
1457 case NFS4_OPEN_CLAIM_PREVIOUS:
1458 encode_claim_previous(xdr, arg->u.delegation_type);
1459 break;
1460 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1461 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1462 break;
1463 default:
1464 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466}
1467
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001468static 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 -07001469{
Trond Myklebustab19b482012-03-04 18:13:57 -05001470 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001471 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001472 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473}
1474
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001475static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476{
Trond Myklebustab19b482012-03-04 18:13:57 -05001477 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001478 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001479 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001480 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481}
1482
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001483static void
Andy Adamsond0179312008-12-23 16:06:17 -05001484encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485{
Trond Myklebustab19b482012-03-04 18:13:57 -05001486 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001487 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488}
1489
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001490static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491{
Trond Myklebustab19b482012-03-04 18:13:57 -05001492 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493}
1494
Trond Myklebust4fc87962012-03-08 17:42:01 -05001495static void encode_open_stateid(struct xdr_stream *xdr,
1496 const struct nfs_open_context *ctx,
1497 const struct nfs_lock_context *l_ctx,
1498 fmode_t fmode,
1499 int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 nfs4_stateid stateid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 if (ctx->state != NULL) {
Trond Myklebust4fc87962012-03-08 17:42:01 -05001504 nfs4_select_rw_stateid(&stateid, ctx->state,
1505 fmode, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001506 if (zero_seqid)
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001507 stateid.seqid = 0;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001508 encode_nfs4_stateid(xdr, &stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 } else
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001510 encode_nfs4_stateid(xdr, &zero_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511}
1512
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001513static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514{
Al Viro8687b632006-10-19 23:28:48 -07001515 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Trond Myklebustab19b482012-03-04 18:13:57 -05001517 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001518 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001519 FMODE_READ, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Benny Halevy13c65ce2009-08-14 17:19:25 +03001521 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001522 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001523 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524}
1525
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001526static 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 -07001527{
Trond Myklebust28331a42011-04-27 13:47:52 -04001528 uint32_t attrs[2] = {
1529 FATTR4_WORD0_RDATTR_ERROR,
1530 FATTR4_WORD1_MOUNTED_ON_FILEID,
1531 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001532 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001533 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001535 if (readdir->plus) {
1536 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001537 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001538 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1539 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1540 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1541 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001542 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001543 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001544 /* Use mounted_on_fileid only if the server supports it */
1545 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1546 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001547
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001548 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001549 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001550 encode_nfs4_verifier(xdr, &readdir->verifier);
1551 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001552 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001553 *p++ = cpu_to_be32(readdir->count);
1554 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001555
Benny Halevye75bc1c2009-08-14 17:18:54 +03001556 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001557 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Chuck Levercd937102012-03-02 17:14:31 -05001558 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001559 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1560 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001561 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001562 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001563 attrs[0] & readdir->bitmask[0],
1564 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565}
1566
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001567static 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 -07001568{
Trond Myklebustab19b482012-03-04 18:13:57 -05001569 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570}
1571
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001572static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573{
Trond Myklebustab19b482012-03-04 18:13:57 -05001574 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001575 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
1577
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001578static 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 -07001579{
Trond Myklebustab19b482012-03-04 18:13:57 -05001580 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001581 encode_string(xdr, oldname->len, oldname->name);
1582 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583}
1584
Chuck Leverbb4dae52012-03-01 17:01:48 -05001585static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1586 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001588 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001589 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590}
1591
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001592static void
Andy Adamsond0179312008-12-23 16:06:17 -05001593encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001594{
Trond Myklebustab19b482012-03-04 18:13:57 -05001595 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001596}
1597
Chuck Lever9f06c712010-12-14 14:59:18 +00001598static void
Andy Adamsond0179312008-12-23 16:06:17 -05001599encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001600{
Al Viro8687b632006-10-19 23:28:48 -07001601 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001602
Trond Myklebustab19b482012-03-04 18:13:57 -05001603 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001604 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001605 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001606 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001607 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001608 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001609 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001610 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001611 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001612}
1613
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001614static void
Andy Adamsond0179312008-12-23 16:06:17 -05001615encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616{
Trond Myklebustab19b482012-03-04 18:13:57 -05001617 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618}
1619
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001620static 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 -07001621{
Trond Myklebustab19b482012-03-04 18:13:57 -05001622 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001623 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001624 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625}
1626
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001627static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628{
Al Viro8687b632006-10-19 23:28:48 -07001629 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
Trond Myklebust70019512012-03-04 20:49:32 -05001631 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001632 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
1634 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001635 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001636 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1638 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001639 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001640 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641}
1642
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001643static 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 -07001644{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001645 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1646 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001647 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001648 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
1650
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001651static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652{
Al Viro8687b632006-10-19 23:28:48 -07001653 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
Trond Myklebustab19b482012-03-04 18:13:57 -05001655 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001656 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001657 FMODE_WRITE, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
Benny Halevy13c65ce2009-08-14 17:19:25 +03001659 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001660 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001661 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001662 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663
1664 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665}
1666
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001667static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668{
Trond Myklebustab19b482012-03-04 18:13:57 -05001669 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001670 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001672
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001673static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1674{
Trond Myklebustab19b482012-03-04 18:13:57 -05001675 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001676 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001677}
1678
Benny Halevy99fe60d2009-04-01 09:22:29 -04001679#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001680/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001681static void encode_exchange_id(struct xdr_stream *xdr,
1682 struct nfs41_exchange_id_args *args,
1683 struct compound_hdr *hdr)
1684{
1685 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001686 char impl_name[NFS4_OPAQUE_LIMIT];
1687 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001688
Trond Myklebust70019512012-03-04 20:49:32 -05001689 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001690 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001691
1692 encode_string(xdr, args->id_len, args->id);
1693
Benny Halevy13c65ce2009-08-14 17:19:25 +03001694 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001695 *p++ = cpu_to_be32(args->flags);
1696 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001697
1698 if (send_implementation_id &&
1699 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1700 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1701 <= NFS4_OPAQUE_LIMIT + 1)
1702 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1703 utsname()->sysname, utsname()->release,
1704 utsname()->version, utsname()->machine);
1705
1706 if (len > 0) {
1707 *p = cpu_to_be32(1); /* implementation id array length=1 */
1708
1709 encode_string(xdr,
1710 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1711 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1712 encode_string(xdr, len, impl_name);
1713 /* just send zeros for nii_date - the date is in nii_name */
1714 p = reserve_space(xdr, 12);
1715 p = xdr_encode_hyper(p, 0);
1716 *p = cpu_to_be32(0);
1717 } else
1718 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001719}
Andy Adamsonfc931582009-04-01 09:22:31 -04001720
1721static void encode_create_session(struct xdr_stream *xdr,
1722 struct nfs41_create_session_args *args,
1723 struct compound_hdr *hdr)
1724{
1725 __be32 *p;
1726 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1727 uint32_t len;
1728 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001729 u32 max_resp_sz_cached;
1730
1731 /*
1732 * Assumes OPEN is the biggest non-idempotent compound.
1733 * 2 is the verifier.
1734 */
1735 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1736 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001737
Andy Adamsonfc931582009-04-01 09:22:31 -04001738 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1739 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001740
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001741 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1742 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001743 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001744 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1745 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001746
Andy Adamsonfc931582009-04-01 09:22:31 -04001747 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001748 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001749 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1750 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001751 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001752 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1753 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1754 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001755
1756 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001757 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001758 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1759 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1760 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1761 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1762 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1763 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001764
Benny Halevye75bc1c2009-08-14 17:18:54 +03001765 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001766 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001767 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001768
1769 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001770 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001771 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001772 *p++ = cpu_to_be32(0); /* UID */
1773 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001774 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001775}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001776
1777static void encode_destroy_session(struct xdr_stream *xdr,
1778 struct nfs4_session *session,
1779 struct compound_hdr *hdr)
1780{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001781 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1782 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001783}
Ricardo Labiaga18019752009-12-05 16:08:40 -05001784
1785static void encode_reclaim_complete(struct xdr_stream *xdr,
1786 struct nfs41_reclaim_complete_args *args,
1787 struct compound_hdr *hdr)
1788{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001789 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1790 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga18019752009-12-05 16:08:40 -05001791}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001792#endif /* CONFIG_NFS_V4_1 */
1793
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001794static void encode_sequence(struct xdr_stream *xdr,
1795 const struct nfs4_sequence_args *args,
1796 struct compound_hdr *hdr)
1797{
1798#if defined(CONFIG_NFS_V4_1)
1799 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001800 struct nfs4_slot_table *tp;
1801 struct nfs4_slot *slot;
1802 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001803
1804 if (!session)
1805 return;
1806
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001807 tp = &session->fc_slot_table;
1808
1809 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1810 slot = tp->slots + args->sa_slotid;
1811
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001812 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001813
1814 /*
1815 * Sessionid + seqid + slotid + max slotid + cache_this
1816 */
1817 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1818 "max_slotid=%d cache_this=%d\n",
1819 __func__,
1820 ((u32 *)session->sess_id.data)[0],
1821 ((u32 *)session->sess_id.data)[1],
1822 ((u32 *)session->sess_id.data)[2],
1823 ((u32 *)session->sess_id.data)[3],
1824 slot->seq_nr, args->sa_slotid,
1825 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001826 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001827 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001828 *p++ = cpu_to_be32(slot->seq_nr);
1829 *p++ = cpu_to_be32(args->sa_slotid);
1830 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001831 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001832#endif /* CONFIG_NFS_V4_1 */
1833}
1834
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001835#ifdef CONFIG_NFS_V4_1
1836static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001837encode_getdevicelist(struct xdr_stream *xdr,
1838 const struct nfs4_getdevicelist_args *args,
1839 struct compound_hdr *hdr)
1840{
1841 __be32 *p;
1842 nfs4_verifier dummy = {
1843 .data = "dummmmmy",
1844 };
1845
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001846 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1847 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001848 *p++ = cpu_to_be32(args->layoutclass);
1849 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1850 xdr_encode_hyper(p, 0ULL); /* cookie */
1851 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001852}
1853
1854static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001855encode_getdeviceinfo(struct xdr_stream *xdr,
1856 const struct nfs4_getdeviceinfo_args *args,
1857 struct compound_hdr *hdr)
1858{
1859 __be32 *p;
1860
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001861 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1862 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001863 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1864 NFS4_DEVICEID4_SIZE);
1865 *p++ = cpu_to_be32(args->pdev->layout_type);
1866 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1867 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001868}
1869
1870static void
1871encode_layoutget(struct xdr_stream *xdr,
1872 const struct nfs4_layoutget_args *args,
1873 struct compound_hdr *hdr)
1874{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001875 __be32 *p;
1876
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001877 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1878 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001879 *p++ = cpu_to_be32(0); /* Signal layout available */
1880 *p++ = cpu_to_be32(args->type);
1881 *p++ = cpu_to_be32(args->range.iomode);
1882 p = xdr_encode_hyper(p, args->range.offset);
1883 p = xdr_encode_hyper(p, args->range.length);
1884 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001885 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001886 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001887
1888 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1889 __func__,
1890 args->type,
1891 args->range.iomode,
1892 (unsigned long)args->range.offset,
1893 (unsigned long)args->range.length,
1894 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001895}
Andy Adamson863a3c62011-03-23 13:27:54 +00001896
1897static int
1898encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001899 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001900 const struct nfs4_layoutcommit_args *args,
1901 struct compound_hdr *hdr)
1902{
1903 __be32 *p;
1904
1905 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1906 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1907
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001908 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1909 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001910 /* Only whole file layouts */
1911 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001912 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001913 *p = cpu_to_be32(0); /* reclaim */
1914 encode_nfs4_stateid(xdr, &args->stateid);
1915 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001916 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1917 p = xdr_encode_hyper(p, args->lastbytewritten);
1918 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1919 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001920
1921 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1922 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1923 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001924 else
1925 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001926
Andy Adamson863a3c62011-03-23 13:27:54 +00001927 return 0;
1928}
Benny Halevycbe82602011-05-22 19:52:37 +03001929
1930static void
1931encode_layoutreturn(struct xdr_stream *xdr,
1932 const struct nfs4_layoutreturn_args *args,
1933 struct compound_hdr *hdr)
1934{
1935 __be32 *p;
1936
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001937 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1938 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001939 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1940 *p++ = cpu_to_be32(args->layout_type);
1941 *p++ = cpu_to_be32(IOMODE_ANY);
1942 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001943 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001944 p = xdr_encode_hyper(p, 0);
1945 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1946 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001947 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001948 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001949 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1950 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1951 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001952 } else
1953 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03001954}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001955
1956static int
1957encode_secinfo_no_name(struct xdr_stream *xdr,
1958 const struct nfs41_secinfo_no_name_args *args,
1959 struct compound_hdr *hdr)
1960{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001961 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1962 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001963 return 0;
1964}
Bryan Schumaker7d974792011-06-02 14:59:08 -04001965
1966static void encode_test_stateid(struct xdr_stream *xdr,
1967 struct nfs41_test_stateid_args *args,
1968 struct compound_hdr *hdr)
1969{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001970 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
1971 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001972 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04001973}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001974
1975static void encode_free_stateid(struct xdr_stream *xdr,
1976 struct nfs41_free_stateid_args *args,
1977 struct compound_hdr *hdr)
1978{
Trond Myklebustab19b482012-03-04 18:13:57 -05001979 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001980 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001981}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001982#endif /* CONFIG_NFS_V4_1 */
1983
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984/*
1985 * END OF "GENERIC" ENCODE ROUTINES.
1986 */
1987
Benny Halevy66cc0422009-04-01 09:22:10 -04001988static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1989{
1990#if defined(CONFIG_NFS_V4_1)
1991 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001992 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001993#endif /* CONFIG_NFS_V4_1 */
1994 return 0;
1995}
1996
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997/*
1998 * Encode an ACCESS request
1999 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002000static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2001 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002004 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
Chuck Lever9f06c712010-12-14 14:59:18 +00002007 encode_compound_hdr(xdr, req, &hdr);
2008 encode_sequence(xdr, &args->seq_args, &hdr);
2009 encode_putfh(xdr, args->fh, &hdr);
2010 encode_access(xdr, args->access, &hdr);
2011 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002012 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013}
2014
2015/*
2016 * Encode LOOKUP request
2017 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002018static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2019 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002022 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
Chuck Lever9f06c712010-12-14 14:59:18 +00002025 encode_compound_hdr(xdr, req, &hdr);
2026 encode_sequence(xdr, &args->seq_args, &hdr);
2027 encode_putfh(xdr, args->dir_fh, &hdr);
2028 encode_lookup(xdr, args->name, &hdr);
2029 encode_getfh(xdr, &hdr);
2030 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002031 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032}
2033
2034/*
2035 * Encode LOOKUP_ROOT request
2036 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002037static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2038 struct xdr_stream *xdr,
2039 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002042 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044
Chuck Lever9f06c712010-12-14 14:59:18 +00002045 encode_compound_hdr(xdr, req, &hdr);
2046 encode_sequence(xdr, &args->seq_args, &hdr);
2047 encode_putrootfh(xdr, &hdr);
2048 encode_getfh(xdr, &hdr);
2049 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002050 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051}
2052
2053/*
2054 * Encode REMOVE request
2055 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002056static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2057 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002060 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
Chuck Lever9f06c712010-12-14 14:59:18 +00002063 encode_compound_hdr(xdr, req, &hdr);
2064 encode_sequence(xdr, &args->seq_args, &hdr);
2065 encode_putfh(xdr, args->fh, &hdr);
2066 encode_remove(xdr, &args->name, &hdr);
2067 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002068 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069}
2070
2071/*
2072 * Encode RENAME request
2073 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002074static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2075 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002078 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
Chuck Lever9f06c712010-12-14 14:59:18 +00002081 encode_compound_hdr(xdr, req, &hdr);
2082 encode_sequence(xdr, &args->seq_args, &hdr);
2083 encode_putfh(xdr, args->old_dir, &hdr);
2084 encode_savefh(xdr, &hdr);
2085 encode_putfh(xdr, args->new_dir, &hdr);
2086 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2087 encode_getfattr(xdr, args->bitmask, &hdr);
2088 encode_restorefh(xdr, &hdr);
2089 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002090 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091}
2092
2093/*
2094 * Encode LINK request
2095 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002096static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2097 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002100 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
Chuck Lever9f06c712010-12-14 14:59:18 +00002103 encode_compound_hdr(xdr, req, &hdr);
2104 encode_sequence(xdr, &args->seq_args, &hdr);
2105 encode_putfh(xdr, args->fh, &hdr);
2106 encode_savefh(xdr, &hdr);
2107 encode_putfh(xdr, args->dir_fh, &hdr);
2108 encode_link(xdr, args->name, &hdr);
2109 encode_getfattr(xdr, args->bitmask, &hdr);
2110 encode_restorefh(xdr, &hdr);
2111 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002112 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113}
2114
2115/*
2116 * Encode CREATE request
2117 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002118static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2119 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002122 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
Chuck Lever9f06c712010-12-14 14:59:18 +00002125 encode_compound_hdr(xdr, req, &hdr);
2126 encode_sequence(xdr, &args->seq_args, &hdr);
2127 encode_putfh(xdr, args->dir_fh, &hdr);
2128 encode_savefh(xdr, &hdr);
2129 encode_create(xdr, args, &hdr);
2130 encode_getfh(xdr, &hdr);
2131 encode_getfattr(xdr, args->bitmask, &hdr);
2132 encode_restorefh(xdr, &hdr);
2133 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002134 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135}
2136
2137/*
2138 * Encode SYMLINK request
2139 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002140static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2141 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142{
Chuck Lever9f06c712010-12-14 14:59:18 +00002143 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144}
2145
2146/*
2147 * Encode GETATTR request
2148 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002149static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2150 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002153 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
Chuck Lever9f06c712010-12-14 14:59:18 +00002156 encode_compound_hdr(xdr, req, &hdr);
2157 encode_sequence(xdr, &args->seq_args, &hdr);
2158 encode_putfh(xdr, args->fh, &hdr);
2159 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002160 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161}
2162
2163/*
2164 * Encode a CLOSE request
2165 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002166static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2167 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168{
Andy Adamson05d564f2008-12-23 16:06:15 -05002169 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002170 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002171 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
Chuck Lever9f06c712010-12-14 14:59:18 +00002173 encode_compound_hdr(xdr, req, &hdr);
2174 encode_sequence(xdr, &args->seq_args, &hdr);
2175 encode_putfh(xdr, args->fh, &hdr);
2176 encode_close(xdr, args, &hdr);
2177 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002178 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179}
2180
2181/*
2182 * Encode an OPEN request
2183 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002184static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2185 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002188 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190
Chuck Lever9f06c712010-12-14 14:59:18 +00002191 encode_compound_hdr(xdr, req, &hdr);
2192 encode_sequence(xdr, &args->seq_args, &hdr);
2193 encode_putfh(xdr, args->fh, &hdr);
2194 encode_savefh(xdr, &hdr);
2195 encode_open(xdr, args, &hdr);
2196 encode_getfh(xdr, &hdr);
2197 encode_getfattr(xdr, args->bitmask, &hdr);
2198 encode_restorefh(xdr, &hdr);
Trond Myklebust6926afd2012-01-07 13:22:46 -05002199 encode_getfattr(xdr, args->dir_bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002200 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201}
2202
2203/*
2204 * Encode an OPEN_CONFIRM request
2205 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002206static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2207 struct xdr_stream *xdr,
2208 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002211 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
Chuck Lever9f06c712010-12-14 14:59:18 +00002214 encode_compound_hdr(xdr, req, &hdr);
2215 encode_putfh(xdr, args->fh, &hdr);
2216 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002217 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218}
2219
2220/*
2221 * Encode an OPEN request with no attributes.
2222 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002223static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2224 struct xdr_stream *xdr,
2225 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002228 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
Chuck Lever9f06c712010-12-14 14:59:18 +00002231 encode_compound_hdr(xdr, req, &hdr);
2232 encode_sequence(xdr, &args->seq_args, &hdr);
2233 encode_putfh(xdr, args->fh, &hdr);
2234 encode_open(xdr, args, &hdr);
2235 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002236 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237}
2238
2239/*
2240 * Encode an OPEN_DOWNGRADE request
2241 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002242static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2243 struct xdr_stream *xdr,
2244 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002247 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249
Chuck Lever9f06c712010-12-14 14:59:18 +00002250 encode_compound_hdr(xdr, req, &hdr);
2251 encode_sequence(xdr, &args->seq_args, &hdr);
2252 encode_putfh(xdr, args->fh, &hdr);
2253 encode_open_downgrade(xdr, args, &hdr);
2254 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002255 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256}
2257
2258/*
2259 * Encode a LOCK request
2260 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002261static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2262 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002265 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
Chuck Lever9f06c712010-12-14 14:59:18 +00002268 encode_compound_hdr(xdr, req, &hdr);
2269 encode_sequence(xdr, &args->seq_args, &hdr);
2270 encode_putfh(xdr, args->fh, &hdr);
2271 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002272 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273}
2274
2275/*
2276 * Encode a LOCKT request
2277 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002278static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2279 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002282 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284
Chuck Lever9f06c712010-12-14 14:59:18 +00002285 encode_compound_hdr(xdr, req, &hdr);
2286 encode_sequence(xdr, &args->seq_args, &hdr);
2287 encode_putfh(xdr, args->fh, &hdr);
2288 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002289 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290}
2291
2292/*
2293 * Encode a LOCKU request
2294 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002295static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2296 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002299 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301
Chuck Lever9f06c712010-12-14 14:59:18 +00002302 encode_compound_hdr(xdr, req, &hdr);
2303 encode_sequence(xdr, &args->seq_args, &hdr);
2304 encode_putfh(xdr, args->fh, &hdr);
2305 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002306 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307}
2308
Chuck Lever9f06c712010-12-14 14:59:18 +00002309static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2310 struct xdr_stream *xdr,
2311 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002312{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002313 struct compound_hdr hdr = {
2314 .minorversion = 0,
2315 };
2316
Chuck Lever9f06c712010-12-14 14:59:18 +00002317 encode_compound_hdr(xdr, req, &hdr);
2318 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002319 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002320}
2321
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322/*
2323 * Encode a READLINK request
2324 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002325static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2326 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002329 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331
Chuck Lever9f06c712010-12-14 14:59:18 +00002332 encode_compound_hdr(xdr, req, &hdr);
2333 encode_sequence(xdr, &args->seq_args, &hdr);
2334 encode_putfh(xdr, args->fh, &hdr);
2335 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002336
Benny Halevy28f56692009-04-01 09:22:09 -04002337 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002338 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002339 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340}
2341
2342/*
2343 * Encode a READDIR request
2344 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002345static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2346 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002349 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351
Chuck Lever9f06c712010-12-14 14:59:18 +00002352 encode_compound_hdr(xdr, req, &hdr);
2353 encode_sequence(xdr, &args->seq_args, &hdr);
2354 encode_putfh(xdr, args->fh, &hdr);
2355 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002356
Benny Halevy28f56692009-04-01 09:22:09 -04002357 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002358 args->pgbase, args->count);
2359 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002360 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002361 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002362 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363}
2364
2365/*
2366 * Encode a READ request
2367 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002368static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2369 struct nfs_readargs *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_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379
Benny Halevy28f56692009-04-01 09:22:09 -04002380 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002382 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002383 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384}
2385
2386/*
2387 * Encode an SETATTR request
2388 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002389static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2390 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391{
Andy Adamson05d564f2008-12-23 16:06:15 -05002392 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002393 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002394 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395
Chuck Lever9f06c712010-12-14 14:59:18 +00002396 encode_compound_hdr(xdr, req, &hdr);
2397 encode_sequence(xdr, &args->seq_args, &hdr);
2398 encode_putfh(xdr, args->fh, &hdr);
2399 encode_setattr(xdr, args, args->server, &hdr);
2400 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002401 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402}
2403
2404/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002405 * Encode a GETACL request
2406 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002407static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2408 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002409{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002410 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002411 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002412 };
Benny Halevy28f56692009-04-01 09:22:09 -04002413 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002414
Chuck Lever9f06c712010-12-14 14:59:18 +00002415 encode_compound_hdr(xdr, req, &hdr);
2416 encode_sequence(xdr, &args->seq_args, &hdr);
2417 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002418 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002419 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002420
Benny Halevy28f56692009-04-01 09:22:09 -04002421 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002422 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002423
Andy Adamsond0179312008-12-23 16:06:17 -05002424 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002425}
2426
2427/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 * Encode a WRITE request
2429 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002430static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2431 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002434 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436
Chuck Lever9f06c712010-12-14 14:59:18 +00002437 encode_compound_hdr(xdr, req, &hdr);
2438 encode_sequence(xdr, &args->seq_args, &hdr);
2439 encode_putfh(xdr, args->fh, &hdr);
2440 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002441 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002442 if (args->bitmask)
2443 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002444 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445}
2446
2447/*
2448 * a COMMIT request
2449 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002450static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2451 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002454 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
Chuck Lever9f06c712010-12-14 14:59:18 +00002457 encode_compound_hdr(xdr, req, &hdr);
2458 encode_sequence(xdr, &args->seq_args, &hdr);
2459 encode_putfh(xdr, args->fh, &hdr);
2460 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002461 if (args->bitmask)
2462 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002463 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464}
2465
2466/*
2467 * FSINFO request
2468 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002469static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2470 struct nfs4_fsinfo_arg *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_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002480 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481}
2482
2483/*
2484 * a PATHCONF request
2485 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002486static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2487 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002490 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492
Chuck Lever9f06c712010-12-14 14:59:18 +00002493 encode_compound_hdr(xdr, req, &hdr);
2494 encode_sequence(xdr, &args->seq_args, &hdr);
2495 encode_putfh(xdr, args->fh, &hdr);
2496 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002497 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002498 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499}
2500
2501/*
2502 * a STATFS request
2503 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002504static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2505 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002508 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510
Chuck Lever9f06c712010-12-14 14:59:18 +00002511 encode_compound_hdr(xdr, req, &hdr);
2512 encode_sequence(xdr, &args->seq_args, &hdr);
2513 encode_putfh(xdr, args->fh, &hdr);
2514 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002515 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002516 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517}
2518
2519/*
2520 * GETATTR_BITMAP request
2521 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002522static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2523 struct xdr_stream *xdr,
2524 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002527 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529
Chuck Lever9f06c712010-12-14 14:59:18 +00002530 encode_compound_hdr(xdr, req, &hdr);
2531 encode_sequence(xdr, &args->seq_args, &hdr);
2532 encode_putfh(xdr, args->fhandle, &hdr);
2533 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002534 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002535 FATTR4_WORD0_LINK_SUPPORT|
2536 FATTR4_WORD0_SYMLINK_SUPPORT|
2537 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002538 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539}
2540
2541/*
2542 * a RENEW request
2543 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002544static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2545 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002548 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 };
2550
Chuck Lever9f06c712010-12-14 14:59:18 +00002551 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002552 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002553 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554}
2555
2556/*
2557 * a SETCLIENTID request
2558 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002559static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2560 struct xdr_stream *xdr,
2561 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002564 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 };
2566
Chuck Lever9f06c712010-12-14 14:59:18 +00002567 encode_compound_hdr(xdr, req, &hdr);
2568 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002569 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570}
2571
2572/*
2573 * a SETCLIENTID_CONFIRM request
2574 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002575static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2576 struct xdr_stream *xdr,
2577 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002580 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 };
Fred Isamandae100c2011-07-30 20:52:37 -04002582 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583
Chuck Lever9f06c712010-12-14 14:59:18 +00002584 encode_compound_hdr(xdr, req, &hdr);
2585 encode_setclientid_confirm(xdr, arg, &hdr);
2586 encode_putrootfh(xdr, &hdr);
2587 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002588 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589}
2590
2591/*
2592 * DELEGRETURN request
2593 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002594static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2595 struct xdr_stream *xdr,
2596 const struct nfs4_delegreturnargs *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->fhandle, &hdr);
2605 encode_delegreturn(xdr, args->stateid, &hdr);
2606 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002607 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608}
2609
2610/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002611 * Encode FS_LOCATIONS request
2612 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002613static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2614 struct xdr_stream *xdr,
2615 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002616{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002617 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002618 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002619 };
Benny Halevy28f56692009-04-01 09:22:09 -04002620 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002621
Chuck Lever9f06c712010-12-14 14:59:18 +00002622 encode_compound_hdr(xdr, req, &hdr);
2623 encode_sequence(xdr, &args->seq_args, &hdr);
2624 encode_putfh(xdr, args->dir_fh, &hdr);
2625 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002626 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002627 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002628
Benny Halevy28f56692009-04-01 09:22:09 -04002629 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002630 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002631 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002632}
2633
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002634/*
2635 * Encode SECINFO request
2636 */
2637static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2638 struct xdr_stream *xdr,
2639 struct nfs4_secinfo_arg *args)
2640{
2641 struct compound_hdr hdr = {
2642 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2643 };
2644
2645 encode_compound_hdr(xdr, req, &hdr);
2646 encode_sequence(xdr, &args->seq_args, &hdr);
2647 encode_putfh(xdr, args->dir_fh, &hdr);
2648 encode_secinfo(xdr, args->name, &hdr);
2649 encode_nops(&hdr);
2650}
2651
Benny Halevy99fe60d2009-04-01 09:22:29 -04002652#if defined(CONFIG_NFS_V4_1)
2653/*
2654 * EXCHANGE_ID request
2655 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002656static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2657 struct xdr_stream *xdr,
2658 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002659{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002660 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002661 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002662 };
2663
Chuck Lever9f06c712010-12-14 14:59:18 +00002664 encode_compound_hdr(xdr, req, &hdr);
2665 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002666 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002667}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002668
2669/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002670 * a CREATE_SESSION request
2671 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002672static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2673 struct xdr_stream *xdr,
2674 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002675{
Andy Adamsonfc931582009-04-01 09:22:31 -04002676 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002677 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002678 };
2679
Chuck Lever9f06c712010-12-14 14:59:18 +00002680 encode_compound_hdr(xdr, req, &hdr);
2681 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002682 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002683}
2684
2685/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002686 * a DESTROY_SESSION request
2687 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002688static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2689 struct xdr_stream *xdr,
2690 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002691{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002692 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002693 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002694 };
2695
Chuck Lever9f06c712010-12-14 14:59:18 +00002696 encode_compound_hdr(xdr, req, &hdr);
2697 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002698 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002699}
2700
2701/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002702 * a SEQUENCE request
2703 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002704static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2705 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002706{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002707 struct compound_hdr hdr = {
2708 .minorversion = nfs4_xdr_minorversion(args),
2709 };
2710
Chuck Lever9f06c712010-12-14 14:59:18 +00002711 encode_compound_hdr(xdr, req, &hdr);
2712 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002713 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002714}
2715
2716/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002717 * a GET_LEASE_TIME request
2718 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002719static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2720 struct xdr_stream *xdr,
2721 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002722{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002723 struct compound_hdr hdr = {
2724 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2725 };
Fred Isamandae100c2011-07-30 20:52:37 -04002726 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002727
Chuck Lever9f06c712010-12-14 14:59:18 +00002728 encode_compound_hdr(xdr, req, &hdr);
2729 encode_sequence(xdr, &args->la_seq_args, &hdr);
2730 encode_putrootfh(xdr, &hdr);
2731 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002732 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002733}
Ricardo Labiaga18019752009-12-05 16:08:40 -05002734
2735/*
2736 * a RECLAIM_COMPLETE request
2737 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002738static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2739 struct xdr_stream *xdr,
2740 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga18019752009-12-05 16:08:40 -05002741{
Ricardo Labiaga18019752009-12-05 16:08:40 -05002742 struct compound_hdr hdr = {
2743 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2744 };
2745
Chuck Lever9f06c712010-12-14 14:59:18 +00002746 encode_compound_hdr(xdr, req, &hdr);
2747 encode_sequence(xdr, &args->seq_args, &hdr);
2748 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05002749 encode_nops(&hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05002750}
2751
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002752/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002753 * Encode GETDEVICELIST request
2754 */
2755static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2756 struct xdr_stream *xdr,
2757 struct nfs4_getdevicelist_args *args)
2758{
2759 struct compound_hdr hdr = {
2760 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2761 };
2762
2763 encode_compound_hdr(xdr, req, &hdr);
2764 encode_sequence(xdr, &args->seq_args, &hdr);
2765 encode_putfh(xdr, args->fh, &hdr);
2766 encode_getdevicelist(xdr, args, &hdr);
2767 encode_nops(&hdr);
2768}
2769
2770/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002771 * Encode GETDEVICEINFO request
2772 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002773static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2774 struct xdr_stream *xdr,
2775 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002776{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002777 struct compound_hdr hdr = {
2778 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2779 };
2780
Chuck Lever9f06c712010-12-14 14:59:18 +00002781 encode_compound_hdr(xdr, req, &hdr);
2782 encode_sequence(xdr, &args->seq_args, &hdr);
2783 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002784
2785 /* set up reply kvec. Subtract notification bitmap max size (2)
2786 * so that notification bitmap is put in xdr_buf tail */
2787 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2788 args->pdev->pages, args->pdev->pgbase,
2789 args->pdev->pglen);
2790
2791 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002792}
2793
2794/*
2795 * Encode LAYOUTGET request
2796 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002797static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2798 struct xdr_stream *xdr,
2799 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002800{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002801 struct compound_hdr hdr = {
2802 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2803 };
2804
Chuck Lever9f06c712010-12-14 14:59:18 +00002805 encode_compound_hdr(xdr, req, &hdr);
2806 encode_sequence(xdr, &args->seq_args, &hdr);
2807 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2808 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002809
2810 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2811 args->layout.pages, 0, args->layout.pglen);
2812
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002813 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002814}
Andy Adamson863a3c62011-03-23 13:27:54 +00002815
2816/*
2817 * Encode LAYOUTCOMMIT request
2818 */
Benny Halevycbe82602011-05-22 19:52:37 +03002819static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2820 struct xdr_stream *xdr,
2821 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002822{
Benny Halevyac7db722011-05-22 19:53:48 +03002823 struct nfs4_layoutcommit_data *data =
2824 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002825 struct compound_hdr hdr = {
2826 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2827 };
2828
2829 encode_compound_hdr(xdr, req, &hdr);
2830 encode_sequence(xdr, &args->seq_args, &hdr);
2831 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002832 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002833 encode_getfattr(xdr, args->bitmask, &hdr);
2834 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002835}
2836
2837/*
2838 * Encode LAYOUTRETURN request
2839 */
2840static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2841 struct xdr_stream *xdr,
2842 struct nfs4_layoutreturn_args *args)
2843{
2844 struct compound_hdr hdr = {
2845 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2846 };
2847
2848 encode_compound_hdr(xdr, req, &hdr);
2849 encode_sequence(xdr, &args->seq_args, &hdr);
2850 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2851 encode_layoutreturn(xdr, args, &hdr);
2852 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002853}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002854
2855/*
2856 * Encode SECINFO_NO_NAME request
2857 */
2858static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2859 struct xdr_stream *xdr,
2860 struct nfs41_secinfo_no_name_args *args)
2861{
2862 struct compound_hdr hdr = {
2863 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2864 };
2865
2866 encode_compound_hdr(xdr, req, &hdr);
2867 encode_sequence(xdr, &args->seq_args, &hdr);
2868 encode_putrootfh(xdr, &hdr);
2869 encode_secinfo_no_name(xdr, args, &hdr);
2870 encode_nops(&hdr);
2871 return 0;
2872}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002873
2874/*
2875 * Encode TEST_STATEID request
2876 */
2877static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2878 struct xdr_stream *xdr,
2879 struct nfs41_test_stateid_args *args)
2880{
2881 struct compound_hdr hdr = {
2882 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2883 };
2884
2885 encode_compound_hdr(xdr, req, &hdr);
2886 encode_sequence(xdr, &args->seq_args, &hdr);
2887 encode_test_stateid(xdr, args, &hdr);
2888 encode_nops(&hdr);
2889}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002890
2891/*
2892 * Encode FREE_STATEID request
2893 */
2894static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2895 struct xdr_stream *xdr,
2896 struct nfs41_free_stateid_args *args)
2897{
2898 struct compound_hdr hdr = {
2899 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2900 };
2901
2902 encode_compound_hdr(xdr, req, &hdr);
2903 encode_sequence(xdr, &args->seq_args, &hdr);
2904 encode_free_stateid(xdr, args, &hdr);
2905 encode_nops(&hdr);
2906}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002907#endif /* CONFIG_NFS_V4_1 */
2908
Benny Halevy686841b2009-08-14 17:19:48 +03002909static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2910{
2911 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2912 "Remaining buffer length is %tu words.\n",
2913 func, xdr->end - xdr->p);
2914}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915
Trond Myklebust683b57b2006-06-09 09:34:22 -04002916static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917{
Al Viro8687b632006-10-19 23:28:48 -07002918 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919
Benny Halevyc0eae662009-08-14 17:20:14 +03002920 p = xdr_inline_decode(xdr, 4);
2921 if (unlikely(!p))
2922 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002923 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002924 p = xdr_inline_decode(xdr, *len);
2925 if (unlikely(!p))
2926 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 *string = (char *)p;
2928 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002929out_overflow:
2930 print_overflow_msg(__func__, xdr);
2931 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932}
2933
2934static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2935{
Al Viro8687b632006-10-19 23:28:48 -07002936 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937
Benny Halevyc0eae662009-08-14 17:20:14 +03002938 p = xdr_inline_decode(xdr, 8);
2939 if (unlikely(!p))
2940 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002941 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002942 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002943
Benny Halevyc0eae662009-08-14 17:20:14 +03002944 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2945 if (unlikely(!p))
2946 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 hdr->tag = (char *)p;
2948 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002949 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002950 if (unlikely(hdr->nops < 1))
2951 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002953out_overflow:
2954 print_overflow_msg(__func__, xdr);
2955 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956}
2957
Trond Myklebust6f8bca22013-12-04 17:39:23 -05002958static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
2959 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960{
Al Viro8687b632006-10-19 23:28:48 -07002961 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 uint32_t opnum;
2963 int32_t nfserr;
2964
Benny Halevyc0eae662009-08-14 17:20:14 +03002965 p = xdr_inline_decode(xdr, 8);
2966 if (unlikely(!p))
2967 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002968 opnum = be32_to_cpup(p++);
Trond Myklebust6f8bca22013-12-04 17:39:23 -05002969 if (unlikely(opnum != expected))
2970 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03002971 nfserr = be32_to_cpup(p);
Trond Myklebust6f8bca22013-12-04 17:39:23 -05002972 if (nfserr == NFS_OK)
2973 *nfs_retval = 0;
2974 else
2975 *nfs_retval = nfs4_stat_to_errno(nfserr);
2976 return true;
2977out_bad_operation:
2978 dprintk("nfs: Server returned operation"
2979 " %d but we issued a request for %d\n",
2980 opnum, expected);
2981 *nfs_retval = -EREMOTEIO;
2982 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03002983out_overflow:
2984 print_overflow_msg(__func__, xdr);
Trond Myklebust6f8bca22013-12-04 17:39:23 -05002985 *nfs_retval = -EIO;
2986 return false;
2987}
2988
2989static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2990{
2991 int retval;
2992
2993 __decode_op_hdr(xdr, expected, &retval);
2994 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995}
2996
2997/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002998static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999{
Al Viro8687b632006-10-19 23:28:48 -07003000 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003001 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 char *str;
3003
Benny Halevyc0eae662009-08-14 17:20:14 +03003004 p = xdr_inline_decode(xdr, 12);
3005 if (likely(p))
3006 return decode_opaque_inline(xdr, &strlen, &str);
3007 print_overflow_msg(__func__, xdr);
3008 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009}
3010
3011static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3012{
Al Viro8687b632006-10-19 23:28:48 -07003013 uint32_t bmlen;
3014 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015
Benny Halevyc0eae662009-08-14 17:20:14 +03003016 p = xdr_inline_decode(xdr, 4);
3017 if (unlikely(!p))
3018 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003019 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020
Fred Isamandae100c2011-07-30 20:52:37 -04003021 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003022 p = xdr_inline_decode(xdr, (bmlen << 2));
3023 if (unlikely(!p))
3024 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003026 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003027 if (bmlen > 1) {
3028 bitmap[1] = be32_to_cpup(p++);
3029 if (bmlen > 2)
3030 bitmap[2] = be32_to_cpup(p);
3031 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 }
3033 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003034out_overflow:
3035 print_overflow_msg(__func__, xdr);
3036 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037}
3038
Al Viro8687b632006-10-19 23:28:48 -07003039static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040{
Al Viro8687b632006-10-19 23:28:48 -07003041 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042
Benny Halevyc0eae662009-08-14 17:20:14 +03003043 p = xdr_inline_decode(xdr, 4);
3044 if (unlikely(!p))
3045 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003046 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 *savep = xdr->p;
3048 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003049out_overflow:
3050 print_overflow_msg(__func__, xdr);
3051 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052}
3053
3054static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3055{
3056 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003057 int ret;
3058 ret = decode_attr_bitmap(xdr, bitmask);
3059 if (unlikely(ret < 0))
3060 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3062 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003063 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3064 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3065 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 return 0;
3067}
3068
3069static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3070{
Al Viro8687b632006-10-19 23:28:48 -07003071 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003072 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073
3074 *type = 0;
3075 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3076 return -EIO;
3077 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003078 p = xdr_inline_decode(xdr, 4);
3079 if (unlikely(!p))
3080 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003081 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003083 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 return -EIO;
3085 }
3086 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003087 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003089 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003090 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003091out_overflow:
3092 print_overflow_msg(__func__, xdr);
3093 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094}
3095
Chuck Lever264e6352012-03-01 17:02:05 -05003096static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3097 uint32_t *bitmap, uint32_t *type)
3098{
3099 __be32 *p;
3100
3101 *type = 0;
3102 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3103 return -EIO;
3104 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3105 p = xdr_inline_decode(xdr, 4);
3106 if (unlikely(!p))
3107 goto out_overflow;
3108 *type = be32_to_cpup(p);
3109 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3110 }
3111 dprintk("%s: expire type=0x%x\n", __func__, *type);
3112 return 0;
3113out_overflow:
3114 print_overflow_msg(__func__, xdr);
3115 return -EIO;
3116}
3117
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3119{
Al Viro8687b632006-10-19 23:28:48 -07003120 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003121 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122
3123 *change = 0;
3124 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3125 return -EIO;
3126 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003127 p = xdr_inline_decode(xdr, 8);
3128 if (unlikely(!p))
3129 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003130 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003132 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003134 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003136 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003137out_overflow:
3138 print_overflow_msg(__func__, xdr);
3139 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140}
3141
3142static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3143{
Al Viro8687b632006-10-19 23:28:48 -07003144 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003145 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146
3147 *size = 0;
3148 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3149 return -EIO;
3150 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003151 p = xdr_inline_decode(xdr, 8);
3152 if (unlikely(!p))
3153 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003154 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003156 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003158 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003159 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003160out_overflow:
3161 print_overflow_msg(__func__, xdr);
3162 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163}
3164
3165static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3166{
Al Viro8687b632006-10-19 23:28:48 -07003167 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168
3169 *res = 0;
3170 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3171 return -EIO;
3172 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003173 p = xdr_inline_decode(xdr, 4);
3174 if (unlikely(!p))
3175 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003176 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3178 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003179 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003181out_overflow:
3182 print_overflow_msg(__func__, xdr);
3183 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184}
3185
3186static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3187{
Al Viro8687b632006-10-19 23:28:48 -07003188 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189
3190 *res = 0;
3191 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3192 return -EIO;
3193 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003194 p = xdr_inline_decode(xdr, 4);
3195 if (unlikely(!p))
3196 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003197 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3199 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003200 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003202out_overflow:
3203 print_overflow_msg(__func__, xdr);
3204 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205}
3206
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003207static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208{
Al Viro8687b632006-10-19 23:28:48 -07003209 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003210 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211
3212 fsid->major = 0;
3213 fsid->minor = 0;
3214 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3215 return -EIO;
3216 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003217 p = xdr_inline_decode(xdr, 16);
3218 if (unlikely(!p))
3219 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003220 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003221 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003223 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003225 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 (unsigned long long)fsid->major,
3227 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003228 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003229out_overflow:
3230 print_overflow_msg(__func__, xdr);
3231 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232}
3233
3234static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3235{
Al Viro8687b632006-10-19 23:28:48 -07003236 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237
3238 *res = 60;
3239 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3240 return -EIO;
3241 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003242 p = xdr_inline_decode(xdr, 4);
3243 if (unlikely(!p))
3244 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003245 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3247 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003248 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003250out_overflow:
3251 print_overflow_msg(__func__, xdr);
3252 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253}
3254
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003255static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003256{
3257 __be32 *p;
3258
3259 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3260 return -EIO;
3261 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3262 p = xdr_inline_decode(xdr, 4);
3263 if (unlikely(!p))
3264 goto out_overflow;
3265 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003266 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003267 }
3268 return 0;
3269out_overflow:
3270 print_overflow_msg(__func__, xdr);
3271 return -EIO;
3272}
3273
3274static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3275{
3276 __be32 *p;
3277 int len;
3278
Trond Myklebust7ad07352010-10-23 15:34:20 -04003279 if (fh != NULL)
3280 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003281
3282 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3283 return -EIO;
3284 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3285 p = xdr_inline_decode(xdr, 4);
3286 if (unlikely(!p))
3287 goto out_overflow;
3288 len = be32_to_cpup(p);
3289 if (len > NFS4_FHSIZE)
3290 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003291 p = xdr_inline_decode(xdr, len);
3292 if (unlikely(!p))
3293 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003294 if (fh != NULL) {
3295 memcpy(fh->data, p, len);
3296 fh->size = len;
3297 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003298 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3299 }
3300 return 0;
3301out_overflow:
3302 print_overflow_msg(__func__, xdr);
3303 return -EIO;
3304}
3305
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3307{
Al Viro8687b632006-10-19 23:28:48 -07003308 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309
3310 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3311 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3312 return -EIO;
3313 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003314 p = xdr_inline_decode(xdr, 4);
3315 if (unlikely(!p))
3316 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003317 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3319 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003320 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003322out_overflow:
3323 print_overflow_msg(__func__, xdr);
3324 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325}
3326
3327static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3328{
Al Viro8687b632006-10-19 23:28:48 -07003329 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003330 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331
3332 *fileid = 0;
3333 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3334 return -EIO;
3335 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003336 p = xdr_inline_decode(xdr, 8);
3337 if (unlikely(!p))
3338 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003339 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003341 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003343 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003344 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003345out_overflow:
3346 print_overflow_msg(__func__, xdr);
3347 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348}
3349
Manoj Naik99baf622006-06-09 09:34:24 -04003350static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3351{
Al Viro8687b632006-10-19 23:28:48 -07003352 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003353 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003354
3355 *fileid = 0;
3356 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3357 return -EIO;
3358 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003359 p = xdr_inline_decode(xdr, 8);
3360 if (unlikely(!p))
3361 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003362 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003363 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003364 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003365 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003366 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003367 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003368out_overflow:
3369 print_overflow_msg(__func__, xdr);
3370 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003371}
3372
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3374{
Al Viro8687b632006-10-19 23:28:48 -07003375 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 int status = 0;
3377
3378 *res = 0;
3379 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3380 return -EIO;
3381 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003382 p = xdr_inline_decode(xdr, 8);
3383 if (unlikely(!p))
3384 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003385 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3387 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003388 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003390out_overflow:
3391 print_overflow_msg(__func__, xdr);
3392 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393}
3394
3395static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3396{
Al Viro8687b632006-10-19 23:28:48 -07003397 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 int status = 0;
3399
3400 *res = 0;
3401 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3402 return -EIO;
3403 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003404 p = xdr_inline_decode(xdr, 8);
3405 if (unlikely(!p))
3406 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003407 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3409 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003410 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003412out_overflow:
3413 print_overflow_msg(__func__, xdr);
3414 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415}
3416
3417static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3418{
Al Viro8687b632006-10-19 23:28:48 -07003419 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 int status = 0;
3421
3422 *res = 0;
3423 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3424 return -EIO;
3425 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003426 p = xdr_inline_decode(xdr, 8);
3427 if (unlikely(!p))
3428 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003429 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3431 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003432 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003434out_overflow:
3435 print_overflow_msg(__func__, xdr);
3436 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437}
3438
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003439static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3440{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003441 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003442 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003443 int status = 0;
3444
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 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003449 if (n == 0)
3450 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003451 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003452 path->ncomponents = 0;
3453 while (path->ncomponents < n) {
3454 struct nfs4_string *component = &path->components[path->ncomponents];
3455 status = decode_opaque_inline(xdr, &component->len, &component->data);
3456 if (unlikely(status != 0))
3457 goto out_eio;
Trond Myklebust95a13f7b2012-03-14 21:55:01 -04003458 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003459 pr_cont("%s%.*s ",
3460 (path->ncomponents != n ? "/ " : ""),
3461 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003462 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3463 path->ncomponents++;
3464 else {
3465 dprintk("cannot parse %d components in path\n", n);
3466 goto out_eio;
3467 }
3468 }
3469out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003470 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003471root_path:
3472/* a root pathname is sent as a zero component4 */
3473 path->ncomponents = 1;
3474 path->components[0].len=0;
3475 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003476 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003477 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003478out_eio:
3479 dprintk(" status %d", status);
3480 status = -EIO;
3481 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003482out_overflow:
3483 print_overflow_msg(__func__, xdr);
3484 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003485}
3486
3487static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003488{
3489 int n;
Al Viro8687b632006-10-19 23:28:48 -07003490 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003491 int status = -EIO;
3492
3493 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3494 goto out;
3495 status = 0;
3496 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3497 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003498 status = -EIO;
3499 /* Ignore borken servers that return unrequested attrs */
3500 if (unlikely(res == NULL))
3501 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003502 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003503 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003504 if (unlikely(status != 0))
3505 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003506 p = xdr_inline_decode(xdr, 4);
3507 if (unlikely(!p))
3508 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003509 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003510 if (n <= 0)
3511 goto out_eio;
3512 res->nlocations = 0;
3513 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003514 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003515 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003516
Benny Halevyc0eae662009-08-14 17:20:14 +03003517 p = xdr_inline_decode(xdr, 4);
3518 if (unlikely(!p))
3519 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003520 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003521
3522 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003523 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003524 while (loc->nservers < m) {
3525 struct nfs4_string *server = &loc->servers[loc->nservers];
3526 status = decode_opaque_inline(xdr, &server->len, &server->data);
3527 if (unlikely(status != 0))
3528 goto out_eio;
3529 dprintk("%s ", server->data);
3530 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3531 loc->nservers++;
3532 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003533 unsigned int i;
3534 dprintk("%s: using first %u of %u servers "
3535 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003536 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003537 NFS4_FS_LOCATION_MAXSERVERS,
3538 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003539 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003540 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003541 char *data;
3542 status = decode_opaque_inline(xdr, &len, &data);
3543 if (unlikely(status != 0))
3544 goto out_eio;
3545 }
3546 }
3547 }
3548 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003549 if (unlikely(status != 0))
3550 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003551 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003552 res->nlocations++;
3553 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003554 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003555 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003556out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003557 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003558 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003559out_overflow:
3560 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003561out_eio:
3562 status = -EIO;
3563 goto out;
3564}
3565
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3567{
Al Viro8687b632006-10-19 23:28:48 -07003568 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 int status = 0;
3570
3571 *res = 0;
3572 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3573 return -EIO;
3574 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003575 p = xdr_inline_decode(xdr, 8);
3576 if (unlikely(!p))
3577 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003578 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3580 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003581 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003583out_overflow:
3584 print_overflow_msg(__func__, xdr);
3585 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586}
3587
3588static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3589{
Al Viro8687b632006-10-19 23:28:48 -07003590 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591 int status = 0;
3592
3593 *maxlink = 1;
3594 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3595 return -EIO;
3596 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003597 p = xdr_inline_decode(xdr, 4);
3598 if (unlikely(!p))
3599 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003600 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3602 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003603 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003605out_overflow:
3606 print_overflow_msg(__func__, xdr);
3607 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608}
3609
3610static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3611{
Al Viro8687b632006-10-19 23:28:48 -07003612 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 int status = 0;
3614
3615 *maxname = 1024;
3616 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3617 return -EIO;
3618 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003619 p = xdr_inline_decode(xdr, 4);
3620 if (unlikely(!p))
3621 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003622 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3624 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003625 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003627out_overflow:
3628 print_overflow_msg(__func__, xdr);
3629 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630}
3631
3632static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3633{
Al Viro8687b632006-10-19 23:28:48 -07003634 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 int status = 0;
3636
3637 *res = 1024;
3638 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3639 return -EIO;
3640 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3641 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003642 p = xdr_inline_decode(xdr, 8);
3643 if (unlikely(!p))
3644 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003645 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 if (maxread > 0x7FFFFFFF)
3647 maxread = 0x7FFFFFFF;
3648 *res = (uint32_t)maxread;
3649 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3650 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003651 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003653out_overflow:
3654 print_overflow_msg(__func__, xdr);
3655 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656}
3657
3658static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3659{
Al Viro8687b632006-10-19 23:28:48 -07003660 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661 int status = 0;
3662
3663 *res = 1024;
3664 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3665 return -EIO;
3666 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3667 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003668 p = xdr_inline_decode(xdr, 8);
3669 if (unlikely(!p))
3670 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003671 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 if (maxwrite > 0x7FFFFFFF)
3673 maxwrite = 0x7FFFFFFF;
3674 *res = (uint32_t)maxwrite;
3675 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3676 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003677 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003679out_overflow:
3680 print_overflow_msg(__func__, xdr);
3681 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682}
3683
Trond Myklebustbca79472009-03-11 14:10:26 -04003684static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685{
Trond Myklebustbca79472009-03-11 14:10:26 -04003686 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003687 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003688 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689
3690 *mode = 0;
3691 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3692 return -EIO;
3693 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003694 p = xdr_inline_decode(xdr, 4);
3695 if (unlikely(!p))
3696 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003697 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003698 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003700 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003702 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003703 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003704out_overflow:
3705 print_overflow_msg(__func__, xdr);
3706 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707}
3708
3709static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3710{
Al Viro8687b632006-10-19 23:28:48 -07003711 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003712 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713
3714 *nlink = 1;
3715 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3716 return -EIO;
3717 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003718 p = xdr_inline_decode(xdr, 4);
3719 if (unlikely(!p))
3720 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003721 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003723 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003725 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003726 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003727out_overflow:
3728 print_overflow_msg(__func__, xdr);
3729 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730}
3731
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003732static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003733 const struct nfs_server *server, uint32_t *uid,
3734 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735{
Al Viro8687b632006-10-19 23:28:48 -07003736 uint32_t len;
3737 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003738 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739
3740 *uid = -2;
3741 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3742 return -EIO;
3743 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003744 p = xdr_inline_decode(xdr, 4);
3745 if (unlikely(!p))
3746 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003747 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003748 p = xdr_inline_decode(xdr, len);
3749 if (unlikely(!p))
3750 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003751 if (owner_name != NULL) {
3752 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3753 if (owner_name->data != NULL) {
3754 owner_name->len = len;
3755 ret = NFS_ATTR_FATTR_OWNER_NAME;
3756 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003757 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003758 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003759 ret = NFS_ATTR_FATTR_OWNER;
3760 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003762 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003764 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003765 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3767 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003768 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003769 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003770out_overflow:
3771 print_overflow_msg(__func__, xdr);
3772 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773}
3774
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003775static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003776 const struct nfs_server *server, uint32_t *gid,
3777 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778{
Al Viro8687b632006-10-19 23:28:48 -07003779 uint32_t len;
3780 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003781 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782
3783 *gid = -2;
3784 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3785 return -EIO;
3786 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003787 p = xdr_inline_decode(xdr, 4);
3788 if (unlikely(!p))
3789 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003790 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003791 p = xdr_inline_decode(xdr, len);
3792 if (unlikely(!p))
3793 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003794 if (group_name != NULL) {
3795 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3796 if (group_name->data != NULL) {
3797 group_name->len = len;
3798 ret = NFS_ATTR_FATTR_GROUP_NAME;
3799 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003800 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003801 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003802 ret = NFS_ATTR_FATTR_GROUP;
3803 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003805 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003807 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003808 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3810 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003811 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003812 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003813out_overflow:
3814 print_overflow_msg(__func__, xdr);
3815 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816}
3817
3818static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3819{
Al Viro8687b632006-10-19 23:28:48 -07003820 uint32_t major = 0, minor = 0;
3821 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003822 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823
3824 *rdev = MKDEV(0,0);
3825 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3826 return -EIO;
3827 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3828 dev_t tmp;
3829
Benny Halevyc0eae662009-08-14 17:20:14 +03003830 p = xdr_inline_decode(xdr, 8);
3831 if (unlikely(!p))
3832 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003833 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003834 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 tmp = MKDEV(major, minor);
3836 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3837 *rdev = tmp;
3838 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003839 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003841 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003842 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003843out_overflow:
3844 print_overflow_msg(__func__, xdr);
3845 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846}
3847
3848static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3849{
Al Viro8687b632006-10-19 23:28:48 -07003850 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 int status = 0;
3852
3853 *res = 0;
3854 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3855 return -EIO;
3856 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003857 p = xdr_inline_decode(xdr, 8);
3858 if (unlikely(!p))
3859 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003860 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3862 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003863 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003865out_overflow:
3866 print_overflow_msg(__func__, xdr);
3867 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868}
3869
3870static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3871{
Al Viro8687b632006-10-19 23:28:48 -07003872 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 int status = 0;
3874
3875 *res = 0;
3876 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3877 return -EIO;
3878 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003879 p = xdr_inline_decode(xdr, 8);
3880 if (unlikely(!p))
3881 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003882 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3884 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003885 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003887out_overflow:
3888 print_overflow_msg(__func__, xdr);
3889 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890}
3891
3892static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3893{
Al Viro8687b632006-10-19 23:28:48 -07003894 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 int status = 0;
3896
3897 *res = 0;
3898 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3899 return -EIO;
3900 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003901 p = xdr_inline_decode(xdr, 8);
3902 if (unlikely(!p))
3903 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003904 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3906 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003907 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003909out_overflow:
3910 print_overflow_msg(__func__, xdr);
3911 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912}
3913
3914static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3915{
Al Viro8687b632006-10-19 23:28:48 -07003916 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003917 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918
3919 *used = 0;
3920 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3921 return -EIO;
3922 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003923 p = xdr_inline_decode(xdr, 8);
3924 if (unlikely(!p))
3925 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003926 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003928 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003930 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003932 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003933out_overflow:
3934 print_overflow_msg(__func__, xdr);
3935 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936}
3937
3938static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3939{
Al Viro8687b632006-10-19 23:28:48 -07003940 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941 uint64_t sec;
3942 uint32_t nsec;
3943
Benny Halevyc0eae662009-08-14 17:20:14 +03003944 p = xdr_inline_decode(xdr, 12);
3945 if (unlikely(!p))
3946 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003947 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003948 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 time->tv_sec = (time_t)sec;
3950 time->tv_nsec = (long)nsec;
3951 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003952out_overflow:
3953 print_overflow_msg(__func__, xdr);
3954 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955}
3956
3957static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3958{
3959 int status = 0;
3960
3961 time->tv_sec = 0;
3962 time->tv_nsec = 0;
3963 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3964 return -EIO;
3965 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3966 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003967 if (status == 0)
3968 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3970 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003971 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 return status;
3973}
3974
3975static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3976{
3977 int status = 0;
3978
3979 time->tv_sec = 0;
3980 time->tv_nsec = 0;
3981 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3982 return -EIO;
3983 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3984 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003985 if (status == 0)
3986 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3988 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003989 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990 return status;
3991}
3992
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003993static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3994 struct timespec *time)
3995{
3996 int status = 0;
3997
3998 time->tv_sec = 0;
3999 time->tv_nsec = 0;
4000 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4001 return -EIO;
4002 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4003 status = decode_attr_time(xdr, time);
4004 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4005 }
4006 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4007 (long)time->tv_nsec);
4008 return status;
4009}
4010
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4012{
4013 int status = 0;
4014
4015 time->tv_sec = 0;
4016 time->tv_nsec = 0;
4017 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4018 return -EIO;
4019 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4020 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004021 if (status == 0)
4022 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004023 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4024 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004025 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026 return status;
4027}
4028
Al Viro8687b632006-10-19 23:28:48 -07004029static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030{
4031 unsigned int attrwords = XDR_QUADLEN(attrlen);
4032 unsigned int nwords = xdr->p - savep;
4033
4034 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004035 dprintk("%s: server returned incorrect attribute length: "
4036 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004037 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 attrwords << 2,
4039 (attrwords < nwords) ? '<' : '>',
4040 nwords << 2);
4041 return -EIO;
4042 }
4043 return 0;
4044}
4045
4046static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4047{
Al Viro8687b632006-10-19 23:28:48 -07004048 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049
Benny Halevyc0eae662009-08-14 17:20:14 +03004050 p = xdr_inline_decode(xdr, 20);
4051 if (unlikely(!p))
4052 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004053 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004054 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004055 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004057out_overflow:
4058 print_overflow_msg(__func__, xdr);
4059 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060}
4061
4062static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4063{
Al Viro8687b632006-10-19 23:28:48 -07004064 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065 uint32_t supp, acc;
4066 int status;
4067
4068 status = decode_op_hdr(xdr, OP_ACCESS);
4069 if (status)
4070 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004071 p = xdr_inline_decode(xdr, 8);
4072 if (unlikely(!p))
4073 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004074 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004075 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 access->supported = supp;
4077 access->access = acc;
4078 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004079out_overflow:
4080 print_overflow_msg(__func__, xdr);
4081 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082}
4083
Benny Halevy07d30432009-08-14 17:19:52 +03004084static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085{
Al Viro8687b632006-10-19 23:28:48 -07004086 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004087
4088 p = xdr_inline_decode(xdr, len);
4089 if (likely(p)) {
4090 memcpy(buf, p, len);
4091 return 0;
4092 }
4093 print_overflow_msg(__func__, xdr);
4094 return -EIO;
4095}
4096
4097static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4098{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004099 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100}
4101
4102static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4103{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104 int status;
4105
4106 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004107 if (status != -EIO)
4108 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004109 if (!status)
4110 status = decode_stateid(xdr, &res->stateid);
4111 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112}
4113
Benny Halevydb942bb2009-08-14 17:19:56 +03004114static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4115{
Chuck Levercd937102012-03-02 17:14:31 -05004116 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117}
4118
4119static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4120{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 int status;
4122
4123 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004124 if (!status)
4125 status = decode_verifier(xdr, res->verf->verifier);
4126 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127}
4128
4129static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4130{
Al Viro8687b632006-10-19 23:28:48 -07004131 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132 uint32_t bmlen;
4133 int status;
4134
4135 status = decode_op_hdr(xdr, OP_CREATE);
4136 if (status)
4137 return status;
4138 if ((status = decode_change_info(xdr, cinfo)))
4139 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004140 p = xdr_inline_decode(xdr, 4);
4141 if (unlikely(!p))
4142 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004143 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004144 p = xdr_inline_decode(xdr, bmlen << 2);
4145 if (likely(p))
4146 return 0;
4147out_overflow:
4148 print_overflow_msg(__func__, xdr);
4149 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150}
4151
4152static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4153{
Al Viro8687b632006-10-19 23:28:48 -07004154 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004155 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156 int status;
4157
4158 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4159 goto xdr_error;
4160 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4161 goto xdr_error;
4162 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4163 goto xdr_error;
4164 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4165 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004166 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4167 &res->fh_expire_type)) != 0)
4168 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4170 goto xdr_error;
4171 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4172 goto xdr_error;
4173 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4174 goto xdr_error;
4175 status = verify_attr_len(xdr, savep, attrlen);
4176xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004177 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178 return status;
4179}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004180
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4182{
Al Viro8687b632006-10-19 23:28:48 -07004183 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004184 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004186
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4188 goto xdr_error;
4189 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4190 goto xdr_error;
4191 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4192 goto xdr_error;
4193
4194 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4195 goto xdr_error;
4196 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4197 goto xdr_error;
4198 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4199 goto xdr_error;
4200 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4201 goto xdr_error;
4202 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4203 goto xdr_error;
4204 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4205 goto xdr_error;
4206
4207 status = verify_attr_len(xdr, savep, attrlen);
4208xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004209 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210 return status;
4211}
4212
4213static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4214{
Al Viro8687b632006-10-19 23:28:48 -07004215 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004216 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004218
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4220 goto xdr_error;
4221 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4222 goto xdr_error;
4223 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4224 goto xdr_error;
4225
4226 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4227 goto xdr_error;
4228 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4229 goto xdr_error;
4230
4231 status = verify_attr_len(xdr, savep, attrlen);
4232xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004233 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 return status;
4235}
4236
Bryan Schumakerae42c702010-10-21 16:33:17 -04004237static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4238 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004239 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004240 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241{
Trond Myklebustbca79472009-03-11 14:10:26 -04004242 int status;
4243 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004244 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004245 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004247 status = decode_attr_type(xdr, bitmap, &type);
4248 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004250 fattr->mode = 0;
4251 if (status != 0) {
4252 fattr->mode |= nfs_type2fmt[type];
4253 fattr->valid |= status;
4254 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004255
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004256 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4257 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004259 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004260
4261 status = decode_attr_size(xdr, bitmap, &fattr->size);
4262 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004264 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004265
4266 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4267 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004269 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004270
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004271 err = 0;
4272 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004273 if (status < 0)
4274 goto xdr_error;
4275
4276 status = decode_attr_filehandle(xdr, bitmap, fh);
4277 if (status < 0)
4278 goto xdr_error;
4279
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004280 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4281 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004283 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004284
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004285 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004286 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004287 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004288 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004289
4290 status = decode_attr_mode(xdr, bitmap, &fmode);
4291 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004293 if (status != 0) {
4294 fattr->mode |= fmode;
4295 fattr->valid |= status;
4296 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004297
4298 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4299 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004301 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004302
Trond Myklebust6926afd2012-01-07 13:22:46 -05004303 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004304 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004306 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004307
Trond Myklebust6926afd2012-01-07 13:22:46 -05004308 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004309 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004311 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004312
4313 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4314 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004316 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004317
4318 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4319 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004321 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004322
4323 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4324 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004326 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004327
4328 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4329 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004331 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004332
4333 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4334 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004335 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004336 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004337
Trond Myklebust28331a42011-04-27 13:47:52 -04004338 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004339 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004340 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004341 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004342
Bryan Schumakerae42c702010-10-21 16:33:17 -04004343xdr_error:
4344 dprintk("%s: xdr returned %d\n", __func__, -status);
4345 return status;
4346}
4347
4348static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004349 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4350 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004351{
4352 __be32 *savep;
4353 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004354 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004355 int status;
4356
4357 status = decode_op_hdr(xdr, OP_GETATTR);
4358 if (status < 0)
4359 goto xdr_error;
4360
4361 status = decode_attr_bitmap(xdr, bitmap);
4362 if (status < 0)
4363 goto xdr_error;
4364
4365 status = decode_attr_length(xdr, &attrlen, &savep);
4366 if (status < 0)
4367 goto xdr_error;
4368
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004369 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004370 if (status < 0)
4371 goto xdr_error;
4372
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004373 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004375 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376 return status;
4377}
4378
Bryan Schumakerae42c702010-10-21 16:33:17 -04004379static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004380 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004381{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004382 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004383}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384
Andy Adamson504913f2010-10-20 00:17:57 -04004385/*
4386 * Decode potentially multiple layout types. Currently we only support
4387 * one layout driver per file system.
4388 */
4389static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4390 uint32_t *layouttype)
4391{
4392 uint32_t *p;
4393 int num;
4394
4395 p = xdr_inline_decode(xdr, 4);
4396 if (unlikely(!p))
4397 goto out_overflow;
4398 num = be32_to_cpup(p);
4399
4400 /* pNFS is not supported by the underlying file system */
4401 if (num == 0) {
4402 *layouttype = 0;
4403 return 0;
4404 }
4405 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004406 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4407 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004408
4409 /* Decode and set first layout type, move xdr->p past unused types */
4410 p = xdr_inline_decode(xdr, num * 4);
4411 if (unlikely(!p))
4412 goto out_overflow;
4413 *layouttype = be32_to_cpup(p);
4414 return 0;
4415out_overflow:
4416 print_overflow_msg(__func__, xdr);
4417 return -EIO;
4418}
4419
4420/*
4421 * The type of file system exported.
4422 * Note we must ensure that layouttype is set in any non-error case.
4423 */
4424static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4425 uint32_t *layouttype)
4426{
4427 int status = 0;
4428
4429 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4430 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4431 return -EIO;
4432 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4433 status = decode_first_pnfs_layout_type(xdr, layouttype);
4434 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4435 } else
4436 *layouttype = 0;
4437 return status;
4438}
4439
Fred Isamandae100c2011-07-30 20:52:37 -04004440/*
4441 * The prefered block size for layout directed io
4442 */
4443static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4444 uint32_t *res)
4445{
4446 __be32 *p;
4447
4448 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4449 *res = 0;
4450 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4451 p = xdr_inline_decode(xdr, 4);
4452 if (unlikely(!p)) {
4453 print_overflow_msg(__func__, xdr);
4454 return -EIO;
4455 }
4456 *res = be32_to_cpup(p);
4457 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4458 }
4459 return 0;
4460}
4461
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4463{
Al Viro8687b632006-10-19 23:28:48 -07004464 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004465 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004466 int status;
4467
4468 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4469 goto xdr_error;
4470 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4471 goto xdr_error;
4472 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4473 goto xdr_error;
4474
4475 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4476
4477 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4478 goto xdr_error;
4479 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4480 goto xdr_error;
4481 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4482 goto xdr_error;
4483 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4484 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4485 goto xdr_error;
4486 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004487 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4488 if (status != 0)
4489 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004490 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4491 if (status != 0)
4492 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004493 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4494 if (status)
4495 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496
4497 status = verify_attr_len(xdr, savep, attrlen);
4498xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004499 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004500 return status;
4501}
4502
4503static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4504{
Al Viro8687b632006-10-19 23:28:48 -07004505 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506 uint32_t len;
4507 int status;
4508
Trond Myklebust99367812007-07-17 21:52:41 -04004509 /* Zero handle first to allow comparisons */
4510 memset(fh, 0, sizeof(*fh));
4511
Linus Torvalds1da177e2005-04-16 15:20:36 -07004512 status = decode_op_hdr(xdr, OP_GETFH);
4513 if (status)
4514 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515
Benny Halevyc0eae662009-08-14 17:20:14 +03004516 p = xdr_inline_decode(xdr, 4);
4517 if (unlikely(!p))
4518 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004519 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004520 if (len > NFS4_FHSIZE)
4521 return -EIO;
4522 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004523 p = xdr_inline_decode(xdr, len);
4524 if (unlikely(!p))
4525 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004526 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004528out_overflow:
4529 print_overflow_msg(__func__, xdr);
4530 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004531}
4532
4533static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4534{
4535 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004536
Linus Torvalds1da177e2005-04-16 15:20:36 -07004537 status = decode_op_hdr(xdr, OP_LINK);
4538 if (status)
4539 return status;
4540 return decode_change_info(xdr, cinfo);
4541}
4542
4543/*
4544 * We create the owner, so we know a proper owner.id length is 4.
4545 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004546static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004548 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004549 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004550 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004552 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004553 if (unlikely(!p))
4554 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004555 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004556 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004557 type = be32_to_cpup(p++); /* 4 byte read */
4558 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004559 fl->fl_start = (loff_t)offset;
4560 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4561 if (length == ~(uint64_t)0)
4562 fl->fl_end = OFFSET_MAX;
4563 fl->fl_type = F_WRLCK;
4564 if (type & 1)
4565 fl->fl_type = F_RDLCK;
4566 fl->fl_pid = 0;
4567 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004568 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4569 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4570 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004571 if (likely(p))
4572 return -NFS4ERR_DENIED;
4573out_overflow:
4574 print_overflow_msg(__func__, xdr);
4575 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576}
4577
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004578static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580 int status;
4581
4582 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004583 if (status == -EIO)
4584 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004586 status = decode_stateid(xdr, &res->stateid);
4587 if (unlikely(status))
4588 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004589 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004590 status = decode_lock_denied(xdr, NULL);
4591 if (res->open_seqid != NULL)
4592 nfs_increment_open_seqid(status, res->open_seqid);
4593 nfs_increment_lock_seqid(status, res->lock_seqid);
4594out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595 return status;
4596}
4597
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004598static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004599{
4600 int status;
4601 status = decode_op_hdr(xdr, OP_LOCKT);
4602 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004603 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004604 return status;
4605}
4606
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004607static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004609 int status;
4610
4611 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004612 if (status != -EIO)
4613 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004614 if (status == 0)
4615 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616 return status;
4617}
4618
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004619static int decode_release_lockowner(struct xdr_stream *xdr)
4620{
4621 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4622}
4623
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624static int decode_lookup(struct xdr_stream *xdr)
4625{
4626 return decode_op_hdr(xdr, OP_LOOKUP);
4627}
4628
4629/* This is too sick! */
4630static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4631{
Andy Adamson05d564f2008-12-23 16:06:15 -05004632 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633 uint32_t limit_type, nblocks, blocksize;
4634
Benny Halevyc0eae662009-08-14 17:20:14 +03004635 p = xdr_inline_decode(xdr, 12);
4636 if (unlikely(!p))
4637 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004638 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004640 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004641 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004642 break;
4643 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004644 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004645 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004646 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647 }
4648 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004649out_overflow:
4650 print_overflow_msg(__func__, xdr);
4651 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652}
4653
4654static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4655{
Andy Adamson05d564f2008-12-23 16:06:15 -05004656 __be32 *p;
4657 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004658 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659
Benny Halevyc0eae662009-08-14 17:20:14 +03004660 p = xdr_inline_decode(xdr, 4);
4661 if (unlikely(!p))
4662 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004663 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004664 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4665 res->delegation_type = 0;
4666 return 0;
4667 }
Benny Halevy07d30432009-08-14 17:19:52 +03004668 status = decode_stateid(xdr, &res->delegation);
4669 if (unlikely(status))
4670 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004671 p = xdr_inline_decode(xdr, 4);
4672 if (unlikely(!p))
4673 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004674 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004675
Linus Torvalds1da177e2005-04-16 15:20:36 -07004676 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004677 case NFS4_OPEN_DELEGATE_READ:
4678 res->delegation_type = FMODE_READ;
4679 break;
4680 case NFS4_OPEN_DELEGATE_WRITE:
4681 res->delegation_type = FMODE_WRITE|FMODE_READ;
4682 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004683 return -EIO;
4684 }
David Howells7539bba2006-08-22 20:06:09 -04004685 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004686out_overflow:
4687 print_overflow_msg(__func__, xdr);
4688 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004689}
4690
4691static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4692{
Andy Adamson05d564f2008-12-23 16:06:15 -05004693 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004694 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004695 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696
Trond Myklebust6f8bca22013-12-04 17:39:23 -05004697 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
4698 return status;
4699 nfs_increment_open_seqid(status, res->seqid);
4700 if (status)
4701 return status;
4702 status = decode_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004703 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004704 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004705
Andy Adamson05d564f2008-12-23 16:06:15 -05004706 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004707
Benny Halevyc0eae662009-08-14 17:20:14 +03004708 p = xdr_inline_decode(xdr, 8);
4709 if (unlikely(!p))
4710 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004711 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004712 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004713 if (bmlen > 10)
4714 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715
Benny Halevyc0eae662009-08-14 17:20:14 +03004716 p = xdr_inline_decode(xdr, bmlen << 2);
4717 if (unlikely(!p))
4718 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004719 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4720 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004721 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004722 for (; i < NFS4_BITMAP_SIZE; i++)
4723 res->attrset[i] = 0;
4724
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725 return decode_delegation(xdr, res);
4726xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004727 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004729out_overflow:
4730 print_overflow_msg(__func__, xdr);
4731 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732}
4733
4734static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4735{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736 int status;
4737
Andy Adamson05d564f2008-12-23 16:06:15 -05004738 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004739 if (status != -EIO)
4740 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004741 if (!status)
4742 status = decode_stateid(xdr, &res->stateid);
4743 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744}
4745
4746static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4747{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748 int status;
4749
4750 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004751 if (status != -EIO)
4752 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004753 if (!status)
4754 status = decode_stateid(xdr, &res->stateid);
4755 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756}
4757
4758static int decode_putfh(struct xdr_stream *xdr)
4759{
4760 return decode_op_hdr(xdr, OP_PUTFH);
4761}
4762
4763static int decode_putrootfh(struct xdr_stream *xdr)
4764{
4765 return decode_op_hdr(xdr, OP_PUTROOTFH);
4766}
4767
4768static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4769{
4770 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004771 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772 uint32_t count, eof, recvd, hdrlen;
4773 int status;
4774
4775 status = decode_op_hdr(xdr, OP_READ);
4776 if (status)
4777 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004778 p = xdr_inline_decode(xdr, 8);
4779 if (unlikely(!p))
4780 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004781 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004782 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004783 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784 recvd = req->rq_rcv_buf.len - hdrlen;
4785 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004786 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787 "count %u > recvd %u\n", count, recvd);
4788 count = recvd;
4789 eof = 0;
4790 }
4791 xdr_read_pages(xdr, count);
4792 res->eof = eof;
4793 res->count = count;
4794 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004795out_overflow:
4796 print_overflow_msg(__func__, xdr);
4797 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798}
4799
4800static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4801{
4802 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004804 size_t hdrlen;
4805 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004806 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004807 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808
4809 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004810 if (!status)
4811 status = decode_verifier(xdr, readdir->verifier.data);
4812 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004814 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004815 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004816 __func__, verf[0], verf[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817
Benny Halevydb942bb2009-08-14 17:19:56 +03004818 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004819 recvd = rcvbuf->len - hdrlen;
4820 if (pglen > recvd)
4821 pglen = recvd;
4822 xdr_read_pages(xdr, pglen);
4823
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004824
Trond Myklebustac396122010-11-15 20:26:22 -05004825 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826}
4827
4828static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4829{
4830 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4831 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004832 size_t hdrlen;
4833 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004834 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835 int status;
4836
4837 status = decode_op_hdr(xdr, OP_READLINK);
4838 if (status)
4839 return status;
4840
4841 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004842 p = xdr_inline_decode(xdr, 4);
4843 if (unlikely(!p))
4844 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004845 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004847 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848 return -ENAMETOOLONG;
4849 }
4850 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4851 recvd = req->rq_rcv_buf.len - hdrlen;
4852 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004853 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854 "count %u > recvd %u\n", len, recvd);
4855 return -EIO;
4856 }
4857 xdr_read_pages(xdr, len);
4858 /*
4859 * The XDR encode routine has set things up so that
4860 * the link text will be copied directly into the
4861 * buffer. We just have to do overflow-checking,
4862 * and and null-terminate the text (the VFS expects
4863 * null-termination).
4864 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004865 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004867out_overflow:
4868 print_overflow_msg(__func__, xdr);
4869 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870}
4871
4872static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4873{
4874 int status;
4875
4876 status = decode_op_hdr(xdr, OP_REMOVE);
4877 if (status)
4878 goto out;
4879 status = decode_change_info(xdr, cinfo);
4880out:
4881 return status;
4882}
4883
4884static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4885 struct nfs4_change_info *new_cinfo)
4886{
4887 int status;
4888
4889 status = decode_op_hdr(xdr, OP_RENAME);
4890 if (status)
4891 goto out;
4892 if ((status = decode_change_info(xdr, old_cinfo)))
4893 goto out;
4894 status = decode_change_info(xdr, new_cinfo);
4895out:
4896 return status;
4897}
4898
4899static int decode_renew(struct xdr_stream *xdr)
4900{
4901 return decode_op_hdr(xdr, OP_RENEW);
4902}
4903
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004904static int
4905decode_restorefh(struct xdr_stream *xdr)
4906{
4907 return decode_op_hdr(xdr, OP_RESTOREFH);
4908}
4909
J. Bruce Fields029d1052005-06-22 17:16:22 +00004910static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05004911 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004912{
Andy Adamsonbf118a32011-12-07 11:55:27 -05004913 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004914 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004915 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00004916 struct kvec *iov = req->rq_rcv_buf.head;
4917 int status;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004918 size_t page_len = xdr->buf->page_len;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004919
Andy Adamsonbf118a32011-12-07 11:55:27 -05004920 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004921 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4922 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004923
Andy Adamsonbf118a32011-12-07 11:55:27 -05004924 bm_p = xdr->p;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004925 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4926 res->acl_data_offset <<= 2;
4927 /* Check if the acl data starts beyond the allocated buffer */
4928 if (res->acl_data_offset > page_len)
4929 return -ERANGE;
4930
J. Bruce Fields029d1052005-06-22 17:16:22 +00004931 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4932 goto out;
4933 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4934 goto out;
4935
4936 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4937 return -EIO;
4938 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004939 size_t hdrlen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004940
Andy Adamsonbf118a32011-12-07 11:55:27 -05004941 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
4942 * are stored with the acl data to handle the problem of
4943 * variable length bitmaps.*/
4944 xdr->p = bm_p;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004945
J. Bruce Fields029d1052005-06-22 17:16:22 +00004946 /* We ignore &savep and don't do consistency checks on
4947 * the attr length. Let userspace figure it out.... */
4948 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004949 attrlen += res->acl_data_offset;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004950 if (attrlen > page_len) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05004951 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
4952 /* getxattr interface called with a NULL buf */
4953 res->acl_len = attrlen;
4954 goto out;
4955 }
Sachin Prabhu5794d212012-04-17 14:36:40 +01004956 dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
Sachin Prabhu5a006892012-04-17 14:35:39 +01004957 attrlen, page_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004958 return -EINVAL;
4959 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004960 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05004961 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004962 } else
4963 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004964
4965out:
4966 return status;
4967}
4968
Linus Torvalds1da177e2005-04-16 15:20:36 -07004969static int
4970decode_savefh(struct xdr_stream *xdr)
4971{
4972 return decode_op_hdr(xdr, OP_SAVEFH);
4973}
4974
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004975static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976{
Al Viro8687b632006-10-19 23:28:48 -07004977 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004978 uint32_t bmlen;
4979 int status;
4980
Linus Torvalds1da177e2005-04-16 15:20:36 -07004981 status = decode_op_hdr(xdr, OP_SETATTR);
4982 if (status)
4983 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004984 p = xdr_inline_decode(xdr, 4);
4985 if (unlikely(!p))
4986 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004987 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004988 p = xdr_inline_decode(xdr, bmlen << 2);
4989 if (likely(p))
4990 return 0;
4991out_overflow:
4992 print_overflow_msg(__func__, xdr);
4993 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994}
4995
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004996static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004997{
Al Viro8687b632006-10-19 23:28:48 -07004998 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999 uint32_t opnum;
5000 int32_t nfserr;
5001
Benny Halevyc0eae662009-08-14 17:20:14 +03005002 p = xdr_inline_decode(xdr, 8);
5003 if (unlikely(!p))
5004 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005005 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005007 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005008 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009 return -EIO;
5010 }
Benny Halevycccddf42009-08-14 17:20:19 +03005011 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005012 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005013 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5014 if (unlikely(!p))
5015 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005016 p = xdr_decode_hyper(p, &res->clientid);
5017 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018 } else if (nfserr == NFSERR_CLID_INUSE) {
5019 uint32_t len;
5020
5021 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005022 p = xdr_inline_decode(xdr, 4);
5023 if (unlikely(!p))
5024 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005025 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005026 p = xdr_inline_decode(xdr, len);
5027 if (unlikely(!p))
5028 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029
5030 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005031 p = xdr_inline_decode(xdr, 4);
5032 if (unlikely(!p))
5033 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005034 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005035 p = xdr_inline_decode(xdr, len);
5036 if (unlikely(!p))
5037 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038 return -NFSERR_CLID_INUSE;
5039 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005040 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041
5042 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005043out_overflow:
5044 print_overflow_msg(__func__, xdr);
5045 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046}
5047
5048static int decode_setclientid_confirm(struct xdr_stream *xdr)
5049{
5050 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5051}
5052
5053static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5054{
Al Viro8687b632006-10-19 23:28:48 -07005055 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056 int status;
5057
5058 status = decode_op_hdr(xdr, OP_WRITE);
5059 if (status)
5060 return status;
5061
Benny Halevyc0eae662009-08-14 17:20:14 +03005062 p = xdr_inline_decode(xdr, 16);
5063 if (unlikely(!p))
5064 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005065 res->count = be32_to_cpup(p++);
5066 res->verf->committed = be32_to_cpup(p++);
Chuck Levercd937102012-03-02 17:14:31 -05005067 memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005069out_overflow:
5070 print_overflow_msg(__func__, xdr);
5071 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005072}
5073
5074static int decode_delegreturn(struct xdr_stream *xdr)
5075{
5076 return decode_op_hdr(xdr, OP_DELEGRETURN);
5077}
5078
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005079static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5080{
5081 __be32 *p;
5082
5083 p = xdr_inline_decode(xdr, 4);
5084 if (unlikely(!p))
5085 goto out_overflow;
5086 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5087 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5088 goto out_err;
5089
5090 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5091 if (unlikely(!p))
5092 goto out_overflow;
5093 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5094
5095 p = xdr_inline_decode(xdr, 8);
5096 if (unlikely(!p))
5097 goto out_overflow;
5098 flavor->gss.qop4 = be32_to_cpup(p++);
5099 flavor->gss.service = be32_to_cpup(p);
5100
5101 return 0;
5102
5103out_overflow:
5104 print_overflow_msg(__func__, xdr);
5105 return -EIO;
5106out_err:
5107 return -EINVAL;
5108}
5109
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005110static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005111{
5112 struct nfs4_secinfo_flavor *sec_flavor;
5113 int status;
5114 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005115 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005116
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005117 p = xdr_inline_decode(xdr, 4);
5118 if (unlikely(!p))
5119 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005120
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005121 res->flavors->num_flavors = 0;
5122 num_flavors = be32_to_cpup(p);
5123
5124 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005125 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005126 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005127 break;
5128
5129 p = xdr_inline_decode(xdr, 4);
5130 if (unlikely(!p))
5131 goto out_overflow;
5132 sec_flavor->flavor = be32_to_cpup(p);
5133
5134 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005135 status = decode_secinfo_gss(xdr, sec_flavor);
5136 if (status)
5137 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005138 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005139 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005140 }
5141
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005142 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005143out:
5144 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005145out_overflow:
5146 print_overflow_msg(__func__, xdr);
5147 return -EIO;
5148}
5149
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005150static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5151{
5152 int status = decode_op_hdr(xdr, OP_SECINFO);
5153 if (status)
5154 return status;
5155 return decode_secinfo_common(xdr, res);
5156}
5157
Benny Halevy99fe60d2009-04-01 09:22:29 -04005158#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005159static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5160{
5161 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5162 if (status)
5163 return status;
5164 return decode_secinfo_common(xdr, res);
5165}
5166
Benny Halevy99fe60d2009-04-01 09:22:29 -04005167static int decode_exchange_id(struct xdr_stream *xdr,
5168 struct nfs41_exchange_id_res *res)
5169{
5170 __be32 *p;
5171 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005172 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005173 int status;
5174 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005175 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005176
5177 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5178 if (status)
5179 return status;
5180
Benny Halevyc0eae662009-08-14 17:20:14 +03005181 p = xdr_inline_decode(xdr, 8);
5182 if (unlikely(!p))
5183 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005184 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005185 p = xdr_inline_decode(xdr, 12);
5186 if (unlikely(!p))
5187 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005188 clp->cl_seqid = be32_to_cpup(p++);
5189 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005190
5191 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005192 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005193 if (dummy != SP4_NONE)
5194 return -EIO;
5195
5196 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005197 p = xdr_inline_decode(xdr, 8);
5198 if (unlikely(!p))
5199 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005200
5201 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005202 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5203 if (unlikely(status))
5204 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005205
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005206 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005207 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5208 if (unlikely(status))
5209 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005210
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005211 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5212 return -EIO;
5213
5214 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5215 res->server_scope->server_scope_sz = dummy;
5216
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005217 /* Implementation Id */
5218 p = xdr_inline_decode(xdr, 4);
5219 if (unlikely(!p))
5220 goto out_overflow;
5221 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005222
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005223 if (impl_id_count) {
5224 /* nii_domain */
5225 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5226 if (unlikely(status))
5227 return status;
5228 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5229 return -EIO;
5230 memcpy(res->impl_id->domain, dummy_str, dummy);
5231
5232 /* nii_name */
5233 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5234 if (unlikely(status))
5235 return status;
5236 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5237 return -EIO;
5238 memcpy(res->impl_id->name, dummy_str, dummy);
5239
5240 /* nii_date */
5241 p = xdr_inline_decode(xdr, 12);
5242 if (unlikely(!p))
5243 goto out_overflow;
5244 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5245 res->impl_id->date.nseconds = be32_to_cpup(p);
5246
5247 /* if there's more than one entry, ignore the rest */
5248 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005249 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005250out_overflow:
5251 print_overflow_msg(__func__, xdr);
5252 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005253}
Andy Adamsonfc931582009-04-01 09:22:31 -04005254
5255static int decode_chan_attrs(struct xdr_stream *xdr,
5256 struct nfs4_channel_attrs *attrs)
5257{
5258 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005259 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005260
Benny Halevyc0eae662009-08-14 17:20:14 +03005261 p = xdr_inline_decode(xdr, 28);
5262 if (unlikely(!p))
5263 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005264 val = be32_to_cpup(p++); /* headerpadsz */
5265 if (val)
5266 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005267 attrs->max_rqst_sz = be32_to_cpup(p++);
5268 attrs->max_resp_sz = be32_to_cpup(p++);
5269 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5270 attrs->max_ops = be32_to_cpup(p++);
5271 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005272 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005273 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005274 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5275 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005276 return -EINVAL;
5277 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005278 if (nr_attrs == 1) {
5279 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5280 if (unlikely(!p))
5281 goto out_overflow;
5282 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005283 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005284out_overflow:
5285 print_overflow_msg(__func__, xdr);
5286 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005287}
5288
Benny Halevye78291e2009-08-14 17:20:00 +03005289static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5290{
5291 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005292}
5293
5294static int decode_create_session(struct xdr_stream *xdr,
5295 struct nfs41_create_session_res *res)
5296{
5297 __be32 *p;
5298 int status;
5299 struct nfs_client *clp = res->client;
5300 struct nfs4_session *session = clp->cl_session;
5301
5302 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005303 if (!status)
5304 status = decode_sessionid(xdr, &session->sess_id);
5305 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005306 return status;
5307
Andy Adamsonfc931582009-04-01 09:22:31 -04005308 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005309 p = xdr_inline_decode(xdr, 8);
5310 if (unlikely(!p))
5311 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005312 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005313 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005314
5315 /* Channel attributes */
5316 status = decode_chan_attrs(xdr, &session->fc_attrs);
5317 if (!status)
5318 status = decode_chan_attrs(xdr, &session->bc_attrs);
5319 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005320out_overflow:
5321 print_overflow_msg(__func__, xdr);
5322 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005323}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005324
5325static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5326{
5327 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5328}
Ricardo Labiaga18019752009-12-05 16:08:40 -05005329
5330static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5331{
5332 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5333}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005334#endif /* CONFIG_NFS_V4_1 */
5335
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005336static int decode_sequence(struct xdr_stream *xdr,
5337 struct nfs4_sequence_res *res,
5338 struct rpc_rqst *rqstp)
5339{
5340#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005341 struct nfs4_sessionid id;
5342 u32 dummy;
5343 int status;
5344 __be32 *p;
5345
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005346 if (!res->sr_session)
5347 return 0;
5348
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005349 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005350 if (!status)
5351 status = decode_sessionid(xdr, &id);
5352 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005353 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005354
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005355 /*
5356 * If the server returns different values for sessionID, slotID or
5357 * sequence number, the server is looney tunes.
5358 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005359 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005360
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005361 if (memcmp(id.data, res->sr_session->sess_id.data,
5362 NFS4_MAX_SESSIONID_LEN)) {
5363 dprintk("%s Invalid session id\n", __func__);
5364 goto out_err;
5365 }
Benny Halevye78291e2009-08-14 17:20:00 +03005366
Benny Halevyc0eae662009-08-14 17:20:14 +03005367 p = xdr_inline_decode(xdr, 20);
5368 if (unlikely(!p))
5369 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005370
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005371 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005372 dummy = be32_to_cpup(p++);
Benny Halevydfb4f302010-09-24 09:17:01 -04005373 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005374 dprintk("%s Invalid sequence number\n", __func__);
5375 goto out_err;
5376 }
5377 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005378 dummy = be32_to_cpup(p++);
Benny Halevydfb4f302010-09-24 09:17:01 -04005379 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005380 dprintk("%s Invalid slot id\n", __func__);
5381 goto out_err;
5382 }
5383 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005384 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005385 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005386 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005387 /* result flags */
5388 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005389 status = 0;
5390out_err:
5391 res->sr_status = status;
5392 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005393out_overflow:
5394 print_overflow_msg(__func__, xdr);
5395 status = -EIO;
5396 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005397#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005398 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005399#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005400}
5401
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005402#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005403/*
5404 * TODO: Need to handle case when EOF != true;
5405 */
5406static int decode_getdevicelist(struct xdr_stream *xdr,
5407 struct pnfs_devicelist *res)
5408{
5409 __be32 *p;
5410 int status, i;
5411 struct nfs_writeverf verftemp;
5412
5413 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5414 if (status)
5415 return status;
5416
5417 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5418 if (unlikely(!p))
5419 goto out_overflow;
5420
5421 /* TODO: Skip cookie for now */
5422 p += 2;
5423
5424 /* Read verifier */
Chuck Levercd937102012-03-02 17:14:31 -05005425 p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005426
5427 res->num_devs = be32_to_cpup(p);
5428
5429 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5430
5431 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005432 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005433 __func__, res->num_devs);
5434 return -EIO;
5435 }
5436
5437 p = xdr_inline_decode(xdr,
5438 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5439 if (unlikely(!p))
5440 goto out_overflow;
5441 for (i = 0; i < res->num_devs; i++)
5442 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5443 NFS4_DEVICEID4_SIZE);
5444 res->eof = be32_to_cpup(p);
5445 return 0;
5446out_overflow:
5447 print_overflow_msg(__func__, xdr);
5448 return -EIO;
5449}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005450
5451static int decode_getdeviceinfo(struct xdr_stream *xdr,
5452 struct pnfs_device *pdev)
5453{
5454 __be32 *p;
5455 uint32_t len, type;
5456 int status;
5457
5458 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5459 if (status) {
5460 if (status == -ETOOSMALL) {
5461 p = xdr_inline_decode(xdr, 4);
5462 if (unlikely(!p))
5463 goto out_overflow;
5464 pdev->mincount = be32_to_cpup(p);
5465 dprintk("%s: Min count too small. mincnt = %u\n",
5466 __func__, pdev->mincount);
5467 }
5468 return status;
5469 }
5470
5471 p = xdr_inline_decode(xdr, 8);
5472 if (unlikely(!p))
5473 goto out_overflow;
5474 type = be32_to_cpup(p++);
5475 if (type != pdev->layout_type) {
5476 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5477 __func__, pdev->layout_type, type);
5478 return -EINVAL;
5479 }
5480 /*
5481 * Get the length of the opaque device_addr4. xdr_read_pages places
5482 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5483 * and places the remaining xdr data in xdr_buf->tail
5484 */
5485 pdev->mincount = be32_to_cpup(p);
5486 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5487
5488 /* Parse notification bitmap, verifying that it is zero. */
5489 p = xdr_inline_decode(xdr, 4);
5490 if (unlikely(!p))
5491 goto out_overflow;
5492 len = be32_to_cpup(p);
5493 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005494 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005495
5496 p = xdr_inline_decode(xdr, 4 * len);
5497 if (unlikely(!p))
5498 goto out_overflow;
5499 for (i = 0; i < len; i++, p++) {
5500 if (be32_to_cpup(p)) {
5501 dprintk("%s: notifications not supported\n",
5502 __func__);
5503 return -EIO;
5504 }
5505 }
5506 }
5507 return 0;
5508out_overflow:
5509 print_overflow_msg(__func__, xdr);
5510 return -EIO;
5511}
5512
5513static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5514 struct nfs4_layoutget_res *res)
5515{
5516 __be32 *p;
5517 int status;
5518 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005519 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5520 struct kvec *iov = rcvbuf->head;
5521 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005522
5523 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5524 if (status)
5525 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005526 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005527 if (unlikely(!p))
5528 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005529 res->return_on_close = be32_to_cpup(p);
5530 decode_stateid(xdr, &res->stateid);
5531 p = xdr_inline_decode(xdr, 4);
5532 if (unlikely(!p))
5533 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005534 layout_count = be32_to_cpup(p);
5535 if (!layout_count) {
5536 dprintk("%s: server responded with empty layout array\n",
5537 __func__);
5538 return -EINVAL;
5539 }
5540
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005541 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005542 if (unlikely(!p))
5543 goto out_overflow;
5544 p = xdr_decode_hyper(p, &res->range.offset);
5545 p = xdr_decode_hyper(p, &res->range.length);
5546 res->range.iomode = be32_to_cpup(p++);
5547 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005548 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005549
5550 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5551 __func__,
5552 (unsigned long)res->range.offset,
5553 (unsigned long)res->range.length,
5554 res->range.iomode,
5555 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005556 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005557
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005558 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5559 recvd = req->rq_rcv_buf.len - hdrlen;
5560 if (res->layoutp->len > recvd) {
5561 dprintk("NFS: server cheating in layoutget reply: "
5562 "layout len %u > recvd %u\n",
5563 res->layoutp->len, recvd);
5564 return -EINVAL;
5565 }
5566
5567 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005568
5569 if (layout_count > 1) {
5570 /* We only handle a length one array at the moment. Any
5571 * further entries are just ignored. Note that this means
5572 * the client may see a response that is less than the
5573 * minimum it requested.
5574 */
5575 dprintk("%s: server responded with %d layouts, dropping tail\n",
5576 __func__, layout_count);
5577 }
5578
5579 return 0;
5580out_overflow:
5581 print_overflow_msg(__func__, xdr);
5582 return -EIO;
5583}
Andy Adamson863a3c62011-03-23 13:27:54 +00005584
Benny Halevycbe82602011-05-22 19:52:37 +03005585static int decode_layoutreturn(struct xdr_stream *xdr,
5586 struct nfs4_layoutreturn_res *res)
5587{
5588 __be32 *p;
5589 int status;
5590
5591 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5592 if (status)
5593 return status;
5594 p = xdr_inline_decode(xdr, 4);
5595 if (unlikely(!p))
5596 goto out_overflow;
5597 res->lrs_present = be32_to_cpup(p);
5598 if (res->lrs_present)
5599 status = decode_stateid(xdr, &res->stateid);
5600 return status;
5601out_overflow:
5602 print_overflow_msg(__func__, xdr);
5603 return -EIO;
5604}
5605
Andy Adamson863a3c62011-03-23 13:27:54 +00005606static int decode_layoutcommit(struct xdr_stream *xdr,
5607 struct rpc_rqst *req,
5608 struct nfs4_layoutcommit_res *res)
5609{
5610 __be32 *p;
5611 __u32 sizechanged;
5612 int status;
5613
5614 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005615 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005616 if (status)
5617 return status;
5618
5619 p = xdr_inline_decode(xdr, 4);
5620 if (unlikely(!p))
5621 goto out_overflow;
5622 sizechanged = be32_to_cpup(p);
5623
5624 if (sizechanged) {
5625 /* throw away new size */
5626 p = xdr_inline_decode(xdr, 8);
5627 if (unlikely(!p))
5628 goto out_overflow;
5629 }
5630 return 0;
5631out_overflow:
5632 print_overflow_msg(__func__, xdr);
5633 return -EIO;
5634}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005635
5636static int decode_test_stateid(struct xdr_stream *xdr,
5637 struct nfs41_test_stateid_res *res)
5638{
5639 __be32 *p;
5640 int status;
5641 int num_res;
5642
5643 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5644 if (status)
5645 return status;
5646
5647 p = xdr_inline_decode(xdr, 4);
5648 if (unlikely(!p))
5649 goto out_overflow;
5650 num_res = be32_to_cpup(p++);
5651 if (num_res != 1)
5652 goto out;
5653
5654 p = xdr_inline_decode(xdr, 4);
5655 if (unlikely(!p))
5656 goto out_overflow;
5657 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005658
5659 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005660out_overflow:
5661 print_overflow_msg(__func__, xdr);
5662out:
5663 return -EIO;
5664}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005665
5666static int decode_free_stateid(struct xdr_stream *xdr,
5667 struct nfs41_free_stateid_res *res)
5668{
5669 __be32 *p;
5670 int status;
5671
5672 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5673 if (status)
5674 return status;
5675
5676 p = xdr_inline_decode(xdr, 4);
5677 if (unlikely(!p))
5678 goto out_overflow;
5679 res->status = be32_to_cpup(p++);
5680 return res->status;
5681out_overflow:
5682 print_overflow_msg(__func__, xdr);
5683 return -EIO;
5684}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005685#endif /* CONFIG_NFS_V4_1 */
5686
Linus Torvalds1da177e2005-04-16 15:20:36 -07005687/*
Benny Halevy49c25592008-12-23 16:06:16 -05005688 * END OF "GENERIC" DECODE ROUTINES.
5689 */
5690
5691/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005692 * Decode OPEN_DOWNGRADE response
5693 */
Chuck Leverbf269552010-12-14 14:59:29 +00005694static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5695 struct xdr_stream *xdr,
5696 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005697{
Andy Adamson05d564f2008-12-23 16:06:15 -05005698 struct compound_hdr hdr;
5699 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005700
Chuck Leverbf269552010-12-14 14:59:29 +00005701 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005702 if (status)
5703 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005704 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005705 if (status)
5706 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005707 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005708 if (status)
5709 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005710 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005711 if (status != 0)
5712 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005713 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005714out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005715 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005716}
5717
5718/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005719 * Decode ACCESS response
5720 */
Chuck Leverbf269552010-12-14 14:59:29 +00005721static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5722 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005723{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005724 struct compound_hdr hdr;
5725 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005726
Chuck Leverbf269552010-12-14 14:59:29 +00005727 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005728 if (status)
5729 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005730 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005731 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005732 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005733 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005734 if (status != 0)
5735 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005736 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005737 if (status != 0)
5738 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005739 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005740out:
5741 return status;
5742}
5743
5744/*
5745 * Decode LOOKUP response
5746 */
Chuck Leverbf269552010-12-14 14:59:29 +00005747static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5748 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005749{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005750 struct compound_hdr hdr;
5751 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005752
Chuck Leverbf269552010-12-14 14:59:29 +00005753 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005754 if (status)
5755 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005756 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005757 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005759 status = decode_putfh(xdr);
5760 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005761 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005762 status = decode_lookup(xdr);
5763 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005764 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005765 status = decode_getfh(xdr, res->fh);
5766 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005768 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005769out:
5770 return status;
5771}
5772
5773/*
5774 * Decode LOOKUP_ROOT response
5775 */
Chuck Leverbf269552010-12-14 14:59:29 +00005776static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5777 struct xdr_stream *xdr,
5778 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005779{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005780 struct compound_hdr hdr;
5781 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005782
Chuck Leverbf269552010-12-14 14:59:29 +00005783 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005784 if (status)
5785 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005786 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005787 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005789 status = decode_putrootfh(xdr);
5790 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005791 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005792 status = decode_getfh(xdr, res->fh);
5793 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005794 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005795out:
5796 return status;
5797}
5798
5799/*
5800 * Decode REMOVE response
5801 */
Chuck Leverbf269552010-12-14 14:59:29 +00005802static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5803 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005804{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005805 struct compound_hdr hdr;
5806 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005807
Chuck Leverbf269552010-12-14 14:59:29 +00005808 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005809 if (status)
5810 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005811 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005812 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005813 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005814 status = decode_putfh(xdr);
5815 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005816 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005817 status = decode_remove(xdr, &res->cinfo);
5818 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005819 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005820 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005821out:
5822 return status;
5823}
5824
5825/*
5826 * Decode RENAME response
5827 */
Chuck Leverbf269552010-12-14 14:59:29 +00005828static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5829 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005830{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005831 struct compound_hdr hdr;
5832 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005833
Chuck Leverbf269552010-12-14 14:59:29 +00005834 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005835 if (status)
5836 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005837 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005838 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005839 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005840 status = decode_putfh(xdr);
5841 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005842 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005843 status = decode_savefh(xdr);
5844 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005846 status = decode_putfh(xdr);
5847 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005848 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005849 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5850 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005851 goto out;
5852 /* Current FH is target directory */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005853 if (decode_getfattr(xdr, res->new_fattr, res->server))
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005854 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005855 status = decode_restorefh(xdr);
5856 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005857 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005858 decode_getfattr(xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005859out:
5860 return status;
5861}
5862
5863/*
5864 * Decode LINK response
5865 */
Chuck Leverbf269552010-12-14 14:59:29 +00005866static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5867 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005869 struct compound_hdr hdr;
5870 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005871
Chuck Leverbf269552010-12-14 14:59:29 +00005872 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005873 if (status)
5874 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005875 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005876 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005878 status = decode_putfh(xdr);
5879 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005880 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005881 status = decode_savefh(xdr);
5882 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005883 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005884 status = decode_putfh(xdr);
5885 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005886 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005887 status = decode_link(xdr, &res->cinfo);
5888 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005889 goto out;
5890 /*
5891 * Note order: OP_LINK leaves the directory as the current
5892 * filehandle.
5893 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005894 if (decode_getfattr(xdr, res->dir_attr, res->server))
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005895 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005896 status = decode_restorefh(xdr);
5897 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005898 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005899 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005900out:
5901 return status;
5902}
5903
5904/*
5905 * Decode CREATE response
5906 */
Chuck Leverbf269552010-12-14 14:59:29 +00005907static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5908 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005910 struct compound_hdr hdr;
5911 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005912
Chuck Leverbf269552010-12-14 14:59:29 +00005913 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005914 if (status)
5915 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005916 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005917 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005918 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005919 status = decode_putfh(xdr);
5920 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005921 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005922 status = decode_savefh(xdr);
5923 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005924 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005925 status = decode_create(xdr, &res->dir_cinfo);
5926 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005927 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005928 status = decode_getfh(xdr, res->fh);
5929 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005930 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005931 if (decode_getfattr(xdr, res->fattr, res->server))
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005932 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005933 status = decode_restorefh(xdr);
5934 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005935 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005936 decode_getfattr(xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005937out:
5938 return status;
5939}
5940
5941/*
5942 * Decode SYMLINK response
5943 */
Chuck Leverbf269552010-12-14 14:59:29 +00005944static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5945 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005946{
Chuck Leverbf269552010-12-14 14:59:29 +00005947 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005948}
5949
5950/*
5951 * Decode GETATTR response
5952 */
Chuck Leverbf269552010-12-14 14:59:29 +00005953static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5954 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005955{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005956 struct compound_hdr hdr;
5957 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005958
Chuck Leverbf269552010-12-14 14:59:29 +00005959 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005960 if (status)
5961 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005962 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005963 if (status)
5964 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005965 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005966 if (status)
5967 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005968 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969out:
5970 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005971}
5972
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005973/*
5974 * Encode an SETACL request
5975 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005976static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5977 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005978{
Andy Adamson05d564f2008-12-23 16:06:15 -05005979 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005980 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005981 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005982
Chuck Lever9f06c712010-12-14 14:59:18 +00005983 encode_compound_hdr(xdr, req, &hdr);
5984 encode_sequence(xdr, &args->seq_args, &hdr);
5985 encode_putfh(xdr, args->fh, &hdr);
5986 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005987 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005988}
Andy Adamson05d564f2008-12-23 16:06:15 -05005989
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005990/*
5991 * Decode SETACL response
5992 */
5993static int
Chuck Leverbf269552010-12-14 14:59:29 +00005994nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005995 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005996{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005997 struct compound_hdr hdr;
5998 int status;
5999
Chuck Leverbf269552010-12-14 14:59:29 +00006000 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006001 if (status)
6002 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006003 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006004 if (status)
6005 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006006 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006007 if (status)
6008 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006009 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006010out:
6011 return status;
6012}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013
6014/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006015 * Decode GETACL response
6016 */
6017static int
Chuck Leverbf269552010-12-14 14:59:29 +00006018nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006019 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006020{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006021 struct compound_hdr hdr;
6022 int status;
6023
Trond Myklebust331818f2012-02-03 18:30:53 -05006024 if (res->acl_scratch != NULL) {
6025 void *p = page_address(res->acl_scratch);
6026 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6027 }
Chuck Leverbf269552010-12-14 14:59:29 +00006028 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006029 if (status)
6030 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006031 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006032 if (status)
6033 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006034 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006035 if (status)
6036 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006037 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006038
6039out:
6040 return status;
6041}
6042
6043/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006044 * Decode CLOSE response
6045 */
Chuck Leverbf269552010-12-14 14:59:29 +00006046static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6047 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006048{
Andy Adamson05d564f2008-12-23 16:06:15 -05006049 struct compound_hdr hdr;
6050 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006051
Chuck Leverbf269552010-12-14 14:59:29 +00006052 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006053 if (status)
6054 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006055 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006056 if (status)
6057 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006058 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006059 if (status)
6060 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006061 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006062 if (status != 0)
6063 goto out;
6064 /*
6065 * Note: Server may do delete on close for this file
6066 * in which case the getattr call will fail with
6067 * an ESTALE error. Shouldn't be a problem,
6068 * though, since fattr->valid will remain unset.
6069 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006070 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006071out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006072 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006073}
6074
6075/*
6076 * Decode OPEN response
6077 */
Chuck Leverbf269552010-12-14 14:59:29 +00006078static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6079 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006080{
Andy Adamson05d564f2008-12-23 16:06:15 -05006081 struct compound_hdr hdr;
6082 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083
Chuck Leverbf269552010-12-14 14:59:29 +00006084 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006085 if (status)
6086 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006087 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006088 if (status)
6089 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006090 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006091 if (status)
6092 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006093 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006094 if (status)
6095 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006096 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006097 if (status)
6098 goto out;
Weston Andros Adamson35eb9b12012-09-06 15:54:27 -04006099 status = decode_getfh(xdr, &res->fh);
6100 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006102 if (decode_getfattr(xdr, res->f_attr, res->server) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006103 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006104 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006105 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006106 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006107out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006108 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109}
6110
6111/*
6112 * Decode OPEN_CONFIRM response
6113 */
Chuck Leverbf269552010-12-14 14:59:29 +00006114static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6115 struct xdr_stream *xdr,
6116 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117{
Andy Adamson05d564f2008-12-23 16:06:15 -05006118 struct compound_hdr hdr;
6119 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006120
Chuck Leverbf269552010-12-14 14:59:29 +00006121 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006122 if (status)
6123 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006124 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006125 if (status)
6126 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006127 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006128out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006129 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006130}
6131
6132/*
6133 * Decode OPEN response
6134 */
Chuck Leverbf269552010-12-14 14:59:29 +00006135static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6136 struct xdr_stream *xdr,
6137 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006138{
Andy Adamson05d564f2008-12-23 16:06:15 -05006139 struct compound_hdr hdr;
6140 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006141
Chuck Leverbf269552010-12-14 14:59:29 +00006142 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006143 if (status)
6144 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006145 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006146 if (status)
6147 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006148 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006149 if (status)
6150 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006151 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006152 if (status)
6153 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006154 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006156 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006157}
6158
6159/*
6160 * Decode SETATTR response
6161 */
Chuck Leverbf269552010-12-14 14:59:29 +00006162static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6163 struct xdr_stream *xdr,
6164 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006165{
Andy Adamson05d564f2008-12-23 16:06:15 -05006166 struct compound_hdr hdr;
6167 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006168
Chuck Leverbf269552010-12-14 14:59:29 +00006169 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006170 if (status)
6171 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006172 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006173 if (status)
6174 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006175 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006176 if (status)
6177 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006178 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006179 if (status)
6180 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006181 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006183 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006184}
6185
6186/*
6187 * Decode LOCK response
6188 */
Chuck Leverbf269552010-12-14 14:59:29 +00006189static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6190 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192 struct compound_hdr hdr;
6193 int status;
6194
Chuck Leverbf269552010-12-14 14:59:29 +00006195 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196 if (status)
6197 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006198 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006199 if (status)
6200 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202 if (status)
6203 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006204 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205out:
6206 return status;
6207}
6208
6209/*
6210 * Decode LOCKT response
6211 */
Chuck Leverbf269552010-12-14 14:59:29 +00006212static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6213 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006215 struct compound_hdr hdr;
6216 int status;
6217
Chuck Leverbf269552010-12-14 14:59:29 +00006218 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219 if (status)
6220 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006221 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006222 if (status)
6223 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006224 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225 if (status)
6226 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006227 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228out:
6229 return status;
6230}
6231
6232/*
6233 * Decode LOCKU response
6234 */
Chuck Leverbf269552010-12-14 14:59:29 +00006235static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6236 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238 struct compound_hdr hdr;
6239 int status;
6240
Chuck Leverbf269552010-12-14 14:59:29 +00006241 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242 if (status)
6243 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006244 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006245 if (status)
6246 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006247 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248 if (status)
6249 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006250 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251out:
6252 return status;
6253}
6254
Chuck Leverbf269552010-12-14 14:59:29 +00006255static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6256 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006257{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006258 struct compound_hdr hdr;
6259 int status;
6260
Chuck Leverbf269552010-12-14 14:59:29 +00006261 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006262 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006263 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006264 return status;
6265}
6266
Linus Torvalds1da177e2005-04-16 15:20:36 -07006267/*
6268 * Decode READLINK response
6269 */
Chuck Leverbf269552010-12-14 14:59:29 +00006270static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6271 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006272 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006274 struct compound_hdr hdr;
6275 int status;
6276
Chuck Leverbf269552010-12-14 14:59:29 +00006277 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006278 if (status)
6279 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006280 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006281 if (status)
6282 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006283 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006284 if (status)
6285 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006286 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006287out:
6288 return status;
6289}
6290
6291/*
6292 * Decode READDIR response
6293 */
Chuck Leverbf269552010-12-14 14:59:29 +00006294static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6295 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006296{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006297 struct compound_hdr hdr;
6298 int status;
6299
Chuck Leverbf269552010-12-14 14:59:29 +00006300 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006301 if (status)
6302 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006303 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006304 if (status)
6305 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006306 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006307 if (status)
6308 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006309 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006310out:
6311 return status;
6312}
6313
6314/*
6315 * Decode Read response
6316 */
Chuck Leverbf269552010-12-14 14:59:29 +00006317static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6318 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006319{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006320 struct compound_hdr hdr;
6321 int status;
6322
Chuck Leverbf269552010-12-14 14:59:29 +00006323 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324 if (status)
6325 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006326 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006327 if (status)
6328 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006329 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006330 if (status)
6331 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006332 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006333 if (!status)
6334 status = res->count;
6335out:
6336 return status;
6337}
6338
6339/*
6340 * Decode WRITE response
6341 */
Chuck Leverbf269552010-12-14 14:59:29 +00006342static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6343 struct nfs_writeres *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_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006358 if (status)
6359 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006360 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006361 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 if (!status)
6363 status = res->count;
6364out:
6365 return status;
6366}
6367
6368/*
6369 * Decode COMMIT response
6370 */
Chuck Leverbf269552010-12-14 14:59:29 +00006371static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6372 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006373{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006374 struct compound_hdr hdr;
6375 int status;
6376
Chuck Leverbf269552010-12-14 14:59:29 +00006377 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378 if (status)
6379 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006380 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006381 if (status)
6382 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006383 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006384 if (status)
6385 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006386 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006387 if (status)
6388 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006389 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006390 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391out:
6392 return status;
6393}
6394
6395/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006396 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006397 */
Chuck Leverbf269552010-12-14 14:59:29 +00006398static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006399 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006401 struct compound_hdr hdr;
6402 int status;
6403
Chuck Leverbf269552010-12-14 14:59:29 +00006404 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006405 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006406 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006407 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006408 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006409 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411 return status;
6412}
6413
6414/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006415 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416 */
Chuck Leverbf269552010-12-14 14:59:29 +00006417static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006418 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006419{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420 struct compound_hdr hdr;
6421 int status;
6422
Chuck Leverbf269552010-12-14 14:59:29 +00006423 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006424 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006425 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006426 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006427 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006428 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006429 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006430 return status;
6431}
6432
6433/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006434 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435 */
Chuck Leverbf269552010-12-14 14:59:29 +00006436static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006437 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006438{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439 struct compound_hdr hdr;
6440 int status;
6441
Chuck Leverbf269552010-12-14 14:59:29 +00006442 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006444 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006445 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006446 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006447 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006448 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006449 return status;
6450}
6451
6452/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006453 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454 */
Chuck Leverbf269552010-12-14 14:59:29 +00006455static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6456 struct xdr_stream *xdr,
6457 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006458{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006459 struct compound_hdr hdr;
6460 int status;
6461
Chuck Leverbf269552010-12-14 14:59:29 +00006462 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006463 if (status)
6464 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006465 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006466 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006468 status = decode_putfh(xdr);
6469 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006470 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006471 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472out:
6473 return status;
6474}
6475
6476/*
6477 * Decode RENEW response
6478 */
Chuck Leverbf269552010-12-14 14:59:29 +00006479static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6480 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006481{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482 struct compound_hdr hdr;
6483 int status;
6484
Chuck Leverbf269552010-12-14 14:59:29 +00006485 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006486 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006487 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006488 return status;
6489}
6490
6491/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006492 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006493 */
Chuck Leverbf269552010-12-14 14:59:29 +00006494static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6495 struct xdr_stream *xdr,
6496 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006498 struct compound_hdr hdr;
6499 int status;
6500
Chuck Leverbf269552010-12-14 14:59:29 +00006501 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006503 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006504 return status;
6505}
6506
6507/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006508 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006509 */
Chuck Leverbf269552010-12-14 14:59:29 +00006510static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6511 struct xdr_stream *xdr,
6512 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006514 struct compound_hdr hdr;
6515 int status;
6516
Chuck Leverbf269552010-12-14 14:59:29 +00006517 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006519 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006521 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006522 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006523 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524 return status;
6525}
6526
6527/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006528 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529 */
Chuck Leverbf269552010-12-14 14:59:29 +00006530static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6531 struct xdr_stream *xdr,
6532 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006533{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006534 struct compound_hdr hdr;
6535 int status;
6536
Chuck Leverbf269552010-12-14 14:59:29 +00006537 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006538 if (status)
6539 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006540 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006541 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006542 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006543 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006544 if (status != 0)
6545 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006546 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006547 if (status != 0)
6548 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006549 decode_getfattr(xdr, res->fattr, res->server);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006550out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551 return status;
6552}
6553
Trond Myklebust683b57b2006-06-09 09:34:22 -04006554/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006555 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006556 */
Chuck Leverbf269552010-12-14 14:59:29 +00006557static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6558 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006559 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006560{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006561 struct compound_hdr hdr;
6562 int status;
6563
Chuck Leverbf269552010-12-14 14:59:29 +00006564 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006565 if (status)
6566 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006567 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006568 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006569 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006570 status = decode_putfh(xdr);
6571 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006572 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006573 status = decode_lookup(xdr);
6574 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006575 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006576 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006577 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6578 NULL, res->fs_locations,
6579 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006580out:
6581 return status;
6582}
6583
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006584/*
6585 * Decode SECINFO response
6586 */
6587static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6588 struct xdr_stream *xdr,
6589 struct nfs4_secinfo_res *res)
6590{
6591 struct compound_hdr hdr;
6592 int status;
6593
6594 status = decode_compound_hdr(xdr, &hdr);
6595 if (status)
6596 goto out;
6597 status = decode_sequence(xdr, &res->seq_res, rqstp);
6598 if (status)
6599 goto out;
6600 status = decode_putfh(xdr);
6601 if (status)
6602 goto out;
6603 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006604out:
6605 return status;
6606}
6607
Benny Halevy99fe60d2009-04-01 09:22:29 -04006608#if defined(CONFIG_NFS_V4_1)
6609/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006610 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006611 */
Chuck Leverbf269552010-12-14 14:59:29 +00006612static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6613 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006614 void *res)
6615{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006616 struct compound_hdr hdr;
6617 int status;
6618
Chuck Leverbf269552010-12-14 14:59:29 +00006619 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006620 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006621 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006622 return status;
6623}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006624
6625/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006626 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006627 */
Chuck Leverbf269552010-12-14 14:59:29 +00006628static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6629 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006630 struct nfs41_create_session_res *res)
6631{
Andy Adamsonfc931582009-04-01 09:22:31 -04006632 struct compound_hdr hdr;
6633 int status;
6634
Chuck Leverbf269552010-12-14 14:59:29 +00006635 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006636 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006637 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006638 return status;
6639}
6640
6641/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006642 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006643 */
Chuck Leverbf269552010-12-14 14:59:29 +00006644static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6645 struct xdr_stream *xdr,
6646 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006647{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006648 struct compound_hdr hdr;
6649 int status;
6650
Chuck Leverbf269552010-12-14 14:59:29 +00006651 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006652 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006653 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006654 return status;
6655}
6656
6657/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006658 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006659 */
Chuck Leverbf269552010-12-14 14:59:29 +00006660static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6661 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006662 struct nfs4_sequence_res *res)
6663{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006664 struct compound_hdr hdr;
6665 int status;
6666
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006668 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006669 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006670 return status;
6671}
6672
6673/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006674 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006675 */
Chuck Leverbf269552010-12-14 14:59:29 +00006676static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6677 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006678 struct nfs4_get_lease_time_res *res)
6679{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006680 struct compound_hdr hdr;
6681 int status;
6682
Chuck Leverbf269552010-12-14 14:59:29 +00006683 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006684 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006685 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006686 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006687 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006688 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006689 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006690 return status;
6691}
Ricardo Labiaga18019752009-12-05 16:08:40 -05006692
6693/*
6694 * Decode RECLAIM_COMPLETE response
6695 */
Chuck Leverbf269552010-12-14 14:59:29 +00006696static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6697 struct xdr_stream *xdr,
Ricardo Labiaga18019752009-12-05 16:08:40 -05006698 struct nfs41_reclaim_complete_res *res)
6699{
Ricardo Labiaga18019752009-12-05 16:08:40 -05006700 struct compound_hdr hdr;
6701 int status;
6702
Chuck Leverbf269552010-12-14 14:59:29 +00006703 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006704 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006705 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006706 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006707 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006708 return status;
6709}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006710
6711/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006712 * Decode GETDEVICELIST response
6713 */
6714static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6715 struct xdr_stream *xdr,
6716 struct nfs4_getdevicelist_res *res)
6717{
6718 struct compound_hdr hdr;
6719 int status;
6720
6721 dprintk("encoding getdevicelist!\n");
6722
6723 status = decode_compound_hdr(xdr, &hdr);
6724 if (status != 0)
6725 goto out;
6726 status = decode_sequence(xdr, &res->seq_res, rqstp);
6727 if (status != 0)
6728 goto out;
6729 status = decode_putfh(xdr);
6730 if (status != 0)
6731 goto out;
6732 status = decode_getdevicelist(xdr, res->devlist);
6733out:
6734 return status;
6735}
6736
6737/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006738 * Decode GETDEVINFO response
6739 */
Chuck Leverbf269552010-12-14 14:59:29 +00006740static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6741 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006742 struct nfs4_getdeviceinfo_res *res)
6743{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006744 struct compound_hdr hdr;
6745 int status;
6746
Chuck Leverbf269552010-12-14 14:59:29 +00006747 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006748 if (status != 0)
6749 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006750 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006751 if (status != 0)
6752 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006753 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006754out:
6755 return status;
6756}
6757
6758/*
6759 * Decode LAYOUTGET response
6760 */
Chuck Leverbf269552010-12-14 14:59:29 +00006761static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6762 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006763 struct nfs4_layoutget_res *res)
6764{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006765 struct compound_hdr hdr;
6766 int status;
6767
Chuck Leverbf269552010-12-14 14:59:29 +00006768 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006769 if (status)
6770 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006771 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006772 if (status)
6773 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006774 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006775 if (status)
6776 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006777 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006778out:
6779 return status;
6780}
Andy Adamson863a3c62011-03-23 13:27:54 +00006781
6782/*
Benny Halevycbe82602011-05-22 19:52:37 +03006783 * Decode LAYOUTRETURN response
6784 */
6785static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6786 struct xdr_stream *xdr,
6787 struct nfs4_layoutreturn_res *res)
6788{
6789 struct compound_hdr hdr;
6790 int status;
6791
6792 status = decode_compound_hdr(xdr, &hdr);
6793 if (status)
6794 goto out;
6795 status = decode_sequence(xdr, &res->seq_res, rqstp);
6796 if (status)
6797 goto out;
6798 status = decode_putfh(xdr);
6799 if (status)
6800 goto out;
6801 status = decode_layoutreturn(xdr, res);
6802out:
6803 return status;
6804}
6805
6806/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006807 * Decode LAYOUTCOMMIT response
6808 */
6809static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6810 struct xdr_stream *xdr,
6811 struct nfs4_layoutcommit_res *res)
6812{
6813 struct compound_hdr hdr;
6814 int status;
6815
6816 status = decode_compound_hdr(xdr, &hdr);
6817 if (status)
6818 goto out;
6819 status = decode_sequence(xdr, &res->seq_res, rqstp);
6820 if (status)
6821 goto out;
6822 status = decode_putfh(xdr);
6823 if (status)
6824 goto out;
6825 status = decode_layoutcommit(xdr, rqstp, res);
6826 if (status)
6827 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006828 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006829out:
6830 return status;
6831}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006832
6833/*
6834 * Decode SECINFO_NO_NAME response
6835 */
6836static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6837 struct xdr_stream *xdr,
6838 struct nfs4_secinfo_res *res)
6839{
6840 struct compound_hdr hdr;
6841 int status;
6842
6843 status = decode_compound_hdr(xdr, &hdr);
6844 if (status)
6845 goto out;
6846 status = decode_sequence(xdr, &res->seq_res, rqstp);
6847 if (status)
6848 goto out;
6849 status = decode_putrootfh(xdr);
6850 if (status)
6851 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04006852 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006853out:
6854 return status;
6855}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006856
6857/*
6858 * Decode TEST_STATEID response
6859 */
6860static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6861 struct xdr_stream *xdr,
6862 struct nfs41_test_stateid_res *res)
6863{
6864 struct compound_hdr hdr;
6865 int status;
6866
6867 status = decode_compound_hdr(xdr, &hdr);
6868 if (status)
6869 goto out;
6870 status = decode_sequence(xdr, &res->seq_res, rqstp);
6871 if (status)
6872 goto out;
6873 status = decode_test_stateid(xdr, res);
6874out:
6875 return status;
6876}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006877
6878/*
6879 * Decode FREE_STATEID response
6880 */
6881static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6882 struct xdr_stream *xdr,
6883 struct nfs41_free_stateid_res *res)
6884{
6885 struct compound_hdr hdr;
6886 int status;
6887
6888 status = decode_compound_hdr(xdr, &hdr);
6889 if (status)
6890 goto out;
6891 status = decode_sequence(xdr, &res->seq_res, rqstp);
6892 if (status)
6893 goto out;
6894 status = decode_free_stateid(xdr, res);
6895out:
6896 return status;
6897}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006898#endif /* CONFIG_NFS_V4_1 */
6899
Chuck Lever573c4e12010-12-14 14:58:11 +00006900/**
6901 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6902 * the local page cache.
6903 * @xdr: XDR stream where entry resides
6904 * @entry: buffer to fill in with entry data
6905 * @plus: boolean indicating whether this should be a readdirplus entry
6906 *
6907 * Returns zero if successful, otherwise a negative errno value is
6908 * returned.
6909 *
6910 * This function is not invoked during READDIR reply decoding, but
6911 * rather whenever an application invokes the getdents(2) system call
6912 * on a directory already in our cache.
6913 */
6914int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6915 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006916{
Fred Isamandae100c2011-07-30 20:52:37 -04006917 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07006918 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006919 __be32 *p = xdr_inline_decode(xdr, 4);
6920 if (unlikely(!p))
6921 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006922 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006923 p = xdr_inline_decode(xdr, 4);
6924 if (unlikely(!p))
6925 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006926 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006927 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006928 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006929 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006930 }
6931
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006932 p = xdr_inline_decode(xdr, 12);
6933 if (unlikely(!p))
6934 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006935 entry->prev_cookie = entry->cookie;
6936 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006937 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006938
Trond Myklebust9af8c222010-10-24 11:52:55 -04006939 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006940 if (unlikely(!p))
6941 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006942 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006943
6944 /*
6945 * In case the server doesn't return an inode number,
6946 * we fake one here. (We don't use inode number 0,
6947 * since glibc seems to choke on it...)
6948 */
6949 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006950 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006951
Trond Myklebust9af8c222010-10-24 11:52:55 -04006952 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006953 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006954
6955 if (decode_attr_length(xdr, &len, &p) < 0)
6956 goto out_overflow;
6957
Chuck Lever573c4e12010-12-14 14:58:11 +00006958 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006959 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006960 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006961 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6962 entry->ino = entry->fattr->mounted_on_fileid;
6963 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006964 entry->ino = entry->fattr->fileid;
6965
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006966 entry->d_type = DT_UNKNOWN;
6967 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6968 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6969
Chuck Lever573c4e12010-12-14 14:58:11 +00006970 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006971
6972out_overflow:
6973 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006974 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006975}
6976
6977/*
6978 * We need to translate between nfs status return values and
6979 * the local errno values which may not be the same.
6980 */
6981static struct {
6982 int stat;
6983 int errno;
6984} nfs_errtbl[] = {
6985 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006986 { NFS4ERR_PERM, -EPERM },
6987 { NFS4ERR_NOENT, -ENOENT },
6988 { NFS4ERR_IO, -errno_NFSERR_IO},
6989 { NFS4ERR_NXIO, -ENXIO },
6990 { NFS4ERR_ACCESS, -EACCES },
6991 { NFS4ERR_EXIST, -EEXIST },
6992 { NFS4ERR_XDEV, -EXDEV },
6993 { NFS4ERR_NOTDIR, -ENOTDIR },
6994 { NFS4ERR_ISDIR, -EISDIR },
6995 { NFS4ERR_INVAL, -EINVAL },
6996 { NFS4ERR_FBIG, -EFBIG },
6997 { NFS4ERR_NOSPC, -ENOSPC },
6998 { NFS4ERR_ROFS, -EROFS },
6999 { NFS4ERR_MLINK, -EMLINK },
7000 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7001 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7002 { NFS4ERR_DQUOT, -EDQUOT },
7003 { NFS4ERR_STALE, -ESTALE },
7004 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007005 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7006 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7007 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007008 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007009 { NFS4ERR_BADTYPE, -EBADTYPE },
7010 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007011 { NFS4ERR_SYMLINK, -ELOOP },
7012 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7013 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007014 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007015};
7016
7017/*
7018 * Convert an NFS error code to a local one.
7019 * This one is used jointly by NFSv2 and NFSv3.
7020 */
7021static int
David Howells0a8ea432006-08-22 20:06:08 -04007022nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007023{
7024 int i;
7025 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7026 if (nfs_errtbl[i].stat == stat)
7027 return nfs_errtbl[i].errno;
7028 }
7029 if (stat <= 10000 || stat > 10100) {
7030 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007031 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007032 }
7033 /* If we cannot translate the error, the recovery routines should
7034 * handle it.
7035 * Note: remaining NFSv4 error codes have values > 10000, so should
7036 * not conflict with native Linux error codes.
7037 */
Benny Halevy856dff32008-03-31 17:39:06 +03007038 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007039}
7040
Linus Torvalds1da177e2005-04-16 15:20:36 -07007041#define PROC(proc, argtype, restype) \
7042[NFSPROC4_CLNT_##proc] = { \
7043 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007044 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007045 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007046 .p_arglen = NFS4_##argtype##_sz, \
7047 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007048 .p_statidx = NFSPROC4_CLNT_##proc, \
7049 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007050}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007051
7052struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007053 PROC(READ, enc_read, dec_read),
7054 PROC(WRITE, enc_write, dec_write),
7055 PROC(COMMIT, enc_commit, dec_commit),
7056 PROC(OPEN, enc_open, dec_open),
7057 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7058 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7059 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7060 PROC(CLOSE, enc_close, dec_close),
7061 PROC(SETATTR, enc_setattr, dec_setattr),
7062 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7063 PROC(RENEW, enc_renew, dec_renew),
7064 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7065 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7066 PROC(LOCK, enc_lock, dec_lock),
7067 PROC(LOCKT, enc_lockt, dec_lockt),
7068 PROC(LOCKU, enc_locku, dec_locku),
7069 PROC(ACCESS, enc_access, dec_access),
7070 PROC(GETATTR, enc_getattr, dec_getattr),
7071 PROC(LOOKUP, enc_lookup, dec_lookup),
7072 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7073 PROC(REMOVE, enc_remove, dec_remove),
7074 PROC(RENAME, enc_rename, dec_rename),
7075 PROC(LINK, enc_link, dec_link),
7076 PROC(SYMLINK, enc_symlink, dec_symlink),
7077 PROC(CREATE, enc_create, dec_create),
7078 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7079 PROC(STATFS, enc_statfs, dec_statfs),
7080 PROC(READLINK, enc_readlink, dec_readlink),
7081 PROC(READDIR, enc_readdir, dec_readdir),
7082 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7083 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7084 PROC(GETACL, enc_getacl, dec_getacl),
7085 PROC(SETACL, enc_setacl, dec_setacl),
7086 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7087 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007088 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007089#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007090 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7091 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7092 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7093 PROC(SEQUENCE, enc_sequence, dec_sequence),
7094 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7095 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7096 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7097 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007098 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007099 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007100 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007101 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007102 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007103 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007104#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007105};
7106
Trond Myklebusta613fa12012-01-20 13:53:56 -05007107const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007108 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007109 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007110 .procs = nfs4_procedures
7111};
7112
7113/*
7114 * Local variables:
7115 * c-basic-offset: 8
7116 * End:
7117 */