blob: d824aedb12376e0b25adc6c02f08079086ef4f97 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
55#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000056#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050057#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040058#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#define NFSDBG_FACILITY NFSDBG_XDR
61
62/* Mapping from NFS error code to "errno" error code. */
63#define errno_NFSERR_IO EIO
64
David Howells0a8ea432006-08-22 20:06:08 -040065static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
68#ifdef DEBUG
69#define NFS4_MAXTAGLEN 20
70#else
71#define NFS4_MAXTAGLEN 0
72#endif
73
Andy Adamson6c0195a2008-12-23 16:06:15 -050074/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040075 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 */
Trond Myklebustd035c362010-12-21 10:45:27 -050077#define open_owner_id_maxsz (1 + 1 + 4)
78#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040079#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
81#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
82#define op_encode_hdr_maxsz (1)
83#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040084#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
85#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
86#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
87#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
89 (NFS4_FHSIZE >> 2))
90#define decode_putfh_maxsz (op_decode_hdr_maxsz)
91#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
92#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
93#define encode_getfh_maxsz (op_encode_hdr_maxsz)
94#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
95 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040096#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000097#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
99#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400100#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
101#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000102/* This is based on getfattr, which uses the most attributes: */
103#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400104 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000105#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
106 nfs4_fattr_value_maxsz)
107#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400108#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 1 + 2 + 1 + \
110 nfs4_owner_maxsz + \
111 nfs4_group_maxsz + \
112 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define encode_savefh_maxsz (op_encode_hdr_maxsz)
114#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400115#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
116#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200117#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400118/* The 5 accounts for the PNFS attributes, and assumes that at most three
119 * layout types will be returned.
120 */
121#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
122 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
124#define decode_renew_maxsz (op_decode_hdr_maxsz)
125#define encode_setclientid_maxsz \
126 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500127 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
128 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
129 1 /* sc_prog */ + \
130 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
131 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
132 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#define decode_setclientid_maxsz \
134 (op_decode_hdr_maxsz + \
135 2 + \
136 1024) /* large value for CLID_INUSE */
137#define encode_setclientid_confirm_maxsz \
138 (op_encode_hdr_maxsz + \
139 3 + (NFS4_VERIFIER_SIZE >> 2))
140#define decode_setclientid_confirm_maxsz \
141 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400142#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
143#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400144#define encode_share_access_maxsz \
145 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500146#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400147#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
148#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
149#define encode_open_maxsz (op_encode_hdr_maxsz + \
150 2 + encode_share_access_maxsz + 2 + \
151 open_owner_id_maxsz + \
152 encode_opentype_maxsz + \
153 encode_claim_null_maxsz)
154#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400155#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400156 decode_ace_maxsz)
157#define decode_change_info_maxsz (5)
158#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400159 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400160 decode_change_info_maxsz + 1 + \
161 nfs4_fattr_bitmap_maxsz + \
162 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400163#define encode_open_confirm_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1)
166#define decode_open_confirm_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169#define encode_open_downgrade_maxsz \
170 (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + 1 + \
172 encode_share_access_maxsz)
173#define decode_open_downgrade_maxsz \
174 (op_decode_hdr_maxsz + \
175 decode_stateid_maxsz)
176#define encode_close_maxsz (op_encode_hdr_maxsz + \
177 1 + encode_stateid_maxsz)
178#define decode_close_maxsz (op_decode_hdr_maxsz + \
179 decode_stateid_maxsz)
180#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
181 encode_stateid_maxsz + \
182 encode_attrs_maxsz)
183#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
184 nfs4_fattr_bitmap_maxsz)
185#define encode_read_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + 3)
187#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
188#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
189 2 + encode_verifier_maxsz + 5)
190#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
191 decode_verifier_maxsz)
192#define encode_readlink_maxsz (op_encode_hdr_maxsz)
193#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
194#define encode_write_maxsz (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + 4)
196#define decode_write_maxsz (op_decode_hdr_maxsz + \
197 2 + decode_verifier_maxsz)
198#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
199#define decode_commit_maxsz (op_decode_hdr_maxsz + \
200 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201#define encode_remove_maxsz (op_encode_hdr_maxsz + \
202 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400203#define decode_remove_maxsz (op_decode_hdr_maxsz + \
204 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#define encode_rename_maxsz (op_encode_hdr_maxsz + \
206 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400207#define decode_rename_maxsz (op_decode_hdr_maxsz + \
208 decode_change_info_maxsz + \
209 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#define encode_link_maxsz (op_encode_hdr_maxsz + \
211 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400212#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400213#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400214#define encode_lock_maxsz (op_encode_hdr_maxsz + \
215 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400216 1 + encode_stateid_maxsz + 1 + \
217 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400218#define decode_lock_denied_maxsz \
219 (8 + decode_lockowner_maxsz)
220#define decode_lock_maxsz (op_decode_hdr_maxsz + \
221 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400222#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
223 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400224#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
225 decode_lock_denied_maxsz)
226#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
227 encode_stateid_maxsz + \
228 4)
229#define decode_locku_maxsz (op_decode_hdr_maxsz + \
230 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400231#define encode_release_lockowner_maxsz \
232 (op_encode_hdr_maxsz + \
233 encode_lockowner_maxsz)
234#define decode_release_lockowner_maxsz \
235 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400236#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
237#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
239 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400240 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000241 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
243#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400244 1 + 2 + nfs4_name_maxsz + \
245 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400246#define decode_create_maxsz (op_decode_hdr_maxsz + \
247 decode_change_info_maxsz + \
248 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400249#define encode_statfs_maxsz (encode_getattr_maxsz)
250#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
252#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400253#define encode_getacl_maxsz (encode_getattr_maxsz)
254#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
255 nfs4_fattr_bitmap_maxsz + 1)
256#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
257 encode_stateid_maxsz + 3)
258#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400259#define encode_fs_locations_maxsz \
260 (encode_getattr_maxsz)
261#define decode_fs_locations_maxsz \
262 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000263#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400264#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400265
266#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400267#define NFS4_MAX_MACHINE_NAME_LEN (64)
268
Benny Halevy99fe60d2009-04-01 09:22:29 -0400269#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
270 encode_verifier_maxsz + \
271 1 /* co_ownerid.len */ + \
272 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
273 1 /* flags */ + \
274 1 /* spa_how */ + \
275 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500276 1 /* implementation id array of size 1 */ + \
277 1 /* nii_domain */ + \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
279 1 /* nii_name */ + \
280 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
281 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400282#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
283 2 /* eir_clientid */ + \
284 1 /* eir_sequenceid */ + \
285 1 /* eir_flags */ + \
286 1 /* spr_how */ + \
287 0 /* SP4_NONE (for now) */ + \
288 2 /* eir_server_owner.so_minor_id */ + \
289 /* eir_server_owner.so_major_id<> */ \
290 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
291 /* eir_server_scope<> */ \
292 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
293 1 /* eir_server_impl_id array length */ + \
294 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400295#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
296#define decode_channel_attrs_maxsz (6 + \
297 1 /* ca_rdma_ird.len */ + \
298 1 /* ca_rdma_ird */)
299#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
300 2 /* csa_clientid */ + \
301 1 /* csa_sequence */ + \
302 1 /* csa_flags */ + \
303 encode_channel_attrs_maxsz + \
304 encode_channel_attrs_maxsz + \
305 1 /* csa_cb_program */ + \
306 1 /* csa_sec_parms.len (1) */ + \
307 1 /* cb_secflavor (AUTH_SYS) */ + \
308 1 /* stamp */ + \
309 1 /* machinename.len */ + \
310 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
311 1 /* uid */ + \
312 1 /* gid */ + \
313 1 /* gids.len (0) */)
314#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
315 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
316 1 /* csr_sequence */ + \
317 1 /* csr_flags */ + \
318 decode_channel_attrs_maxsz + \
319 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400320#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
321#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400322#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
323 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
324#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
325 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500326#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
327#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400328#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
329 encode_verifier_maxsz)
330#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
331 2 /* nfs_cookie4 gdlr_cookie */ + \
332 decode_verifier_maxsz \
333 /* verifier4 gdlr_verifier */ + \
334 1 /* gdlr_deviceid_list count */ + \
335 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
336 NFS4_DEVICEID4_SIZE) \
337 /* gdlr_deviceid_list */ + \
338 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400339#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
340 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
341#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
342 1 /* layout type */ + \
343 1 /* opaque devaddr4 length */ + \
344 /* devaddr4 payload is read into page */ \
345 1 /* notification bitmap length */ + \
346 1 /* notification bitmap */)
347#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
348 encode_stateid_maxsz)
349#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
350 decode_stateid_maxsz + \
351 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000352#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
353 2 /* offset */ + \
354 2 /* length */ + \
355 1 /* reclaim */ + \
356 encode_stateid_maxsz + \
357 1 /* new offset (true) */ + \
358 2 /* last byte written */ + \
359 1 /* nt_timechanged (false) */ + \
360 1 /* layoutupdate4 layout type */ + \
361 1 /* NULL filelayout layoutupdate4 payload */)
362#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300363#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
364 encode_stateid_maxsz + \
365 1 /* FIXME: opaque lrf_body always empty at the moment */)
366#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
367 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400368#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
369#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400370#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
371 XDR_QUADLEN(NFS4_STATEID_SIZE))
372#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400373#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
374 XDR_QUADLEN(NFS4_STATEID_SIZE))
375#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400376#else /* CONFIG_NFS_V4_1 */
377#define encode_sequence_maxsz 0
378#define decode_sequence_maxsz 0
379#endif /* CONFIG_NFS_V4_1 */
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
382#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
383#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400384 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400386 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400388 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400390 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400392 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400394 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400396 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400398 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400400 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400402 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400404 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400406 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400410 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400411 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400413 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400415 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400416 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400418 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400420 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400421 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400423 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400425 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400426 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400428 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400429 encode_putfh_maxsz + \
430 encode_savefh_maxsz + \
431 encode_open_maxsz + \
432 encode_getfh_maxsz + \
433 encode_getattr_maxsz + \
434 encode_restorefh_maxsz + \
435 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400438 decode_putfh_maxsz + \
439 decode_savefh_maxsz + \
440 decode_open_maxsz + \
441 decode_getfh_maxsz + \
442 decode_getattr_maxsz + \
443 decode_restorefh_maxsz + \
444 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400445#define NFS4_enc_open_confirm_sz \
446 (compound_encode_hdr_maxsz + \
447 encode_putfh_maxsz + \
448 encode_open_confirm_maxsz)
449#define NFS4_dec_open_confirm_sz \
450 (compound_decode_hdr_maxsz + \
451 decode_putfh_maxsz + \
452 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400454 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400456 encode_open_maxsz + \
457 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400459 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400461 decode_open_maxsz + \
462 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#define NFS4_enc_open_downgrade_sz \
464 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400465 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400466 encode_putfh_maxsz + \
467 encode_open_downgrade_maxsz + \
468 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469#define NFS4_dec_open_downgrade_sz \
470 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400471 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400472 decode_putfh_maxsz + \
473 decode_open_downgrade_maxsz + \
474 decode_getattr_maxsz)
475#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400476 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400477 encode_putfh_maxsz + \
478 encode_close_maxsz + \
479 encode_getattr_maxsz)
480#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400481 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400482 decode_putfh_maxsz + \
483 decode_close_maxsz + \
484 decode_getattr_maxsz)
485#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400486 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400487 encode_putfh_maxsz + \
488 encode_setattr_maxsz + \
489 encode_getattr_maxsz)
490#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400491 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400492 decode_putfh_maxsz + \
493 decode_setattr_maxsz + \
494 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 encode_putfh_maxsz + \
498 encode_fsinfo_maxsz)
499#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400500 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 decode_putfh_maxsz + \
502 decode_fsinfo_maxsz)
503#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
504 encode_renew_maxsz)
505#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
506 decode_renew_maxsz)
507#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
508 encode_setclientid_maxsz)
509#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
510 decode_setclientid_maxsz)
511#define NFS4_enc_setclientid_confirm_sz \
512 (compound_encode_hdr_maxsz + \
513 encode_setclientid_confirm_maxsz + \
514 encode_putrootfh_maxsz + \
515 encode_fsinfo_maxsz)
516#define NFS4_dec_setclientid_confirm_sz \
517 (compound_decode_hdr_maxsz + \
518 decode_setclientid_confirm_maxsz + \
519 decode_putrootfh_maxsz + \
520 decode_fsinfo_maxsz)
521#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400522 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400524 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400526 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400528 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400532 encode_lockt_maxsz)
533#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400535 decode_putfh_maxsz + \
536 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400540 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400544 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400545#define NFS4_enc_release_lockowner_sz \
546 (compound_encode_hdr_maxsz + \
547 encode_lockowner_maxsz)
548#define NFS4_dec_release_lockowner_sz \
549 (compound_decode_hdr_maxsz + \
550 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400552 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400554 encode_access_maxsz + \
555 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400557 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400559 decode_access_maxsz + \
560 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 encode_putfh_maxsz + \
564 encode_getattr_maxsz)
565#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 decode_putfh_maxsz + \
568 decode_getattr_maxsz)
569#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 encode_putfh_maxsz + \
572 encode_lookup_maxsz + \
573 encode_getattr_maxsz + \
574 encode_getfh_maxsz)
575#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400576 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400578 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 decode_getattr_maxsz + \
580 decode_getfh_maxsz)
581#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 encode_putrootfh_maxsz + \
584 encode_getattr_maxsz + \
585 encode_getfh_maxsz)
586#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400587 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 decode_putrootfh_maxsz + \
589 decode_getattr_maxsz + \
590 decode_getfh_maxsz)
591#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400592 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400594 encode_remove_maxsz + \
595 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400597 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400599 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400600 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400602 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 encode_putfh_maxsz + \
604 encode_savefh_maxsz + \
605 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400606 encode_rename_maxsz + \
607 encode_getattr_maxsz + \
608 encode_restorefh_maxsz + \
609 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400611 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 decode_putfh_maxsz + \
613 decode_savefh_maxsz + \
614 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400615 decode_rename_maxsz + \
616 decode_getattr_maxsz + \
617 decode_restorefh_maxsz + \
618 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400620 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 encode_putfh_maxsz + \
622 encode_savefh_maxsz + \
623 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400624 encode_link_maxsz + \
625 decode_getattr_maxsz + \
626 encode_restorefh_maxsz + \
627 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400629 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 decode_putfh_maxsz + \
631 decode_savefh_maxsz + \
632 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400633 decode_link_maxsz + \
634 decode_getattr_maxsz + \
635 decode_restorefh_maxsz + \
636 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400638 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 encode_putfh_maxsz + \
640 encode_symlink_maxsz + \
641 encode_getattr_maxsz + \
642 encode_getfh_maxsz)
643#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400644 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 decode_putfh_maxsz + \
646 decode_symlink_maxsz + \
647 decode_getattr_maxsz + \
648 decode_getfh_maxsz)
649#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400652 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400654 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400656 encode_restorefh_maxsz + \
657 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400659 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400661 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400663 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400665 decode_restorefh_maxsz + \
666 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400668 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 encode_putfh_maxsz + \
670 encode_getattr_maxsz)
671#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 decode_putfh_maxsz + \
674 decode_getattr_maxsz)
675#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400678 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400682 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800685 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 encode_getattr_maxsz)
687#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800689 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 decode_getattr_maxsz)
691#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100694 encode_delegreturn_maxsz + \
695 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400697 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100698 decode_delegreturn_maxsz + \
699 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000700#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400701 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000702 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400703 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000704#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400705 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000706 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400707 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000708#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400709 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000710 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400711 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000712#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000714 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400715 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400716#define NFS4_enc_fs_locations_sz \
717 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400718 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400719 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400720 encode_lookup_maxsz + \
721 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400722#define NFS4_dec_fs_locations_sz \
723 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400724 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400725 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400726 decode_lookup_maxsz + \
727 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000728#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
729 encode_sequence_maxsz + \
730 encode_putfh_maxsz + \
731 encode_secinfo_maxsz)
732#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
733 decode_sequence_maxsz + \
734 decode_putfh_maxsz + \
735 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400736#if defined(CONFIG_NFS_V4_1)
737#define NFS4_enc_exchange_id_sz \
738 (compound_encode_hdr_maxsz + \
739 encode_exchange_id_maxsz)
740#define NFS4_dec_exchange_id_sz \
741 (compound_decode_hdr_maxsz + \
742 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400743#define NFS4_enc_create_session_sz \
744 (compound_encode_hdr_maxsz + \
745 encode_create_session_maxsz)
746#define NFS4_dec_create_session_sz \
747 (compound_decode_hdr_maxsz + \
748 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400749#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
750 encode_destroy_session_maxsz)
751#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
752 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400753#define NFS4_enc_sequence_sz \
754 (compound_decode_hdr_maxsz + \
755 encode_sequence_maxsz)
756#define NFS4_dec_sequence_sz \
757 (compound_decode_hdr_maxsz + \
758 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400759#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
760 encode_sequence_maxsz + \
761 encode_putrootfh_maxsz + \
762 encode_fsinfo_maxsz)
763#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
764 decode_sequence_maxsz + \
765 decode_putrootfh_maxsz + \
766 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500767#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
768 encode_sequence_maxsz + \
769 encode_reclaim_complete_maxsz)
770#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
771 decode_sequence_maxsz + \
772 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400773#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
774 encode_sequence_maxsz + \
775 encode_putfh_maxsz + \
776 encode_getdevicelist_maxsz)
777#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
778 decode_sequence_maxsz + \
779 decode_putfh_maxsz + \
780 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400781#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
782 encode_sequence_maxsz +\
783 encode_getdeviceinfo_maxsz)
784#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
785 decode_sequence_maxsz + \
786 decode_getdeviceinfo_maxsz)
787#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
788 encode_sequence_maxsz + \
789 encode_putfh_maxsz + \
790 encode_layoutget_maxsz)
791#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
792 decode_sequence_maxsz + \
793 decode_putfh_maxsz + \
794 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000795#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
796 encode_sequence_maxsz +\
797 encode_putfh_maxsz + \
798 encode_layoutcommit_maxsz + \
799 encode_getattr_maxsz)
800#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
801 decode_sequence_maxsz + \
802 decode_putfh_maxsz + \
803 decode_layoutcommit_maxsz + \
804 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300805#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
806 encode_sequence_maxsz + \
807 encode_putfh_maxsz + \
808 encode_layoutreturn_maxsz)
809#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
810 decode_sequence_maxsz + \
811 decode_putfh_maxsz + \
812 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400813#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
814 encode_sequence_maxsz + \
815 encode_putrootfh_maxsz +\
816 encode_secinfo_no_name_maxsz)
817#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
818 decode_sequence_maxsz + \
819 decode_putrootfh_maxsz + \
820 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400821#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
822 encode_sequence_maxsz + \
823 encode_test_stateid_maxsz)
824#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
825 decode_sequence_maxsz + \
826 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400827#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
828 encode_sequence_maxsz + \
829 encode_free_stateid_maxsz)
830#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
831 decode_sequence_maxsz + \
832 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500833
834const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
835 compound_encode_hdr_maxsz +
836 encode_sequence_maxsz +
837 encode_putfh_maxsz +
838 encode_getattr_maxsz) *
839 XDR_UNIT);
840
841const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
842 compound_decode_hdr_maxsz +
843 decode_sequence_maxsz +
844 decode_putfh_maxsz) *
845 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400846#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500848static unsigned short send_implementation_id = 1;
849
850module_param(send_implementation_id, ushort, 0644);
851MODULE_PARM_DESC(send_implementation_id,
852 "Send implementation ID with NFSv4.1 exchange_id");
853
Trond Myklebustbca79472009-03-11 14:10:26 -0400854static const umode_t nfs_type2fmt[] = {
855 [NF4BAD] = 0,
856 [NF4REG] = S_IFREG,
857 [NF4DIR] = S_IFDIR,
858 [NF4BLK] = S_IFBLK,
859 [NF4CHR] = S_IFCHR,
860 [NF4LNK] = S_IFLNK,
861 [NF4SOCK] = S_IFSOCK,
862 [NF4FIFO] = S_IFIFO,
863 [NF4ATTRDIR] = 0,
864 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865};
866
867struct compound_hdr {
868 int32_t status;
869 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500870 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 uint32_t taglen;
872 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400873 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400874 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875};
876
Benny Halevy13c65ce2009-08-14 17:19:25 +0300877static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
878{
879 __be32 *p = xdr_reserve_space(xdr, nbytes);
880 BUG_ON(!p);
881 return p;
882}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
884static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
885{
Al Viro8687b632006-10-19 23:28:48 -0700886 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
888 p = xdr_reserve_space(xdr, 4 + len);
889 BUG_ON(p == NULL);
890 xdr_encode_opaque(p, str, len);
891}
892
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400893static void encode_compound_hdr(struct xdr_stream *xdr,
894 struct rpc_rqst *req,
895 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896{
Al Viro8687b632006-10-19 23:28:48 -0700897 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400898 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400899
900 /* initialize running count of expected bytes in reply.
901 * NOTE: the replied tag SHOULD be the same is the one sent,
902 * but this is not required as a MUST for the server to do so. */
903 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
905 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
906 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300907 p = reserve_space(xdr, 4 + hdr->taglen + 8);
908 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300909 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500910 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300911 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500912}
913
914static void encode_nops(struct compound_hdr *hdr)
915{
Andy Adamsonfc931582009-04-01 09:22:31 -0400916 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500917 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918}
919
920static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
921{
Al Viro8687b632006-10-19 23:28:48 -0700922 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
925 BUG_ON(p == NULL);
926 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
927}
928
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500929static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930{
931 char owner_name[IDMAP_NAMESZ];
932 char owner_group[IDMAP_NAMESZ];
933 int owner_namelen = 0;
934 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700935 __be32 *p;
936 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 int len;
938 uint32_t bmval0 = 0;
939 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 /*
942 * We reserve enough space to write the entire attribute buffer at once.
943 * In the worst-case, this would be
944 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
945 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000946 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 */
948 len = 16;
949
950 /* Sigh */
951 if (iap->ia_valid & ATTR_SIZE)
952 len += 8;
953 if (iap->ia_valid & ATTR_MODE)
954 len += 4;
955 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800956 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400958 dprintk("nfs: couldn't resolve uid %d to string\n",
959 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 /* XXX */
961 strcpy(owner_name, "nobody");
962 owner_namelen = sizeof("nobody") - 1;
963 /* goto out; */
964 }
965 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
966 }
967 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800968 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400970 dprintk("nfs: couldn't resolve gid %d to string\n",
971 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 strcpy(owner_group, "nobody");
973 owner_grouplen = sizeof("nobody") - 1;
974 /* goto out; */
975 }
976 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
977 }
978 if (iap->ia_valid & ATTR_ATIME_SET)
979 len += 16;
980 else if (iap->ia_valid & ATTR_ATIME)
981 len += 4;
982 if (iap->ia_valid & ATTR_MTIME_SET)
983 len += 16;
984 else if (iap->ia_valid & ATTR_MTIME)
985 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300986 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
988 /*
989 * We write the bitmap length now, but leave the bitmap and the attribute
990 * buffer length to be backfilled at the end of this routine.
991 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300992 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 q = p;
994 p += 3;
995
996 if (iap->ia_valid & ATTR_SIZE) {
997 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300998 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 }
1000 if (iap->ia_valid & ATTR_MODE) {
1001 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001002 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 }
1004 if (iap->ia_valid & ATTR_UID) {
1005 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001006 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 }
1008 if (iap->ia_valid & ATTR_GID) {
1009 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001010 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
1012 if (iap->ia_valid & ATTR_ATIME_SET) {
1013 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001014 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1015 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001016 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1017 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 }
1019 else if (iap->ia_valid & ATTR_ATIME) {
1020 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001021 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 }
1023 if (iap->ia_valid & ATTR_MTIME_SET) {
1024 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001025 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1026 *p++ = cpu_to_be32(0);
1027 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1028 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 }
1030 else if (iap->ia_valid & ATTR_MTIME) {
1031 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001032 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001034
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 /*
1036 * Now we backfill the bitmap and the attribute buffer length.
1037 */
1038 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001039 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 len, ((char *)p - (char *)q) + 4);
1041 BUG();
1042 }
1043 len = (char *)p - (char *)q - 12;
1044 *q++ = htonl(bmval0);
1045 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001046 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049}
1050
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001051static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052{
Al Viro8687b632006-10-19 23:28:48 -07001053 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
Benny Halevy13c65ce2009-08-14 17:19:25 +03001055 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001056 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +03001057 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -05001058 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001059 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060}
1061
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001062static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063{
Al Viro8687b632006-10-19 23:28:48 -07001064 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Benny Halevy13c65ce2009-08-14 17:19:25 +03001066 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001067 *p++ = cpu_to_be32(OP_CLOSE);
1068 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +03001069 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001070 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001071 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072}
1073
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001074static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075{
Al Viro8687b632006-10-19 23:28:48 -07001076 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001077
Benny Halevy13c65ce2009-08-14 17:19:25 +03001078 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001079 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001080 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001081 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001082 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001083 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084}
1085
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001086static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087{
Al Viro8687b632006-10-19 23:28:48 -07001088 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001089
Benny Halevy13c65ce2009-08-14 17:19:25 +03001090 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001091 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001092 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
1094 switch (create->ftype) {
1095 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001096 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001097 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001098 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 break;
1100
1101 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001102 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001103 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001104 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 break;
1106
1107 default:
1108 break;
1109 }
1110
Benny Halevy811652b2009-08-14 17:19:34 +03001111 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001112 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001113 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001115 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001118static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
Andy Adamson05d564f2008-12-23 16:06:15 -05001120 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
Benny Halevy13c65ce2009-08-14 17:19:25 +03001122 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001123 *p++ = cpu_to_be32(OP_GETATTR);
1124 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001125 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001126 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001127 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128}
1129
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001130static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131{
Andy Adamson05d564f2008-12-23 16:06:15 -05001132 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Benny Halevy13c65ce2009-08-14 17:19:25 +03001134 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001135 *p++ = cpu_to_be32(OP_GETATTR);
1136 *p++ = cpu_to_be32(2);
1137 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001138 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001139 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001140 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
Fred Isamandae100c2011-07-30 20:52:37 -04001143static void
1144encode_getattr_three(struct xdr_stream *xdr,
1145 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1146 struct compound_hdr *hdr)
1147{
1148 __be32 *p;
1149
1150 p = reserve_space(xdr, 4);
1151 *p = cpu_to_be32(OP_GETATTR);
1152 if (bm2) {
1153 p = reserve_space(xdr, 16);
1154 *p++ = cpu_to_be32(3);
1155 *p++ = cpu_to_be32(bm0);
1156 *p++ = cpu_to_be32(bm1);
1157 *p = cpu_to_be32(bm2);
1158 } else if (bm1) {
1159 p = reserve_space(xdr, 12);
1160 *p++ = cpu_to_be32(2);
1161 *p++ = cpu_to_be32(bm0);
1162 *p = cpu_to_be32(bm1);
1163 } else {
1164 p = reserve_space(xdr, 8);
1165 *p++ = cpu_to_be32(1);
1166 *p = cpu_to_be32(bm0);
1167 }
1168 hdr->nops++;
1169 hdr->replen += decode_getattr_maxsz;
1170}
1171
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001172static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001174 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1175 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176}
1177
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001178static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179{
Fred Isamandae100c2011-07-30 20:52:37 -04001180 encode_getattr_three(xdr,
1181 bitmask[0] & nfs4_fsinfo_bitmap[0],
1182 bitmask[1] & nfs4_fsinfo_bitmap[1],
1183 bitmask[2] & nfs4_fsinfo_bitmap[2],
1184 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185}
1186
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001187static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001188{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001189 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1190 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001191}
1192
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001193static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194{
Al Viro8687b632006-10-19 23:28:48 -07001195 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Benny Halevy13c65ce2009-08-14 17:19:25 +03001197 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001198 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001199 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001200 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201}
1202
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001203static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204{
Al Viro8687b632006-10-19 23:28:48 -07001205 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Benny Halevy13c65ce2009-08-14 17:19:25 +03001207 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001208 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001209 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001210 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001211 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212}
1213
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001214static inline int nfs4_lock_type(struct file_lock *fl, int block)
1215{
1216 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1217 return block ? NFS4_READW_LT : NFS4_READ_LT;
1218 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1219}
1220
1221static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1222{
1223 if (fl->fl_end == OFFSET_MAX)
1224 return ~(uint64_t)0;
1225 return fl->fl_end - fl->fl_start + 1;
1226}
1227
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001228static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1229{
1230 __be32 *p;
1231
Trond Myklebustd035c362010-12-21 10:45:27 -05001232 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001233 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001234 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001235 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001236 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001237 xdr_encode_hyper(p, lowner->id);
1238}
1239
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240/*
1241 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1242 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1243 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001244static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245{
Al Viro8687b632006-10-19 23:28:48 -07001246 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Benny Halevy13c65ce2009-08-14 17:19:25 +03001248 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001249 *p++ = cpu_to_be32(OP_LOCK);
1250 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1251 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001252 p = xdr_encode_hyper(p, args->fl->fl_start);
1253 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001254 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001255 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001256 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001257 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001258 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001259 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001260 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 }
1262 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001263 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001264 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001265 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 }
Andy Adamsond0179312008-12-23 16:06:17 -05001267 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001268 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269}
1270
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001271static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272{
Al Viro8687b632006-10-19 23:28:48 -07001273 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001275 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001276 *p++ = cpu_to_be32(OP_LOCKT);
1277 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001278 p = xdr_encode_hyper(p, args->fl->fl_start);
1279 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001280 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001281 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001282 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283}
1284
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001285static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286{
Al Viro8687b632006-10-19 23:28:48 -07001287 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
Benny Halevy13c65ce2009-08-14 17:19:25 +03001289 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001290 *p++ = cpu_to_be32(OP_LOCKU);
1291 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1292 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001293 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001294 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001295 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001296 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001297 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298}
1299
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001300static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1301{
1302 __be32 *p;
1303
1304 p = reserve_space(xdr, 4);
1305 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1306 encode_lockowner(xdr, lowner);
1307 hdr->nops++;
1308 hdr->replen += decode_release_lockowner_maxsz;
1309}
1310
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001311static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312{
1313 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001314 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
Benny Halevy13c65ce2009-08-14 17:19:25 +03001316 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001317 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001318 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001319 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001320 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321}
1322
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001323static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324{
Al Viro8687b632006-10-19 23:28:48 -07001325 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Benny Halevy13c65ce2009-08-14 17:19:25 +03001327 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001328 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001329 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001330 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001331 break;
1332 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001333 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001334 break;
1335 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001336 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001337 break;
1338 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001339 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 }
Benny Halevy34558512009-08-14 17:19:30 +03001341 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342}
1343
1344static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1345{
Al Viro8687b632006-10-19 23:28:48 -07001346 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 /*
1348 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1349 * owner 4 = 32
1350 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001351 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001352 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001353 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001354 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001355 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001356 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001357 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001358 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001359 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001360 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361}
1362
1363static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1364{
Al Viro8687b632006-10-19 23:28:48 -07001365 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001366 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
Benny Halevy13c65ce2009-08-14 17:19:25 +03001368 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001370 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001371 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001372 encode_attrs(xdr, arg->u.attrs, arg->server);
1373 break;
1374 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001375 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001376 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001377 if (nfs4_has_persistent_session(clp)) {
1378 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1379 encode_attrs(xdr, arg->u.attrs, arg->server);
1380 } else {
1381 struct iattr dummy;
1382
1383 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1384 encode_nfs4_verifier(xdr, &arg->u.verifier);
1385 dummy.ia_valid = 0;
1386 encode_attrs(xdr, &dummy, arg->server);
1387 }
1388 } else {
1389 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1390 encode_nfs4_verifier(xdr, &arg->u.verifier);
1391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 }
1393}
1394
1395static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1396{
Al Viro8687b632006-10-19 23:28:48 -07001397 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
Benny Halevy13c65ce2009-08-14 17:19:25 +03001399 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001401 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001402 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001403 break;
1404 default:
1405 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001406 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001407 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 }
1409}
1410
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001411static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412{
Al Viro8687b632006-10-19 23:28:48 -07001413 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Benny Halevy13c65ce2009-08-14 17:19:25 +03001415 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001417 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001418 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001419 break;
1420 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001421 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001422 break;
1423 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001424 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001425 break;
1426 default:
1427 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 }
1429}
1430
1431static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1432{
Al Viro8687b632006-10-19 23:28:48 -07001433 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
Benny Halevy13c65ce2009-08-14 17:19:25 +03001435 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001436 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 encode_string(xdr, name->len, name->name);
1438}
1439
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001440static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441{
Al Viro8687b632006-10-19 23:28:48 -07001442 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
Benny Halevy13c65ce2009-08-14 17:19:25 +03001444 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001445 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 encode_delegation_type(xdr, type);
1447}
1448
1449static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1450{
Al Viro8687b632006-10-19 23:28:48 -07001451 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Benny Halevy13c65ce2009-08-14 17:19:25 +03001453 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001454 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001455 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 encode_string(xdr, name->len, name->name);
1457}
1458
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001459static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460{
1461 encode_openhdr(xdr, arg);
1462 encode_opentype(xdr, arg);
1463 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001464 case NFS4_OPEN_CLAIM_NULL:
1465 encode_claim_null(xdr, arg->name);
1466 break;
1467 case NFS4_OPEN_CLAIM_PREVIOUS:
1468 encode_claim_previous(xdr, arg->u.delegation_type);
1469 break;
1470 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1471 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1472 break;
1473 default:
1474 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 }
Andy Adamsond0179312008-12-23 16:06:17 -05001476 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001477 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478}
1479
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001480static 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 -07001481{
Al Viro8687b632006-10-19 23:28:48 -07001482 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Benny Halevy13c65ce2009-08-14 17:19:25 +03001484 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001485 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001486 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001487 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001488 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001489 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490}
1491
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001492static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493{
Al Viro8687b632006-10-19 23:28:48 -07001494 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
Benny Halevy13c65ce2009-08-14 17:19:25 +03001496 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001497 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001498 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001499 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001500 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001501 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001502 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503}
1504
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001505static void
Andy Adamsond0179312008-12-23 16:06:17 -05001506encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507{
1508 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001509 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Benny Halevy13c65ce2009-08-14 17:19:25 +03001511 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001512 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001513 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001514 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001515 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516}
1517
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001518static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519{
Andy Adamson05d564f2008-12-23 16:06:15 -05001520 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001521
Benny Halevy13c65ce2009-08-14 17:19:25 +03001522 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001523 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001524 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001525 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526}
1527
Andy Adamson89d1ea62011-03-01 01:34:09 +00001528static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001531 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Benny Halevy13c65ce2009-08-14 17:19:25 +03001533 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001535 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001536 if (zero_seqid)
1537 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001538 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 } else
Benny Halevy34558512009-08-14 17:19:30 +03001540 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541}
1542
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001543static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544{
Al Viro8687b632006-10-19 23:28:48 -07001545 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
Benny Halevy13c65ce2009-08-14 17:19:25 +03001547 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001548 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Andy Adamson89d1ea62011-03-01 01:34:09 +00001550 encode_stateid(xdr, args->context, args->lock_context,
1551 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Benny Halevy13c65ce2009-08-14 17:19:25 +03001553 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001554 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001555 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001556 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001557 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558}
1559
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001560static 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 -07001561{
Trond Myklebust28331a42011-04-27 13:47:52 -04001562 uint32_t attrs[2] = {
1563 FATTR4_WORD0_RDATTR_ERROR,
1564 FATTR4_WORD1_MOUNTED_ON_FILEID,
1565 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001566 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001567 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001569 if (readdir->plus) {
1570 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001571 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001572 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1573 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1574 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1575 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001576 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001577 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001578 /* Use mounted_on_fileid only if the server supports it */
1579 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1580 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001581
Benny Halevy13c65ce2009-08-14 17:19:25 +03001582 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001583 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001584 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001585 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001586 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001587 *p++ = cpu_to_be32(readdir->count);
1588 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001589
Benny Halevye75bc1c2009-08-14 17:18:54 +03001590 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001591 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001592 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001593 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001594 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1595 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001596 (unsigned long long)readdir->cookie,
1597 ((u32 *)readdir->verifier.data)[0],
1598 ((u32 *)readdir->verifier.data)[1],
1599 attrs[0] & readdir->bitmask[0],
1600 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601}
1602
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001603static 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 -07001604{
Al Viro8687b632006-10-19 23:28:48 -07001605 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606
Benny Halevy13c65ce2009-08-14 17:19:25 +03001607 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001608 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001609 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001610 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611}
1612
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001613static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614{
Al Viro8687b632006-10-19 23:28:48 -07001615 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
Benny Halevy13c65ce2009-08-14 17:19:25 +03001617 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001618 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001619 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001620 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001621 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622}
1623
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001624static 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 -07001625{
Al Viro8687b632006-10-19 23:28:48 -07001626 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
Benny Halevy811652b2009-08-14 17:19:34 +03001628 p = reserve_space(xdr, 4);
1629 *p = cpu_to_be32(OP_RENAME);
1630 encode_string(xdr, oldname->len, oldname->name);
1631 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001632 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001633 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634}
1635
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001636static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637{
Al Viro8687b632006-10-19 23:28:48 -07001638 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
Benny Halevy13c65ce2009-08-14 17:19:25 +03001640 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001641 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001642 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001643 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001644 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645}
1646
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001647static void
Andy Adamsond0179312008-12-23 16:06:17 -05001648encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001649{
Al Viro8687b632006-10-19 23:28:48 -07001650 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001651
Benny Halevy13c65ce2009-08-14 17:19:25 +03001652 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001653 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001654 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001655 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001656}
1657
Chuck Lever9f06c712010-12-14 14:59:18 +00001658static void
Andy Adamsond0179312008-12-23 16:06:17 -05001659encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001660{
Al Viro8687b632006-10-19 23:28:48 -07001661 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001662
Benny Halevy13c65ce2009-08-14 17:19:25 +03001663 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001664 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001665 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001666 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001667 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001668 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001669 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001670 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001671 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001672 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001673 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001674 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001675}
1676
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001677static void
Andy Adamsond0179312008-12-23 16:06:17 -05001678encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679{
Al Viro8687b632006-10-19 23:28:48 -07001680 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
Benny Halevy13c65ce2009-08-14 17:19:25 +03001682 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001683 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001684 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001685 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686}
1687
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001688static 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 -07001689{
Al Viro8687b632006-10-19 23:28:48 -07001690 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001691
Benny Halevy13c65ce2009-08-14 17:19:25 +03001692 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001693 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001694 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001695 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001696 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001697 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698}
1699
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001700static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701{
Al Viro8687b632006-10-19 23:28:48 -07001702 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
Benny Halevy13c65ce2009-08-14 17:19:25 +03001704 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001705 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001706 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
1708 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001709 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001710 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1712 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001713 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001714 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001715 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001716 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717}
1718
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001719static 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 -07001720{
Andy Adamson05d564f2008-12-23 16:06:15 -05001721 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
Benny Halevy13c65ce2009-08-14 17:19:25 +03001723 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001724 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001725 p = xdr_encode_hyper(p, arg->clientid);
1726 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001727 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001728 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729}
1730
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001731static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732{
Al Viro8687b632006-10-19 23:28:48 -07001733 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
Benny Halevy13c65ce2009-08-14 17:19:25 +03001735 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001736 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
Andy Adamson89d1ea62011-03-01 01:34:09 +00001738 encode_stateid(xdr, args->context, args->lock_context,
1739 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Benny Halevy13c65ce2009-08-14 17:19:25 +03001741 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001742 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001743 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001744 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
1746 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001747 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001748 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749}
1750
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001751static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752{
Al Viro8687b632006-10-19 23:28:48 -07001753 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
Benny Halevy13c65ce2009-08-14 17:19:25 +03001755 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756
Benny Halevye75bc1c2009-08-14 17:18:54 +03001757 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001758 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001759 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001760 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001762
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001763static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1764{
1765 int len = name->len;
1766 __be32 *p;
1767
1768 p = reserve_space(xdr, 8 + len);
1769 *p++ = cpu_to_be32(OP_SECINFO);
1770 xdr_encode_opaque(p, name->name, len);
1771 hdr->nops++;
1772 hdr->replen += decode_secinfo_maxsz;
1773}
1774
Benny Halevy99fe60d2009-04-01 09:22:29 -04001775#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001776/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001777static void encode_exchange_id(struct xdr_stream *xdr,
1778 struct nfs41_exchange_id_args *args,
1779 struct compound_hdr *hdr)
1780{
1781 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001782 char impl_name[NFS4_OPAQUE_LIMIT];
1783 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001784
Benny Halevy13c65ce2009-08-14 17:19:25 +03001785 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001786 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001787 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001788
1789 encode_string(xdr, args->id_len, args->id);
1790
Benny Halevy13c65ce2009-08-14 17:19:25 +03001791 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001792 *p++ = cpu_to_be32(args->flags);
1793 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001794
1795 if (send_implementation_id &&
1796 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1797 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1798 <= NFS4_OPAQUE_LIMIT + 1)
1799 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1800 utsname()->sysname, utsname()->release,
1801 utsname()->version, utsname()->machine);
1802
1803 if (len > 0) {
1804 *p = cpu_to_be32(1); /* implementation id array length=1 */
1805
1806 encode_string(xdr,
1807 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1808 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1809 encode_string(xdr, len, impl_name);
1810 /* just send zeros for nii_date - the date is in nii_name */
1811 p = reserve_space(xdr, 12);
1812 p = xdr_encode_hyper(p, 0);
1813 *p = cpu_to_be32(0);
1814 } else
1815 *p = cpu_to_be32(0); /* implementation id array length=0 */
1816
Benny Halevy99fe60d2009-04-01 09:22:29 -04001817 hdr->nops++;
1818 hdr->replen += decode_exchange_id_maxsz;
1819}
Andy Adamsonfc931582009-04-01 09:22:31 -04001820
1821static void encode_create_session(struct xdr_stream *xdr,
1822 struct nfs41_create_session_args *args,
1823 struct compound_hdr *hdr)
1824{
1825 __be32 *p;
1826 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1827 uint32_t len;
1828 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001829 u32 max_resp_sz_cached;
1830
1831 /*
1832 * Assumes OPEN is the biggest non-idempotent compound.
1833 * 2 is the verifier.
1834 */
1835 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1836 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001837
Andy Adamsonfc931582009-04-01 09:22:31 -04001838 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1839 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001840
Benny Halevy13c65ce2009-08-14 17:19:25 +03001841 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001842 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001843 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001844 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1845 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001846
Andy Adamsonfc931582009-04-01 09:22:31 -04001847 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001848 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001849 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1850 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001851 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001852 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1853 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1854 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001855
1856 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001857 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001858 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1859 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1860 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1861 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1862 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1863 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001864
Benny Halevye75bc1c2009-08-14 17:18:54 +03001865 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001866 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001867 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001868
1869 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001870 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001871 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001872 *p++ = cpu_to_be32(0); /* UID */
1873 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001874 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001875 hdr->nops++;
1876 hdr->replen += decode_create_session_maxsz;
1877}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001878
1879static void encode_destroy_session(struct xdr_stream *xdr,
1880 struct nfs4_session *session,
1881 struct compound_hdr *hdr)
1882{
1883 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001884 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001885 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001886 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001887 hdr->nops++;
1888 hdr->replen += decode_destroy_session_maxsz;
1889}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001890
1891static void encode_reclaim_complete(struct xdr_stream *xdr,
1892 struct nfs41_reclaim_complete_args *args,
1893 struct compound_hdr *hdr)
1894{
1895 __be32 *p;
1896
1897 p = reserve_space(xdr, 8);
1898 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1899 *p++ = cpu_to_be32(args->one_fs);
1900 hdr->nops++;
1901 hdr->replen += decode_reclaim_complete_maxsz;
1902}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001903#endif /* CONFIG_NFS_V4_1 */
1904
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001905static void encode_sequence(struct xdr_stream *xdr,
1906 const struct nfs4_sequence_args *args,
1907 struct compound_hdr *hdr)
1908{
1909#if defined(CONFIG_NFS_V4_1)
1910 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001911 struct nfs4_slot_table *tp;
1912 struct nfs4_slot *slot;
1913 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001914
1915 if (!session)
1916 return;
1917
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001918 tp = &session->fc_slot_table;
1919
1920 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1921 slot = tp->slots + args->sa_slotid;
1922
Benny Halevy13c65ce2009-08-14 17:19:25 +03001923 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001924 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001925
1926 /*
1927 * Sessionid + seqid + slotid + max slotid + cache_this
1928 */
1929 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1930 "max_slotid=%d cache_this=%d\n",
1931 __func__,
1932 ((u32 *)session->sess_id.data)[0],
1933 ((u32 *)session->sess_id.data)[1],
1934 ((u32 *)session->sess_id.data)[2],
1935 ((u32 *)session->sess_id.data)[3],
1936 slot->seq_nr, args->sa_slotid,
1937 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001938 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001939 *p++ = cpu_to_be32(slot->seq_nr);
1940 *p++ = cpu_to_be32(args->sa_slotid);
1941 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001942 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001943 hdr->nops++;
1944 hdr->replen += decode_sequence_maxsz;
1945#endif /* CONFIG_NFS_V4_1 */
1946}
1947
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001948#ifdef CONFIG_NFS_V4_1
1949static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001950encode_getdevicelist(struct xdr_stream *xdr,
1951 const struct nfs4_getdevicelist_args *args,
1952 struct compound_hdr *hdr)
1953{
1954 __be32 *p;
1955 nfs4_verifier dummy = {
1956 .data = "dummmmmy",
1957 };
1958
1959 p = reserve_space(xdr, 20);
1960 *p++ = cpu_to_be32(OP_GETDEVICELIST);
1961 *p++ = cpu_to_be32(args->layoutclass);
1962 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1963 xdr_encode_hyper(p, 0ULL); /* cookie */
1964 encode_nfs4_verifier(xdr, &dummy);
1965 hdr->nops++;
1966 hdr->replen += decode_getdevicelist_maxsz;
1967}
1968
1969static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001970encode_getdeviceinfo(struct xdr_stream *xdr,
1971 const struct nfs4_getdeviceinfo_args *args,
1972 struct compound_hdr *hdr)
1973{
1974 __be32 *p;
1975
1976 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1977 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1978 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1979 NFS4_DEVICEID4_SIZE);
1980 *p++ = cpu_to_be32(args->pdev->layout_type);
1981 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1982 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1983 hdr->nops++;
1984 hdr->replen += decode_getdeviceinfo_maxsz;
1985}
1986
1987static void
1988encode_layoutget(struct xdr_stream *xdr,
1989 const struct nfs4_layoutget_args *args,
1990 struct compound_hdr *hdr)
1991{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001992 __be32 *p;
1993
1994 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1995 *p++ = cpu_to_be32(OP_LAYOUTGET);
1996 *p++ = cpu_to_be32(0); /* Signal layout available */
1997 *p++ = cpu_to_be32(args->type);
1998 *p++ = cpu_to_be32(args->range.iomode);
1999 p = xdr_encode_hyper(p, args->range.offset);
2000 p = xdr_encode_hyper(p, args->range.length);
2001 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00002002 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002003 *p = cpu_to_be32(args->maxcount);
2004
2005 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
2006 __func__,
2007 args->type,
2008 args->range.iomode,
2009 (unsigned long)args->range.offset,
2010 (unsigned long)args->range.length,
2011 args->maxcount);
2012 hdr->nops++;
2013 hdr->replen += decode_layoutget_maxsz;
2014}
Andy Adamson863a3c62011-03-23 13:27:54 +00002015
2016static int
2017encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03002018 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00002019 const struct nfs4_layoutcommit_args *args,
2020 struct compound_hdr *hdr)
2021{
2022 __be32 *p;
2023
2024 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2025 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2026
Benny Halevyac7db722011-05-22 19:53:48 +03002027 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
Andy Adamson863a3c62011-03-23 13:27:54 +00002028 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
2029 /* Only whole file layouts */
2030 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002031 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Andy Adamson863a3c62011-03-23 13:27:54 +00002032 *p++ = cpu_to_be32(0); /* reclaim */
2033 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
2034 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2035 p = xdr_encode_hyper(p, args->lastbytewritten);
2036 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2037 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002038
2039 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2040 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2041 NFS_I(inode)->layout, xdr, args);
2042 else {
2043 p = reserve_space(xdr, 4);
2044 *p = cpu_to_be32(0); /* no layout-type payload */
2045 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002046
2047 hdr->nops++;
2048 hdr->replen += decode_layoutcommit_maxsz;
2049 return 0;
2050}
Benny Halevycbe82602011-05-22 19:52:37 +03002051
2052static void
2053encode_layoutreturn(struct xdr_stream *xdr,
2054 const struct nfs4_layoutreturn_args *args,
2055 struct compound_hdr *hdr)
2056{
2057 __be32 *p;
2058
2059 p = reserve_space(xdr, 20);
2060 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
2061 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2062 *p++ = cpu_to_be32(args->layout_type);
2063 *p++ = cpu_to_be32(IOMODE_ANY);
2064 *p = cpu_to_be32(RETURN_FILE);
2065 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
2066 p = xdr_encode_hyper(p, 0);
2067 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2068 spin_lock(&args->inode->i_lock);
2069 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
2070 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002071 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2072 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2073 NFS_I(args->inode)->layout, xdr, args);
2074 } else {
2075 p = reserve_space(xdr, 4);
2076 *p = cpu_to_be32(0);
2077 }
Benny Halevycbe82602011-05-22 19:52:37 +03002078 hdr->nops++;
2079 hdr->replen += decode_layoutreturn_maxsz;
2080}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002081
2082static int
2083encode_secinfo_no_name(struct xdr_stream *xdr,
2084 const struct nfs41_secinfo_no_name_args *args,
2085 struct compound_hdr *hdr)
2086{
2087 __be32 *p;
2088 p = reserve_space(xdr, 8);
2089 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2090 *p++ = cpu_to_be32(args->style);
2091 hdr->nops++;
2092 hdr->replen += decode_secinfo_no_name_maxsz;
2093 return 0;
2094}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002095
2096static void encode_test_stateid(struct xdr_stream *xdr,
2097 struct nfs41_test_stateid_args *args,
2098 struct compound_hdr *hdr)
2099{
2100 __be32 *p;
2101
2102 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
2103 *p++ = cpu_to_be32(OP_TEST_STATEID);
2104 *p++ = cpu_to_be32(1);
2105 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2106 hdr->nops++;
2107 hdr->replen += decode_test_stateid_maxsz;
2108}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002109
2110static void encode_free_stateid(struct xdr_stream *xdr,
2111 struct nfs41_free_stateid_args *args,
2112 struct compound_hdr *hdr)
2113{
2114 __be32 *p;
2115 p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
2116 *p++ = cpu_to_be32(OP_FREE_STATEID);
2117 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2118 hdr->nops++;
2119 hdr->replen += decode_free_stateid_maxsz;
2120}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002121#endif /* CONFIG_NFS_V4_1 */
2122
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123/*
2124 * END OF "GENERIC" ENCODE ROUTINES.
2125 */
2126
Benny Halevy66cc0422009-04-01 09:22:10 -04002127static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2128{
2129#if defined(CONFIG_NFS_V4_1)
2130 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04002131 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002132#endif /* CONFIG_NFS_V4_1 */
2133 return 0;
2134}
2135
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136/*
2137 * Encode an ACCESS request
2138 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002139static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2140 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002143 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145
Chuck Lever9f06c712010-12-14 14:59:18 +00002146 encode_compound_hdr(xdr, req, &hdr);
2147 encode_sequence(xdr, &args->seq_args, &hdr);
2148 encode_putfh(xdr, args->fh, &hdr);
2149 encode_access(xdr, args->access, &hdr);
2150 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002151 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152}
2153
2154/*
2155 * Encode LOOKUP request
2156 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002157static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2158 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002161 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
Chuck Lever9f06c712010-12-14 14:59:18 +00002164 encode_compound_hdr(xdr, req, &hdr);
2165 encode_sequence(xdr, &args->seq_args, &hdr);
2166 encode_putfh(xdr, args->dir_fh, &hdr);
2167 encode_lookup(xdr, args->name, &hdr);
2168 encode_getfh(xdr, &hdr);
2169 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002170 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171}
2172
2173/*
2174 * Encode LOOKUP_ROOT request
2175 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002176static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2177 struct xdr_stream *xdr,
2178 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002181 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183
Chuck Lever9f06c712010-12-14 14:59:18 +00002184 encode_compound_hdr(xdr, req, &hdr);
2185 encode_sequence(xdr, &args->seq_args, &hdr);
2186 encode_putrootfh(xdr, &hdr);
2187 encode_getfh(xdr, &hdr);
2188 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002189 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190}
2191
2192/*
2193 * Encode REMOVE request
2194 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002195static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2196 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002199 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
Chuck Lever9f06c712010-12-14 14:59:18 +00002202 encode_compound_hdr(xdr, req, &hdr);
2203 encode_sequence(xdr, &args->seq_args, &hdr);
2204 encode_putfh(xdr, args->fh, &hdr);
2205 encode_remove(xdr, &args->name, &hdr);
2206 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002207 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208}
2209
2210/*
2211 * Encode RENAME request
2212 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002213static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2214 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002217 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219
Chuck Lever9f06c712010-12-14 14:59:18 +00002220 encode_compound_hdr(xdr, req, &hdr);
2221 encode_sequence(xdr, &args->seq_args, &hdr);
2222 encode_putfh(xdr, args->old_dir, &hdr);
2223 encode_savefh(xdr, &hdr);
2224 encode_putfh(xdr, args->new_dir, &hdr);
2225 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2226 encode_getfattr(xdr, args->bitmask, &hdr);
2227 encode_restorefh(xdr, &hdr);
2228 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002229 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230}
2231
2232/*
2233 * Encode LINK request
2234 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002235static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2236 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002239 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
Chuck Lever9f06c712010-12-14 14:59:18 +00002242 encode_compound_hdr(xdr, req, &hdr);
2243 encode_sequence(xdr, &args->seq_args, &hdr);
2244 encode_putfh(xdr, args->fh, &hdr);
2245 encode_savefh(xdr, &hdr);
2246 encode_putfh(xdr, args->dir_fh, &hdr);
2247 encode_link(xdr, args->name, &hdr);
2248 encode_getfattr(xdr, args->bitmask, &hdr);
2249 encode_restorefh(xdr, &hdr);
2250 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002251 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252}
2253
2254/*
2255 * Encode CREATE request
2256 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002257static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2258 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002261 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263
Chuck Lever9f06c712010-12-14 14:59:18 +00002264 encode_compound_hdr(xdr, req, &hdr);
2265 encode_sequence(xdr, &args->seq_args, &hdr);
2266 encode_putfh(xdr, args->dir_fh, &hdr);
2267 encode_savefh(xdr, &hdr);
2268 encode_create(xdr, args, &hdr);
2269 encode_getfh(xdr, &hdr);
2270 encode_getfattr(xdr, args->bitmask, &hdr);
2271 encode_restorefh(xdr, &hdr);
2272 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002273 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274}
2275
2276/*
2277 * Encode SYMLINK request
2278 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002279static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2280 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281{
Chuck Lever9f06c712010-12-14 14:59:18 +00002282 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283}
2284
2285/*
2286 * Encode GETATTR request
2287 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002288static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2289 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002292 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
Chuck Lever9f06c712010-12-14 14:59:18 +00002295 encode_compound_hdr(xdr, req, &hdr);
2296 encode_sequence(xdr, &args->seq_args, &hdr);
2297 encode_putfh(xdr, args->fh, &hdr);
2298 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002299 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300}
2301
2302/*
2303 * Encode a CLOSE request
2304 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002305static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2306 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307{
Andy Adamson05d564f2008-12-23 16:06:15 -05002308 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002309 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002310 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
Chuck Lever9f06c712010-12-14 14:59:18 +00002312 encode_compound_hdr(xdr, req, &hdr);
2313 encode_sequence(xdr, &args->seq_args, &hdr);
2314 encode_putfh(xdr, args->fh, &hdr);
2315 encode_close(xdr, args, &hdr);
2316 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002317 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318}
2319
2320/*
2321 * Encode an OPEN request
2322 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002323static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2324 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002327 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329
Chuck Lever9f06c712010-12-14 14:59:18 +00002330 encode_compound_hdr(xdr, req, &hdr);
2331 encode_sequence(xdr, &args->seq_args, &hdr);
2332 encode_putfh(xdr, args->fh, &hdr);
2333 encode_savefh(xdr, &hdr);
2334 encode_open(xdr, args, &hdr);
2335 encode_getfh(xdr, &hdr);
2336 encode_getfattr(xdr, args->bitmask, &hdr);
2337 encode_restorefh(xdr, &hdr);
Trond Myklebust6926afd2012-01-07 13:22:46 -05002338 encode_getfattr(xdr, args->dir_bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002339 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340}
2341
2342/*
2343 * Encode an OPEN_CONFIRM request
2344 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002345static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2346 struct xdr_stream *xdr,
2347 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002350 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352
Chuck Lever9f06c712010-12-14 14:59:18 +00002353 encode_compound_hdr(xdr, req, &hdr);
2354 encode_putfh(xdr, args->fh, &hdr);
2355 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002356 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357}
2358
2359/*
2360 * Encode an OPEN request with no attributes.
2361 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002362static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2363 struct xdr_stream *xdr,
2364 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002367 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369
Chuck Lever9f06c712010-12-14 14:59:18 +00002370 encode_compound_hdr(xdr, req, &hdr);
2371 encode_sequence(xdr, &args->seq_args, &hdr);
2372 encode_putfh(xdr, args->fh, &hdr);
2373 encode_open(xdr, args, &hdr);
2374 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002375 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376}
2377
2378/*
2379 * Encode an OPEN_DOWNGRADE request
2380 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002381static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2382 struct xdr_stream *xdr,
2383 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002386 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388
Chuck Lever9f06c712010-12-14 14:59:18 +00002389 encode_compound_hdr(xdr, req, &hdr);
2390 encode_sequence(xdr, &args->seq_args, &hdr);
2391 encode_putfh(xdr, args->fh, &hdr);
2392 encode_open_downgrade(xdr, args, &hdr);
2393 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002394 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395}
2396
2397/*
2398 * Encode a LOCK request
2399 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002400static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2401 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002404 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
Chuck Lever9f06c712010-12-14 14:59:18 +00002407 encode_compound_hdr(xdr, req, &hdr);
2408 encode_sequence(xdr, &args->seq_args, &hdr);
2409 encode_putfh(xdr, args->fh, &hdr);
2410 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002411 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412}
2413
2414/*
2415 * Encode a LOCKT request
2416 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002417static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2418 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002421 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423
Chuck Lever9f06c712010-12-14 14:59:18 +00002424 encode_compound_hdr(xdr, req, &hdr);
2425 encode_sequence(xdr, &args->seq_args, &hdr);
2426 encode_putfh(xdr, args->fh, &hdr);
2427 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002428 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429}
2430
2431/*
2432 * Encode a LOCKU request
2433 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002434static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2435 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002438 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440
Chuck Lever9f06c712010-12-14 14:59:18 +00002441 encode_compound_hdr(xdr, req, &hdr);
2442 encode_sequence(xdr, &args->seq_args, &hdr);
2443 encode_putfh(xdr, args->fh, &hdr);
2444 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002445 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446}
2447
Chuck Lever9f06c712010-12-14 14:59:18 +00002448static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2449 struct xdr_stream *xdr,
2450 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002451{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002452 struct compound_hdr hdr = {
2453 .minorversion = 0,
2454 };
2455
Chuck Lever9f06c712010-12-14 14:59:18 +00002456 encode_compound_hdr(xdr, req, &hdr);
2457 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002458 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002459}
2460
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461/*
2462 * Encode a READLINK request
2463 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002464static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2465 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002468 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470
Chuck Lever9f06c712010-12-14 14:59:18 +00002471 encode_compound_hdr(xdr, req, &hdr);
2472 encode_sequence(xdr, &args->seq_args, &hdr);
2473 encode_putfh(xdr, args->fh, &hdr);
2474 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002475
Benny Halevy28f56692009-04-01 09:22:09 -04002476 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002477 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002478 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479}
2480
2481/*
2482 * Encode a READDIR request
2483 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002484static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2485 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002488 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490
Chuck Lever9f06c712010-12-14 14:59:18 +00002491 encode_compound_hdr(xdr, req, &hdr);
2492 encode_sequence(xdr, &args->seq_args, &hdr);
2493 encode_putfh(xdr, args->fh, &hdr);
2494 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002495
Benny Halevy28f56692009-04-01 09:22:09 -04002496 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002497 args->pgbase, args->count);
2498 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002499 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002500 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002501 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502}
2503
2504/*
2505 * Encode a READ request
2506 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002507static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2508 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002511 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513
Chuck Lever9f06c712010-12-14 14:59:18 +00002514 encode_compound_hdr(xdr, req, &hdr);
2515 encode_sequence(xdr, &args->seq_args, &hdr);
2516 encode_putfh(xdr, args->fh, &hdr);
2517 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
Benny Halevy28f56692009-04-01 09:22:09 -04002519 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002521 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002522 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523}
2524
2525/*
2526 * Encode an SETATTR request
2527 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002528static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2529 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530{
Andy Adamson05d564f2008-12-23 16:06:15 -05002531 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002532 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002533 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534
Chuck Lever9f06c712010-12-14 14:59:18 +00002535 encode_compound_hdr(xdr, req, &hdr);
2536 encode_sequence(xdr, &args->seq_args, &hdr);
2537 encode_putfh(xdr, args->fh, &hdr);
2538 encode_setattr(xdr, args, args->server, &hdr);
2539 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002540 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541}
2542
2543/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002544 * Encode a GETACL request
2545 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002546static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2547 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002548{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002549 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002550 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002551 };
Benny Halevy28f56692009-04-01 09:22:09 -04002552 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002553
Chuck Lever9f06c712010-12-14 14:59:18 +00002554 encode_compound_hdr(xdr, req, &hdr);
2555 encode_sequence(xdr, &args->seq_args, &hdr);
2556 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002557 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002558 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002559
Benny Halevy28f56692009-04-01 09:22:09 -04002560 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002561 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002562 xdr_set_scratch_buffer(xdr, page_address(args->acl_scratch), PAGE_SIZE);
2563
Andy Adamsond0179312008-12-23 16:06:17 -05002564 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002565}
2566
2567/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 * Encode a WRITE request
2569 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002570static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2571 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002574 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576
Chuck Lever9f06c712010-12-14 14:59:18 +00002577 encode_compound_hdr(xdr, req, &hdr);
2578 encode_sequence(xdr, &args->seq_args, &hdr);
2579 encode_putfh(xdr, args->fh, &hdr);
2580 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002581 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002582 if (args->bitmask)
2583 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002584 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585}
2586
2587/*
2588 * a COMMIT request
2589 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002590static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2591 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002594 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596
Chuck Lever9f06c712010-12-14 14:59:18 +00002597 encode_compound_hdr(xdr, req, &hdr);
2598 encode_sequence(xdr, &args->seq_args, &hdr);
2599 encode_putfh(xdr, args->fh, &hdr);
2600 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002601 if (args->bitmask)
2602 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002603 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604}
2605
2606/*
2607 * FSINFO request
2608 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002609static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2610 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002613 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615
Chuck Lever9f06c712010-12-14 14:59:18 +00002616 encode_compound_hdr(xdr, req, &hdr);
2617 encode_sequence(xdr, &args->seq_args, &hdr);
2618 encode_putfh(xdr, args->fh, &hdr);
2619 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002620 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621}
2622
2623/*
2624 * a PATHCONF request
2625 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002626static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2627 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002630 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632
Chuck Lever9f06c712010-12-14 14:59:18 +00002633 encode_compound_hdr(xdr, req, &hdr);
2634 encode_sequence(xdr, &args->seq_args, &hdr);
2635 encode_putfh(xdr, args->fh, &hdr);
2636 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002637 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002638 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639}
2640
2641/*
2642 * a STATFS request
2643 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002644static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2645 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002648 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650
Chuck Lever9f06c712010-12-14 14:59:18 +00002651 encode_compound_hdr(xdr, req, &hdr);
2652 encode_sequence(xdr, &args->seq_args, &hdr);
2653 encode_putfh(xdr, args->fh, &hdr);
2654 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002655 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002656 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657}
2658
2659/*
2660 * GETATTR_BITMAP request
2661 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002662static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2663 struct xdr_stream *xdr,
2664 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002667 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669
Chuck Lever9f06c712010-12-14 14:59:18 +00002670 encode_compound_hdr(xdr, req, &hdr);
2671 encode_sequence(xdr, &args->seq_args, &hdr);
2672 encode_putfh(xdr, args->fhandle, &hdr);
2673 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002674 FATTR4_WORD0_LINK_SUPPORT|
2675 FATTR4_WORD0_SYMLINK_SUPPORT|
2676 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002677 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678}
2679
2680/*
2681 * a RENEW request
2682 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002683static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2684 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002687 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 };
2689
Chuck Lever9f06c712010-12-14 14:59:18 +00002690 encode_compound_hdr(xdr, req, &hdr);
2691 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002692 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693}
2694
2695/*
2696 * a SETCLIENTID request
2697 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002698static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2699 struct xdr_stream *xdr,
2700 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002703 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 };
2705
Chuck Lever9f06c712010-12-14 14:59:18 +00002706 encode_compound_hdr(xdr, req, &hdr);
2707 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002708 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709}
2710
2711/*
2712 * a SETCLIENTID_CONFIRM request
2713 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002714static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2715 struct xdr_stream *xdr,
2716 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002719 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 };
Fred Isamandae100c2011-07-30 20:52:37 -04002721 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
Chuck Lever9f06c712010-12-14 14:59:18 +00002723 encode_compound_hdr(xdr, req, &hdr);
2724 encode_setclientid_confirm(xdr, arg, &hdr);
2725 encode_putrootfh(xdr, &hdr);
2726 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002727 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728}
2729
2730/*
2731 * DELEGRETURN request
2732 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002733static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2734 struct xdr_stream *xdr,
2735 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002738 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740
Chuck Lever9f06c712010-12-14 14:59:18 +00002741 encode_compound_hdr(xdr, req, &hdr);
2742 encode_sequence(xdr, &args->seq_args, &hdr);
2743 encode_putfh(xdr, args->fhandle, &hdr);
2744 encode_delegreturn(xdr, args->stateid, &hdr);
2745 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002746 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747}
2748
2749/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002750 * Encode FS_LOCATIONS request
2751 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002752static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2753 struct xdr_stream *xdr,
2754 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002755{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002756 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002757 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002758 };
Benny Halevy28f56692009-04-01 09:22:09 -04002759 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002760
Chuck Lever9f06c712010-12-14 14:59:18 +00002761 encode_compound_hdr(xdr, req, &hdr);
2762 encode_sequence(xdr, &args->seq_args, &hdr);
2763 encode_putfh(xdr, args->dir_fh, &hdr);
2764 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002765 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002766 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002767
Benny Halevy28f56692009-04-01 09:22:09 -04002768 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002769 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002770 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002771}
2772
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002773/*
2774 * Encode SECINFO request
2775 */
2776static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2777 struct xdr_stream *xdr,
2778 struct nfs4_secinfo_arg *args)
2779{
2780 struct compound_hdr hdr = {
2781 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2782 };
2783
2784 encode_compound_hdr(xdr, req, &hdr);
2785 encode_sequence(xdr, &args->seq_args, &hdr);
2786 encode_putfh(xdr, args->dir_fh, &hdr);
2787 encode_secinfo(xdr, args->name, &hdr);
2788 encode_nops(&hdr);
2789}
2790
Benny Halevy99fe60d2009-04-01 09:22:29 -04002791#if defined(CONFIG_NFS_V4_1)
2792/*
2793 * EXCHANGE_ID request
2794 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002795static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2796 struct xdr_stream *xdr,
2797 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002798{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002799 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002800 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002801 };
2802
Chuck Lever9f06c712010-12-14 14:59:18 +00002803 encode_compound_hdr(xdr, req, &hdr);
2804 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002805 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002806}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002807
2808/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002809 * a CREATE_SESSION request
2810 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002811static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2812 struct xdr_stream *xdr,
2813 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002814{
Andy Adamsonfc931582009-04-01 09:22:31 -04002815 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002816 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002817 };
2818
Chuck Lever9f06c712010-12-14 14:59:18 +00002819 encode_compound_hdr(xdr, req, &hdr);
2820 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002821 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002822}
2823
2824/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002825 * a DESTROY_SESSION request
2826 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002827static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2828 struct xdr_stream *xdr,
2829 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002830{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002831 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002832 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002833 };
2834
Chuck Lever9f06c712010-12-14 14:59:18 +00002835 encode_compound_hdr(xdr, req, &hdr);
2836 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002837 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002838}
2839
2840/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002841 * a SEQUENCE request
2842 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002843static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2844 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002845{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002846 struct compound_hdr hdr = {
2847 .minorversion = nfs4_xdr_minorversion(args),
2848 };
2849
Chuck Lever9f06c712010-12-14 14:59:18 +00002850 encode_compound_hdr(xdr, req, &hdr);
2851 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002852 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002853}
2854
2855/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002856 * a GET_LEASE_TIME request
2857 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002858static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2859 struct xdr_stream *xdr,
2860 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002861{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002862 struct compound_hdr hdr = {
2863 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2864 };
Fred Isamandae100c2011-07-30 20:52:37 -04002865 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002866
Chuck Lever9f06c712010-12-14 14:59:18 +00002867 encode_compound_hdr(xdr, req, &hdr);
2868 encode_sequence(xdr, &args->la_seq_args, &hdr);
2869 encode_putrootfh(xdr, &hdr);
2870 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002871 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002872}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002873
2874/*
2875 * a RECLAIM_COMPLETE request
2876 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002877static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2878 struct xdr_stream *xdr,
2879 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002880{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002881 struct compound_hdr hdr = {
2882 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2883 };
2884
Chuck Lever9f06c712010-12-14 14:59:18 +00002885 encode_compound_hdr(xdr, req, &hdr);
2886 encode_sequence(xdr, &args->seq_args, &hdr);
2887 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002888 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002889}
2890
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002891/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002892 * Encode GETDEVICELIST request
2893 */
2894static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2895 struct xdr_stream *xdr,
2896 struct nfs4_getdevicelist_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_putfh(xdr, args->fh, &hdr);
2905 encode_getdevicelist(xdr, args, &hdr);
2906 encode_nops(&hdr);
2907}
2908
2909/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002910 * Encode GETDEVICEINFO request
2911 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002912static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2913 struct xdr_stream *xdr,
2914 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002915{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002916 struct compound_hdr hdr = {
2917 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2918 };
2919
Chuck Lever9f06c712010-12-14 14:59:18 +00002920 encode_compound_hdr(xdr, req, &hdr);
2921 encode_sequence(xdr, &args->seq_args, &hdr);
2922 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002923
2924 /* set up reply kvec. Subtract notification bitmap max size (2)
2925 * so that notification bitmap is put in xdr_buf tail */
2926 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2927 args->pdev->pages, args->pdev->pgbase,
2928 args->pdev->pglen);
2929
2930 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002931}
2932
2933/*
2934 * Encode LAYOUTGET request
2935 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002936static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2937 struct xdr_stream *xdr,
2938 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002939{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002940 struct compound_hdr hdr = {
2941 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2942 };
2943
Chuck Lever9f06c712010-12-14 14:59:18 +00002944 encode_compound_hdr(xdr, req, &hdr);
2945 encode_sequence(xdr, &args->seq_args, &hdr);
2946 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2947 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002948
2949 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2950 args->layout.pages, 0, args->layout.pglen);
2951
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002952 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002953}
Andy Adamson863a3c62011-03-23 13:27:54 +00002954
2955/*
2956 * Encode LAYOUTCOMMIT request
2957 */
Benny Halevycbe82602011-05-22 19:52:37 +03002958static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2959 struct xdr_stream *xdr,
2960 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002961{
Benny Halevyac7db722011-05-22 19:53:48 +03002962 struct nfs4_layoutcommit_data *data =
2963 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002964 struct compound_hdr hdr = {
2965 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2966 };
2967
2968 encode_compound_hdr(xdr, req, &hdr);
2969 encode_sequence(xdr, &args->seq_args, &hdr);
2970 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002971 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002972 encode_getfattr(xdr, args->bitmask, &hdr);
2973 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002974}
2975
2976/*
2977 * Encode LAYOUTRETURN request
2978 */
2979static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2980 struct xdr_stream *xdr,
2981 struct nfs4_layoutreturn_args *args)
2982{
2983 struct compound_hdr hdr = {
2984 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2985 };
2986
2987 encode_compound_hdr(xdr, req, &hdr);
2988 encode_sequence(xdr, &args->seq_args, &hdr);
2989 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2990 encode_layoutreturn(xdr, args, &hdr);
2991 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002992}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002993
2994/*
2995 * Encode SECINFO_NO_NAME request
2996 */
2997static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2998 struct xdr_stream *xdr,
2999 struct nfs41_secinfo_no_name_args *args)
3000{
3001 struct compound_hdr hdr = {
3002 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3003 };
3004
3005 encode_compound_hdr(xdr, req, &hdr);
3006 encode_sequence(xdr, &args->seq_args, &hdr);
3007 encode_putrootfh(xdr, &hdr);
3008 encode_secinfo_no_name(xdr, args, &hdr);
3009 encode_nops(&hdr);
3010 return 0;
3011}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003012
3013/*
3014 * Encode TEST_STATEID request
3015 */
3016static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3017 struct xdr_stream *xdr,
3018 struct nfs41_test_stateid_args *args)
3019{
3020 struct compound_hdr hdr = {
3021 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3022 };
3023
3024 encode_compound_hdr(xdr, req, &hdr);
3025 encode_sequence(xdr, &args->seq_args, &hdr);
3026 encode_test_stateid(xdr, args, &hdr);
3027 encode_nops(&hdr);
3028}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003029
3030/*
3031 * Encode FREE_STATEID request
3032 */
3033static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3034 struct xdr_stream *xdr,
3035 struct nfs41_free_stateid_args *args)
3036{
3037 struct compound_hdr hdr = {
3038 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3039 };
3040
3041 encode_compound_hdr(xdr, req, &hdr);
3042 encode_sequence(xdr, &args->seq_args, &hdr);
3043 encode_free_stateid(xdr, args, &hdr);
3044 encode_nops(&hdr);
3045}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003046#endif /* CONFIG_NFS_V4_1 */
3047
Benny Halevy686841b2009-08-14 17:19:48 +03003048static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3049{
3050 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3051 "Remaining buffer length is %tu words.\n",
3052 func, xdr->end - xdr->p);
3053}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054
Trond Myklebust683b57b2006-06-09 09:34:22 -04003055static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056{
Al Viro8687b632006-10-19 23:28:48 -07003057 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058
Benny Halevyc0eae662009-08-14 17:20:14 +03003059 p = xdr_inline_decode(xdr, 4);
3060 if (unlikely(!p))
3061 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003062 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003063 p = xdr_inline_decode(xdr, *len);
3064 if (unlikely(!p))
3065 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 *string = (char *)p;
3067 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003068out_overflow:
3069 print_overflow_msg(__func__, xdr);
3070 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071}
3072
3073static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3074{
Al Viro8687b632006-10-19 23:28:48 -07003075 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076
Benny Halevyc0eae662009-08-14 17:20:14 +03003077 p = xdr_inline_decode(xdr, 8);
3078 if (unlikely(!p))
3079 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003080 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003081 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003082
Benny Halevyc0eae662009-08-14 17:20:14 +03003083 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3084 if (unlikely(!p))
3085 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 hdr->tag = (char *)p;
3087 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003088 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003089 if (unlikely(hdr->nops < 1))
3090 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003092out_overflow:
3093 print_overflow_msg(__func__, xdr);
3094 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095}
3096
3097static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3098{
Al Viro8687b632006-10-19 23:28:48 -07003099 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 uint32_t opnum;
3101 int32_t nfserr;
3102
Benny Halevyc0eae662009-08-14 17:20:14 +03003103 p = xdr_inline_decode(xdr, 8);
3104 if (unlikely(!p))
3105 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003106 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003108 dprintk("nfs: Server returned operation"
3109 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 opnum, expected);
3111 return -EIO;
3112 }
Benny Halevycccddf42009-08-14 17:20:19 +03003113 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003115 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003117out_overflow:
3118 print_overflow_msg(__func__, xdr);
3119 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120}
3121
3122/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003123static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124{
Al Viro8687b632006-10-19 23:28:48 -07003125 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003126 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 char *str;
3128
Benny Halevyc0eae662009-08-14 17:20:14 +03003129 p = xdr_inline_decode(xdr, 12);
3130 if (likely(p))
3131 return decode_opaque_inline(xdr, &strlen, &str);
3132 print_overflow_msg(__func__, xdr);
3133 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134}
3135
3136static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3137{
Al Viro8687b632006-10-19 23:28:48 -07003138 uint32_t bmlen;
3139 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140
Benny Halevyc0eae662009-08-14 17:20:14 +03003141 p = xdr_inline_decode(xdr, 4);
3142 if (unlikely(!p))
3143 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003144 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145
Fred Isamandae100c2011-07-30 20:52:37 -04003146 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003147 p = xdr_inline_decode(xdr, (bmlen << 2));
3148 if (unlikely(!p))
3149 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003151 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003152 if (bmlen > 1) {
3153 bitmap[1] = be32_to_cpup(p++);
3154 if (bmlen > 2)
3155 bitmap[2] = be32_to_cpup(p);
3156 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 }
3158 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003159out_overflow:
3160 print_overflow_msg(__func__, xdr);
3161 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162}
3163
Al Viro8687b632006-10-19 23:28:48 -07003164static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165{
Al Viro8687b632006-10-19 23:28:48 -07003166 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167
Benny Halevyc0eae662009-08-14 17:20:14 +03003168 p = xdr_inline_decode(xdr, 4);
3169 if (unlikely(!p))
3170 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003171 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 *savep = xdr->p;
3173 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003174out_overflow:
3175 print_overflow_msg(__func__, xdr);
3176 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177}
3178
3179static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3180{
3181 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003182 int ret;
3183 ret = decode_attr_bitmap(xdr, bitmask);
3184 if (unlikely(ret < 0))
3185 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3187 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003188 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3189 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3190 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 return 0;
3192}
3193
3194static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3195{
Al Viro8687b632006-10-19 23:28:48 -07003196 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003197 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198
3199 *type = 0;
3200 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3201 return -EIO;
3202 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003203 p = xdr_inline_decode(xdr, 4);
3204 if (unlikely(!p))
3205 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003206 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003208 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 return -EIO;
3210 }
3211 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003212 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003214 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003215 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003216out_overflow:
3217 print_overflow_msg(__func__, xdr);
3218 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219}
3220
3221static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3222{
Al Viro8687b632006-10-19 23:28:48 -07003223 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003224 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225
3226 *change = 0;
3227 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3228 return -EIO;
3229 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003230 p = xdr_inline_decode(xdr, 8);
3231 if (unlikely(!p))
3232 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003233 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003235 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003237 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003239 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003240out_overflow:
3241 print_overflow_msg(__func__, xdr);
3242 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243}
3244
3245static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3246{
Al Viro8687b632006-10-19 23:28:48 -07003247 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003248 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249
3250 *size = 0;
3251 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3252 return -EIO;
3253 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003254 p = xdr_inline_decode(xdr, 8);
3255 if (unlikely(!p))
3256 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003257 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003259 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003261 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003262 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003263out_overflow:
3264 print_overflow_msg(__func__, xdr);
3265 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266}
3267
3268static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3269{
Al Viro8687b632006-10-19 23:28:48 -07003270 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271
3272 *res = 0;
3273 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3274 return -EIO;
3275 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003276 p = xdr_inline_decode(xdr, 4);
3277 if (unlikely(!p))
3278 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003279 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3281 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003282 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003284out_overflow:
3285 print_overflow_msg(__func__, xdr);
3286 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287}
3288
3289static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3290{
Al Viro8687b632006-10-19 23:28:48 -07003291 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292
3293 *res = 0;
3294 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3295 return -EIO;
3296 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003297 p = xdr_inline_decode(xdr, 4);
3298 if (unlikely(!p))
3299 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003300 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3302 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003303 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003305out_overflow:
3306 print_overflow_msg(__func__, xdr);
3307 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308}
3309
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003310static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311{
Al Viro8687b632006-10-19 23:28:48 -07003312 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003313 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314
3315 fsid->major = 0;
3316 fsid->minor = 0;
3317 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3318 return -EIO;
3319 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003320 p = xdr_inline_decode(xdr, 16);
3321 if (unlikely(!p))
3322 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003323 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003324 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003326 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003328 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 (unsigned long long)fsid->major,
3330 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003331 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003332out_overflow:
3333 print_overflow_msg(__func__, xdr);
3334 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335}
3336
3337static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3338{
Al Viro8687b632006-10-19 23:28:48 -07003339 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340
3341 *res = 60;
3342 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3343 return -EIO;
3344 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003345 p = xdr_inline_decode(xdr, 4);
3346 if (unlikely(!p))
3347 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003348 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3350 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003351 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003353out_overflow:
3354 print_overflow_msg(__func__, xdr);
3355 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356}
3357
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003358static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003359{
3360 __be32 *p;
3361
3362 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3363 return -EIO;
3364 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3365 p = xdr_inline_decode(xdr, 4);
3366 if (unlikely(!p))
3367 goto out_overflow;
3368 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003369 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003370 }
3371 return 0;
3372out_overflow:
3373 print_overflow_msg(__func__, xdr);
3374 return -EIO;
3375}
3376
3377static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3378{
3379 __be32 *p;
3380 int len;
3381
Trond Myklebust7ad07352010-10-23 15:34:20 -04003382 if (fh != NULL)
3383 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003384
3385 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3386 return -EIO;
3387 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3388 p = xdr_inline_decode(xdr, 4);
3389 if (unlikely(!p))
3390 goto out_overflow;
3391 len = be32_to_cpup(p);
3392 if (len > NFS4_FHSIZE)
3393 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003394 p = xdr_inline_decode(xdr, len);
3395 if (unlikely(!p))
3396 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003397 if (fh != NULL) {
3398 memcpy(fh->data, p, len);
3399 fh->size = len;
3400 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003401 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3402 }
3403 return 0;
3404out_overflow:
3405 print_overflow_msg(__func__, xdr);
3406 return -EIO;
3407}
3408
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3410{
Al Viro8687b632006-10-19 23:28:48 -07003411 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412
3413 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3414 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3415 return -EIO;
3416 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003417 p = xdr_inline_decode(xdr, 4);
3418 if (unlikely(!p))
3419 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003420 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3422 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003423 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003425out_overflow:
3426 print_overflow_msg(__func__, xdr);
3427 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428}
3429
3430static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3431{
Al Viro8687b632006-10-19 23:28:48 -07003432 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003433 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434
3435 *fileid = 0;
3436 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3437 return -EIO;
3438 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003439 p = xdr_inline_decode(xdr, 8);
3440 if (unlikely(!p))
3441 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003442 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003444 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003446 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003447 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003448out_overflow:
3449 print_overflow_msg(__func__, xdr);
3450 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451}
3452
Manoj Naik99baf622006-06-09 09:34:24 -04003453static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3454{
Al Viro8687b632006-10-19 23:28:48 -07003455 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003456 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003457
3458 *fileid = 0;
3459 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3460 return -EIO;
3461 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003462 p = xdr_inline_decode(xdr, 8);
3463 if (unlikely(!p))
3464 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003465 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003466 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003467 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003468 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003469 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003470 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003471out_overflow:
3472 print_overflow_msg(__func__, xdr);
3473 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003474}
3475
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3477{
Al Viro8687b632006-10-19 23:28:48 -07003478 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 int status = 0;
3480
3481 *res = 0;
3482 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3483 return -EIO;
3484 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003485 p = xdr_inline_decode(xdr, 8);
3486 if (unlikely(!p))
3487 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003488 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3490 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003491 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003493out_overflow:
3494 print_overflow_msg(__func__, xdr);
3495 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496}
3497
3498static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3499{
Al Viro8687b632006-10-19 23:28:48 -07003500 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 int status = 0;
3502
3503 *res = 0;
3504 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3505 return -EIO;
3506 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003507 p = xdr_inline_decode(xdr, 8);
3508 if (unlikely(!p))
3509 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003510 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3512 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003513 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003515out_overflow:
3516 print_overflow_msg(__func__, xdr);
3517 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518}
3519
3520static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3521{
Al Viro8687b632006-10-19 23:28:48 -07003522 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 int status = 0;
3524
3525 *res = 0;
3526 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3527 return -EIO;
3528 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003529 p = xdr_inline_decode(xdr, 8);
3530 if (unlikely(!p))
3531 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003532 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3534 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003535 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003537out_overflow:
3538 print_overflow_msg(__func__, xdr);
3539 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540}
3541
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003542static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3543{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003544 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003545 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003546 int status = 0;
3547
Benny Halevyc0eae662009-08-14 17:20:14 +03003548 p = xdr_inline_decode(xdr, 4);
3549 if (unlikely(!p))
3550 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003551 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003552 if (n == 0)
3553 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003554 dprintk("path ");
3555 path->ncomponents = 0;
3556 while (path->ncomponents < n) {
3557 struct nfs4_string *component = &path->components[path->ncomponents];
3558 status = decode_opaque_inline(xdr, &component->len, &component->data);
3559 if (unlikely(status != 0))
3560 goto out_eio;
3561 if (path->ncomponents != n)
3562 dprintk("/");
3563 dprintk("%s", component->data);
3564 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3565 path->ncomponents++;
3566 else {
3567 dprintk("cannot parse %d components in path\n", n);
3568 goto out_eio;
3569 }
3570 }
3571out:
3572 dprintk("\n");
3573 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003574root_path:
3575/* a root pathname is sent as a zero component4 */
3576 path->ncomponents = 1;
3577 path->components[0].len=0;
3578 path->components[0].data=NULL;
3579 dprintk("path /\n");
3580 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003581out_eio:
3582 dprintk(" status %d", status);
3583 status = -EIO;
3584 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003585out_overflow:
3586 print_overflow_msg(__func__, xdr);
3587 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003588}
3589
3590static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003591{
3592 int n;
Al Viro8687b632006-10-19 23:28:48 -07003593 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003594 int status = -EIO;
3595
3596 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3597 goto out;
3598 status = 0;
3599 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3600 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003601 status = -EIO;
3602 /* Ignore borken servers that return unrequested attrs */
3603 if (unlikely(res == NULL))
3604 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003605 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003606 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003607 if (unlikely(status != 0))
3608 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003609 p = xdr_inline_decode(xdr, 4);
3610 if (unlikely(!p))
3611 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003612 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003613 if (n <= 0)
3614 goto out_eio;
3615 res->nlocations = 0;
3616 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003617 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003618 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003619
Benny Halevyc0eae662009-08-14 17:20:14 +03003620 p = xdr_inline_decode(xdr, 4);
3621 if (unlikely(!p))
3622 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003623 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003624
3625 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003626 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003627 while (loc->nservers < m) {
3628 struct nfs4_string *server = &loc->servers[loc->nservers];
3629 status = decode_opaque_inline(xdr, &server->len, &server->data);
3630 if (unlikely(status != 0))
3631 goto out_eio;
3632 dprintk("%s ", server->data);
3633 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3634 loc->nservers++;
3635 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003636 unsigned int i;
3637 dprintk("%s: using first %u of %u servers "
3638 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003639 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003640 NFS4_FS_LOCATION_MAXSERVERS,
3641 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003642 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003643 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003644 char *data;
3645 status = decode_opaque_inline(xdr, &len, &data);
3646 if (unlikely(status != 0))
3647 goto out_eio;
3648 }
3649 }
3650 }
3651 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003652 if (unlikely(status != 0))
3653 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003654 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003655 res->nlocations++;
3656 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003657 if (res->nlocations != 0)
3658 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003659out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003660 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003661 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003662out_overflow:
3663 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003664out_eio:
3665 status = -EIO;
3666 goto out;
3667}
3668
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3670{
Al Viro8687b632006-10-19 23:28:48 -07003671 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 int status = 0;
3673
3674 *res = 0;
3675 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3676 return -EIO;
3677 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003678 p = xdr_inline_decode(xdr, 8);
3679 if (unlikely(!p))
3680 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003681 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3683 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003684 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003686out_overflow:
3687 print_overflow_msg(__func__, xdr);
3688 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689}
3690
3691static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3692{
Al Viro8687b632006-10-19 23:28:48 -07003693 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694 int status = 0;
3695
3696 *maxlink = 1;
3697 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3698 return -EIO;
3699 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003700 p = xdr_inline_decode(xdr, 4);
3701 if (unlikely(!p))
3702 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003703 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3705 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003706 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003708out_overflow:
3709 print_overflow_msg(__func__, xdr);
3710 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711}
3712
3713static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3714{
Al Viro8687b632006-10-19 23:28:48 -07003715 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 int status = 0;
3717
3718 *maxname = 1024;
3719 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3720 return -EIO;
3721 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003722 p = xdr_inline_decode(xdr, 4);
3723 if (unlikely(!p))
3724 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003725 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3727 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003728 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003730out_overflow:
3731 print_overflow_msg(__func__, xdr);
3732 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733}
3734
3735static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3736{
Al Viro8687b632006-10-19 23:28:48 -07003737 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 int status = 0;
3739
3740 *res = 1024;
3741 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3742 return -EIO;
3743 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3744 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003745 p = xdr_inline_decode(xdr, 8);
3746 if (unlikely(!p))
3747 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003748 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 if (maxread > 0x7FFFFFFF)
3750 maxread = 0x7FFFFFFF;
3751 *res = (uint32_t)maxread;
3752 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3753 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003754 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003756out_overflow:
3757 print_overflow_msg(__func__, xdr);
3758 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759}
3760
3761static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3762{
Al Viro8687b632006-10-19 23:28:48 -07003763 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764 int status = 0;
3765
3766 *res = 1024;
3767 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3768 return -EIO;
3769 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3770 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003771 p = xdr_inline_decode(xdr, 8);
3772 if (unlikely(!p))
3773 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003774 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 if (maxwrite > 0x7FFFFFFF)
3776 maxwrite = 0x7FFFFFFF;
3777 *res = (uint32_t)maxwrite;
3778 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3779 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003780 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003782out_overflow:
3783 print_overflow_msg(__func__, xdr);
3784 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785}
3786
Trond Myklebustbca79472009-03-11 14:10:26 -04003787static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788{
Trond Myklebustbca79472009-03-11 14:10:26 -04003789 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003790 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003791 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792
3793 *mode = 0;
3794 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3795 return -EIO;
3796 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003797 p = xdr_inline_decode(xdr, 4);
3798 if (unlikely(!p))
3799 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003800 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003801 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003803 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003805 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003806 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003807out_overflow:
3808 print_overflow_msg(__func__, xdr);
3809 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810}
3811
3812static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3813{
Al Viro8687b632006-10-19 23:28:48 -07003814 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003815 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816
3817 *nlink = 1;
3818 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3819 return -EIO;
3820 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003821 p = xdr_inline_decode(xdr, 4);
3822 if (unlikely(!p))
3823 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003824 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003826 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003828 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003829 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003830out_overflow:
3831 print_overflow_msg(__func__, xdr);
3832 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833}
3834
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003835static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003836 const struct nfs_server *server, uint32_t *uid,
3837 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838{
Al Viro8687b632006-10-19 23:28:48 -07003839 uint32_t len;
3840 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003841 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842
3843 *uid = -2;
3844 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3845 return -EIO;
3846 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003847 p = xdr_inline_decode(xdr, 4);
3848 if (unlikely(!p))
3849 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003850 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003851 p = xdr_inline_decode(xdr, len);
3852 if (unlikely(!p))
3853 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003854 if (owner_name != NULL) {
3855 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3856 if (owner_name->data != NULL) {
3857 owner_name->len = len;
3858 ret = NFS_ATTR_FATTR_OWNER_NAME;
3859 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003860 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003861 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003862 ret = NFS_ATTR_FATTR_OWNER;
3863 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003865 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003867 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003868 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3870 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003871 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003872 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003873out_overflow:
3874 print_overflow_msg(__func__, xdr);
3875 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876}
3877
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003878static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003879 const struct nfs_server *server, uint32_t *gid,
3880 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881{
Al Viro8687b632006-10-19 23:28:48 -07003882 uint32_t len;
3883 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003884 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885
3886 *gid = -2;
3887 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3888 return -EIO;
3889 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003890 p = xdr_inline_decode(xdr, 4);
3891 if (unlikely(!p))
3892 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003893 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003894 p = xdr_inline_decode(xdr, len);
3895 if (unlikely(!p))
3896 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003897 if (group_name != NULL) {
3898 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3899 if (group_name->data != NULL) {
3900 group_name->len = len;
3901 ret = NFS_ATTR_FATTR_GROUP_NAME;
3902 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003903 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003904 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003905 ret = NFS_ATTR_FATTR_GROUP;
3906 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003908 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003910 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003911 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3913 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003914 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003915 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003916out_overflow:
3917 print_overflow_msg(__func__, xdr);
3918 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919}
3920
3921static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3922{
Al Viro8687b632006-10-19 23:28:48 -07003923 uint32_t major = 0, minor = 0;
3924 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003925 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926
3927 *rdev = MKDEV(0,0);
3928 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3929 return -EIO;
3930 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3931 dev_t tmp;
3932
Benny Halevyc0eae662009-08-14 17:20:14 +03003933 p = xdr_inline_decode(xdr, 8);
3934 if (unlikely(!p))
3935 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003936 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003937 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 tmp = MKDEV(major, minor);
3939 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3940 *rdev = tmp;
3941 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003942 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003944 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003945 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003946out_overflow:
3947 print_overflow_msg(__func__, xdr);
3948 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949}
3950
3951static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3952{
Al Viro8687b632006-10-19 23:28:48 -07003953 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 int status = 0;
3955
3956 *res = 0;
3957 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3958 return -EIO;
3959 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003960 p = xdr_inline_decode(xdr, 8);
3961 if (unlikely(!p))
3962 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003963 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3965 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003966 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003968out_overflow:
3969 print_overflow_msg(__func__, xdr);
3970 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971}
3972
3973static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3974{
Al Viro8687b632006-10-19 23:28:48 -07003975 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 int status = 0;
3977
3978 *res = 0;
3979 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3980 return -EIO;
3981 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003982 p = xdr_inline_decode(xdr, 8);
3983 if (unlikely(!p))
3984 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003985 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3987 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003988 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003990out_overflow:
3991 print_overflow_msg(__func__, xdr);
3992 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993}
3994
3995static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3996{
Al Viro8687b632006-10-19 23:28:48 -07003997 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 int status = 0;
3999
4000 *res = 0;
4001 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4002 return -EIO;
4003 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004004 p = xdr_inline_decode(xdr, 8);
4005 if (unlikely(!p))
4006 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004007 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4009 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004010 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004012out_overflow:
4013 print_overflow_msg(__func__, xdr);
4014 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015}
4016
4017static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4018{
Al Viro8687b632006-10-19 23:28:48 -07004019 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004020 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021
4022 *used = 0;
4023 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4024 return -EIO;
4025 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004026 p = xdr_inline_decode(xdr, 8);
4027 if (unlikely(!p))
4028 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004029 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004031 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004033 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004035 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004036out_overflow:
4037 print_overflow_msg(__func__, xdr);
4038 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039}
4040
4041static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4042{
Al Viro8687b632006-10-19 23:28:48 -07004043 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044 uint64_t sec;
4045 uint32_t nsec;
4046
Benny Halevyc0eae662009-08-14 17:20:14 +03004047 p = xdr_inline_decode(xdr, 12);
4048 if (unlikely(!p))
4049 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004050 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004051 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 time->tv_sec = (time_t)sec;
4053 time->tv_nsec = (long)nsec;
4054 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004055out_overflow:
4056 print_overflow_msg(__func__, xdr);
4057 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058}
4059
4060static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4061{
4062 int status = 0;
4063
4064 time->tv_sec = 0;
4065 time->tv_nsec = 0;
4066 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4067 return -EIO;
4068 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4069 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004070 if (status == 0)
4071 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4073 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004074 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 return status;
4076}
4077
4078static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4079{
4080 int status = 0;
4081
4082 time->tv_sec = 0;
4083 time->tv_nsec = 0;
4084 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4085 return -EIO;
4086 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4087 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004088 if (status == 0)
4089 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4091 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004092 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093 return status;
4094}
4095
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004096static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4097 struct timespec *time)
4098{
4099 int status = 0;
4100
4101 time->tv_sec = 0;
4102 time->tv_nsec = 0;
4103 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4104 return -EIO;
4105 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4106 status = decode_attr_time(xdr, time);
4107 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4108 }
4109 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4110 (long)time->tv_nsec);
4111 return status;
4112}
4113
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4115{
4116 int status = 0;
4117
4118 time->tv_sec = 0;
4119 time->tv_nsec = 0;
4120 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4121 return -EIO;
4122 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4123 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004124 if (status == 0)
4125 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4127 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004128 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 return status;
4130}
4131
Al Viro8687b632006-10-19 23:28:48 -07004132static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133{
4134 unsigned int attrwords = XDR_QUADLEN(attrlen);
4135 unsigned int nwords = xdr->p - savep;
4136
4137 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004138 dprintk("%s: server returned incorrect attribute length: "
4139 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004140 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141 attrwords << 2,
4142 (attrwords < nwords) ? '<' : '>',
4143 nwords << 2);
4144 return -EIO;
4145 }
4146 return 0;
4147}
4148
4149static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4150{
Al Viro8687b632006-10-19 23:28:48 -07004151 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152
Benny Halevyc0eae662009-08-14 17:20:14 +03004153 p = xdr_inline_decode(xdr, 20);
4154 if (unlikely(!p))
4155 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004156 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004157 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004158 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004160out_overflow:
4161 print_overflow_msg(__func__, xdr);
4162 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163}
4164
4165static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4166{
Al Viro8687b632006-10-19 23:28:48 -07004167 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168 uint32_t supp, acc;
4169 int status;
4170
4171 status = decode_op_hdr(xdr, OP_ACCESS);
4172 if (status)
4173 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004174 p = xdr_inline_decode(xdr, 8);
4175 if (unlikely(!p))
4176 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004177 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004178 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179 access->supported = supp;
4180 access->access = acc;
4181 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004182out_overflow:
4183 print_overflow_msg(__func__, xdr);
4184 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185}
4186
Benny Halevy07d30432009-08-14 17:19:52 +03004187static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188{
Al Viro8687b632006-10-19 23:28:48 -07004189 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004190
4191 p = xdr_inline_decode(xdr, len);
4192 if (likely(p)) {
4193 memcpy(buf, p, len);
4194 return 0;
4195 }
4196 print_overflow_msg(__func__, xdr);
4197 return -EIO;
4198}
4199
4200static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4201{
4202 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203}
4204
4205static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4206{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 int status;
4208
4209 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004210 if (status != -EIO)
4211 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004212 if (!status)
4213 status = decode_stateid(xdr, &res->stateid);
4214 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215}
4216
Benny Halevydb942bb2009-08-14 17:19:56 +03004217static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4218{
4219 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220}
4221
4222static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4223{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 int status;
4225
4226 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004227 if (!status)
4228 status = decode_verifier(xdr, res->verf->verifier);
4229 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230}
4231
4232static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4233{
Al Viro8687b632006-10-19 23:28:48 -07004234 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 uint32_t bmlen;
4236 int status;
4237
4238 status = decode_op_hdr(xdr, OP_CREATE);
4239 if (status)
4240 return status;
4241 if ((status = decode_change_info(xdr, cinfo)))
4242 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004243 p = xdr_inline_decode(xdr, 4);
4244 if (unlikely(!p))
4245 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004246 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004247 p = xdr_inline_decode(xdr, bmlen << 2);
4248 if (likely(p))
4249 return 0;
4250out_overflow:
4251 print_overflow_msg(__func__, xdr);
4252 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253}
4254
4255static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4256{
Al Viro8687b632006-10-19 23:28:48 -07004257 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004258 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004259 int status;
4260
4261 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4262 goto xdr_error;
4263 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4264 goto xdr_error;
4265 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4266 goto xdr_error;
4267 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4268 goto xdr_error;
4269 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4270 goto xdr_error;
4271 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4272 goto xdr_error;
4273 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4274 goto xdr_error;
4275 status = verify_attr_len(xdr, savep, attrlen);
4276xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004277 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278 return status;
4279}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004280
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4282{
Al Viro8687b632006-10-19 23:28:48 -07004283 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004284 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004286
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4288 goto xdr_error;
4289 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4290 goto xdr_error;
4291 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4292 goto xdr_error;
4293
4294 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4295 goto xdr_error;
4296 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4297 goto xdr_error;
4298 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4299 goto xdr_error;
4300 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4301 goto xdr_error;
4302 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4303 goto xdr_error;
4304 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4305 goto xdr_error;
4306
4307 status = verify_attr_len(xdr, savep, attrlen);
4308xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004309 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310 return status;
4311}
4312
4313static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4314{
Al Viro8687b632006-10-19 23:28:48 -07004315 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004316 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004318
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4320 goto xdr_error;
4321 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4322 goto xdr_error;
4323 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4324 goto xdr_error;
4325
4326 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4327 goto xdr_error;
4328 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4329 goto xdr_error;
4330
4331 status = verify_attr_len(xdr, savep, attrlen);
4332xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004333 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334 return status;
4335}
4336
Bryan Schumakerae42c702010-10-21 16:33:17 -04004337static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4338 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004339 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004340 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004341{
Trond Myklebustbca79472009-03-11 14:10:26 -04004342 int status;
4343 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004344 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004345 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004347 status = decode_attr_type(xdr, bitmap, &type);
4348 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004350 fattr->mode = 0;
4351 if (status != 0) {
4352 fattr->mode |= nfs_type2fmt[type];
4353 fattr->valid |= status;
4354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004356 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4357 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004359 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004360
4361 status = decode_attr_size(xdr, bitmap, &fattr->size);
4362 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004364 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004365
4366 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4367 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004369 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004370
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004371 err = 0;
4372 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004373 if (status < 0)
4374 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004375 if (err == -NFS4ERR_WRONGSEC)
4376 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004377
4378 status = decode_attr_filehandle(xdr, bitmap, fh);
4379 if (status < 0)
4380 goto xdr_error;
4381
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004382 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4383 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004385 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004386
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004387 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004388 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004389 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004390 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004391
4392 status = decode_attr_mode(xdr, bitmap, &fmode);
4393 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004395 if (status != 0) {
4396 fattr->mode |= fmode;
4397 fattr->valid |= status;
4398 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004399
4400 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4401 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004403 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004404
Trond Myklebust6926afd2012-01-07 13:22:46 -05004405 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004406 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004408 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004409
Trond Myklebust6926afd2012-01-07 13:22:46 -05004410 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004411 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004412 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004413 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004414
4415 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4416 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004418 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004419
4420 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4421 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004423 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004424
4425 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4426 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004428 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004429
4430 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4431 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004432 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004433 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004434
4435 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4436 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004437 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004438 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004439
Trond Myklebust28331a42011-04-27 13:47:52 -04004440 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004441 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004442 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004443 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004444
Bryan Schumakerae42c702010-10-21 16:33:17 -04004445xdr_error:
4446 dprintk("%s: xdr returned %d\n", __func__, -status);
4447 return status;
4448}
4449
4450static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004451 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4452 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004453{
4454 __be32 *savep;
4455 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004456 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004457 int status;
4458
4459 status = decode_op_hdr(xdr, OP_GETATTR);
4460 if (status < 0)
4461 goto xdr_error;
4462
4463 status = decode_attr_bitmap(xdr, bitmap);
4464 if (status < 0)
4465 goto xdr_error;
4466
4467 status = decode_attr_length(xdr, &attrlen, &savep);
4468 if (status < 0)
4469 goto xdr_error;
4470
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004471 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004472 if (status < 0)
4473 goto xdr_error;
4474
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004475 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004477 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 return status;
4479}
4480
Bryan Schumakerae42c702010-10-21 16:33:17 -04004481static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004482 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004483{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004484 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004485}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486
Andy Adamson504913f2010-10-20 00:17:57 -04004487/*
4488 * Decode potentially multiple layout types. Currently we only support
4489 * one layout driver per file system.
4490 */
4491static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4492 uint32_t *layouttype)
4493{
4494 uint32_t *p;
4495 int num;
4496
4497 p = xdr_inline_decode(xdr, 4);
4498 if (unlikely(!p))
4499 goto out_overflow;
4500 num = be32_to_cpup(p);
4501
4502 /* pNFS is not supported by the underlying file system */
4503 if (num == 0) {
4504 *layouttype = 0;
4505 return 0;
4506 }
4507 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004508 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4509 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004510
4511 /* Decode and set first layout type, move xdr->p past unused types */
4512 p = xdr_inline_decode(xdr, num * 4);
4513 if (unlikely(!p))
4514 goto out_overflow;
4515 *layouttype = be32_to_cpup(p);
4516 return 0;
4517out_overflow:
4518 print_overflow_msg(__func__, xdr);
4519 return -EIO;
4520}
4521
4522/*
4523 * The type of file system exported.
4524 * Note we must ensure that layouttype is set in any non-error case.
4525 */
4526static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4527 uint32_t *layouttype)
4528{
4529 int status = 0;
4530
4531 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4532 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4533 return -EIO;
4534 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4535 status = decode_first_pnfs_layout_type(xdr, layouttype);
4536 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4537 } else
4538 *layouttype = 0;
4539 return status;
4540}
4541
Fred Isamandae100c2011-07-30 20:52:37 -04004542/*
4543 * The prefered block size for layout directed io
4544 */
4545static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4546 uint32_t *res)
4547{
4548 __be32 *p;
4549
4550 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4551 *res = 0;
4552 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4553 p = xdr_inline_decode(xdr, 4);
4554 if (unlikely(!p)) {
4555 print_overflow_msg(__func__, xdr);
4556 return -EIO;
4557 }
4558 *res = be32_to_cpup(p);
4559 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4560 }
4561 return 0;
4562}
4563
Linus Torvalds1da177e2005-04-16 15:20:36 -07004564static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4565{
Al Viro8687b632006-10-19 23:28:48 -07004566 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004567 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568 int status;
4569
4570 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4571 goto xdr_error;
4572 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4573 goto xdr_error;
4574 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4575 goto xdr_error;
4576
4577 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4578
4579 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4580 goto xdr_error;
4581 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4582 goto xdr_error;
4583 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4584 goto xdr_error;
4585 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4586 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4587 goto xdr_error;
4588 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004589 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4590 if (status != 0)
4591 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004592 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4593 if (status != 0)
4594 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004595 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4596 if (status)
4597 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598
4599 status = verify_attr_len(xdr, savep, attrlen);
4600xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004601 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004602 return status;
4603}
4604
4605static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4606{
Al Viro8687b632006-10-19 23:28:48 -07004607 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 uint32_t len;
4609 int status;
4610
Trond Myklebust99367812007-07-17 21:52:41 -04004611 /* Zero handle first to allow comparisons */
4612 memset(fh, 0, sizeof(*fh));
4613
Linus Torvalds1da177e2005-04-16 15:20:36 -07004614 status = decode_op_hdr(xdr, OP_GETFH);
4615 if (status)
4616 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617
Benny Halevyc0eae662009-08-14 17:20:14 +03004618 p = xdr_inline_decode(xdr, 4);
4619 if (unlikely(!p))
4620 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004621 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004622 if (len > NFS4_FHSIZE)
4623 return -EIO;
4624 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004625 p = xdr_inline_decode(xdr, len);
4626 if (unlikely(!p))
4627 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004628 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004630out_overflow:
4631 print_overflow_msg(__func__, xdr);
4632 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633}
4634
4635static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4636{
4637 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004638
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 status = decode_op_hdr(xdr, OP_LINK);
4640 if (status)
4641 return status;
4642 return decode_change_info(xdr, cinfo);
4643}
4644
4645/*
4646 * We create the owner, so we know a proper owner.id length is 4.
4647 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004648static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004650 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004651 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004652 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004653
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004654 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004655 if (unlikely(!p))
4656 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004657 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004658 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004659 type = be32_to_cpup(p++); /* 4 byte read */
4660 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004661 fl->fl_start = (loff_t)offset;
4662 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4663 if (length == ~(uint64_t)0)
4664 fl->fl_end = OFFSET_MAX;
4665 fl->fl_type = F_WRLCK;
4666 if (type & 1)
4667 fl->fl_type = F_RDLCK;
4668 fl->fl_pid = 0;
4669 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004670 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4671 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4672 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004673 if (likely(p))
4674 return -NFS4ERR_DENIED;
4675out_overflow:
4676 print_overflow_msg(__func__, xdr);
4677 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678}
4679
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004680static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004681{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682 int status;
4683
4684 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004685 if (status == -EIO)
4686 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004687 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004688 status = decode_stateid(xdr, &res->stateid);
4689 if (unlikely(status))
4690 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004692 status = decode_lock_denied(xdr, NULL);
4693 if (res->open_seqid != NULL)
4694 nfs_increment_open_seqid(status, res->open_seqid);
4695 nfs_increment_lock_seqid(status, res->lock_seqid);
4696out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004697 return status;
4698}
4699
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004700static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004701{
4702 int status;
4703 status = decode_op_hdr(xdr, OP_LOCKT);
4704 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004705 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706 return status;
4707}
4708
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004709static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004710{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711 int status;
4712
4713 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004714 if (status != -EIO)
4715 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004716 if (status == 0)
4717 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718 return status;
4719}
4720
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004721static int decode_release_lockowner(struct xdr_stream *xdr)
4722{
4723 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4724}
4725
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726static int decode_lookup(struct xdr_stream *xdr)
4727{
4728 return decode_op_hdr(xdr, OP_LOOKUP);
4729}
4730
4731/* This is too sick! */
4732static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4733{
Andy Adamson05d564f2008-12-23 16:06:15 -05004734 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 uint32_t limit_type, nblocks, blocksize;
4736
Benny Halevyc0eae662009-08-14 17:20:14 +03004737 p = xdr_inline_decode(xdr, 12);
4738 if (unlikely(!p))
4739 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004740 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004742 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004743 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004744 break;
4745 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004746 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004747 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004748 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 }
4750 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004751out_overflow:
4752 print_overflow_msg(__func__, xdr);
4753 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754}
4755
4756static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4757{
Andy Adamson05d564f2008-12-23 16:06:15 -05004758 __be32 *p;
4759 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004760 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004761
Benny Halevyc0eae662009-08-14 17:20:14 +03004762 p = xdr_inline_decode(xdr, 4);
4763 if (unlikely(!p))
4764 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004765 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4767 res->delegation_type = 0;
4768 return 0;
4769 }
Benny Halevy07d30432009-08-14 17:19:52 +03004770 status = decode_stateid(xdr, &res->delegation);
4771 if (unlikely(status))
4772 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004773 p = xdr_inline_decode(xdr, 4);
4774 if (unlikely(!p))
4775 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004776 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004777
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004779 case NFS4_OPEN_DELEGATE_READ:
4780 res->delegation_type = FMODE_READ;
4781 break;
4782 case NFS4_OPEN_DELEGATE_WRITE:
4783 res->delegation_type = FMODE_WRITE|FMODE_READ;
4784 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785 return -EIO;
4786 }
David Howells7539bba2006-08-22 20:06:09 -04004787 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004788out_overflow:
4789 print_overflow_msg(__func__, xdr);
4790 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004791}
4792
4793static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4794{
Andy Adamson05d564f2008-12-23 16:06:15 -05004795 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004796 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004797 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798
Andy Adamson05d564f2008-12-23 16:06:15 -05004799 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004800 if (status != -EIO)
4801 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004802 if (!status)
4803 status = decode_stateid(xdr, &res->stateid);
4804 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004805 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806
Andy Adamson05d564f2008-12-23 16:06:15 -05004807 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808
Benny Halevyc0eae662009-08-14 17:20:14 +03004809 p = xdr_inline_decode(xdr, 8);
4810 if (unlikely(!p))
4811 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004812 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004813 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004814 if (bmlen > 10)
4815 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816
Benny Halevyc0eae662009-08-14 17:20:14 +03004817 p = xdr_inline_decode(xdr, bmlen << 2);
4818 if (unlikely(!p))
4819 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004820 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4821 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004822 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004823 for (; i < NFS4_BITMAP_SIZE; i++)
4824 res->attrset[i] = 0;
4825
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826 return decode_delegation(xdr, res);
4827xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004828 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004829 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004830out_overflow:
4831 print_overflow_msg(__func__, xdr);
4832 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004833}
4834
4835static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4836{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837 int status;
4838
Andy Adamson05d564f2008-12-23 16:06:15 -05004839 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004840 if (status != -EIO)
4841 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004842 if (!status)
4843 status = decode_stateid(xdr, &res->stateid);
4844 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845}
4846
4847static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4848{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849 int status;
4850
4851 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004852 if (status != -EIO)
4853 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004854 if (!status)
4855 status = decode_stateid(xdr, &res->stateid);
4856 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857}
4858
4859static int decode_putfh(struct xdr_stream *xdr)
4860{
4861 return decode_op_hdr(xdr, OP_PUTFH);
4862}
4863
4864static int decode_putrootfh(struct xdr_stream *xdr)
4865{
4866 return decode_op_hdr(xdr, OP_PUTROOTFH);
4867}
4868
4869static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4870{
4871 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004872 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873 uint32_t count, eof, recvd, hdrlen;
4874 int status;
4875
4876 status = decode_op_hdr(xdr, OP_READ);
4877 if (status)
4878 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004879 p = xdr_inline_decode(xdr, 8);
4880 if (unlikely(!p))
4881 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004882 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004883 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004884 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885 recvd = req->rq_rcv_buf.len - hdrlen;
4886 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004887 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004888 "count %u > recvd %u\n", count, recvd);
4889 count = recvd;
4890 eof = 0;
4891 }
4892 xdr_read_pages(xdr, count);
4893 res->eof = eof;
4894 res->count = count;
4895 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004896out_overflow:
4897 print_overflow_msg(__func__, xdr);
4898 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899}
4900
4901static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4902{
4903 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004905 size_t hdrlen;
4906 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004907 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908
4909 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004910 if (!status)
4911 status = decode_verifier(xdr, readdir->verifier.data);
4912 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004914 dprintk("%s: verifier = %08x:%08x\n",
4915 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004916 ((u32 *)readdir->verifier.data)[0],
4917 ((u32 *)readdir->verifier.data)[1]);
4918
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919
Benny Halevydb942bb2009-08-14 17:19:56 +03004920 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921 recvd = rcvbuf->len - hdrlen;
4922 if (pglen > recvd)
4923 pglen = recvd;
4924 xdr_read_pages(xdr, pglen);
4925
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004926
Trond Myklebustac396122010-11-15 20:26:22 -05004927 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928}
4929
4930static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4931{
4932 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4933 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004934 size_t hdrlen;
4935 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004936 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004937 int status;
4938
4939 status = decode_op_hdr(xdr, OP_READLINK);
4940 if (status)
4941 return status;
4942
4943 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004944 p = xdr_inline_decode(xdr, 4);
4945 if (unlikely(!p))
4946 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004947 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004949 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004950 return -ENAMETOOLONG;
4951 }
4952 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4953 recvd = req->rq_rcv_buf.len - hdrlen;
4954 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004955 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004956 "count %u > recvd %u\n", len, recvd);
4957 return -EIO;
4958 }
4959 xdr_read_pages(xdr, len);
4960 /*
4961 * The XDR encode routine has set things up so that
4962 * the link text will be copied directly into the
4963 * buffer. We just have to do overflow-checking,
4964 * and and null-terminate the text (the VFS expects
4965 * null-termination).
4966 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004967 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004968 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004969out_overflow:
4970 print_overflow_msg(__func__, xdr);
4971 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972}
4973
4974static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4975{
4976 int status;
4977
4978 status = decode_op_hdr(xdr, OP_REMOVE);
4979 if (status)
4980 goto out;
4981 status = decode_change_info(xdr, cinfo);
4982out:
4983 return status;
4984}
4985
4986static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4987 struct nfs4_change_info *new_cinfo)
4988{
4989 int status;
4990
4991 status = decode_op_hdr(xdr, OP_RENAME);
4992 if (status)
4993 goto out;
4994 if ((status = decode_change_info(xdr, old_cinfo)))
4995 goto out;
4996 status = decode_change_info(xdr, new_cinfo);
4997out:
4998 return status;
4999}
5000
5001static int decode_renew(struct xdr_stream *xdr)
5002{
5003 return decode_op_hdr(xdr, OP_RENEW);
5004}
5005
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005006static int
5007decode_restorefh(struct xdr_stream *xdr)
5008{
5009 return decode_op_hdr(xdr, OP_RESTOREFH);
5010}
5011
J. Bruce Fields029d1052005-06-22 17:16:22 +00005012static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005013 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005014{
Andy Adamsonbf118a32011-12-07 11:55:27 -05005015 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005016 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005017 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005018 struct kvec *iov = req->rq_rcv_buf.head;
5019 int status;
5020
Andy Adamsonbf118a32011-12-07 11:55:27 -05005021 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005022 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5023 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005024 bm_p = xdr->p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005025 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5026 goto out;
5027 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5028 goto out;
5029
5030 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5031 return -EIO;
5032 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04005033 size_t hdrlen;
5034 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005035
Andy Adamsonbf118a32011-12-07 11:55:27 -05005036 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5037 * are stored with the acl data to handle the problem of
5038 * variable length bitmaps.*/
5039 xdr->p = bm_p;
5040 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
5041 res->acl_data_offset <<= 2;
5042
J. Bruce Fields029d1052005-06-22 17:16:22 +00005043 /* We ignore &savep and don't do consistency checks on
5044 * the attr length. Let userspace figure it out.... */
5045 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005046 attrlen += res->acl_data_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005047 recvd = req->rq_rcv_buf.len - hdrlen;
5048 if (attrlen > recvd) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05005049 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
5050 /* getxattr interface called with a NULL buf */
5051 res->acl_len = attrlen;
5052 goto out;
5053 }
5054 dprintk("NFS: acl reply: attrlen %u > recvd %u\n",
J. Bruce Fields029d1052005-06-22 17:16:22 +00005055 attrlen, recvd);
5056 return -EINVAL;
5057 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04005058 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05005059 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005060 } else
5061 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005062
5063out:
5064 return status;
5065}
5066
Linus Torvalds1da177e2005-04-16 15:20:36 -07005067static int
5068decode_savefh(struct xdr_stream *xdr)
5069{
5070 return decode_op_hdr(xdr, OP_SAVEFH);
5071}
5072
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005073static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074{
Al Viro8687b632006-10-19 23:28:48 -07005075 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005076 uint32_t bmlen;
5077 int status;
5078
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079 status = decode_op_hdr(xdr, OP_SETATTR);
5080 if (status)
5081 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005082 p = xdr_inline_decode(xdr, 4);
5083 if (unlikely(!p))
5084 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005085 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005086 p = xdr_inline_decode(xdr, bmlen << 2);
5087 if (likely(p))
5088 return 0;
5089out_overflow:
5090 print_overflow_msg(__func__, xdr);
5091 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005092}
5093
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005094static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005095{
Al Viro8687b632006-10-19 23:28:48 -07005096 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005097 uint32_t opnum;
5098 int32_t nfserr;
5099
Benny Halevyc0eae662009-08-14 17:20:14 +03005100 p = xdr_inline_decode(xdr, 8);
5101 if (unlikely(!p))
5102 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005103 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005105 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005106 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107 return -EIO;
5108 }
Benny Halevycccddf42009-08-14 17:20:19 +03005109 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005110 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005111 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5112 if (unlikely(!p))
5113 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005114 p = xdr_decode_hyper(p, &res->clientid);
5115 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116 } else if (nfserr == NFSERR_CLID_INUSE) {
5117 uint32_t len;
5118
5119 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005120 p = xdr_inline_decode(xdr, 4);
5121 if (unlikely(!p))
5122 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005123 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005124 p = xdr_inline_decode(xdr, len);
5125 if (unlikely(!p))
5126 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127
5128 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005129 p = xdr_inline_decode(xdr, 4);
5130 if (unlikely(!p))
5131 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005132 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005133 p = xdr_inline_decode(xdr, len);
5134 if (unlikely(!p))
5135 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136 return -NFSERR_CLID_INUSE;
5137 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005138 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139
5140 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005141out_overflow:
5142 print_overflow_msg(__func__, xdr);
5143 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144}
5145
5146static int decode_setclientid_confirm(struct xdr_stream *xdr)
5147{
5148 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5149}
5150
5151static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5152{
Al Viro8687b632006-10-19 23:28:48 -07005153 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005154 int status;
5155
5156 status = decode_op_hdr(xdr, OP_WRITE);
5157 if (status)
5158 return status;
5159
Benny Halevyc0eae662009-08-14 17:20:14 +03005160 p = xdr_inline_decode(xdr, 16);
5161 if (unlikely(!p))
5162 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005163 res->count = be32_to_cpup(p++);
5164 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03005165 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005166 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005167out_overflow:
5168 print_overflow_msg(__func__, xdr);
5169 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170}
5171
5172static int decode_delegreturn(struct xdr_stream *xdr)
5173{
5174 return decode_op_hdr(xdr, OP_DELEGRETURN);
5175}
5176
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005177static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5178{
5179 __be32 *p;
5180
5181 p = xdr_inline_decode(xdr, 4);
5182 if (unlikely(!p))
5183 goto out_overflow;
5184 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5185 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5186 goto out_err;
5187
5188 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5189 if (unlikely(!p))
5190 goto out_overflow;
5191 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5192
5193 p = xdr_inline_decode(xdr, 8);
5194 if (unlikely(!p))
5195 goto out_overflow;
5196 flavor->gss.qop4 = be32_to_cpup(p++);
5197 flavor->gss.service = be32_to_cpup(p);
5198
5199 return 0;
5200
5201out_overflow:
5202 print_overflow_msg(__func__, xdr);
5203 return -EIO;
5204out_err:
5205 return -EINVAL;
5206}
5207
5208static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5209{
5210 struct nfs4_secinfo_flavor *sec_flavor;
5211 int status;
5212 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005213 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005214
5215 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04005216 if (status)
5217 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005218 p = xdr_inline_decode(xdr, 4);
5219 if (unlikely(!p))
5220 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005221
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005222 res->flavors->num_flavors = 0;
5223 num_flavors = be32_to_cpup(p);
5224
5225 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005226 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005227 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005228 break;
5229
5230 p = xdr_inline_decode(xdr, 4);
5231 if (unlikely(!p))
5232 goto out_overflow;
5233 sec_flavor->flavor = be32_to_cpup(p);
5234
5235 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005236 status = decode_secinfo_gss(xdr, sec_flavor);
5237 if (status)
5238 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005239 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005240 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005241 }
5242
Bryan Schumaker613e9012011-04-27 15:28:44 -04005243out:
5244 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005245out_overflow:
5246 print_overflow_msg(__func__, xdr);
5247 return -EIO;
5248}
5249
Benny Halevy99fe60d2009-04-01 09:22:29 -04005250#if defined(CONFIG_NFS_V4_1)
5251static int decode_exchange_id(struct xdr_stream *xdr,
5252 struct nfs41_exchange_id_res *res)
5253{
5254 __be32 *p;
5255 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005256 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005257 int status;
5258 struct nfs_client *clp = res->client;
5259
5260 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5261 if (status)
5262 return status;
5263
Benny Halevyc0eae662009-08-14 17:20:14 +03005264 p = xdr_inline_decode(xdr, 8);
5265 if (unlikely(!p))
5266 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005267 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005268 p = xdr_inline_decode(xdr, 12);
5269 if (unlikely(!p))
5270 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005271 clp->cl_seqid = be32_to_cpup(p++);
5272 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005273
5274 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005275 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005276 if (dummy != SP4_NONE)
5277 return -EIO;
5278
5279 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005280 p = xdr_inline_decode(xdr, 8);
5281 if (unlikely(!p))
5282 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005283
5284 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005285 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5286 if (unlikely(status))
5287 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005288
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005289 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005290 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5291 if (unlikely(status))
5292 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005293
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005294 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5295 return -EIO;
5296
5297 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5298 res->server_scope->server_scope_sz = dummy;
5299
Benny Halevy99fe60d2009-04-01 09:22:29 -04005300 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03005301 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5302 if (unlikely(status))
5303 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005304
5305 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005306out_overflow:
5307 print_overflow_msg(__func__, xdr);
5308 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005309}
Andy Adamsonfc931582009-04-01 09:22:31 -04005310
5311static int decode_chan_attrs(struct xdr_stream *xdr,
5312 struct nfs4_channel_attrs *attrs)
5313{
5314 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005315 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005316
Benny Halevyc0eae662009-08-14 17:20:14 +03005317 p = xdr_inline_decode(xdr, 28);
5318 if (unlikely(!p))
5319 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005320 val = be32_to_cpup(p++); /* headerpadsz */
5321 if (val)
5322 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005323 attrs->max_rqst_sz = be32_to_cpup(p++);
5324 attrs->max_resp_sz = be32_to_cpup(p++);
5325 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5326 attrs->max_ops = be32_to_cpup(p++);
5327 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005328 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005329 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005330 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5331 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005332 return -EINVAL;
5333 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005334 if (nr_attrs == 1) {
5335 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5336 if (unlikely(!p))
5337 goto out_overflow;
5338 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005339 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005340out_overflow:
5341 print_overflow_msg(__func__, xdr);
5342 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005343}
5344
Benny Halevye78291e2009-08-14 17:20:00 +03005345static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5346{
5347 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005348}
5349
5350static int decode_create_session(struct xdr_stream *xdr,
5351 struct nfs41_create_session_res *res)
5352{
5353 __be32 *p;
5354 int status;
5355 struct nfs_client *clp = res->client;
5356 struct nfs4_session *session = clp->cl_session;
5357
5358 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005359 if (!status)
5360 status = decode_sessionid(xdr, &session->sess_id);
5361 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005362 return status;
5363
Andy Adamsonfc931582009-04-01 09:22:31 -04005364 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005365 p = xdr_inline_decode(xdr, 8);
5366 if (unlikely(!p))
5367 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005368 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005369 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005370
5371 /* Channel attributes */
5372 status = decode_chan_attrs(xdr, &session->fc_attrs);
5373 if (!status)
5374 status = decode_chan_attrs(xdr, &session->bc_attrs);
5375 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005376out_overflow:
5377 print_overflow_msg(__func__, xdr);
5378 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005379}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005380
5381static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5382{
5383 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5384}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005385
5386static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5387{
5388 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5389}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005390#endif /* CONFIG_NFS_V4_1 */
5391
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005392static int decode_sequence(struct xdr_stream *xdr,
5393 struct nfs4_sequence_res *res,
5394 struct rpc_rqst *rqstp)
5395{
5396#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005397 struct nfs4_sessionid id;
5398 u32 dummy;
5399 int status;
5400 __be32 *p;
5401
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005402 if (!res->sr_session)
5403 return 0;
5404
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005405 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005406 if (!status)
5407 status = decode_sessionid(xdr, &id);
5408 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005409 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005410
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005411 /*
5412 * If the server returns different values for sessionID, slotID or
5413 * sequence number, the server is looney tunes.
5414 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005415 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005416
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005417 if (memcmp(id.data, res->sr_session->sess_id.data,
5418 NFS4_MAX_SESSIONID_LEN)) {
5419 dprintk("%s Invalid session id\n", __func__);
5420 goto out_err;
5421 }
Benny Halevye78291e2009-08-14 17:20:00 +03005422
Benny Halevyc0eae662009-08-14 17:20:14 +03005423 p = xdr_inline_decode(xdr, 20);
5424 if (unlikely(!p))
5425 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005426
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005427 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005428 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005429 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005430 dprintk("%s Invalid sequence number\n", __func__);
5431 goto out_err;
5432 }
5433 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005434 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005435 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005436 dprintk("%s Invalid slot id\n", __func__);
5437 goto out_err;
5438 }
5439 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005440 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005441 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005442 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005443 /* result flags */
5444 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005445 status = 0;
5446out_err:
5447 res->sr_status = status;
5448 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005449out_overflow:
5450 print_overflow_msg(__func__, xdr);
5451 status = -EIO;
5452 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005453#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005454 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005455#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005456}
5457
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005458#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005459/*
5460 * TODO: Need to handle case when EOF != true;
5461 */
5462static int decode_getdevicelist(struct xdr_stream *xdr,
5463 struct pnfs_devicelist *res)
5464{
5465 __be32 *p;
5466 int status, i;
5467 struct nfs_writeverf verftemp;
5468
5469 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5470 if (status)
5471 return status;
5472
5473 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5474 if (unlikely(!p))
5475 goto out_overflow;
5476
5477 /* TODO: Skip cookie for now */
5478 p += 2;
5479
5480 /* Read verifier */
5481 p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8);
5482
5483 res->num_devs = be32_to_cpup(p);
5484
5485 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5486
5487 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005488 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005489 __func__, res->num_devs);
5490 return -EIO;
5491 }
5492
5493 p = xdr_inline_decode(xdr,
5494 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5495 if (unlikely(!p))
5496 goto out_overflow;
5497 for (i = 0; i < res->num_devs; i++)
5498 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5499 NFS4_DEVICEID4_SIZE);
5500 res->eof = be32_to_cpup(p);
5501 return 0;
5502out_overflow:
5503 print_overflow_msg(__func__, xdr);
5504 return -EIO;
5505}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005506
5507static int decode_getdeviceinfo(struct xdr_stream *xdr,
5508 struct pnfs_device *pdev)
5509{
5510 __be32 *p;
5511 uint32_t len, type;
5512 int status;
5513
5514 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5515 if (status) {
5516 if (status == -ETOOSMALL) {
5517 p = xdr_inline_decode(xdr, 4);
5518 if (unlikely(!p))
5519 goto out_overflow;
5520 pdev->mincount = be32_to_cpup(p);
5521 dprintk("%s: Min count too small. mincnt = %u\n",
5522 __func__, pdev->mincount);
5523 }
5524 return status;
5525 }
5526
5527 p = xdr_inline_decode(xdr, 8);
5528 if (unlikely(!p))
5529 goto out_overflow;
5530 type = be32_to_cpup(p++);
5531 if (type != pdev->layout_type) {
5532 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5533 __func__, pdev->layout_type, type);
5534 return -EINVAL;
5535 }
5536 /*
5537 * Get the length of the opaque device_addr4. xdr_read_pages places
5538 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5539 * and places the remaining xdr data in xdr_buf->tail
5540 */
5541 pdev->mincount = be32_to_cpup(p);
5542 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5543
5544 /* Parse notification bitmap, verifying that it is zero. */
5545 p = xdr_inline_decode(xdr, 4);
5546 if (unlikely(!p))
5547 goto out_overflow;
5548 len = be32_to_cpup(p);
5549 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005550 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005551
5552 p = xdr_inline_decode(xdr, 4 * len);
5553 if (unlikely(!p))
5554 goto out_overflow;
5555 for (i = 0; i < len; i++, p++) {
5556 if (be32_to_cpup(p)) {
5557 dprintk("%s: notifications not supported\n",
5558 __func__);
5559 return -EIO;
5560 }
5561 }
5562 }
5563 return 0;
5564out_overflow:
5565 print_overflow_msg(__func__, xdr);
5566 return -EIO;
5567}
5568
5569static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5570 struct nfs4_layoutget_res *res)
5571{
5572 __be32 *p;
5573 int status;
5574 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005575 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5576 struct kvec *iov = rcvbuf->head;
5577 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005578
5579 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5580 if (status)
5581 return status;
5582 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5583 if (unlikely(!p))
5584 goto out_overflow;
5585 res->return_on_close = be32_to_cpup(p++);
5586 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5587 layout_count = be32_to_cpup(p);
5588 if (!layout_count) {
5589 dprintk("%s: server responded with empty layout array\n",
5590 __func__);
5591 return -EINVAL;
5592 }
5593
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005594 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005595 if (unlikely(!p))
5596 goto out_overflow;
5597 p = xdr_decode_hyper(p, &res->range.offset);
5598 p = xdr_decode_hyper(p, &res->range.length);
5599 res->range.iomode = be32_to_cpup(p++);
5600 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005601 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005602
5603 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5604 __func__,
5605 (unsigned long)res->range.offset,
5606 (unsigned long)res->range.length,
5607 res->range.iomode,
5608 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005609 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005610
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005611 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5612 recvd = req->rq_rcv_buf.len - hdrlen;
5613 if (res->layoutp->len > recvd) {
5614 dprintk("NFS: server cheating in layoutget reply: "
5615 "layout len %u > recvd %u\n",
5616 res->layoutp->len, recvd);
5617 return -EINVAL;
5618 }
5619
5620 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005621
5622 if (layout_count > 1) {
5623 /* We only handle a length one array at the moment. Any
5624 * further entries are just ignored. Note that this means
5625 * the client may see a response that is less than the
5626 * minimum it requested.
5627 */
5628 dprintk("%s: server responded with %d layouts, dropping tail\n",
5629 __func__, layout_count);
5630 }
5631
5632 return 0;
5633out_overflow:
5634 print_overflow_msg(__func__, xdr);
5635 return -EIO;
5636}
Andy Adamson863a3c62011-03-23 13:27:54 +00005637
Benny Halevycbe82602011-05-22 19:52:37 +03005638static int decode_layoutreturn(struct xdr_stream *xdr,
5639 struct nfs4_layoutreturn_res *res)
5640{
5641 __be32 *p;
5642 int status;
5643
5644 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5645 if (status)
5646 return status;
5647 p = xdr_inline_decode(xdr, 4);
5648 if (unlikely(!p))
5649 goto out_overflow;
5650 res->lrs_present = be32_to_cpup(p);
5651 if (res->lrs_present)
5652 status = decode_stateid(xdr, &res->stateid);
5653 return status;
5654out_overflow:
5655 print_overflow_msg(__func__, xdr);
5656 return -EIO;
5657}
5658
Andy Adamson863a3c62011-03-23 13:27:54 +00005659static int decode_layoutcommit(struct xdr_stream *xdr,
5660 struct rpc_rqst *req,
5661 struct nfs4_layoutcommit_res *res)
5662{
5663 __be32 *p;
5664 __u32 sizechanged;
5665 int status;
5666
5667 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005668 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005669 if (status)
5670 return status;
5671
5672 p = xdr_inline_decode(xdr, 4);
5673 if (unlikely(!p))
5674 goto out_overflow;
5675 sizechanged = be32_to_cpup(p);
5676
5677 if (sizechanged) {
5678 /* throw away new size */
5679 p = xdr_inline_decode(xdr, 8);
5680 if (unlikely(!p))
5681 goto out_overflow;
5682 }
5683 return 0;
5684out_overflow:
5685 print_overflow_msg(__func__, xdr);
5686 return -EIO;
5687}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005688
5689static int decode_test_stateid(struct xdr_stream *xdr,
5690 struct nfs41_test_stateid_res *res)
5691{
5692 __be32 *p;
5693 int status;
5694 int num_res;
5695
5696 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5697 if (status)
5698 return status;
5699
5700 p = xdr_inline_decode(xdr, 4);
5701 if (unlikely(!p))
5702 goto out_overflow;
5703 num_res = be32_to_cpup(p++);
5704 if (num_res != 1)
5705 goto out;
5706
5707 p = xdr_inline_decode(xdr, 4);
5708 if (unlikely(!p))
5709 goto out_overflow;
5710 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005711
5712 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005713out_overflow:
5714 print_overflow_msg(__func__, xdr);
5715out:
5716 return -EIO;
5717}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005718
5719static int decode_free_stateid(struct xdr_stream *xdr,
5720 struct nfs41_free_stateid_res *res)
5721{
5722 __be32 *p;
5723 int status;
5724
5725 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5726 if (status)
5727 return status;
5728
5729 p = xdr_inline_decode(xdr, 4);
5730 if (unlikely(!p))
5731 goto out_overflow;
5732 res->status = be32_to_cpup(p++);
5733 return res->status;
5734out_overflow:
5735 print_overflow_msg(__func__, xdr);
5736 return -EIO;
5737}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005738#endif /* CONFIG_NFS_V4_1 */
5739
Linus Torvalds1da177e2005-04-16 15:20:36 -07005740/*
Benny Halevy49c25592008-12-23 16:06:16 -05005741 * END OF "GENERIC" DECODE ROUTINES.
5742 */
5743
5744/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745 * Decode OPEN_DOWNGRADE response
5746 */
Chuck Leverbf269552010-12-14 14:59:29 +00005747static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5748 struct xdr_stream *xdr,
5749 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005750{
Andy Adamson05d564f2008-12-23 16:06:15 -05005751 struct compound_hdr hdr;
5752 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005753
Chuck Leverbf269552010-12-14 14:59:29 +00005754 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005755 if (status)
5756 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005757 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005758 if (status)
5759 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005760 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005761 if (status)
5762 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005763 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005764 if (status != 0)
5765 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005766 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005768 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005769}
5770
5771/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005772 * Decode ACCESS response
5773 */
Chuck Leverbf269552010-12-14 14:59:29 +00005774static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5775 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005776{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005777 struct compound_hdr hdr;
5778 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005779
Chuck Leverbf269552010-12-14 14:59:29 +00005780 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005781 if (status)
5782 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005783 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005784 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005785 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005786 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005787 if (status != 0)
5788 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005789 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005790 if (status != 0)
5791 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005792 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005793out:
5794 return status;
5795}
5796
5797/*
5798 * Decode LOOKUP response
5799 */
Chuck Leverbf269552010-12-14 14:59:29 +00005800static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5801 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005802{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005803 struct compound_hdr hdr;
5804 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005805
Chuck Leverbf269552010-12-14 14:59:29 +00005806 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005807 if (status)
5808 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005809 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005810 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005811 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005812 status = decode_putfh(xdr);
5813 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005814 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005815 status = decode_lookup(xdr);
5816 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005817 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005818 status = decode_getfh(xdr, res->fh);
5819 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005820 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005821 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005822out:
5823 return status;
5824}
5825
5826/*
5827 * Decode LOOKUP_ROOT response
5828 */
Chuck Leverbf269552010-12-14 14:59:29 +00005829static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5830 struct xdr_stream *xdr,
5831 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005832{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005833 struct compound_hdr hdr;
5834 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005835
Chuck Leverbf269552010-12-14 14:59:29 +00005836 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005837 if (status)
5838 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005839 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005840 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005841 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005842 status = decode_putrootfh(xdr);
5843 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005845 status = decode_getfh(xdr, res->fh);
5846 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005847 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005848out:
5849 return status;
5850}
5851
5852/*
5853 * Decode REMOVE response
5854 */
Chuck Leverbf269552010-12-14 14:59:29 +00005855static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5856 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005858 struct compound_hdr hdr;
5859 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005860
Chuck Leverbf269552010-12-14 14:59:29 +00005861 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005862 if (status)
5863 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005864 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005865 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005866 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005867 status = decode_putfh(xdr);
5868 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005869 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005870 status = decode_remove(xdr, &res->cinfo);
5871 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005872 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005873 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005874out:
5875 return status;
5876}
5877
5878/*
5879 * Decode RENAME response
5880 */
Chuck Leverbf269552010-12-14 14:59:29 +00005881static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5882 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005883{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005884 struct compound_hdr hdr;
5885 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005886
Chuck Leverbf269552010-12-14 14:59:29 +00005887 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005888 if (status)
5889 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005890 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005891 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005893 status = decode_putfh(xdr);
5894 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005895 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005896 status = decode_savefh(xdr);
5897 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005898 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005899 status = decode_putfh(xdr);
5900 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005901 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005902 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5903 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005904 goto out;
5905 /* Current FH is target directory */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005906 if (decode_getfattr(xdr, res->new_fattr, res->server))
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005907 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005908 status = decode_restorefh(xdr);
5909 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005910 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005911 decode_getfattr(xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005912out:
5913 return status;
5914}
5915
5916/*
5917 * Decode LINK response
5918 */
Chuck Leverbf269552010-12-14 14:59:29 +00005919static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5920 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005921{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005922 struct compound_hdr hdr;
5923 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005924
Chuck Leverbf269552010-12-14 14:59:29 +00005925 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005926 if (status)
5927 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005928 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005929 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005930 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005931 status = decode_putfh(xdr);
5932 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005933 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005934 status = decode_savefh(xdr);
5935 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005936 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005937 status = decode_putfh(xdr);
5938 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005939 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005940 status = decode_link(xdr, &res->cinfo);
5941 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005942 goto out;
5943 /*
5944 * Note order: OP_LINK leaves the directory as the current
5945 * filehandle.
5946 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005947 if (decode_getfattr(xdr, res->dir_attr, res->server))
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005948 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005949 status = decode_restorefh(xdr);
5950 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005951 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005952 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005953out:
5954 return status;
5955}
5956
5957/*
5958 * Decode CREATE response
5959 */
Chuck Leverbf269552010-12-14 14:59:29 +00005960static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5961 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005962{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963 struct compound_hdr hdr;
5964 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005965
Chuck Leverbf269552010-12-14 14:59:29 +00005966 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005967 if (status)
5968 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005969 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005970 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005971 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005972 status = decode_putfh(xdr);
5973 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005974 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005975 status = decode_savefh(xdr);
5976 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005977 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005978 status = decode_create(xdr, &res->dir_cinfo);
5979 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005980 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005981 status = decode_getfh(xdr, res->fh);
5982 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005983 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005984 if (decode_getfattr(xdr, res->fattr, res->server))
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005985 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005986 status = decode_restorefh(xdr);
5987 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005988 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005989 decode_getfattr(xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005990out:
5991 return status;
5992}
5993
5994/*
5995 * Decode SYMLINK response
5996 */
Chuck Leverbf269552010-12-14 14:59:29 +00005997static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5998 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005999{
Chuck Leverbf269552010-12-14 14:59:29 +00006000 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006001}
6002
6003/*
6004 * Decode GETATTR response
6005 */
Chuck Leverbf269552010-12-14 14:59:29 +00006006static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6007 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006009 struct compound_hdr hdr;
6010 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006011
Chuck Leverbf269552010-12-14 14:59:29 +00006012 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013 if (status)
6014 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006015 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006016 if (status)
6017 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006018 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006019 if (status)
6020 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006021 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006022out:
6023 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024}
6025
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006026/*
6027 * Encode an SETACL request
6028 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006029static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6030 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006031{
Andy Adamson05d564f2008-12-23 16:06:15 -05006032 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006033 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006034 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006035
Chuck Lever9f06c712010-12-14 14:59:18 +00006036 encode_compound_hdr(xdr, req, &hdr);
6037 encode_sequence(xdr, &args->seq_args, &hdr);
6038 encode_putfh(xdr, args->fh, &hdr);
6039 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006040 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006041}
Andy Adamson05d564f2008-12-23 16:06:15 -05006042
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006043/*
6044 * Decode SETACL response
6045 */
6046static int
Chuck Leverbf269552010-12-14 14:59:29 +00006047nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006048 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006049{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006050 struct compound_hdr hdr;
6051 int status;
6052
Chuck Leverbf269552010-12-14 14:59:29 +00006053 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006054 if (status)
6055 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006056 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006057 if (status)
6058 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006059 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006060 if (status)
6061 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006062 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006063out:
6064 return status;
6065}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006066
6067/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006068 * Decode GETACL response
6069 */
6070static int
Chuck Leverbf269552010-12-14 14:59:29 +00006071nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006072 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006073{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006074 struct compound_hdr hdr;
6075 int status;
6076
Chuck Leverbf269552010-12-14 14:59:29 +00006077 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006078 if (status)
6079 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006080 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006081 if (status)
6082 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006083 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006084 if (status)
6085 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006086 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006087
6088out:
6089 return status;
6090}
6091
6092/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006093 * Decode CLOSE response
6094 */
Chuck Leverbf269552010-12-14 14:59:29 +00006095static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6096 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097{
Andy Adamson05d564f2008-12-23 16:06:15 -05006098 struct compound_hdr hdr;
6099 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006100
Chuck Leverbf269552010-12-14 14:59:29 +00006101 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006102 if (status)
6103 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006104 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006105 if (status)
6106 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006107 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006108 if (status)
6109 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006110 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006111 if (status != 0)
6112 goto out;
6113 /*
6114 * Note: Server may do delete on close for this file
6115 * in which case the getattr call will fail with
6116 * an ESTALE error. Shouldn't be a problem,
6117 * though, since fattr->valid will remain unset.
6118 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006119 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006120out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006121 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006122}
6123
6124/*
6125 * Decode OPEN response
6126 */
Chuck Leverbf269552010-12-14 14:59:29 +00006127static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6128 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006129{
Andy Adamson05d564f2008-12-23 16:06:15 -05006130 struct compound_hdr hdr;
6131 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006132
Chuck Leverbf269552010-12-14 14:59:29 +00006133 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006134 if (status)
6135 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006137 if (status)
6138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006139 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006140 if (status)
6141 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006142 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006143 if (status)
6144 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006145 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006146 if (status)
6147 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006148 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006149 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006150 if (decode_getfattr(xdr, res->f_attr, res->server) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006151 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006152 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006153 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006154 decode_getfattr(xdr, res->dir_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 OPEN_CONFIRM response
6161 */
Chuck Leverbf269552010-12-14 14:59:29 +00006162static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6163 struct xdr_stream *xdr,
6164 struct nfs_open_confirmres *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_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006173 if (status)
6174 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006175 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006176out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006177 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006178}
6179
6180/*
6181 * Decode OPEN response
6182 */
Chuck Leverbf269552010-12-14 14:59:29 +00006183static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6184 struct xdr_stream *xdr,
6185 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006186{
Andy Adamson05d564f2008-12-23 16:06:15 -05006187 struct compound_hdr hdr;
6188 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189
Chuck Leverbf269552010-12-14 14:59:29 +00006190 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006191 if (status)
6192 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006193 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006194 if (status)
6195 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006196 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006197 if (status)
6198 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006199 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006200 if (status)
6201 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006202 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006204 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205}
6206
6207/*
6208 * Decode SETATTR response
6209 */
Chuck Leverbf269552010-12-14 14:59:29 +00006210static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6211 struct xdr_stream *xdr,
6212 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006213{
Andy Adamson05d564f2008-12-23 16:06:15 -05006214 struct compound_hdr hdr;
6215 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216
Chuck Leverbf269552010-12-14 14:59:29 +00006217 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006218 if (status)
6219 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006220 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006221 if (status)
6222 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006223 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006224 if (status)
6225 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006226 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006227 if (status)
6228 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006229 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006230out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006231 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006232}
6233
6234/*
6235 * Decode LOCK response
6236 */
Chuck Leverbf269552010-12-14 14:59:29 +00006237static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6238 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006240 struct compound_hdr hdr;
6241 int status;
6242
Chuck Leverbf269552010-12-14 14:59:29 +00006243 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006244 if (status)
6245 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006246 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006247 if (status)
6248 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006249 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006250 if (status)
6251 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006252 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006253out:
6254 return status;
6255}
6256
6257/*
6258 * Decode LOCKT response
6259 */
Chuck Leverbf269552010-12-14 14:59:29 +00006260static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6261 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006263 struct compound_hdr hdr;
6264 int status;
6265
Chuck Leverbf269552010-12-14 14:59:29 +00006266 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006267 if (status)
6268 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006269 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006270 if (status)
6271 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006272 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273 if (status)
6274 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006275 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276out:
6277 return status;
6278}
6279
6280/*
6281 * Decode LOCKU response
6282 */
Chuck Leverbf269552010-12-14 14:59:29 +00006283static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6284 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006286 struct compound_hdr hdr;
6287 int status;
6288
Chuck Leverbf269552010-12-14 14:59:29 +00006289 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290 if (status)
6291 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006292 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006293 if (status)
6294 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006295 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006296 if (status)
6297 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006298 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299out:
6300 return status;
6301}
6302
Chuck Leverbf269552010-12-14 14:59:29 +00006303static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6304 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006305{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006306 struct compound_hdr hdr;
6307 int status;
6308
Chuck Leverbf269552010-12-14 14:59:29 +00006309 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006310 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006311 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006312 return status;
6313}
6314
Linus Torvalds1da177e2005-04-16 15:20:36 -07006315/*
6316 * Decode READLINK response
6317 */
Chuck Leverbf269552010-12-14 14:59:29 +00006318static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6319 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006320 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006321{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006322 struct compound_hdr hdr;
6323 int status;
6324
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006326 if (status)
6327 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006328 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006329 if (status)
6330 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006331 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332 if (status)
6333 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006334 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335out:
6336 return status;
6337}
6338
6339/*
6340 * Decode READDIR response
6341 */
Chuck Leverbf269552010-12-14 14:59:29 +00006342static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6343 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006344{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 struct compound_hdr hdr;
6346 int status;
6347
Chuck Leverbf269552010-12-14 14:59:29 +00006348 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006349 if (status)
6350 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006351 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006352 if (status)
6353 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006354 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006355 if (status)
6356 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006357 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358out:
6359 return status;
6360}
6361
6362/*
6363 * Decode Read response
6364 */
Chuck Leverbf269552010-12-14 14:59:29 +00006365static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6366 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006367{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368 struct compound_hdr hdr;
6369 int status;
6370
Chuck Leverbf269552010-12-14 14:59:29 +00006371 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372 if (status)
6373 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006374 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006375 if (status)
6376 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006377 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378 if (status)
6379 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006380 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381 if (!status)
6382 status = res->count;
6383out:
6384 return status;
6385}
6386
6387/*
6388 * Decode WRITE response
6389 */
Chuck Leverbf269552010-12-14 14:59:29 +00006390static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6391 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006392{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006393 struct compound_hdr hdr;
6394 int status;
6395
Chuck Leverbf269552010-12-14 14:59:29 +00006396 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006397 if (status)
6398 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006399 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006400 if (status)
6401 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006402 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006403 if (status)
6404 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006405 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006406 if (status)
6407 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006408 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006409 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006410 if (!status)
6411 status = res->count;
6412out:
6413 return status;
6414}
6415
6416/*
6417 * Decode COMMIT response
6418 */
Chuck Leverbf269552010-12-14 14:59:29 +00006419static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6420 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006421{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006422 struct compound_hdr hdr;
6423 int status;
6424
Chuck Leverbf269552010-12-14 14:59:29 +00006425 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426 if (status)
6427 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006428 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006429 if (status)
6430 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006431 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006432 if (status)
6433 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006434 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006435 if (status)
6436 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006437 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006438 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439out:
6440 return status;
6441}
6442
6443/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006444 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006445 */
Chuck Leverbf269552010-12-14 14:59:29 +00006446static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006447 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006449 struct compound_hdr hdr;
6450 int status;
6451
Chuck Leverbf269552010-12-14 14:59:29 +00006452 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006454 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006455 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006456 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006457 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006458 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006459 return status;
6460}
6461
6462/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006463 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464 */
Chuck Leverbf269552010-12-14 14:59:29 +00006465static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006466 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006468 struct compound_hdr hdr;
6469 int status;
6470
Chuck Leverbf269552010-12-14 14:59:29 +00006471 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006473 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006474 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006475 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006476 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006477 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006478 return status;
6479}
6480
6481/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006482 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006483 */
Chuck Leverbf269552010-12-14 14:59:29 +00006484static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006485 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006486{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006487 struct compound_hdr hdr;
6488 int status;
6489
Chuck Leverbf269552010-12-14 14:59:29 +00006490 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006492 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006493 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006494 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006496 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497 return status;
6498}
6499
6500/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006501 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502 */
Chuck Leverbf269552010-12-14 14:59:29 +00006503static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6504 struct xdr_stream *xdr,
6505 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006506{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507 struct compound_hdr hdr;
6508 int status;
6509
Chuck Leverbf269552010-12-14 14:59:29 +00006510 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006511 if (status)
6512 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006513 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006514 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006515 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006516 status = decode_putfh(xdr);
6517 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006519 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520out:
6521 return status;
6522}
6523
6524/*
6525 * Decode RENEW response
6526 */
Chuck Leverbf269552010-12-14 14:59:29 +00006527static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6528 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530 struct compound_hdr hdr;
6531 int status;
6532
Chuck Leverbf269552010-12-14 14:59:29 +00006533 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006534 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006535 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536 return status;
6537}
6538
6539/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006540 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541 */
Chuck Leverbf269552010-12-14 14:59:29 +00006542static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6543 struct xdr_stream *xdr,
6544 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006546 struct compound_hdr hdr;
6547 int status;
6548
Chuck Leverbf269552010-12-14 14:59:29 +00006549 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006552 return status;
6553}
6554
6555/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006556 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006557 */
Chuck Leverbf269552010-12-14 14:59:29 +00006558static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6559 struct xdr_stream *xdr,
6560 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006561{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006562 struct compound_hdr hdr;
6563 int status;
6564
Chuck Leverbf269552010-12-14 14:59:29 +00006565 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006566 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006567 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006568 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006569 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006570 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006571 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006572 return status;
6573}
6574
6575/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006576 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006577 */
Chuck Leverbf269552010-12-14 14:59:29 +00006578static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6579 struct xdr_stream *xdr,
6580 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006581{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006582 struct compound_hdr hdr;
6583 int status;
6584
Chuck Leverbf269552010-12-14 14:59:29 +00006585 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006586 if (status)
6587 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006588 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006589 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006590 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006591 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006592 if (status != 0)
6593 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006594 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006595 if (status != 0)
6596 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006597 decode_getfattr(xdr, res->fattr, res->server);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006598out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006599 return status;
6600}
6601
Trond Myklebust683b57b2006-06-09 09:34:22 -04006602/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006603 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006604 */
Chuck Leverbf269552010-12-14 14:59:29 +00006605static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6606 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006607 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006608{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006609 struct compound_hdr hdr;
6610 int status;
6611
Chuck Leverbf269552010-12-14 14:59:29 +00006612 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006613 if (status)
6614 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006615 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006616 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006617 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006618 status = decode_putfh(xdr);
6619 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006620 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006621 status = decode_lookup(xdr);
6622 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006623 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006624 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006625 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6626 NULL, res->fs_locations,
6627 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006628out:
6629 return status;
6630}
6631
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006632/*
6633 * Decode SECINFO response
6634 */
6635static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6636 struct xdr_stream *xdr,
6637 struct nfs4_secinfo_res *res)
6638{
6639 struct compound_hdr hdr;
6640 int status;
6641
6642 status = decode_compound_hdr(xdr, &hdr);
6643 if (status)
6644 goto out;
6645 status = decode_sequence(xdr, &res->seq_res, rqstp);
6646 if (status)
6647 goto out;
6648 status = decode_putfh(xdr);
6649 if (status)
6650 goto out;
6651 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006652out:
6653 return status;
6654}
6655
Benny Halevy99fe60d2009-04-01 09:22:29 -04006656#if defined(CONFIG_NFS_V4_1)
6657/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006658 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006659 */
Chuck Leverbf269552010-12-14 14:59:29 +00006660static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6661 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006662 void *res)
6663{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006664 struct compound_hdr hdr;
6665 int status;
6666
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006668 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006669 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006670 return status;
6671}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006672
6673/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006674 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006675 */
Chuck Leverbf269552010-12-14 14:59:29 +00006676static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6677 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006678 struct nfs41_create_session_res *res)
6679{
Andy Adamsonfc931582009-04-01 09:22:31 -04006680 struct compound_hdr hdr;
6681 int status;
6682
Chuck Leverbf269552010-12-14 14:59:29 +00006683 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006684 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006685 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006686 return status;
6687}
6688
6689/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006690 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006691 */
Chuck Leverbf269552010-12-14 14:59:29 +00006692static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6693 struct xdr_stream *xdr,
6694 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006695{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006696 struct compound_hdr hdr;
6697 int status;
6698
Chuck Leverbf269552010-12-14 14:59:29 +00006699 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006700 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006701 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006702 return status;
6703}
6704
6705/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006706 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006707 */
Chuck Leverbf269552010-12-14 14:59:29 +00006708static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6709 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006710 struct nfs4_sequence_res *res)
6711{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006712 struct compound_hdr hdr;
6713 int status;
6714
Chuck Leverbf269552010-12-14 14:59:29 +00006715 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006716 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006717 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006718 return status;
6719}
6720
6721/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006722 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006723 */
Chuck Leverbf269552010-12-14 14:59:29 +00006724static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6725 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006726 struct nfs4_get_lease_time_res *res)
6727{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006728 struct compound_hdr hdr;
6729 int status;
6730
Chuck Leverbf269552010-12-14 14:59:29 +00006731 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006732 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006733 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006734 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006735 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006736 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006737 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006738 return status;
6739}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006740
6741/*
6742 * Decode RECLAIM_COMPLETE response
6743 */
Chuck Leverbf269552010-12-14 14:59:29 +00006744static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6745 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006746 struct nfs41_reclaim_complete_res *res)
6747{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006748 struct compound_hdr hdr;
6749 int status;
6750
Chuck Leverbf269552010-12-14 14:59:29 +00006751 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006752 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006753 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006754 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006755 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006756 return status;
6757}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006758
6759/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006760 * Decode GETDEVICELIST response
6761 */
6762static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6763 struct xdr_stream *xdr,
6764 struct nfs4_getdevicelist_res *res)
6765{
6766 struct compound_hdr hdr;
6767 int status;
6768
6769 dprintk("encoding getdevicelist!\n");
6770
6771 status = decode_compound_hdr(xdr, &hdr);
6772 if (status != 0)
6773 goto out;
6774 status = decode_sequence(xdr, &res->seq_res, rqstp);
6775 if (status != 0)
6776 goto out;
6777 status = decode_putfh(xdr);
6778 if (status != 0)
6779 goto out;
6780 status = decode_getdevicelist(xdr, res->devlist);
6781out:
6782 return status;
6783}
6784
6785/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006786 * Decode GETDEVINFO response
6787 */
Chuck Leverbf269552010-12-14 14:59:29 +00006788static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6789 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006790 struct nfs4_getdeviceinfo_res *res)
6791{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006792 struct compound_hdr hdr;
6793 int status;
6794
Chuck Leverbf269552010-12-14 14:59:29 +00006795 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006796 if (status != 0)
6797 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006798 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006799 if (status != 0)
6800 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006801 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006802out:
6803 return status;
6804}
6805
6806/*
6807 * Decode LAYOUTGET response
6808 */
Chuck Leverbf269552010-12-14 14:59:29 +00006809static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6810 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006811 struct nfs4_layoutget_res *res)
6812{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006813 struct compound_hdr hdr;
6814 int status;
6815
Chuck Leverbf269552010-12-14 14:59:29 +00006816 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006817 if (status)
6818 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006819 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006820 if (status)
6821 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006822 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006823 if (status)
6824 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006825 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006826out:
6827 return status;
6828}
Andy Adamson863a3c62011-03-23 13:27:54 +00006829
6830/*
Benny Halevycbe82602011-05-22 19:52:37 +03006831 * Decode LAYOUTRETURN response
6832 */
6833static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6834 struct xdr_stream *xdr,
6835 struct nfs4_layoutreturn_res *res)
6836{
6837 struct compound_hdr hdr;
6838 int status;
6839
6840 status = decode_compound_hdr(xdr, &hdr);
6841 if (status)
6842 goto out;
6843 status = decode_sequence(xdr, &res->seq_res, rqstp);
6844 if (status)
6845 goto out;
6846 status = decode_putfh(xdr);
6847 if (status)
6848 goto out;
6849 status = decode_layoutreturn(xdr, res);
6850out:
6851 return status;
6852}
6853
6854/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006855 * Decode LAYOUTCOMMIT response
6856 */
6857static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6858 struct xdr_stream *xdr,
6859 struct nfs4_layoutcommit_res *res)
6860{
6861 struct compound_hdr hdr;
6862 int status;
6863
6864 status = decode_compound_hdr(xdr, &hdr);
6865 if (status)
6866 goto out;
6867 status = decode_sequence(xdr, &res->seq_res, rqstp);
6868 if (status)
6869 goto out;
6870 status = decode_putfh(xdr);
6871 if (status)
6872 goto out;
6873 status = decode_layoutcommit(xdr, rqstp, res);
6874 if (status)
6875 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006876 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006877out:
6878 return status;
6879}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006880
6881/*
6882 * Decode SECINFO_NO_NAME response
6883 */
6884static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6885 struct xdr_stream *xdr,
6886 struct nfs4_secinfo_res *res)
6887{
6888 struct compound_hdr hdr;
6889 int status;
6890
6891 status = decode_compound_hdr(xdr, &hdr);
6892 if (status)
6893 goto out;
6894 status = decode_sequence(xdr, &res->seq_res, rqstp);
6895 if (status)
6896 goto out;
6897 status = decode_putrootfh(xdr);
6898 if (status)
6899 goto out;
6900 status = decode_secinfo(xdr, res);
6901out:
6902 return status;
6903}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006904
6905/*
6906 * Decode TEST_STATEID response
6907 */
6908static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6909 struct xdr_stream *xdr,
6910 struct nfs41_test_stateid_res *res)
6911{
6912 struct compound_hdr hdr;
6913 int status;
6914
6915 status = decode_compound_hdr(xdr, &hdr);
6916 if (status)
6917 goto out;
6918 status = decode_sequence(xdr, &res->seq_res, rqstp);
6919 if (status)
6920 goto out;
6921 status = decode_test_stateid(xdr, res);
6922out:
6923 return status;
6924}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006925
6926/*
6927 * Decode FREE_STATEID response
6928 */
6929static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6930 struct xdr_stream *xdr,
6931 struct nfs41_free_stateid_res *res)
6932{
6933 struct compound_hdr hdr;
6934 int status;
6935
6936 status = decode_compound_hdr(xdr, &hdr);
6937 if (status)
6938 goto out;
6939 status = decode_sequence(xdr, &res->seq_res, rqstp);
6940 if (status)
6941 goto out;
6942 status = decode_free_stateid(xdr, res);
6943out:
6944 return status;
6945}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006946#endif /* CONFIG_NFS_V4_1 */
6947
Chuck Lever573c4e12010-12-14 14:58:11 +00006948/**
6949 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6950 * the local page cache.
6951 * @xdr: XDR stream where entry resides
6952 * @entry: buffer to fill in with entry data
6953 * @plus: boolean indicating whether this should be a readdirplus entry
6954 *
6955 * Returns zero if successful, otherwise a negative errno value is
6956 * returned.
6957 *
6958 * This function is not invoked during READDIR reply decoding, but
6959 * rather whenever an application invokes the getdents(2) system call
6960 * on a directory already in our cache.
6961 */
6962int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6963 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006964{
Fred Isamandae100c2011-07-30 20:52:37 -04006965 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07006966 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006967 __be32 *p = xdr_inline_decode(xdr, 4);
6968 if (unlikely(!p))
6969 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006970 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006971 p = xdr_inline_decode(xdr, 4);
6972 if (unlikely(!p))
6973 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006974 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006975 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006976 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006977 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006978 }
6979
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006980 p = xdr_inline_decode(xdr, 12);
6981 if (unlikely(!p))
6982 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006983 entry->prev_cookie = entry->cookie;
6984 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006985 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006986
Trond Myklebust9af8c222010-10-24 11:52:55 -04006987 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006988 if (unlikely(!p))
6989 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006990 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006991
6992 /*
6993 * In case the server doesn't return an inode number,
6994 * we fake one here. (We don't use inode number 0,
6995 * since glibc seems to choke on it...)
6996 */
6997 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006998 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006999
Trond Myklebust9af8c222010-10-24 11:52:55 -04007000 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007001 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007002
7003 if (decode_attr_length(xdr, &len, &p) < 0)
7004 goto out_overflow;
7005
Chuck Lever573c4e12010-12-14 14:58:11 +00007006 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007007 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007008 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007009 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7010 entry->ino = entry->fattr->mounted_on_fileid;
7011 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007012 entry->ino = entry->fattr->fileid;
7013
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007014 entry->d_type = DT_UNKNOWN;
7015 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7016 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7017
Chuck Lever573c4e12010-12-14 14:58:11 +00007018 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007019
7020out_overflow:
7021 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007022 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007023}
7024
7025/*
7026 * We need to translate between nfs status return values and
7027 * the local errno values which may not be the same.
7028 */
7029static struct {
7030 int stat;
7031 int errno;
7032} nfs_errtbl[] = {
7033 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007034 { NFS4ERR_PERM, -EPERM },
7035 { NFS4ERR_NOENT, -ENOENT },
7036 { NFS4ERR_IO, -errno_NFSERR_IO},
7037 { NFS4ERR_NXIO, -ENXIO },
7038 { NFS4ERR_ACCESS, -EACCES },
7039 { NFS4ERR_EXIST, -EEXIST },
7040 { NFS4ERR_XDEV, -EXDEV },
7041 { NFS4ERR_NOTDIR, -ENOTDIR },
7042 { NFS4ERR_ISDIR, -EISDIR },
7043 { NFS4ERR_INVAL, -EINVAL },
7044 { NFS4ERR_FBIG, -EFBIG },
7045 { NFS4ERR_NOSPC, -ENOSPC },
7046 { NFS4ERR_ROFS, -EROFS },
7047 { NFS4ERR_MLINK, -EMLINK },
7048 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7049 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7050 { NFS4ERR_DQUOT, -EDQUOT },
7051 { NFS4ERR_STALE, -ESTALE },
7052 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007053 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7054 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7055 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007056 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007057 { NFS4ERR_BADTYPE, -EBADTYPE },
7058 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007059 { NFS4ERR_SYMLINK, -ELOOP },
7060 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7061 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007062 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007063};
7064
7065/*
7066 * Convert an NFS error code to a local one.
7067 * This one is used jointly by NFSv2 and NFSv3.
7068 */
7069static int
David Howells0a8ea432006-08-22 20:06:08 -04007070nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007071{
7072 int i;
7073 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7074 if (nfs_errtbl[i].stat == stat)
7075 return nfs_errtbl[i].errno;
7076 }
7077 if (stat <= 10000 || stat > 10100) {
7078 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007079 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007080 }
7081 /* If we cannot translate the error, the recovery routines should
7082 * handle it.
7083 * Note: remaining NFSv4 error codes have values > 10000, so should
7084 * not conflict with native Linux error codes.
7085 */
Benny Halevy856dff32008-03-31 17:39:06 +03007086 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007087}
7088
Linus Torvalds1da177e2005-04-16 15:20:36 -07007089#define PROC(proc, argtype, restype) \
7090[NFSPROC4_CLNT_##proc] = { \
7091 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007092 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007093 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007094 .p_arglen = NFS4_##argtype##_sz, \
7095 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007096 .p_statidx = NFSPROC4_CLNT_##proc, \
7097 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007098}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007099
7100struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007101 PROC(READ, enc_read, dec_read),
7102 PROC(WRITE, enc_write, dec_write),
7103 PROC(COMMIT, enc_commit, dec_commit),
7104 PROC(OPEN, enc_open, dec_open),
7105 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7106 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7107 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7108 PROC(CLOSE, enc_close, dec_close),
7109 PROC(SETATTR, enc_setattr, dec_setattr),
7110 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7111 PROC(RENEW, enc_renew, dec_renew),
7112 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7113 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7114 PROC(LOCK, enc_lock, dec_lock),
7115 PROC(LOCKT, enc_lockt, dec_lockt),
7116 PROC(LOCKU, enc_locku, dec_locku),
7117 PROC(ACCESS, enc_access, dec_access),
7118 PROC(GETATTR, enc_getattr, dec_getattr),
7119 PROC(LOOKUP, enc_lookup, dec_lookup),
7120 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7121 PROC(REMOVE, enc_remove, dec_remove),
7122 PROC(RENAME, enc_rename, dec_rename),
7123 PROC(LINK, enc_link, dec_link),
7124 PROC(SYMLINK, enc_symlink, dec_symlink),
7125 PROC(CREATE, enc_create, dec_create),
7126 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7127 PROC(STATFS, enc_statfs, dec_statfs),
7128 PROC(READLINK, enc_readlink, dec_readlink),
7129 PROC(READDIR, enc_readdir, dec_readdir),
7130 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7131 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7132 PROC(GETACL, enc_getacl, dec_getacl),
7133 PROC(SETACL, enc_setacl, dec_setacl),
7134 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7135 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007136 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007137#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007138 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7139 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7140 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7141 PROC(SEQUENCE, enc_sequence, dec_sequence),
7142 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7143 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7144 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7145 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007146 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007147 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007148 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007149 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007150 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007151 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007152#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007153};
7154
Trond Myklebusta613fa12012-01-20 13:53:56 -05007155const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007156 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007157 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007158 .procs = nfs4_procedures
7159};
7160
7161/*
7162 * Local variables:
7163 * c-basic-offset: 8
7164 * End:
7165 */