blob: 48f539314f257dc5bad20564285563b453ee8e18 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
55#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000056#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050057#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040058#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#define NFSDBG_FACILITY NFSDBG_XDR
61
62/* Mapping from NFS error code to "errno" error code. */
63#define errno_NFSERR_IO EIO
64
David Howells0a8ea432006-08-22 20:06:08 -040065static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
68#ifdef DEBUG
69#define NFS4_MAXTAGLEN 20
70#else
71#define NFS4_MAXTAGLEN 0
72#endif
73
Andy Adamson6c0195a2008-12-23 16:06:15 -050074/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040075 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 */
Trond Myklebustd035c362010-12-21 10:45:27 -050077#define open_owner_id_maxsz (1 + 1 + 4)
78#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040079#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
81#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
82#define op_encode_hdr_maxsz (1)
83#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040084#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
85#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
86#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
87#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
89 (NFS4_FHSIZE >> 2))
90#define decode_putfh_maxsz (op_decode_hdr_maxsz)
91#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
92#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
93#define encode_getfh_maxsz (op_encode_hdr_maxsz)
94#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
95 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040096#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000097#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
99#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400100#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
101#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000102/* This is based on getfattr, which uses the most attributes: */
103#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400104 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000105#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
106 nfs4_fattr_value_maxsz)
107#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400108#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 1 + 2 + 1 + \
110 nfs4_owner_maxsz + \
111 nfs4_group_maxsz + \
112 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define encode_savefh_maxsz (op_encode_hdr_maxsz)
114#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400115#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
116#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200117#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400118/* The 5 accounts for the PNFS attributes, and assumes that at most three
119 * layout types will be returned.
120 */
121#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
122 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
124#define decode_renew_maxsz (op_decode_hdr_maxsz)
125#define encode_setclientid_maxsz \
126 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500127 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
128 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
129 1 /* sc_prog */ + \
130 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
131 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
132 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#define decode_setclientid_maxsz \
134 (op_decode_hdr_maxsz + \
135 2 + \
136 1024) /* large value for CLID_INUSE */
137#define encode_setclientid_confirm_maxsz \
138 (op_encode_hdr_maxsz + \
139 3 + (NFS4_VERIFIER_SIZE >> 2))
140#define decode_setclientid_confirm_maxsz \
141 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400142#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
143#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400144#define encode_share_access_maxsz \
145 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500146#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400147#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
148#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
149#define encode_open_maxsz (op_encode_hdr_maxsz + \
150 2 + encode_share_access_maxsz + 2 + \
151 open_owner_id_maxsz + \
152 encode_opentype_maxsz + \
153 encode_claim_null_maxsz)
154#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400155#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400156 decode_ace_maxsz)
157#define decode_change_info_maxsz (5)
158#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400159 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400160 decode_change_info_maxsz + 1 + \
161 nfs4_fattr_bitmap_maxsz + \
162 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400163#define encode_open_confirm_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1)
166#define decode_open_confirm_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169#define encode_open_downgrade_maxsz \
170 (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + 1 + \
172 encode_share_access_maxsz)
173#define decode_open_downgrade_maxsz \
174 (op_decode_hdr_maxsz + \
175 decode_stateid_maxsz)
176#define encode_close_maxsz (op_encode_hdr_maxsz + \
177 1 + encode_stateid_maxsz)
178#define decode_close_maxsz (op_decode_hdr_maxsz + \
179 decode_stateid_maxsz)
180#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
181 encode_stateid_maxsz + \
182 encode_attrs_maxsz)
183#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
184 nfs4_fattr_bitmap_maxsz)
185#define encode_read_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + 3)
187#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
188#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
189 2 + encode_verifier_maxsz + 5)
190#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
191 decode_verifier_maxsz)
192#define encode_readlink_maxsz (op_encode_hdr_maxsz)
193#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
194#define encode_write_maxsz (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + 4)
196#define decode_write_maxsz (op_decode_hdr_maxsz + \
197 2 + decode_verifier_maxsz)
198#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
199#define decode_commit_maxsz (op_decode_hdr_maxsz + \
200 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201#define encode_remove_maxsz (op_encode_hdr_maxsz + \
202 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400203#define decode_remove_maxsz (op_decode_hdr_maxsz + \
204 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#define encode_rename_maxsz (op_encode_hdr_maxsz + \
206 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400207#define decode_rename_maxsz (op_decode_hdr_maxsz + \
208 decode_change_info_maxsz + \
209 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#define encode_link_maxsz (op_encode_hdr_maxsz + \
211 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400212#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400213#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400214#define encode_lock_maxsz (op_encode_hdr_maxsz + \
215 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400216 1 + encode_stateid_maxsz + 1 + \
217 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400218#define decode_lock_denied_maxsz \
219 (8 + decode_lockowner_maxsz)
220#define decode_lock_maxsz (op_decode_hdr_maxsz + \
221 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400222#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
223 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400224#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
225 decode_lock_denied_maxsz)
226#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
227 encode_stateid_maxsz + \
228 4)
229#define decode_locku_maxsz (op_decode_hdr_maxsz + \
230 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400231#define encode_release_lockowner_maxsz \
232 (op_encode_hdr_maxsz + \
233 encode_lockowner_maxsz)
234#define decode_release_lockowner_maxsz \
235 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400236#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
237#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
239 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400240 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000241 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
243#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400244 1 + 2 + nfs4_name_maxsz + \
245 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400246#define decode_create_maxsz (op_decode_hdr_maxsz + \
247 decode_change_info_maxsz + \
248 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400249#define encode_statfs_maxsz (encode_getattr_maxsz)
250#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
252#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400253#define encode_getacl_maxsz (encode_getattr_maxsz)
254#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
255 nfs4_fattr_bitmap_maxsz + 1)
256#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
257 encode_stateid_maxsz + 3)
258#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400259#define encode_fs_locations_maxsz \
260 (encode_getattr_maxsz)
261#define decode_fs_locations_maxsz \
262 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000263#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400264#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400265
266#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400267#define NFS4_MAX_MACHINE_NAME_LEN (64)
268
Benny Halevy99fe60d2009-04-01 09:22:29 -0400269#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
270 encode_verifier_maxsz + \
271 1 /* co_ownerid.len */ + \
272 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
273 1 /* flags */ + \
274 1 /* spa_how */ + \
275 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500276 1 /* implementation id array of size 1 */ + \
277 1 /* nii_domain */ + \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
279 1 /* nii_name */ + \
280 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
281 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400282#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
283 2 /* eir_clientid */ + \
284 1 /* eir_sequenceid */ + \
285 1 /* eir_flags */ + \
286 1 /* spr_how */ + \
287 0 /* SP4_NONE (for now) */ + \
288 2 /* eir_server_owner.so_minor_id */ + \
289 /* eir_server_owner.so_major_id<> */ \
290 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
291 /* eir_server_scope<> */ \
292 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
293 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500294 1 /* nii_domain */ + \
295 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
296 1 /* nii_name */ + \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
298 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400299#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
300#define decode_channel_attrs_maxsz (6 + \
301 1 /* ca_rdma_ird.len */ + \
302 1 /* ca_rdma_ird */)
303#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
304 2 /* csa_clientid */ + \
305 1 /* csa_sequence */ + \
306 1 /* csa_flags */ + \
307 encode_channel_attrs_maxsz + \
308 encode_channel_attrs_maxsz + \
309 1 /* csa_cb_program */ + \
310 1 /* csa_sec_parms.len (1) */ + \
311 1 /* cb_secflavor (AUTH_SYS) */ + \
312 1 /* stamp */ + \
313 1 /* machinename.len */ + \
314 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
315 1 /* uid */ + \
316 1 /* gid */ + \
317 1 /* gids.len (0) */)
318#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
319 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
320 1 /* csr_sequence */ + \
321 1 /* csr_flags */ + \
322 decode_channel_attrs_maxsz + \
323 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400324#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
325#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400326#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
327 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
328#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
329 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500330#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
331#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400332#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
333 encode_verifier_maxsz)
334#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
335 2 /* nfs_cookie4 gdlr_cookie */ + \
336 decode_verifier_maxsz \
337 /* verifier4 gdlr_verifier */ + \
338 1 /* gdlr_deviceid_list count */ + \
339 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
340 NFS4_DEVICEID4_SIZE) \
341 /* gdlr_deviceid_list */ + \
342 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400343#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
344 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
345#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
346 1 /* layout type */ + \
347 1 /* opaque devaddr4 length */ + \
348 /* devaddr4 payload is read into page */ \
349 1 /* notification bitmap length */ + \
350 1 /* notification bitmap */)
351#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
352 encode_stateid_maxsz)
353#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
354 decode_stateid_maxsz + \
355 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000356#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
357 2 /* offset */ + \
358 2 /* length */ + \
359 1 /* reclaim */ + \
360 encode_stateid_maxsz + \
361 1 /* new offset (true) */ + \
362 2 /* last byte written */ + \
363 1 /* nt_timechanged (false) */ + \
364 1 /* layoutupdate4 layout type */ + \
365 1 /* NULL filelayout layoutupdate4 payload */)
366#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300367#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
368 encode_stateid_maxsz + \
369 1 /* FIXME: opaque lrf_body always empty at the moment */)
370#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
371 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400372#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
373#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400374#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
375 XDR_QUADLEN(NFS4_STATEID_SIZE))
376#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400377#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
378 XDR_QUADLEN(NFS4_STATEID_SIZE))
379#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400380#else /* CONFIG_NFS_V4_1 */
381#define encode_sequence_maxsz 0
382#define decode_sequence_maxsz 0
383#endif /* CONFIG_NFS_V4_1 */
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
386#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
387#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400388 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400390 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400392 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400394 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400396 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400398 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400400 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400402 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400404 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400406 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400410 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400412 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400415 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400417 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400420 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400425 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400429 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400430 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400433 encode_putfh_maxsz + \
434 encode_savefh_maxsz + \
435 encode_open_maxsz + \
436 encode_getfh_maxsz + \
437 encode_getattr_maxsz + \
438 encode_restorefh_maxsz + \
439 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400441 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400442 decode_putfh_maxsz + \
443 decode_savefh_maxsz + \
444 decode_open_maxsz + \
445 decode_getfh_maxsz + \
446 decode_getattr_maxsz + \
447 decode_restorefh_maxsz + \
448 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400449#define NFS4_enc_open_confirm_sz \
450 (compound_encode_hdr_maxsz + \
451 encode_putfh_maxsz + \
452 encode_open_confirm_maxsz)
453#define NFS4_dec_open_confirm_sz \
454 (compound_decode_hdr_maxsz + \
455 decode_putfh_maxsz + \
456 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400460 encode_open_maxsz + \
461 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400465 decode_open_maxsz + \
466 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_enc_open_downgrade_sz \
468 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400470 encode_putfh_maxsz + \
471 encode_open_downgrade_maxsz + \
472 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_dec_open_downgrade_sz \
474 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400475 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400476 decode_putfh_maxsz + \
477 decode_open_downgrade_maxsz + \
478 decode_getattr_maxsz)
479#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400480 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400481 encode_putfh_maxsz + \
482 encode_close_maxsz + \
483 encode_getattr_maxsz)
484#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400486 decode_putfh_maxsz + \
487 decode_close_maxsz + \
488 decode_getattr_maxsz)
489#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400490 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400491 encode_putfh_maxsz + \
492 encode_setattr_maxsz + \
493 encode_getattr_maxsz)
494#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400495 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400496 decode_putfh_maxsz + \
497 decode_setattr_maxsz + \
498 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400500 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 encode_putfh_maxsz + \
502 encode_fsinfo_maxsz)
503#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400504 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 decode_putfh_maxsz + \
506 decode_fsinfo_maxsz)
507#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
508 encode_renew_maxsz)
509#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
510 decode_renew_maxsz)
511#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
512 encode_setclientid_maxsz)
513#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
514 decode_setclientid_maxsz)
515#define NFS4_enc_setclientid_confirm_sz \
516 (compound_encode_hdr_maxsz + \
517 encode_setclientid_confirm_maxsz + \
518 encode_putrootfh_maxsz + \
519 encode_fsinfo_maxsz)
520#define NFS4_dec_setclientid_confirm_sz \
521 (compound_decode_hdr_maxsz + \
522 decode_setclientid_confirm_maxsz + \
523 decode_putrootfh_maxsz + \
524 decode_fsinfo_maxsz)
525#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400526 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400528 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400532 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400536 encode_lockt_maxsz)
537#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400539 decode_putfh_maxsz + \
540 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400544 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400548 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400549#define NFS4_enc_release_lockowner_sz \
550 (compound_encode_hdr_maxsz + \
551 encode_lockowner_maxsz)
552#define NFS4_dec_release_lockowner_sz \
553 (compound_decode_hdr_maxsz + \
554 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400558 encode_access_maxsz + \
559 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400561 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400563 decode_access_maxsz + \
564 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 encode_putfh_maxsz + \
568 encode_getattr_maxsz)
569#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 decode_putfh_maxsz + \
572 decode_getattr_maxsz)
573#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 encode_putfh_maxsz + \
576 encode_lookup_maxsz + \
577 encode_getattr_maxsz + \
578 encode_getfh_maxsz)
579#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400582 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_getattr_maxsz + \
584 decode_getfh_maxsz)
585#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 encode_putrootfh_maxsz + \
588 encode_getattr_maxsz + \
589 encode_getfh_maxsz)
590#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400591 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 decode_putrootfh_maxsz + \
593 decode_getattr_maxsz + \
594 decode_getfh_maxsz)
595#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400598 encode_remove_maxsz + \
599 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400603 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400604 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 encode_putfh_maxsz + \
608 encode_savefh_maxsz + \
609 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400610 encode_rename_maxsz + \
611 encode_getattr_maxsz + \
612 encode_restorefh_maxsz + \
613 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400615 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 decode_putfh_maxsz + \
617 decode_savefh_maxsz + \
618 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400619 decode_rename_maxsz + \
620 decode_getattr_maxsz + \
621 decode_restorefh_maxsz + \
622 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400624 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 encode_putfh_maxsz + \
626 encode_savefh_maxsz + \
627 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400628 encode_link_maxsz + \
629 decode_getattr_maxsz + \
630 encode_restorefh_maxsz + \
631 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400633 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 decode_putfh_maxsz + \
635 decode_savefh_maxsz + \
636 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400637 decode_link_maxsz + \
638 decode_getattr_maxsz + \
639 decode_restorefh_maxsz + \
640 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 encode_putfh_maxsz + \
644 encode_symlink_maxsz + \
645 encode_getattr_maxsz + \
646 encode_getfh_maxsz)
647#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 decode_putfh_maxsz + \
650 decode_symlink_maxsz + \
651 decode_getattr_maxsz + \
652 decode_getfh_maxsz)
653#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400656 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400658 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400660 encode_restorefh_maxsz + \
661 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400663 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400665 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400667 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400669 decode_restorefh_maxsz + \
670 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 encode_putfh_maxsz + \
674 encode_getattr_maxsz)
675#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 decode_putfh_maxsz + \
678 decode_getattr_maxsz)
679#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400682 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400686 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800689 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 encode_getattr_maxsz)
691#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800693 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 decode_getattr_maxsz)
695#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100698 encode_delegreturn_maxsz + \
699 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400701 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100702 decode_delegreturn_maxsz + \
703 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000704#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400705 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000706 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400707 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000708#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400709 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000710 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400711 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000712#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000714 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400715 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000716#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000718 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400719 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400720#define NFS4_enc_fs_locations_sz \
721 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400722 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400723 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400724 encode_lookup_maxsz + \
725 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400726#define NFS4_dec_fs_locations_sz \
727 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400728 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400729 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400730 decode_lookup_maxsz + \
731 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000732#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
733 encode_sequence_maxsz + \
734 encode_putfh_maxsz + \
735 encode_secinfo_maxsz)
736#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
737 decode_sequence_maxsz + \
738 decode_putfh_maxsz + \
739 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400740#if defined(CONFIG_NFS_V4_1)
741#define NFS4_enc_exchange_id_sz \
742 (compound_encode_hdr_maxsz + \
743 encode_exchange_id_maxsz)
744#define NFS4_dec_exchange_id_sz \
745 (compound_decode_hdr_maxsz + \
746 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400747#define NFS4_enc_create_session_sz \
748 (compound_encode_hdr_maxsz + \
749 encode_create_session_maxsz)
750#define NFS4_dec_create_session_sz \
751 (compound_decode_hdr_maxsz + \
752 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400753#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
754 encode_destroy_session_maxsz)
755#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
756 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400757#define NFS4_enc_sequence_sz \
758 (compound_decode_hdr_maxsz + \
759 encode_sequence_maxsz)
760#define NFS4_dec_sequence_sz \
761 (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400763#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
764 encode_sequence_maxsz + \
765 encode_putrootfh_maxsz + \
766 encode_fsinfo_maxsz)
767#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
768 decode_sequence_maxsz + \
769 decode_putrootfh_maxsz + \
770 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500771#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
772 encode_sequence_maxsz + \
773 encode_reclaim_complete_maxsz)
774#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
775 decode_sequence_maxsz + \
776 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400777#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
778 encode_sequence_maxsz + \
779 encode_putfh_maxsz + \
780 encode_getdevicelist_maxsz)
781#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
782 decode_sequence_maxsz + \
783 decode_putfh_maxsz + \
784 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400785#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
786 encode_sequence_maxsz +\
787 encode_getdeviceinfo_maxsz)
788#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
789 decode_sequence_maxsz + \
790 decode_getdeviceinfo_maxsz)
791#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
792 encode_sequence_maxsz + \
793 encode_putfh_maxsz + \
794 encode_layoutget_maxsz)
795#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
796 decode_sequence_maxsz + \
797 decode_putfh_maxsz + \
798 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000799#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
800 encode_sequence_maxsz +\
801 encode_putfh_maxsz + \
802 encode_layoutcommit_maxsz + \
803 encode_getattr_maxsz)
804#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
805 decode_sequence_maxsz + \
806 decode_putfh_maxsz + \
807 decode_layoutcommit_maxsz + \
808 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300809#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz + \
811 encode_putfh_maxsz + \
812 encode_layoutreturn_maxsz)
813#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
814 decode_sequence_maxsz + \
815 decode_putfh_maxsz + \
816 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400817#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
818 encode_sequence_maxsz + \
819 encode_putrootfh_maxsz +\
820 encode_secinfo_no_name_maxsz)
821#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
822 decode_sequence_maxsz + \
823 decode_putrootfh_maxsz + \
824 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400825#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
826 encode_sequence_maxsz + \
827 encode_test_stateid_maxsz)
828#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
829 decode_sequence_maxsz + \
830 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400831#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
832 encode_sequence_maxsz + \
833 encode_free_stateid_maxsz)
834#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
835 decode_sequence_maxsz + \
836 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500837
838const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
839 compound_encode_hdr_maxsz +
840 encode_sequence_maxsz +
841 encode_putfh_maxsz +
842 encode_getattr_maxsz) *
843 XDR_UNIT);
844
845const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
846 compound_decode_hdr_maxsz +
847 decode_sequence_maxsz +
848 decode_putfh_maxsz) *
849 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400850#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500852static unsigned short send_implementation_id = 1;
853
854module_param(send_implementation_id, ushort, 0644);
855MODULE_PARM_DESC(send_implementation_id,
856 "Send implementation ID with NFSv4.1 exchange_id");
857
Trond Myklebustbca79472009-03-11 14:10:26 -0400858static const umode_t nfs_type2fmt[] = {
859 [NF4BAD] = 0,
860 [NF4REG] = S_IFREG,
861 [NF4DIR] = S_IFDIR,
862 [NF4BLK] = S_IFBLK,
863 [NF4CHR] = S_IFCHR,
864 [NF4LNK] = S_IFLNK,
865 [NF4SOCK] = S_IFSOCK,
866 [NF4FIFO] = S_IFIFO,
867 [NF4ATTRDIR] = 0,
868 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869};
870
871struct compound_hdr {
872 int32_t status;
873 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500874 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 uint32_t taglen;
876 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400877 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400878 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879};
880
Benny Halevy13c65ce2009-08-14 17:19:25 +0300881static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
882{
883 __be32 *p = xdr_reserve_space(xdr, nbytes);
884 BUG_ON(!p);
885 return p;
886}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
888static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
889{
Al Viro8687b632006-10-19 23:28:48 -0700890 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
892 p = xdr_reserve_space(xdr, 4 + len);
893 BUG_ON(p == NULL);
894 xdr_encode_opaque(p, str, len);
895}
896
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400897static void encode_compound_hdr(struct xdr_stream *xdr,
898 struct rpc_rqst *req,
899 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900{
Al Viro8687b632006-10-19 23:28:48 -0700901 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400902 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400903
904 /* initialize running count of expected bytes in reply.
905 * NOTE: the replied tag SHOULD be the same is the one sent,
906 * but this is not required as a MUST for the server to do so. */
907 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
909 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
910 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300911 p = reserve_space(xdr, 4 + hdr->taglen + 8);
912 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300913 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500914 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300915 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500916}
917
918static void encode_nops(struct compound_hdr *hdr)
919{
Andy Adamsonfc931582009-04-01 09:22:31 -0400920 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500921 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922}
923
924static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
925{
Al Viro8687b632006-10-19 23:28:48 -0700926 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
929 BUG_ON(p == NULL);
930 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
931}
932
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500933static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
935 char owner_name[IDMAP_NAMESZ];
936 char owner_group[IDMAP_NAMESZ];
937 int owner_namelen = 0;
938 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700939 __be32 *p;
940 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 int len;
942 uint32_t bmval0 = 0;
943 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
945 /*
946 * We reserve enough space to write the entire attribute buffer at once.
947 * In the worst-case, this would be
948 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
949 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000950 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 */
952 len = 16;
953
954 /* Sigh */
955 if (iap->ia_valid & ATTR_SIZE)
956 len += 8;
957 if (iap->ia_valid & ATTR_MODE)
958 len += 4;
959 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800960 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400962 dprintk("nfs: couldn't resolve uid %d to string\n",
963 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 /* XXX */
965 strcpy(owner_name, "nobody");
966 owner_namelen = sizeof("nobody") - 1;
967 /* goto out; */
968 }
969 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
970 }
971 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800972 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400974 dprintk("nfs: couldn't resolve gid %d to string\n",
975 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 strcpy(owner_group, "nobody");
977 owner_grouplen = sizeof("nobody") - 1;
978 /* goto out; */
979 }
980 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
981 }
982 if (iap->ia_valid & ATTR_ATIME_SET)
983 len += 16;
984 else if (iap->ia_valid & ATTR_ATIME)
985 len += 4;
986 if (iap->ia_valid & ATTR_MTIME_SET)
987 len += 16;
988 else if (iap->ia_valid & ATTR_MTIME)
989 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300990 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
992 /*
993 * We write the bitmap length now, but leave the bitmap and the attribute
994 * buffer length to be backfilled at the end of this routine.
995 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300996 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 q = p;
998 p += 3;
999
1000 if (iap->ia_valid & ATTR_SIZE) {
1001 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001002 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 }
1004 if (iap->ia_valid & ATTR_MODE) {
1005 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001006 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 }
1008 if (iap->ia_valid & ATTR_UID) {
1009 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001010 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
1012 if (iap->ia_valid & ATTR_GID) {
1013 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001014 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 }
1016 if (iap->ia_valid & ATTR_ATIME_SET) {
1017 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001018 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1019 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001020 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1021 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 }
1023 else if (iap->ia_valid & ATTR_ATIME) {
1024 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001025 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 }
1027 if (iap->ia_valid & ATTR_MTIME_SET) {
1028 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001029 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1030 *p++ = cpu_to_be32(0);
1031 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1032 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
1034 else if (iap->ia_valid & ATTR_MTIME) {
1035 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001036 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 /*
1040 * Now we backfill the bitmap and the attribute buffer length.
1041 */
1042 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001043 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 len, ((char *)p - (char *)q) + 4);
1045 BUG();
1046 }
1047 len = (char *)p - (char *)q - 12;
1048 *q++ = htonl(bmval0);
1049 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001050 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053}
1054
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001055static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056{
Al Viro8687b632006-10-19 23:28:48 -07001057 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
Benny Halevy13c65ce2009-08-14 17:19:25 +03001059 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001060 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +03001061 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -05001062 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001063 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064}
1065
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001066static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067{
Al Viro8687b632006-10-19 23:28:48 -07001068 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Benny Halevy13c65ce2009-08-14 17:19:25 +03001070 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001071 *p++ = cpu_to_be32(OP_CLOSE);
1072 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +03001073 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001074 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001075 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076}
1077
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001078static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079{
Al Viro8687b632006-10-19 23:28:48 -07001080 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001081
Benny Halevy13c65ce2009-08-14 17:19:25 +03001082 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001083 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001084 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001085 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001086 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001087 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001090static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
Al Viro8687b632006-10-19 23:28:48 -07001092 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001093
Benny Halevy13c65ce2009-08-14 17:19:25 +03001094 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001095 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001096 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
1098 switch (create->ftype) {
1099 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001100 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001101 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001102 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 break;
1104
1105 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001106 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001107 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001108 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 break;
1110
1111 default:
1112 break;
1113 }
1114
Benny Halevy811652b2009-08-14 17:19:34 +03001115 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001116 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001117 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001119 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120}
1121
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001122static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123{
Andy Adamson05d564f2008-12-23 16:06:15 -05001124 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Benny Halevy13c65ce2009-08-14 17:19:25 +03001126 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001127 *p++ = cpu_to_be32(OP_GETATTR);
1128 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001129 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001130 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001131 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132}
1133
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001134static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135{
Andy Adamson05d564f2008-12-23 16:06:15 -05001136 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Benny Halevy13c65ce2009-08-14 17:19:25 +03001138 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001139 *p++ = cpu_to_be32(OP_GETATTR);
1140 *p++ = cpu_to_be32(2);
1141 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001142 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001143 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001144 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145}
1146
Fred Isamandae100c2011-07-30 20:52:37 -04001147static void
1148encode_getattr_three(struct xdr_stream *xdr,
1149 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1150 struct compound_hdr *hdr)
1151{
1152 __be32 *p;
1153
1154 p = reserve_space(xdr, 4);
1155 *p = cpu_to_be32(OP_GETATTR);
1156 if (bm2) {
1157 p = reserve_space(xdr, 16);
1158 *p++ = cpu_to_be32(3);
1159 *p++ = cpu_to_be32(bm0);
1160 *p++ = cpu_to_be32(bm1);
1161 *p = cpu_to_be32(bm2);
1162 } else if (bm1) {
1163 p = reserve_space(xdr, 12);
1164 *p++ = cpu_to_be32(2);
1165 *p++ = cpu_to_be32(bm0);
1166 *p = cpu_to_be32(bm1);
1167 } else {
1168 p = reserve_space(xdr, 8);
1169 *p++ = cpu_to_be32(1);
1170 *p = cpu_to_be32(bm0);
1171 }
1172 hdr->nops++;
1173 hdr->replen += decode_getattr_maxsz;
1174}
1175
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001176static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001178 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1179 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180}
1181
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001182static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183{
Fred Isamandae100c2011-07-30 20:52:37 -04001184 encode_getattr_three(xdr,
1185 bitmask[0] & nfs4_fsinfo_bitmap[0],
1186 bitmask[1] & nfs4_fsinfo_bitmap[1],
1187 bitmask[2] & nfs4_fsinfo_bitmap[2],
1188 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189}
1190
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001191static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001192{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001193 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1194 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001195}
1196
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001197static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198{
Al Viro8687b632006-10-19 23:28:48 -07001199 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Benny Halevy13c65ce2009-08-14 17:19:25 +03001201 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001202 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001203 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001204 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205}
1206
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001207static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208{
Al Viro8687b632006-10-19 23:28:48 -07001209 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Benny Halevy13c65ce2009-08-14 17:19:25 +03001211 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001212 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001213 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001214 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001215 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216}
1217
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001218static inline int nfs4_lock_type(struct file_lock *fl, int block)
1219{
1220 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1221 return block ? NFS4_READW_LT : NFS4_READ_LT;
1222 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1223}
1224
1225static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1226{
1227 if (fl->fl_end == OFFSET_MAX)
1228 return ~(uint64_t)0;
1229 return fl->fl_end - fl->fl_start + 1;
1230}
1231
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001232static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1233{
1234 __be32 *p;
1235
Trond Myklebustd035c362010-12-21 10:45:27 -05001236 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001237 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001238 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001239 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001240 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001241 xdr_encode_hyper(p, lowner->id);
1242}
1243
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244/*
1245 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1246 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1247 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001248static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Al Viro8687b632006-10-19 23:28:48 -07001250 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Benny Halevy13c65ce2009-08-14 17:19:25 +03001252 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001253 *p++ = cpu_to_be32(OP_LOCK);
1254 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1255 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001256 p = xdr_encode_hyper(p, args->fl->fl_start);
1257 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001258 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001259 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001260 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001261 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001262 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001263 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001264 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 }
1266 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001267 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001268 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001269 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 }
Andy Adamsond0179312008-12-23 16:06:17 -05001271 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001272 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273}
1274
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001275static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276{
Al Viro8687b632006-10-19 23:28:48 -07001277 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001279 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001280 *p++ = cpu_to_be32(OP_LOCKT);
1281 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001282 p = xdr_encode_hyper(p, args->fl->fl_start);
1283 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001284 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001285 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001286 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287}
1288
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001289static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290{
Al Viro8687b632006-10-19 23:28:48 -07001291 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Benny Halevy13c65ce2009-08-14 17:19:25 +03001293 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001294 *p++ = cpu_to_be32(OP_LOCKU);
1295 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1296 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001297 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001298 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001299 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001300 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001301 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302}
1303
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001304static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1305{
1306 __be32 *p;
1307
1308 p = reserve_space(xdr, 4);
1309 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1310 encode_lockowner(xdr, lowner);
1311 hdr->nops++;
1312 hdr->replen += decode_release_lockowner_maxsz;
1313}
1314
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001315static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316{
1317 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001318 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
Benny Halevy13c65ce2009-08-14 17:19:25 +03001320 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001321 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001322 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001323 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001324 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325}
1326
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001327static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328{
Al Viro8687b632006-10-19 23:28:48 -07001329 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Benny Halevy13c65ce2009-08-14 17:19:25 +03001331 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001332 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001333 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001334 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001335 break;
1336 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001337 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001338 break;
1339 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001340 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001341 break;
1342 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001343 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
Benny Halevy34558512009-08-14 17:19:30 +03001345 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346}
1347
1348static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1349{
Al Viro8687b632006-10-19 23:28:48 -07001350 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 /*
1352 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1353 * owner 4 = 32
1354 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001355 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001356 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001357 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001358 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001359 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001360 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001361 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001362 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001363 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001364 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365}
1366
1367static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1368{
Al Viro8687b632006-10-19 23:28:48 -07001369 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001370 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
Benny Halevy13c65ce2009-08-14 17:19:25 +03001372 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001374 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001375 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001376 encode_attrs(xdr, arg->u.attrs, arg->server);
1377 break;
1378 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001379 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001380 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001381 if (nfs4_has_persistent_session(clp)) {
1382 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1383 encode_attrs(xdr, arg->u.attrs, arg->server);
1384 } else {
1385 struct iattr dummy;
1386
1387 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1388 encode_nfs4_verifier(xdr, &arg->u.verifier);
1389 dummy.ia_valid = 0;
1390 encode_attrs(xdr, &dummy, arg->server);
1391 }
1392 } else {
1393 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1394 encode_nfs4_verifier(xdr, &arg->u.verifier);
1395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 }
1397}
1398
1399static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1400{
Al Viro8687b632006-10-19 23:28:48 -07001401 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Benny Halevy13c65ce2009-08-14 17:19:25 +03001403 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001405 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001406 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001407 break;
1408 default:
1409 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001410 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001411 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 }
1413}
1414
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001415static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416{
Al Viro8687b632006-10-19 23:28:48 -07001417 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Benny Halevy13c65ce2009-08-14 17:19:25 +03001419 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001421 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001422 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001423 break;
1424 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001425 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001426 break;
1427 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001428 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001429 break;
1430 default:
1431 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 }
1433}
1434
1435static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1436{
Al Viro8687b632006-10-19 23:28:48 -07001437 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
Benny Halevy13c65ce2009-08-14 17:19:25 +03001439 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001440 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 encode_string(xdr, name->len, name->name);
1442}
1443
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001444static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445{
Al Viro8687b632006-10-19 23:28:48 -07001446 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
Benny Halevy13c65ce2009-08-14 17:19:25 +03001448 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001449 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 encode_delegation_type(xdr, type);
1451}
1452
1453static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1454{
Al Viro8687b632006-10-19 23:28:48 -07001455 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
Benny Halevy13c65ce2009-08-14 17:19:25 +03001457 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001458 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001459 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 encode_string(xdr, name->len, name->name);
1461}
1462
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001463static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464{
1465 encode_openhdr(xdr, arg);
1466 encode_opentype(xdr, arg);
1467 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001468 case NFS4_OPEN_CLAIM_NULL:
1469 encode_claim_null(xdr, arg->name);
1470 break;
1471 case NFS4_OPEN_CLAIM_PREVIOUS:
1472 encode_claim_previous(xdr, arg->u.delegation_type);
1473 break;
1474 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1475 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1476 break;
1477 default:
1478 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 }
Andy Adamsond0179312008-12-23 16:06:17 -05001480 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001481 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482}
1483
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001484static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485{
Al Viro8687b632006-10-19 23:28:48 -07001486 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Benny Halevy13c65ce2009-08-14 17:19:25 +03001488 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001489 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001490 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001491 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001492 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001493 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494}
1495
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001496static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497{
Al Viro8687b632006-10-19 23:28:48 -07001498 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
Benny Halevy13c65ce2009-08-14 17:19:25 +03001500 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001501 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001502 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001503 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001504 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001505 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001506 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507}
1508
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001509static void
Andy Adamsond0179312008-12-23 16:06:17 -05001510encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511{
1512 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001513 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
Benny Halevy13c65ce2009-08-14 17:19:25 +03001515 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001516 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001517 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001518 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001519 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520}
1521
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001522static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
Andy Adamson05d564f2008-12-23 16:06:15 -05001524 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001525
Benny Halevy13c65ce2009-08-14 17:19:25 +03001526 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001527 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001528 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001529 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530}
1531
Andy Adamson89d1ea62011-03-01 01:34:09 +00001532static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001535 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Benny Halevy13c65ce2009-08-14 17:19:25 +03001537 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001539 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001540 if (zero_seqid)
1541 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001542 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 } else
Benny Halevy34558512009-08-14 17:19:30 +03001544 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545}
1546
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001547static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548{
Al Viro8687b632006-10-19 23:28:48 -07001549 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Benny Halevy13c65ce2009-08-14 17:19:25 +03001551 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001552 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
Andy Adamson89d1ea62011-03-01 01:34:09 +00001554 encode_stateid(xdr, args->context, args->lock_context,
1555 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
Benny Halevy13c65ce2009-08-14 17:19:25 +03001557 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001558 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001559 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001560 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001561 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562}
1563
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001564static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565{
Trond Myklebust28331a42011-04-27 13:47:52 -04001566 uint32_t attrs[2] = {
1567 FATTR4_WORD0_RDATTR_ERROR,
1568 FATTR4_WORD1_MOUNTED_ON_FILEID,
1569 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001570 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001571 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001573 if (readdir->plus) {
1574 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001575 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001576 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1577 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1578 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1579 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001580 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001581 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001582 /* Use mounted_on_fileid only if the server supports it */
1583 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1584 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001585
Benny Halevy13c65ce2009-08-14 17:19:25 +03001586 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001587 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001588 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001589 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001590 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001591 *p++ = cpu_to_be32(readdir->count);
1592 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001593
Benny Halevye75bc1c2009-08-14 17:18:54 +03001594 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001595 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001596 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001597 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001598 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1599 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001600 (unsigned long long)readdir->cookie,
1601 ((u32 *)readdir->verifier.data)[0],
1602 ((u32 *)readdir->verifier.data)[1],
1603 attrs[0] & readdir->bitmask[0],
1604 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605}
1606
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001607static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608{
Al Viro8687b632006-10-19 23:28:48 -07001609 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
Benny Halevy13c65ce2009-08-14 17:19:25 +03001611 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001612 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001613 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001614 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615}
1616
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001617static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618{
Al Viro8687b632006-10-19 23:28:48 -07001619 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
Benny Halevy13c65ce2009-08-14 17:19:25 +03001621 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001622 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001623 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001624 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001625 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626}
1627
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001628static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629{
Al Viro8687b632006-10-19 23:28:48 -07001630 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
Benny Halevy811652b2009-08-14 17:19:34 +03001632 p = reserve_space(xdr, 4);
1633 *p = cpu_to_be32(OP_RENAME);
1634 encode_string(xdr, oldname->len, oldname->name);
1635 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001636 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001637 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638}
1639
Chuck Leverbb4dae52012-03-01 17:01:48 -05001640static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1641 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642{
Al Viro8687b632006-10-19 23:28:48 -07001643 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
Benny Halevy13c65ce2009-08-14 17:19:25 +03001645 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001646 *p++ = cpu_to_be32(OP_RENEW);
Chuck Leverbb4dae52012-03-01 17:01:48 -05001647 xdr_encode_hyper(p, clid);
Andy Adamsond0179312008-12-23 16:06:17 -05001648 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001649 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650}
1651
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001652static void
Andy Adamsond0179312008-12-23 16:06:17 -05001653encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001654{
Al Viro8687b632006-10-19 23:28:48 -07001655 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001656
Benny Halevy13c65ce2009-08-14 17:19:25 +03001657 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001658 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001659 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001660 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001661}
1662
Chuck Lever9f06c712010-12-14 14:59:18 +00001663static void
Andy Adamsond0179312008-12-23 16:06:17 -05001664encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001665{
Al Viro8687b632006-10-19 23:28:48 -07001666 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001667
Benny Halevy13c65ce2009-08-14 17:19:25 +03001668 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001669 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001670 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001671 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001672 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001673 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001674 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001675 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001676 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001677 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001678 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001679 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001680}
1681
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001682static void
Andy Adamsond0179312008-12-23 16:06:17 -05001683encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684{
Al Viro8687b632006-10-19 23:28:48 -07001685 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686
Benny Halevy13c65ce2009-08-14 17:19:25 +03001687 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001688 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001689 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001690 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691}
1692
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001693static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694{
Al Viro8687b632006-10-19 23:28:48 -07001695 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001696
Benny Halevy13c65ce2009-08-14 17:19:25 +03001697 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001698 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001699 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001700 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001701 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001702 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703}
1704
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001705static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706{
Al Viro8687b632006-10-19 23:28:48 -07001707 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
Benny Halevy13c65ce2009-08-14 17:19:25 +03001709 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001710 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001711 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712
1713 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001714 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001715 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1717 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001718 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001719 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001720 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001721 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722}
1723
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001724static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725{
Andy Adamson05d564f2008-12-23 16:06:15 -05001726 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
Benny Halevy13c65ce2009-08-14 17:19:25 +03001728 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001729 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001730 p = xdr_encode_hyper(p, arg->clientid);
1731 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001732 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001733 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734}
1735
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001736static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737{
Al Viro8687b632006-10-19 23:28:48 -07001738 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
Benny Halevy13c65ce2009-08-14 17:19:25 +03001740 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001741 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
Andy Adamson89d1ea62011-03-01 01:34:09 +00001743 encode_stateid(xdr, args->context, args->lock_context,
1744 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
Benny Halevy13c65ce2009-08-14 17:19:25 +03001746 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001747 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001748 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001749 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
1751 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001752 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001753 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754}
1755
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001756static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757{
Al Viro8687b632006-10-19 23:28:48 -07001758 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
Benny Halevy13c65ce2009-08-14 17:19:25 +03001760 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
Benny Halevye75bc1c2009-08-14 17:18:54 +03001762 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001763 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001764 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001765 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001767
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001768static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1769{
1770 int len = name->len;
1771 __be32 *p;
1772
1773 p = reserve_space(xdr, 8 + len);
1774 *p++ = cpu_to_be32(OP_SECINFO);
1775 xdr_encode_opaque(p, name->name, len);
1776 hdr->nops++;
1777 hdr->replen += decode_secinfo_maxsz;
1778}
1779
Benny Halevy99fe60d2009-04-01 09:22:29 -04001780#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001781/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001782static void encode_exchange_id(struct xdr_stream *xdr,
1783 struct nfs41_exchange_id_args *args,
1784 struct compound_hdr *hdr)
1785{
1786 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001787 char impl_name[NFS4_OPAQUE_LIMIT];
1788 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001789
Benny Halevy13c65ce2009-08-14 17:19:25 +03001790 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001791 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001792 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001793
1794 encode_string(xdr, args->id_len, args->id);
1795
Benny Halevy13c65ce2009-08-14 17:19:25 +03001796 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001797 *p++ = cpu_to_be32(args->flags);
1798 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001799
1800 if (send_implementation_id &&
1801 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1802 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1803 <= NFS4_OPAQUE_LIMIT + 1)
1804 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1805 utsname()->sysname, utsname()->release,
1806 utsname()->version, utsname()->machine);
1807
1808 if (len > 0) {
1809 *p = cpu_to_be32(1); /* implementation id array length=1 */
1810
1811 encode_string(xdr,
1812 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1813 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1814 encode_string(xdr, len, impl_name);
1815 /* just send zeros for nii_date - the date is in nii_name */
1816 p = reserve_space(xdr, 12);
1817 p = xdr_encode_hyper(p, 0);
1818 *p = cpu_to_be32(0);
1819 } else
1820 *p = cpu_to_be32(0); /* implementation id array length=0 */
1821
Benny Halevy99fe60d2009-04-01 09:22:29 -04001822 hdr->nops++;
1823 hdr->replen += decode_exchange_id_maxsz;
1824}
Andy Adamsonfc931582009-04-01 09:22:31 -04001825
1826static void encode_create_session(struct xdr_stream *xdr,
1827 struct nfs41_create_session_args *args,
1828 struct compound_hdr *hdr)
1829{
1830 __be32 *p;
1831 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1832 uint32_t len;
1833 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001834 u32 max_resp_sz_cached;
1835
1836 /*
1837 * Assumes OPEN is the biggest non-idempotent compound.
1838 * 2 is the verifier.
1839 */
1840 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1841 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001842
Andy Adamsonfc931582009-04-01 09:22:31 -04001843 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1844 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001845
Benny Halevy13c65ce2009-08-14 17:19:25 +03001846 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001847 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001848 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001849 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1850 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001851
Andy Adamsonfc931582009-04-01 09:22:31 -04001852 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001853 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001854 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1855 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001856 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001857 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1858 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1859 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001860
1861 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001862 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001863 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1864 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1865 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1866 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1867 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1868 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001869
Benny Halevye75bc1c2009-08-14 17:18:54 +03001870 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001871 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001872 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001873
1874 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001875 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001876 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001877 *p++ = cpu_to_be32(0); /* UID */
1878 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001879 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001880 hdr->nops++;
1881 hdr->replen += decode_create_session_maxsz;
1882}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001883
1884static void encode_destroy_session(struct xdr_stream *xdr,
1885 struct nfs4_session *session,
1886 struct compound_hdr *hdr)
1887{
1888 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001889 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001890 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001891 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001892 hdr->nops++;
1893 hdr->replen += decode_destroy_session_maxsz;
1894}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001895
1896static void encode_reclaim_complete(struct xdr_stream *xdr,
1897 struct nfs41_reclaim_complete_args *args,
1898 struct compound_hdr *hdr)
1899{
1900 __be32 *p;
1901
1902 p = reserve_space(xdr, 8);
1903 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1904 *p++ = cpu_to_be32(args->one_fs);
1905 hdr->nops++;
1906 hdr->replen += decode_reclaim_complete_maxsz;
1907}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001908#endif /* CONFIG_NFS_V4_1 */
1909
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001910static void encode_sequence(struct xdr_stream *xdr,
1911 const struct nfs4_sequence_args *args,
1912 struct compound_hdr *hdr)
1913{
1914#if defined(CONFIG_NFS_V4_1)
1915 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001916 struct nfs4_slot_table *tp;
1917 struct nfs4_slot *slot;
1918 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001919
1920 if (!session)
1921 return;
1922
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001923 tp = &session->fc_slot_table;
1924
1925 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1926 slot = tp->slots + args->sa_slotid;
1927
Benny Halevy13c65ce2009-08-14 17:19:25 +03001928 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001929 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001930
1931 /*
1932 * Sessionid + seqid + slotid + max slotid + cache_this
1933 */
1934 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1935 "max_slotid=%d cache_this=%d\n",
1936 __func__,
1937 ((u32 *)session->sess_id.data)[0],
1938 ((u32 *)session->sess_id.data)[1],
1939 ((u32 *)session->sess_id.data)[2],
1940 ((u32 *)session->sess_id.data)[3],
1941 slot->seq_nr, args->sa_slotid,
1942 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001943 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001944 *p++ = cpu_to_be32(slot->seq_nr);
1945 *p++ = cpu_to_be32(args->sa_slotid);
1946 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001947 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001948 hdr->nops++;
1949 hdr->replen += decode_sequence_maxsz;
1950#endif /* CONFIG_NFS_V4_1 */
1951}
1952
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001953#ifdef CONFIG_NFS_V4_1
1954static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001955encode_getdevicelist(struct xdr_stream *xdr,
1956 const struct nfs4_getdevicelist_args *args,
1957 struct compound_hdr *hdr)
1958{
1959 __be32 *p;
1960 nfs4_verifier dummy = {
1961 .data = "dummmmmy",
1962 };
1963
1964 p = reserve_space(xdr, 20);
1965 *p++ = cpu_to_be32(OP_GETDEVICELIST);
1966 *p++ = cpu_to_be32(args->layoutclass);
1967 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1968 xdr_encode_hyper(p, 0ULL); /* cookie */
1969 encode_nfs4_verifier(xdr, &dummy);
1970 hdr->nops++;
1971 hdr->replen += decode_getdevicelist_maxsz;
1972}
1973
1974static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001975encode_getdeviceinfo(struct xdr_stream *xdr,
1976 const struct nfs4_getdeviceinfo_args *args,
1977 struct compound_hdr *hdr)
1978{
1979 __be32 *p;
1980
1981 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1982 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1983 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1984 NFS4_DEVICEID4_SIZE);
1985 *p++ = cpu_to_be32(args->pdev->layout_type);
1986 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1987 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1988 hdr->nops++;
1989 hdr->replen += decode_getdeviceinfo_maxsz;
1990}
1991
1992static void
1993encode_layoutget(struct xdr_stream *xdr,
1994 const struct nfs4_layoutget_args *args,
1995 struct compound_hdr *hdr)
1996{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001997 __be32 *p;
1998
1999 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
2000 *p++ = cpu_to_be32(OP_LAYOUTGET);
2001 *p++ = cpu_to_be32(0); /* Signal layout available */
2002 *p++ = cpu_to_be32(args->type);
2003 *p++ = cpu_to_be32(args->range.iomode);
2004 p = xdr_encode_hyper(p, args->range.offset);
2005 p = xdr_encode_hyper(p, args->range.length);
2006 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00002007 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002008 *p = cpu_to_be32(args->maxcount);
2009
2010 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
2011 __func__,
2012 args->type,
2013 args->range.iomode,
2014 (unsigned long)args->range.offset,
2015 (unsigned long)args->range.length,
2016 args->maxcount);
2017 hdr->nops++;
2018 hdr->replen += decode_layoutget_maxsz;
2019}
Andy Adamson863a3c62011-03-23 13:27:54 +00002020
2021static int
2022encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03002023 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00002024 const struct nfs4_layoutcommit_args *args,
2025 struct compound_hdr *hdr)
2026{
2027 __be32 *p;
2028
2029 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2030 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2031
Benny Halevyac7db722011-05-22 19:53:48 +03002032 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
Andy Adamson863a3c62011-03-23 13:27:54 +00002033 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
2034 /* Only whole file layouts */
2035 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002036 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Andy Adamson863a3c62011-03-23 13:27:54 +00002037 *p++ = cpu_to_be32(0); /* reclaim */
2038 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
2039 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2040 p = xdr_encode_hyper(p, args->lastbytewritten);
2041 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2042 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002043
2044 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2045 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2046 NFS_I(inode)->layout, xdr, args);
2047 else {
2048 p = reserve_space(xdr, 4);
2049 *p = cpu_to_be32(0); /* no layout-type payload */
2050 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002051
2052 hdr->nops++;
2053 hdr->replen += decode_layoutcommit_maxsz;
2054 return 0;
2055}
Benny Halevycbe82602011-05-22 19:52:37 +03002056
2057static void
2058encode_layoutreturn(struct xdr_stream *xdr,
2059 const struct nfs4_layoutreturn_args *args,
2060 struct compound_hdr *hdr)
2061{
2062 __be32 *p;
2063
2064 p = reserve_space(xdr, 20);
2065 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
2066 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2067 *p++ = cpu_to_be32(args->layout_type);
2068 *p++ = cpu_to_be32(IOMODE_ANY);
2069 *p = cpu_to_be32(RETURN_FILE);
2070 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
2071 p = xdr_encode_hyper(p, 0);
2072 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2073 spin_lock(&args->inode->i_lock);
2074 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
2075 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002076 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2077 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2078 NFS_I(args->inode)->layout, xdr, args);
2079 } else {
2080 p = reserve_space(xdr, 4);
2081 *p = cpu_to_be32(0);
2082 }
Benny Halevycbe82602011-05-22 19:52:37 +03002083 hdr->nops++;
2084 hdr->replen += decode_layoutreturn_maxsz;
2085}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002086
2087static int
2088encode_secinfo_no_name(struct xdr_stream *xdr,
2089 const struct nfs41_secinfo_no_name_args *args,
2090 struct compound_hdr *hdr)
2091{
2092 __be32 *p;
2093 p = reserve_space(xdr, 8);
2094 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2095 *p++ = cpu_to_be32(args->style);
2096 hdr->nops++;
2097 hdr->replen += decode_secinfo_no_name_maxsz;
2098 return 0;
2099}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002100
2101static void encode_test_stateid(struct xdr_stream *xdr,
2102 struct nfs41_test_stateid_args *args,
2103 struct compound_hdr *hdr)
2104{
2105 __be32 *p;
2106
2107 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
2108 *p++ = cpu_to_be32(OP_TEST_STATEID);
2109 *p++ = cpu_to_be32(1);
2110 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2111 hdr->nops++;
2112 hdr->replen += decode_test_stateid_maxsz;
2113}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002114
2115static void encode_free_stateid(struct xdr_stream *xdr,
2116 struct nfs41_free_stateid_args *args,
2117 struct compound_hdr *hdr)
2118{
2119 __be32 *p;
2120 p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
2121 *p++ = cpu_to_be32(OP_FREE_STATEID);
2122 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2123 hdr->nops++;
2124 hdr->replen += decode_free_stateid_maxsz;
2125}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002126#endif /* CONFIG_NFS_V4_1 */
2127
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128/*
2129 * END OF "GENERIC" ENCODE ROUTINES.
2130 */
2131
Benny Halevy66cc0422009-04-01 09:22:10 -04002132static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2133{
2134#if defined(CONFIG_NFS_V4_1)
2135 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04002136 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002137#endif /* CONFIG_NFS_V4_1 */
2138 return 0;
2139}
2140
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141/*
2142 * Encode an ACCESS request
2143 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002144static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2145 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002148 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
Chuck Lever9f06c712010-12-14 14:59:18 +00002151 encode_compound_hdr(xdr, req, &hdr);
2152 encode_sequence(xdr, &args->seq_args, &hdr);
2153 encode_putfh(xdr, args->fh, &hdr);
2154 encode_access(xdr, args->access, &hdr);
2155 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002156 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157}
2158
2159/*
2160 * Encode LOOKUP request
2161 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002162static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2163 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002166 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
Chuck Lever9f06c712010-12-14 14:59:18 +00002169 encode_compound_hdr(xdr, req, &hdr);
2170 encode_sequence(xdr, &args->seq_args, &hdr);
2171 encode_putfh(xdr, args->dir_fh, &hdr);
2172 encode_lookup(xdr, args->name, &hdr);
2173 encode_getfh(xdr, &hdr);
2174 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002175 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176}
2177
2178/*
2179 * Encode LOOKUP_ROOT request
2180 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002181static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2182 struct xdr_stream *xdr,
2183 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002186 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
Chuck Lever9f06c712010-12-14 14:59:18 +00002189 encode_compound_hdr(xdr, req, &hdr);
2190 encode_sequence(xdr, &args->seq_args, &hdr);
2191 encode_putrootfh(xdr, &hdr);
2192 encode_getfh(xdr, &hdr);
2193 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002194 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195}
2196
2197/*
2198 * Encode REMOVE request
2199 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002200static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2201 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002204 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206
Chuck Lever9f06c712010-12-14 14:59:18 +00002207 encode_compound_hdr(xdr, req, &hdr);
2208 encode_sequence(xdr, &args->seq_args, &hdr);
2209 encode_putfh(xdr, args->fh, &hdr);
2210 encode_remove(xdr, &args->name, &hdr);
2211 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002212 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213}
2214
2215/*
2216 * Encode RENAME request
2217 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002218static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2219 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002222 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
Chuck Lever9f06c712010-12-14 14:59:18 +00002225 encode_compound_hdr(xdr, req, &hdr);
2226 encode_sequence(xdr, &args->seq_args, &hdr);
2227 encode_putfh(xdr, args->old_dir, &hdr);
2228 encode_savefh(xdr, &hdr);
2229 encode_putfh(xdr, args->new_dir, &hdr);
2230 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2231 encode_getfattr(xdr, args->bitmask, &hdr);
2232 encode_restorefh(xdr, &hdr);
2233 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002234 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235}
2236
2237/*
2238 * Encode LINK request
2239 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002240static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2241 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002244 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246
Chuck Lever9f06c712010-12-14 14:59:18 +00002247 encode_compound_hdr(xdr, req, &hdr);
2248 encode_sequence(xdr, &args->seq_args, &hdr);
2249 encode_putfh(xdr, args->fh, &hdr);
2250 encode_savefh(xdr, &hdr);
2251 encode_putfh(xdr, args->dir_fh, &hdr);
2252 encode_link(xdr, args->name, &hdr);
2253 encode_getfattr(xdr, args->bitmask, &hdr);
2254 encode_restorefh(xdr, &hdr);
2255 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002256 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257}
2258
2259/*
2260 * Encode CREATE request
2261 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002262static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2263 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002266 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
Chuck Lever9f06c712010-12-14 14:59:18 +00002269 encode_compound_hdr(xdr, req, &hdr);
2270 encode_sequence(xdr, &args->seq_args, &hdr);
2271 encode_putfh(xdr, args->dir_fh, &hdr);
2272 encode_savefh(xdr, &hdr);
2273 encode_create(xdr, args, &hdr);
2274 encode_getfh(xdr, &hdr);
2275 encode_getfattr(xdr, args->bitmask, &hdr);
2276 encode_restorefh(xdr, &hdr);
2277 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002278 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279}
2280
2281/*
2282 * Encode SYMLINK request
2283 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002284static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2285 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286{
Chuck Lever9f06c712010-12-14 14:59:18 +00002287 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288}
2289
2290/*
2291 * Encode GETATTR request
2292 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002293static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2294 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002297 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299
Chuck Lever9f06c712010-12-14 14:59:18 +00002300 encode_compound_hdr(xdr, req, &hdr);
2301 encode_sequence(xdr, &args->seq_args, &hdr);
2302 encode_putfh(xdr, args->fh, &hdr);
2303 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002304 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305}
2306
2307/*
2308 * Encode a CLOSE request
2309 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002310static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2311 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312{
Andy Adamson05d564f2008-12-23 16:06:15 -05002313 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002314 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002315 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316
Chuck Lever9f06c712010-12-14 14:59:18 +00002317 encode_compound_hdr(xdr, req, &hdr);
2318 encode_sequence(xdr, &args->seq_args, &hdr);
2319 encode_putfh(xdr, args->fh, &hdr);
2320 encode_close(xdr, args, &hdr);
2321 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002322 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323}
2324
2325/*
2326 * Encode an OPEN request
2327 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002328static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2329 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002332 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334
Chuck Lever9f06c712010-12-14 14:59:18 +00002335 encode_compound_hdr(xdr, req, &hdr);
2336 encode_sequence(xdr, &args->seq_args, &hdr);
2337 encode_putfh(xdr, args->fh, &hdr);
2338 encode_savefh(xdr, &hdr);
2339 encode_open(xdr, args, &hdr);
2340 encode_getfh(xdr, &hdr);
2341 encode_getfattr(xdr, args->bitmask, &hdr);
2342 encode_restorefh(xdr, &hdr);
Trond Myklebust6926afd2012-01-07 13:22:46 -05002343 encode_getfattr(xdr, args->dir_bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002344 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345}
2346
2347/*
2348 * Encode an OPEN_CONFIRM request
2349 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002350static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2351 struct xdr_stream *xdr,
2352 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002355 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
Chuck Lever9f06c712010-12-14 14:59:18 +00002358 encode_compound_hdr(xdr, req, &hdr);
2359 encode_putfh(xdr, args->fh, &hdr);
2360 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002361 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362}
2363
2364/*
2365 * Encode an OPEN request with no attributes.
2366 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002367static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2368 struct xdr_stream *xdr,
2369 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002372 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374
Chuck Lever9f06c712010-12-14 14:59:18 +00002375 encode_compound_hdr(xdr, req, &hdr);
2376 encode_sequence(xdr, &args->seq_args, &hdr);
2377 encode_putfh(xdr, args->fh, &hdr);
2378 encode_open(xdr, args, &hdr);
2379 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002380 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381}
2382
2383/*
2384 * Encode an OPEN_DOWNGRADE request
2385 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002386static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2387 struct xdr_stream *xdr,
2388 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002391 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393
Chuck Lever9f06c712010-12-14 14:59:18 +00002394 encode_compound_hdr(xdr, req, &hdr);
2395 encode_sequence(xdr, &args->seq_args, &hdr);
2396 encode_putfh(xdr, args->fh, &hdr);
2397 encode_open_downgrade(xdr, args, &hdr);
2398 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002399 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400}
2401
2402/*
2403 * Encode a LOCK request
2404 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002405static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2406 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002409 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411
Chuck Lever9f06c712010-12-14 14:59:18 +00002412 encode_compound_hdr(xdr, req, &hdr);
2413 encode_sequence(xdr, &args->seq_args, &hdr);
2414 encode_putfh(xdr, args->fh, &hdr);
2415 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002416 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417}
2418
2419/*
2420 * Encode a LOCKT request
2421 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002422static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2423 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002426 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
Chuck Lever9f06c712010-12-14 14:59:18 +00002429 encode_compound_hdr(xdr, req, &hdr);
2430 encode_sequence(xdr, &args->seq_args, &hdr);
2431 encode_putfh(xdr, args->fh, &hdr);
2432 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002433 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434}
2435
2436/*
2437 * Encode a LOCKU request
2438 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002439static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2440 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002443 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
Chuck Lever9f06c712010-12-14 14:59:18 +00002446 encode_compound_hdr(xdr, req, &hdr);
2447 encode_sequence(xdr, &args->seq_args, &hdr);
2448 encode_putfh(xdr, args->fh, &hdr);
2449 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002450 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451}
2452
Chuck Lever9f06c712010-12-14 14:59:18 +00002453static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2454 struct xdr_stream *xdr,
2455 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002456{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002457 struct compound_hdr hdr = {
2458 .minorversion = 0,
2459 };
2460
Chuck Lever9f06c712010-12-14 14:59:18 +00002461 encode_compound_hdr(xdr, req, &hdr);
2462 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002463 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002464}
2465
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466/*
2467 * Encode a READLINK request
2468 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002469static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2470 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002473 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
Chuck Lever9f06c712010-12-14 14:59:18 +00002476 encode_compound_hdr(xdr, req, &hdr);
2477 encode_sequence(xdr, &args->seq_args, &hdr);
2478 encode_putfh(xdr, args->fh, &hdr);
2479 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002480
Benny Halevy28f56692009-04-01 09:22:09 -04002481 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002482 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002483 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484}
2485
2486/*
2487 * Encode a READDIR request
2488 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002489static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2490 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002493 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495
Chuck Lever9f06c712010-12-14 14:59:18 +00002496 encode_compound_hdr(xdr, req, &hdr);
2497 encode_sequence(xdr, &args->seq_args, &hdr);
2498 encode_putfh(xdr, args->fh, &hdr);
2499 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002500
Benny Halevy28f56692009-04-01 09:22:09 -04002501 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002502 args->pgbase, args->count);
2503 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002504 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002505 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002506 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507}
2508
2509/*
2510 * Encode a READ request
2511 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002512static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2513 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002516 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
Chuck Lever9f06c712010-12-14 14:59:18 +00002519 encode_compound_hdr(xdr, req, &hdr);
2520 encode_sequence(xdr, &args->seq_args, &hdr);
2521 encode_putfh(xdr, args->fh, &hdr);
2522 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523
Benny Halevy28f56692009-04-01 09:22:09 -04002524 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002526 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002527 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528}
2529
2530/*
2531 * Encode an SETATTR request
2532 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002533static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2534 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535{
Andy Adamson05d564f2008-12-23 16:06:15 -05002536 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002537 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002538 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539
Chuck Lever9f06c712010-12-14 14:59:18 +00002540 encode_compound_hdr(xdr, req, &hdr);
2541 encode_sequence(xdr, &args->seq_args, &hdr);
2542 encode_putfh(xdr, args->fh, &hdr);
2543 encode_setattr(xdr, args, args->server, &hdr);
2544 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002545 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546}
2547
2548/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002549 * Encode a GETACL request
2550 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002551static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2552 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002553{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002554 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002555 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002556 };
Benny Halevy28f56692009-04-01 09:22:09 -04002557 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002558
Chuck Lever9f06c712010-12-14 14:59:18 +00002559 encode_compound_hdr(xdr, req, &hdr);
2560 encode_sequence(xdr, &args->seq_args, &hdr);
2561 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002562 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002563 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002564
Benny Halevy28f56692009-04-01 09:22:09 -04002565 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002566 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002567 xdr_set_scratch_buffer(xdr, page_address(args->acl_scratch), PAGE_SIZE);
2568
Andy Adamsond0179312008-12-23 16:06:17 -05002569 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002570}
2571
2572/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 * Encode a WRITE request
2574 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002575static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2576 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002579 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581
Chuck Lever9f06c712010-12-14 14:59:18 +00002582 encode_compound_hdr(xdr, req, &hdr);
2583 encode_sequence(xdr, &args->seq_args, &hdr);
2584 encode_putfh(xdr, args->fh, &hdr);
2585 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002586 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002587 if (args->bitmask)
2588 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002589 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590}
2591
2592/*
2593 * a COMMIT request
2594 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002595static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2596 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002599 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601
Chuck Lever9f06c712010-12-14 14:59:18 +00002602 encode_compound_hdr(xdr, req, &hdr);
2603 encode_sequence(xdr, &args->seq_args, &hdr);
2604 encode_putfh(xdr, args->fh, &hdr);
2605 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002606 if (args->bitmask)
2607 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002608 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609}
2610
2611/*
2612 * FSINFO request
2613 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002614static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2615 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002618 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620
Chuck Lever9f06c712010-12-14 14:59:18 +00002621 encode_compound_hdr(xdr, req, &hdr);
2622 encode_sequence(xdr, &args->seq_args, &hdr);
2623 encode_putfh(xdr, args->fh, &hdr);
2624 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002625 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626}
2627
2628/*
2629 * a PATHCONF request
2630 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002631static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2632 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002635 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637
Chuck Lever9f06c712010-12-14 14:59:18 +00002638 encode_compound_hdr(xdr, req, &hdr);
2639 encode_sequence(xdr, &args->seq_args, &hdr);
2640 encode_putfh(xdr, args->fh, &hdr);
2641 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002642 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002643 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644}
2645
2646/*
2647 * a STATFS request
2648 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002649static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2650 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002653 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
Chuck Lever9f06c712010-12-14 14:59:18 +00002656 encode_compound_hdr(xdr, req, &hdr);
2657 encode_sequence(xdr, &args->seq_args, &hdr);
2658 encode_putfh(xdr, args->fh, &hdr);
2659 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002660 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002661 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662}
2663
2664/*
2665 * GETATTR_BITMAP request
2666 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002667static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2668 struct xdr_stream *xdr,
2669 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002672 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674
Chuck Lever9f06c712010-12-14 14:59:18 +00002675 encode_compound_hdr(xdr, req, &hdr);
2676 encode_sequence(xdr, &args->seq_args, &hdr);
2677 encode_putfh(xdr, args->fhandle, &hdr);
2678 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002679 FATTR4_WORD0_LINK_SUPPORT|
2680 FATTR4_WORD0_SYMLINK_SUPPORT|
2681 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002682 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683}
2684
2685/*
2686 * a RENEW request
2687 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002688static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2689 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002692 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 };
2694
Chuck Lever9f06c712010-12-14 14:59:18 +00002695 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002696 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002697 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698}
2699
2700/*
2701 * a SETCLIENTID request
2702 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002703static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2704 struct xdr_stream *xdr,
2705 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002708 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 };
2710
Chuck Lever9f06c712010-12-14 14:59:18 +00002711 encode_compound_hdr(xdr, req, &hdr);
2712 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002713 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714}
2715
2716/*
2717 * a SETCLIENTID_CONFIRM request
2718 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002719static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2720 struct xdr_stream *xdr,
2721 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002724 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 };
Fred Isamandae100c2011-07-30 20:52:37 -04002726 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727
Chuck Lever9f06c712010-12-14 14:59:18 +00002728 encode_compound_hdr(xdr, req, &hdr);
2729 encode_setclientid_confirm(xdr, arg, &hdr);
2730 encode_putrootfh(xdr, &hdr);
2731 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002732 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733}
2734
2735/*
2736 * DELEGRETURN request
2737 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002738static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2739 struct xdr_stream *xdr,
2740 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002743 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
Chuck Lever9f06c712010-12-14 14:59:18 +00002746 encode_compound_hdr(xdr, req, &hdr);
2747 encode_sequence(xdr, &args->seq_args, &hdr);
2748 encode_putfh(xdr, args->fhandle, &hdr);
2749 encode_delegreturn(xdr, args->stateid, &hdr);
2750 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002751 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752}
2753
2754/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002755 * Encode FS_LOCATIONS request
2756 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002757static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2758 struct xdr_stream *xdr,
2759 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002760{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002761 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002762 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002763 };
Benny Halevy28f56692009-04-01 09:22:09 -04002764 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002765
Chuck Lever9f06c712010-12-14 14:59:18 +00002766 encode_compound_hdr(xdr, req, &hdr);
2767 encode_sequence(xdr, &args->seq_args, &hdr);
2768 encode_putfh(xdr, args->dir_fh, &hdr);
2769 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002770 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002771 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002772
Benny Halevy28f56692009-04-01 09:22:09 -04002773 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002774 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002775 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002776}
2777
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002778/*
2779 * Encode SECINFO request
2780 */
2781static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2782 struct xdr_stream *xdr,
2783 struct nfs4_secinfo_arg *args)
2784{
2785 struct compound_hdr hdr = {
2786 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2787 };
2788
2789 encode_compound_hdr(xdr, req, &hdr);
2790 encode_sequence(xdr, &args->seq_args, &hdr);
2791 encode_putfh(xdr, args->dir_fh, &hdr);
2792 encode_secinfo(xdr, args->name, &hdr);
2793 encode_nops(&hdr);
2794}
2795
Benny Halevy99fe60d2009-04-01 09:22:29 -04002796#if defined(CONFIG_NFS_V4_1)
2797/*
2798 * EXCHANGE_ID request
2799 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002800static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2801 struct xdr_stream *xdr,
2802 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002803{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002804 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002805 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002806 };
2807
Chuck Lever9f06c712010-12-14 14:59:18 +00002808 encode_compound_hdr(xdr, req, &hdr);
2809 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002810 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002811}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002812
2813/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002814 * a CREATE_SESSION request
2815 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002816static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2817 struct xdr_stream *xdr,
2818 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002819{
Andy Adamsonfc931582009-04-01 09:22:31 -04002820 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002821 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002822 };
2823
Chuck Lever9f06c712010-12-14 14:59:18 +00002824 encode_compound_hdr(xdr, req, &hdr);
2825 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002826 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002827}
2828
2829/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002830 * a DESTROY_SESSION request
2831 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002832static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2833 struct xdr_stream *xdr,
2834 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002835{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002836 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002837 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002838 };
2839
Chuck Lever9f06c712010-12-14 14:59:18 +00002840 encode_compound_hdr(xdr, req, &hdr);
2841 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002842 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002843}
2844
2845/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002846 * a SEQUENCE request
2847 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002848static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2849 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002850{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002851 struct compound_hdr hdr = {
2852 .minorversion = nfs4_xdr_minorversion(args),
2853 };
2854
Chuck Lever9f06c712010-12-14 14:59:18 +00002855 encode_compound_hdr(xdr, req, &hdr);
2856 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002857 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002858}
2859
2860/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002861 * a GET_LEASE_TIME request
2862 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002863static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2864 struct xdr_stream *xdr,
2865 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002866{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002867 struct compound_hdr hdr = {
2868 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2869 };
Fred Isamandae100c2011-07-30 20:52:37 -04002870 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002871
Chuck Lever9f06c712010-12-14 14:59:18 +00002872 encode_compound_hdr(xdr, req, &hdr);
2873 encode_sequence(xdr, &args->la_seq_args, &hdr);
2874 encode_putrootfh(xdr, &hdr);
2875 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002876 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002877}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002878
2879/*
2880 * a RECLAIM_COMPLETE request
2881 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002882static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2883 struct xdr_stream *xdr,
2884 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002885{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002886 struct compound_hdr hdr = {
2887 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2888 };
2889
Chuck Lever9f06c712010-12-14 14:59:18 +00002890 encode_compound_hdr(xdr, req, &hdr);
2891 encode_sequence(xdr, &args->seq_args, &hdr);
2892 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002893 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002894}
2895
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002896/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002897 * Encode GETDEVICELIST request
2898 */
2899static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2900 struct xdr_stream *xdr,
2901 struct nfs4_getdevicelist_args *args)
2902{
2903 struct compound_hdr hdr = {
2904 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2905 };
2906
2907 encode_compound_hdr(xdr, req, &hdr);
2908 encode_sequence(xdr, &args->seq_args, &hdr);
2909 encode_putfh(xdr, args->fh, &hdr);
2910 encode_getdevicelist(xdr, args, &hdr);
2911 encode_nops(&hdr);
2912}
2913
2914/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002915 * Encode GETDEVICEINFO request
2916 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002917static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2918 struct xdr_stream *xdr,
2919 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002920{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002921 struct compound_hdr hdr = {
2922 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2923 };
2924
Chuck Lever9f06c712010-12-14 14:59:18 +00002925 encode_compound_hdr(xdr, req, &hdr);
2926 encode_sequence(xdr, &args->seq_args, &hdr);
2927 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002928
2929 /* set up reply kvec. Subtract notification bitmap max size (2)
2930 * so that notification bitmap is put in xdr_buf tail */
2931 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2932 args->pdev->pages, args->pdev->pgbase,
2933 args->pdev->pglen);
2934
2935 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002936}
2937
2938/*
2939 * Encode LAYOUTGET request
2940 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002941static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2942 struct xdr_stream *xdr,
2943 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002944{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002945 struct compound_hdr hdr = {
2946 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2947 };
2948
Chuck Lever9f06c712010-12-14 14:59:18 +00002949 encode_compound_hdr(xdr, req, &hdr);
2950 encode_sequence(xdr, &args->seq_args, &hdr);
2951 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2952 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002953
2954 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2955 args->layout.pages, 0, args->layout.pglen);
2956
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002957 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002958}
Andy Adamson863a3c62011-03-23 13:27:54 +00002959
2960/*
2961 * Encode LAYOUTCOMMIT request
2962 */
Benny Halevycbe82602011-05-22 19:52:37 +03002963static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2964 struct xdr_stream *xdr,
2965 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002966{
Benny Halevyac7db722011-05-22 19:53:48 +03002967 struct nfs4_layoutcommit_data *data =
2968 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002969 struct compound_hdr hdr = {
2970 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2971 };
2972
2973 encode_compound_hdr(xdr, req, &hdr);
2974 encode_sequence(xdr, &args->seq_args, &hdr);
2975 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002976 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002977 encode_getfattr(xdr, args->bitmask, &hdr);
2978 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002979}
2980
2981/*
2982 * Encode LAYOUTRETURN request
2983 */
2984static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2985 struct xdr_stream *xdr,
2986 struct nfs4_layoutreturn_args *args)
2987{
2988 struct compound_hdr hdr = {
2989 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2990 };
2991
2992 encode_compound_hdr(xdr, req, &hdr);
2993 encode_sequence(xdr, &args->seq_args, &hdr);
2994 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2995 encode_layoutreturn(xdr, args, &hdr);
2996 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002997}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002998
2999/*
3000 * Encode SECINFO_NO_NAME request
3001 */
3002static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3003 struct xdr_stream *xdr,
3004 struct nfs41_secinfo_no_name_args *args)
3005{
3006 struct compound_hdr hdr = {
3007 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3008 };
3009
3010 encode_compound_hdr(xdr, req, &hdr);
3011 encode_sequence(xdr, &args->seq_args, &hdr);
3012 encode_putrootfh(xdr, &hdr);
3013 encode_secinfo_no_name(xdr, args, &hdr);
3014 encode_nops(&hdr);
3015 return 0;
3016}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003017
3018/*
3019 * Encode TEST_STATEID request
3020 */
3021static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3022 struct xdr_stream *xdr,
3023 struct nfs41_test_stateid_args *args)
3024{
3025 struct compound_hdr hdr = {
3026 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3027 };
3028
3029 encode_compound_hdr(xdr, req, &hdr);
3030 encode_sequence(xdr, &args->seq_args, &hdr);
3031 encode_test_stateid(xdr, args, &hdr);
3032 encode_nops(&hdr);
3033}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003034
3035/*
3036 * Encode FREE_STATEID request
3037 */
3038static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3039 struct xdr_stream *xdr,
3040 struct nfs41_free_stateid_args *args)
3041{
3042 struct compound_hdr hdr = {
3043 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3044 };
3045
3046 encode_compound_hdr(xdr, req, &hdr);
3047 encode_sequence(xdr, &args->seq_args, &hdr);
3048 encode_free_stateid(xdr, args, &hdr);
3049 encode_nops(&hdr);
3050}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003051#endif /* CONFIG_NFS_V4_1 */
3052
Benny Halevy686841b2009-08-14 17:19:48 +03003053static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3054{
3055 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3056 "Remaining buffer length is %tu words.\n",
3057 func, xdr->end - xdr->p);
3058}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059
Trond Myklebust683b57b2006-06-09 09:34:22 -04003060static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061{
Al Viro8687b632006-10-19 23:28:48 -07003062 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063
Benny Halevyc0eae662009-08-14 17:20:14 +03003064 p = xdr_inline_decode(xdr, 4);
3065 if (unlikely(!p))
3066 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003067 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003068 p = xdr_inline_decode(xdr, *len);
3069 if (unlikely(!p))
3070 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 *string = (char *)p;
3072 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003073out_overflow:
3074 print_overflow_msg(__func__, xdr);
3075 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076}
3077
3078static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3079{
Al Viro8687b632006-10-19 23:28:48 -07003080 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081
Benny Halevyc0eae662009-08-14 17:20:14 +03003082 p = xdr_inline_decode(xdr, 8);
3083 if (unlikely(!p))
3084 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003085 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003086 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003087
Benny Halevyc0eae662009-08-14 17:20:14 +03003088 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3089 if (unlikely(!p))
3090 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 hdr->tag = (char *)p;
3092 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003093 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003094 if (unlikely(hdr->nops < 1))
3095 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003097out_overflow:
3098 print_overflow_msg(__func__, xdr);
3099 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100}
3101
3102static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3103{
Al Viro8687b632006-10-19 23:28:48 -07003104 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 uint32_t opnum;
3106 int32_t nfserr;
3107
Benny Halevyc0eae662009-08-14 17:20:14 +03003108 p = xdr_inline_decode(xdr, 8);
3109 if (unlikely(!p))
3110 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003111 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003113 dprintk("nfs: Server returned operation"
3114 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 opnum, expected);
3116 return -EIO;
3117 }
Benny Halevycccddf42009-08-14 17:20:19 +03003118 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003120 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003122out_overflow:
3123 print_overflow_msg(__func__, xdr);
3124 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125}
3126
3127/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003128static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129{
Al Viro8687b632006-10-19 23:28:48 -07003130 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003131 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 char *str;
3133
Benny Halevyc0eae662009-08-14 17:20:14 +03003134 p = xdr_inline_decode(xdr, 12);
3135 if (likely(p))
3136 return decode_opaque_inline(xdr, &strlen, &str);
3137 print_overflow_msg(__func__, xdr);
3138 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139}
3140
3141static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3142{
Al Viro8687b632006-10-19 23:28:48 -07003143 uint32_t bmlen;
3144 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145
Benny Halevyc0eae662009-08-14 17:20:14 +03003146 p = xdr_inline_decode(xdr, 4);
3147 if (unlikely(!p))
3148 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003149 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150
Fred Isamandae100c2011-07-30 20:52:37 -04003151 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003152 p = xdr_inline_decode(xdr, (bmlen << 2));
3153 if (unlikely(!p))
3154 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003156 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003157 if (bmlen > 1) {
3158 bitmap[1] = be32_to_cpup(p++);
3159 if (bmlen > 2)
3160 bitmap[2] = be32_to_cpup(p);
3161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 }
3163 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003164out_overflow:
3165 print_overflow_msg(__func__, xdr);
3166 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167}
3168
Al Viro8687b632006-10-19 23:28:48 -07003169static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170{
Al Viro8687b632006-10-19 23:28:48 -07003171 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172
Benny Halevyc0eae662009-08-14 17:20:14 +03003173 p = xdr_inline_decode(xdr, 4);
3174 if (unlikely(!p))
3175 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003176 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 *savep = xdr->p;
3178 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003179out_overflow:
3180 print_overflow_msg(__func__, xdr);
3181 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182}
3183
3184static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3185{
3186 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003187 int ret;
3188 ret = decode_attr_bitmap(xdr, bitmask);
3189 if (unlikely(ret < 0))
3190 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3192 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003193 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3194 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3195 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 return 0;
3197}
3198
3199static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3200{
Al Viro8687b632006-10-19 23:28:48 -07003201 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003202 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203
3204 *type = 0;
3205 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3206 return -EIO;
3207 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003208 p = xdr_inline_decode(xdr, 4);
3209 if (unlikely(!p))
3210 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003211 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003213 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 return -EIO;
3215 }
3216 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003217 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003219 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003220 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003221out_overflow:
3222 print_overflow_msg(__func__, xdr);
3223 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224}
3225
3226static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3227{
Al Viro8687b632006-10-19 23:28:48 -07003228 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003229 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230
3231 *change = 0;
3232 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3233 return -EIO;
3234 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003235 p = xdr_inline_decode(xdr, 8);
3236 if (unlikely(!p))
3237 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003238 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003240 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003242 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003244 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003245out_overflow:
3246 print_overflow_msg(__func__, xdr);
3247 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248}
3249
3250static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3251{
Al Viro8687b632006-10-19 23:28:48 -07003252 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003253 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254
3255 *size = 0;
3256 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3257 return -EIO;
3258 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003259 p = xdr_inline_decode(xdr, 8);
3260 if (unlikely(!p))
3261 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003262 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003264 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003266 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003267 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003268out_overflow:
3269 print_overflow_msg(__func__, xdr);
3270 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271}
3272
3273static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3274{
Al Viro8687b632006-10-19 23:28:48 -07003275 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276
3277 *res = 0;
3278 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3279 return -EIO;
3280 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003281 p = xdr_inline_decode(xdr, 4);
3282 if (unlikely(!p))
3283 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003284 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3286 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003287 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003289out_overflow:
3290 print_overflow_msg(__func__, xdr);
3291 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292}
3293
3294static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3295{
Al Viro8687b632006-10-19 23:28:48 -07003296 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297
3298 *res = 0;
3299 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3300 return -EIO;
3301 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003302 p = xdr_inline_decode(xdr, 4);
3303 if (unlikely(!p))
3304 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003305 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3307 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003308 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003310out_overflow:
3311 print_overflow_msg(__func__, xdr);
3312 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313}
3314
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003315static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316{
Al Viro8687b632006-10-19 23:28:48 -07003317 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003318 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319
3320 fsid->major = 0;
3321 fsid->minor = 0;
3322 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3323 return -EIO;
3324 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003325 p = xdr_inline_decode(xdr, 16);
3326 if (unlikely(!p))
3327 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003328 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003329 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003331 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003333 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 (unsigned long long)fsid->major,
3335 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003336 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003337out_overflow:
3338 print_overflow_msg(__func__, xdr);
3339 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340}
3341
3342static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3343{
Al Viro8687b632006-10-19 23:28:48 -07003344 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345
3346 *res = 60;
3347 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3348 return -EIO;
3349 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003350 p = xdr_inline_decode(xdr, 4);
3351 if (unlikely(!p))
3352 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003353 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3355 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003356 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003358out_overflow:
3359 print_overflow_msg(__func__, xdr);
3360 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361}
3362
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003363static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003364{
3365 __be32 *p;
3366
3367 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3368 return -EIO;
3369 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3370 p = xdr_inline_decode(xdr, 4);
3371 if (unlikely(!p))
3372 goto out_overflow;
3373 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003374 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003375 }
3376 return 0;
3377out_overflow:
3378 print_overflow_msg(__func__, xdr);
3379 return -EIO;
3380}
3381
3382static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3383{
3384 __be32 *p;
3385 int len;
3386
Trond Myklebust7ad07352010-10-23 15:34:20 -04003387 if (fh != NULL)
3388 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003389
3390 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3391 return -EIO;
3392 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3393 p = xdr_inline_decode(xdr, 4);
3394 if (unlikely(!p))
3395 goto out_overflow;
3396 len = be32_to_cpup(p);
3397 if (len > NFS4_FHSIZE)
3398 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003399 p = xdr_inline_decode(xdr, len);
3400 if (unlikely(!p))
3401 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003402 if (fh != NULL) {
3403 memcpy(fh->data, p, len);
3404 fh->size = len;
3405 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003406 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3407 }
3408 return 0;
3409out_overflow:
3410 print_overflow_msg(__func__, xdr);
3411 return -EIO;
3412}
3413
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3415{
Al Viro8687b632006-10-19 23:28:48 -07003416 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417
3418 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3419 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3420 return -EIO;
3421 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003422 p = xdr_inline_decode(xdr, 4);
3423 if (unlikely(!p))
3424 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003425 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3427 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003428 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003430out_overflow:
3431 print_overflow_msg(__func__, xdr);
3432 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433}
3434
3435static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3436{
Al Viro8687b632006-10-19 23:28:48 -07003437 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003438 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439
3440 *fileid = 0;
3441 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3442 return -EIO;
3443 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003444 p = xdr_inline_decode(xdr, 8);
3445 if (unlikely(!p))
3446 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003447 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003449 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003451 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003452 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003453out_overflow:
3454 print_overflow_msg(__func__, xdr);
3455 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456}
3457
Manoj Naik99baf622006-06-09 09:34:24 -04003458static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3459{
Al Viro8687b632006-10-19 23:28:48 -07003460 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003461 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003462
3463 *fileid = 0;
3464 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3465 return -EIO;
3466 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003467 p = xdr_inline_decode(xdr, 8);
3468 if (unlikely(!p))
3469 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003470 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003471 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003472 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003473 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003474 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003475 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003476out_overflow:
3477 print_overflow_msg(__func__, xdr);
3478 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003479}
3480
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3482{
Al Viro8687b632006-10-19 23:28:48 -07003483 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 int status = 0;
3485
3486 *res = 0;
3487 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3488 return -EIO;
3489 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003490 p = xdr_inline_decode(xdr, 8);
3491 if (unlikely(!p))
3492 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003493 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3495 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003496 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003498out_overflow:
3499 print_overflow_msg(__func__, xdr);
3500 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501}
3502
3503static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3504{
Al Viro8687b632006-10-19 23:28:48 -07003505 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 int status = 0;
3507
3508 *res = 0;
3509 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3510 return -EIO;
3511 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003512 p = xdr_inline_decode(xdr, 8);
3513 if (unlikely(!p))
3514 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003515 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3517 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003518 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003520out_overflow:
3521 print_overflow_msg(__func__, xdr);
3522 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523}
3524
3525static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3526{
Al Viro8687b632006-10-19 23:28:48 -07003527 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 int status = 0;
3529
3530 *res = 0;
3531 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3532 return -EIO;
3533 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003534 p = xdr_inline_decode(xdr, 8);
3535 if (unlikely(!p))
3536 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003537 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3539 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003540 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003542out_overflow:
3543 print_overflow_msg(__func__, xdr);
3544 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545}
3546
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003547static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3548{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003549 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003550 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003551 int status = 0;
3552
Benny Halevyc0eae662009-08-14 17:20:14 +03003553 p = xdr_inline_decode(xdr, 4);
3554 if (unlikely(!p))
3555 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003556 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003557 if (n == 0)
3558 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003559 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003560 path->ncomponents = 0;
3561 while (path->ncomponents < n) {
3562 struct nfs4_string *component = &path->components[path->ncomponents];
3563 status = decode_opaque_inline(xdr, &component->len, &component->data);
3564 if (unlikely(status != 0))
3565 goto out_eio;
Chuck Lever02a29762012-03-01 17:00:31 -05003566 if (unlikely(nfs_debug & NFSDBG_XDR))
3567 pr_cont("%s%.*s ",
3568 (path->ncomponents != n ? "/ " : ""),
3569 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003570 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3571 path->ncomponents++;
3572 else {
3573 dprintk("cannot parse %d components in path\n", n);
3574 goto out_eio;
3575 }
3576 }
3577out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003578 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003579root_path:
3580/* a root pathname is sent as a zero component4 */
3581 path->ncomponents = 1;
3582 path->components[0].len=0;
3583 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003584 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003585 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003586out_eio:
3587 dprintk(" status %d", status);
3588 status = -EIO;
3589 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003590out_overflow:
3591 print_overflow_msg(__func__, xdr);
3592 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003593}
3594
3595static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003596{
3597 int n;
Al Viro8687b632006-10-19 23:28:48 -07003598 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003599 int status = -EIO;
3600
3601 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3602 goto out;
3603 status = 0;
3604 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3605 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003606 status = -EIO;
3607 /* Ignore borken servers that return unrequested attrs */
3608 if (unlikely(res == NULL))
3609 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003610 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003611 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003612 if (unlikely(status != 0))
3613 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003614 p = xdr_inline_decode(xdr, 4);
3615 if (unlikely(!p))
3616 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003617 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003618 if (n <= 0)
3619 goto out_eio;
3620 res->nlocations = 0;
3621 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003622 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003623 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003624
Benny Halevyc0eae662009-08-14 17:20:14 +03003625 p = xdr_inline_decode(xdr, 4);
3626 if (unlikely(!p))
3627 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003628 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003629
3630 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003631 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003632 while (loc->nservers < m) {
3633 struct nfs4_string *server = &loc->servers[loc->nservers];
3634 status = decode_opaque_inline(xdr, &server->len, &server->data);
3635 if (unlikely(status != 0))
3636 goto out_eio;
3637 dprintk("%s ", server->data);
3638 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3639 loc->nservers++;
3640 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003641 unsigned int i;
3642 dprintk("%s: using first %u of %u servers "
3643 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003644 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003645 NFS4_FS_LOCATION_MAXSERVERS,
3646 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003647 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003648 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003649 char *data;
3650 status = decode_opaque_inline(xdr, &len, &data);
3651 if (unlikely(status != 0))
3652 goto out_eio;
3653 }
3654 }
3655 }
3656 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003657 if (unlikely(status != 0))
3658 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003659 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003660 res->nlocations++;
3661 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003662 if (res->nlocations != 0)
3663 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003664out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003665 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003666 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003667out_overflow:
3668 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003669out_eio:
3670 status = -EIO;
3671 goto out;
3672}
3673
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3675{
Al Viro8687b632006-10-19 23:28:48 -07003676 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677 int status = 0;
3678
3679 *res = 0;
3680 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3681 return -EIO;
3682 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003683 p = xdr_inline_decode(xdr, 8);
3684 if (unlikely(!p))
3685 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003686 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3688 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003689 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003691out_overflow:
3692 print_overflow_msg(__func__, xdr);
3693 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694}
3695
3696static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3697{
Al Viro8687b632006-10-19 23:28:48 -07003698 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 int status = 0;
3700
3701 *maxlink = 1;
3702 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3703 return -EIO;
3704 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003705 p = xdr_inline_decode(xdr, 4);
3706 if (unlikely(!p))
3707 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003708 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3710 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003711 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003713out_overflow:
3714 print_overflow_msg(__func__, xdr);
3715 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716}
3717
3718static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3719{
Al Viro8687b632006-10-19 23:28:48 -07003720 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 int status = 0;
3722
3723 *maxname = 1024;
3724 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3725 return -EIO;
3726 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003727 p = xdr_inline_decode(xdr, 4);
3728 if (unlikely(!p))
3729 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003730 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3732 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003733 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003735out_overflow:
3736 print_overflow_msg(__func__, xdr);
3737 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738}
3739
3740static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3741{
Al Viro8687b632006-10-19 23:28:48 -07003742 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743 int status = 0;
3744
3745 *res = 1024;
3746 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3747 return -EIO;
3748 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3749 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003750 p = xdr_inline_decode(xdr, 8);
3751 if (unlikely(!p))
3752 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003753 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 if (maxread > 0x7FFFFFFF)
3755 maxread = 0x7FFFFFFF;
3756 *res = (uint32_t)maxread;
3757 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3758 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003759 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003761out_overflow:
3762 print_overflow_msg(__func__, xdr);
3763 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764}
3765
3766static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3767{
Al Viro8687b632006-10-19 23:28:48 -07003768 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769 int status = 0;
3770
3771 *res = 1024;
3772 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3773 return -EIO;
3774 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3775 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003776 p = xdr_inline_decode(xdr, 8);
3777 if (unlikely(!p))
3778 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003779 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780 if (maxwrite > 0x7FFFFFFF)
3781 maxwrite = 0x7FFFFFFF;
3782 *res = (uint32_t)maxwrite;
3783 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3784 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003785 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003787out_overflow:
3788 print_overflow_msg(__func__, xdr);
3789 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790}
3791
Trond Myklebustbca79472009-03-11 14:10:26 -04003792static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793{
Trond Myklebustbca79472009-03-11 14:10:26 -04003794 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003795 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003796 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797
3798 *mode = 0;
3799 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3800 return -EIO;
3801 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003802 p = xdr_inline_decode(xdr, 4);
3803 if (unlikely(!p))
3804 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003805 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003806 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003808 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003810 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003811 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003812out_overflow:
3813 print_overflow_msg(__func__, xdr);
3814 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815}
3816
3817static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3818{
Al Viro8687b632006-10-19 23:28:48 -07003819 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003820 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821
3822 *nlink = 1;
3823 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3824 return -EIO;
3825 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003826 p = xdr_inline_decode(xdr, 4);
3827 if (unlikely(!p))
3828 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003829 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003831 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003833 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003834 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003835out_overflow:
3836 print_overflow_msg(__func__, xdr);
3837 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838}
3839
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003840static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003841 const struct nfs_server *server, uint32_t *uid,
3842 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843{
Al Viro8687b632006-10-19 23:28:48 -07003844 uint32_t len;
3845 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003846 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847
3848 *uid = -2;
3849 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3850 return -EIO;
3851 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003852 p = xdr_inline_decode(xdr, 4);
3853 if (unlikely(!p))
3854 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003855 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003856 p = xdr_inline_decode(xdr, len);
3857 if (unlikely(!p))
3858 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003859 if (owner_name != NULL) {
3860 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3861 if (owner_name->data != NULL) {
3862 owner_name->len = len;
3863 ret = NFS_ATTR_FATTR_OWNER_NAME;
3864 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003865 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003866 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003867 ret = NFS_ATTR_FATTR_OWNER;
3868 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003870 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003872 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003873 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3875 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003876 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003877 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003878out_overflow:
3879 print_overflow_msg(__func__, xdr);
3880 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881}
3882
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003883static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003884 const struct nfs_server *server, uint32_t *gid,
3885 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886{
Al Viro8687b632006-10-19 23:28:48 -07003887 uint32_t len;
3888 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003889 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890
3891 *gid = -2;
3892 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3893 return -EIO;
3894 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003895 p = xdr_inline_decode(xdr, 4);
3896 if (unlikely(!p))
3897 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003898 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003899 p = xdr_inline_decode(xdr, len);
3900 if (unlikely(!p))
3901 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003902 if (group_name != NULL) {
3903 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3904 if (group_name->data != NULL) {
3905 group_name->len = len;
3906 ret = NFS_ATTR_FATTR_GROUP_NAME;
3907 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003908 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003909 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003910 ret = NFS_ATTR_FATTR_GROUP;
3911 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003913 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003915 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003916 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3918 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003919 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003920 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003921out_overflow:
3922 print_overflow_msg(__func__, xdr);
3923 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924}
3925
3926static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3927{
Al Viro8687b632006-10-19 23:28:48 -07003928 uint32_t major = 0, minor = 0;
3929 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003930 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931
3932 *rdev = MKDEV(0,0);
3933 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3934 return -EIO;
3935 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3936 dev_t tmp;
3937
Benny Halevyc0eae662009-08-14 17:20:14 +03003938 p = xdr_inline_decode(xdr, 8);
3939 if (unlikely(!p))
3940 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003941 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003942 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 tmp = MKDEV(major, minor);
3944 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3945 *rdev = tmp;
3946 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003947 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003949 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003950 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003951out_overflow:
3952 print_overflow_msg(__func__, xdr);
3953 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954}
3955
3956static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3957{
Al Viro8687b632006-10-19 23:28:48 -07003958 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959 int status = 0;
3960
3961 *res = 0;
3962 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3963 return -EIO;
3964 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003965 p = xdr_inline_decode(xdr, 8);
3966 if (unlikely(!p))
3967 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003968 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3970 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003971 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003973out_overflow:
3974 print_overflow_msg(__func__, xdr);
3975 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976}
3977
3978static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3979{
Al Viro8687b632006-10-19 23:28:48 -07003980 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 int status = 0;
3982
3983 *res = 0;
3984 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3985 return -EIO;
3986 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003987 p = xdr_inline_decode(xdr, 8);
3988 if (unlikely(!p))
3989 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003990 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3992 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003993 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003995out_overflow:
3996 print_overflow_msg(__func__, xdr);
3997 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998}
3999
4000static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4001{
Al Viro8687b632006-10-19 23:28:48 -07004002 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 int status = 0;
4004
4005 *res = 0;
4006 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4007 return -EIO;
4008 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004009 p = xdr_inline_decode(xdr, 8);
4010 if (unlikely(!p))
4011 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004012 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4014 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004015 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004017out_overflow:
4018 print_overflow_msg(__func__, xdr);
4019 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020}
4021
4022static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4023{
Al Viro8687b632006-10-19 23:28:48 -07004024 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004025 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026
4027 *used = 0;
4028 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4029 return -EIO;
4030 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004031 p = xdr_inline_decode(xdr, 8);
4032 if (unlikely(!p))
4033 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004034 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004036 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004038 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004040 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004041out_overflow:
4042 print_overflow_msg(__func__, xdr);
4043 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044}
4045
4046static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4047{
Al Viro8687b632006-10-19 23:28:48 -07004048 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049 uint64_t sec;
4050 uint32_t nsec;
4051
Benny Halevyc0eae662009-08-14 17:20:14 +03004052 p = xdr_inline_decode(xdr, 12);
4053 if (unlikely(!p))
4054 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004055 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004056 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 time->tv_sec = (time_t)sec;
4058 time->tv_nsec = (long)nsec;
4059 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004060out_overflow:
4061 print_overflow_msg(__func__, xdr);
4062 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063}
4064
4065static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4066{
4067 int status = 0;
4068
4069 time->tv_sec = 0;
4070 time->tv_nsec = 0;
4071 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4072 return -EIO;
4073 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4074 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004075 if (status == 0)
4076 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4078 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004079 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 return status;
4081}
4082
4083static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4084{
4085 int status = 0;
4086
4087 time->tv_sec = 0;
4088 time->tv_nsec = 0;
4089 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4090 return -EIO;
4091 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4092 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004093 if (status == 0)
4094 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4096 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004097 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 return status;
4099}
4100
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004101static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4102 struct timespec *time)
4103{
4104 int status = 0;
4105
4106 time->tv_sec = 0;
4107 time->tv_nsec = 0;
4108 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4109 return -EIO;
4110 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4111 status = decode_attr_time(xdr, time);
4112 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4113 }
4114 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4115 (long)time->tv_nsec);
4116 return status;
4117}
4118
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4120{
4121 int status = 0;
4122
4123 time->tv_sec = 0;
4124 time->tv_nsec = 0;
4125 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4126 return -EIO;
4127 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4128 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004129 if (status == 0)
4130 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4132 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004133 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 return status;
4135}
4136
Al Viro8687b632006-10-19 23:28:48 -07004137static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138{
4139 unsigned int attrwords = XDR_QUADLEN(attrlen);
4140 unsigned int nwords = xdr->p - savep;
4141
4142 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004143 dprintk("%s: server returned incorrect attribute length: "
4144 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004145 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 attrwords << 2,
4147 (attrwords < nwords) ? '<' : '>',
4148 nwords << 2);
4149 return -EIO;
4150 }
4151 return 0;
4152}
4153
4154static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4155{
Al Viro8687b632006-10-19 23:28:48 -07004156 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157
Benny Halevyc0eae662009-08-14 17:20:14 +03004158 p = xdr_inline_decode(xdr, 20);
4159 if (unlikely(!p))
4160 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004161 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004162 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004163 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004165out_overflow:
4166 print_overflow_msg(__func__, xdr);
4167 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168}
4169
4170static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4171{
Al Viro8687b632006-10-19 23:28:48 -07004172 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173 uint32_t supp, acc;
4174 int status;
4175
4176 status = decode_op_hdr(xdr, OP_ACCESS);
4177 if (status)
4178 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004179 p = xdr_inline_decode(xdr, 8);
4180 if (unlikely(!p))
4181 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004182 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004183 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 access->supported = supp;
4185 access->access = acc;
4186 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004187out_overflow:
4188 print_overflow_msg(__func__, xdr);
4189 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190}
4191
Benny Halevy07d30432009-08-14 17:19:52 +03004192static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193{
Al Viro8687b632006-10-19 23:28:48 -07004194 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004195
4196 p = xdr_inline_decode(xdr, len);
4197 if (likely(p)) {
4198 memcpy(buf, p, len);
4199 return 0;
4200 }
4201 print_overflow_msg(__func__, xdr);
4202 return -EIO;
4203}
4204
4205static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4206{
4207 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208}
4209
4210static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4211{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 int status;
4213
4214 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004215 if (status != -EIO)
4216 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004217 if (!status)
4218 status = decode_stateid(xdr, &res->stateid);
4219 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220}
4221
Benny Halevydb942bb2009-08-14 17:19:56 +03004222static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4223{
4224 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225}
4226
4227static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4228{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229 int status;
4230
4231 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004232 if (!status)
4233 status = decode_verifier(xdr, res->verf->verifier);
4234 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235}
4236
4237static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4238{
Al Viro8687b632006-10-19 23:28:48 -07004239 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240 uint32_t bmlen;
4241 int status;
4242
4243 status = decode_op_hdr(xdr, OP_CREATE);
4244 if (status)
4245 return status;
4246 if ((status = decode_change_info(xdr, cinfo)))
4247 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004248 p = xdr_inline_decode(xdr, 4);
4249 if (unlikely(!p))
4250 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004251 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004252 p = xdr_inline_decode(xdr, bmlen << 2);
4253 if (likely(p))
4254 return 0;
4255out_overflow:
4256 print_overflow_msg(__func__, xdr);
4257 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258}
4259
4260static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4261{
Al Viro8687b632006-10-19 23:28:48 -07004262 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004263 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264 int status;
4265
4266 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4267 goto xdr_error;
4268 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4269 goto xdr_error;
4270 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4271 goto xdr_error;
4272 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4273 goto xdr_error;
4274 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4275 goto xdr_error;
4276 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4277 goto xdr_error;
4278 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4279 goto xdr_error;
4280 status = verify_attr_len(xdr, savep, attrlen);
4281xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004282 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 return status;
4284}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004285
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4287{
Al Viro8687b632006-10-19 23:28:48 -07004288 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004289 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004290 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004291
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4293 goto xdr_error;
4294 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4295 goto xdr_error;
4296 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4297 goto xdr_error;
4298
4299 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4300 goto xdr_error;
4301 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4302 goto xdr_error;
4303 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4304 goto xdr_error;
4305 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4306 goto xdr_error;
4307 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4308 goto xdr_error;
4309 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4310 goto xdr_error;
4311
4312 status = verify_attr_len(xdr, savep, attrlen);
4313xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004314 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 return status;
4316}
4317
4318static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4319{
Al Viro8687b632006-10-19 23:28:48 -07004320 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004321 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004323
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4325 goto xdr_error;
4326 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4327 goto xdr_error;
4328 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4329 goto xdr_error;
4330
4331 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4332 goto xdr_error;
4333 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4334 goto xdr_error;
4335
4336 status = verify_attr_len(xdr, savep, attrlen);
4337xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004338 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004339 return status;
4340}
4341
Bryan Schumakerae42c702010-10-21 16:33:17 -04004342static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4343 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004344 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004345 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346{
Trond Myklebustbca79472009-03-11 14:10:26 -04004347 int status;
4348 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004349 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004350 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004352 status = decode_attr_type(xdr, bitmap, &type);
4353 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004355 fattr->mode = 0;
4356 if (status != 0) {
4357 fattr->mode |= nfs_type2fmt[type];
4358 fattr->valid |= status;
4359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004361 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
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_size(xdr, bitmap, &fattr->size);
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
4371 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4372 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004374 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004375
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004376 err = 0;
4377 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004378 if (status < 0)
4379 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004380 if (err == -NFS4ERR_WRONGSEC)
4381 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004382
4383 status = decode_attr_filehandle(xdr, bitmap, fh);
4384 if (status < 0)
4385 goto xdr_error;
4386
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004387 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4388 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004390 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004391
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004392 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004393 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004394 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004395 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004396
4397 status = decode_attr_mode(xdr, bitmap, &fmode);
4398 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004400 if (status != 0) {
4401 fattr->mode |= fmode;
4402 fattr->valid |= status;
4403 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004404
4405 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4406 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_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_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
Trond Myklebust6926afd2012-01-07 13:22:46 -05004415 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004416 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_rdev(xdr, bitmap, &fattr->rdev);
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_space_used(xdr, bitmap, &fattr->du.nfs3.used);
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_access(xdr, bitmap, &fattr->atime);
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_metadata(xdr, bitmap, &fattr->ctime);
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
4440 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4441 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004443 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004444
Trond Myklebust28331a42011-04-27 13:47:52 -04004445 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004446 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004447 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004448 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004449
Bryan Schumakerae42c702010-10-21 16:33:17 -04004450xdr_error:
4451 dprintk("%s: xdr returned %d\n", __func__, -status);
4452 return status;
4453}
4454
4455static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004456 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4457 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004458{
4459 __be32 *savep;
4460 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004461 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004462 int status;
4463
4464 status = decode_op_hdr(xdr, OP_GETATTR);
4465 if (status < 0)
4466 goto xdr_error;
4467
4468 status = decode_attr_bitmap(xdr, bitmap);
4469 if (status < 0)
4470 goto xdr_error;
4471
4472 status = decode_attr_length(xdr, &attrlen, &savep);
4473 if (status < 0)
4474 goto xdr_error;
4475
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004476 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004477 if (status < 0)
4478 goto xdr_error;
4479
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004480 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004482 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483 return status;
4484}
4485
Bryan Schumakerae42c702010-10-21 16:33:17 -04004486static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004487 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004488{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004489 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004490}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491
Andy Adamson504913f2010-10-20 00:17:57 -04004492/*
4493 * Decode potentially multiple layout types. Currently we only support
4494 * one layout driver per file system.
4495 */
4496static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4497 uint32_t *layouttype)
4498{
4499 uint32_t *p;
4500 int num;
4501
4502 p = xdr_inline_decode(xdr, 4);
4503 if (unlikely(!p))
4504 goto out_overflow;
4505 num = be32_to_cpup(p);
4506
4507 /* pNFS is not supported by the underlying file system */
4508 if (num == 0) {
4509 *layouttype = 0;
4510 return 0;
4511 }
4512 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004513 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4514 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004515
4516 /* Decode and set first layout type, move xdr->p past unused types */
4517 p = xdr_inline_decode(xdr, num * 4);
4518 if (unlikely(!p))
4519 goto out_overflow;
4520 *layouttype = be32_to_cpup(p);
4521 return 0;
4522out_overflow:
4523 print_overflow_msg(__func__, xdr);
4524 return -EIO;
4525}
4526
4527/*
4528 * The type of file system exported.
4529 * Note we must ensure that layouttype is set in any non-error case.
4530 */
4531static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4532 uint32_t *layouttype)
4533{
4534 int status = 0;
4535
4536 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4537 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4538 return -EIO;
4539 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4540 status = decode_first_pnfs_layout_type(xdr, layouttype);
4541 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4542 } else
4543 *layouttype = 0;
4544 return status;
4545}
4546
Fred Isamandae100c2011-07-30 20:52:37 -04004547/*
4548 * The prefered block size for layout directed io
4549 */
4550static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4551 uint32_t *res)
4552{
4553 __be32 *p;
4554
4555 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4556 *res = 0;
4557 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4558 p = xdr_inline_decode(xdr, 4);
4559 if (unlikely(!p)) {
4560 print_overflow_msg(__func__, xdr);
4561 return -EIO;
4562 }
4563 *res = be32_to_cpup(p);
4564 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4565 }
4566 return 0;
4567}
4568
Linus Torvalds1da177e2005-04-16 15:20:36 -07004569static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4570{
Al Viro8687b632006-10-19 23:28:48 -07004571 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004572 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573 int status;
4574
4575 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4576 goto xdr_error;
4577 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4578 goto xdr_error;
4579 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4580 goto xdr_error;
4581
4582 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4583
4584 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4585 goto xdr_error;
4586 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4587 goto xdr_error;
4588 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4589 goto xdr_error;
4590 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4591 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4592 goto xdr_error;
4593 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004594 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4595 if (status != 0)
4596 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004597 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4598 if (status != 0)
4599 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004600 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4601 if (status)
4602 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603
4604 status = verify_attr_len(xdr, savep, attrlen);
4605xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004606 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004607 return status;
4608}
4609
4610static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4611{
Al Viro8687b632006-10-19 23:28:48 -07004612 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613 uint32_t len;
4614 int status;
4615
Trond Myklebust99367812007-07-17 21:52:41 -04004616 /* Zero handle first to allow comparisons */
4617 memset(fh, 0, sizeof(*fh));
4618
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619 status = decode_op_hdr(xdr, OP_GETFH);
4620 if (status)
4621 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004622
Benny Halevyc0eae662009-08-14 17:20:14 +03004623 p = xdr_inline_decode(xdr, 4);
4624 if (unlikely(!p))
4625 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004626 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004627 if (len > NFS4_FHSIZE)
4628 return -EIO;
4629 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004630 p = xdr_inline_decode(xdr, len);
4631 if (unlikely(!p))
4632 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004633 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004635out_overflow:
4636 print_overflow_msg(__func__, xdr);
4637 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638}
4639
4640static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4641{
4642 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004643
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644 status = decode_op_hdr(xdr, OP_LINK);
4645 if (status)
4646 return status;
4647 return decode_change_info(xdr, cinfo);
4648}
4649
4650/*
4651 * We create the owner, so we know a proper owner.id length is 4.
4652 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004653static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004655 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004656 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004657 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004659 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004660 if (unlikely(!p))
4661 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004662 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004663 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004664 type = be32_to_cpup(p++); /* 4 byte read */
4665 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004666 fl->fl_start = (loff_t)offset;
4667 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4668 if (length == ~(uint64_t)0)
4669 fl->fl_end = OFFSET_MAX;
4670 fl->fl_type = F_WRLCK;
4671 if (type & 1)
4672 fl->fl_type = F_RDLCK;
4673 fl->fl_pid = 0;
4674 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004675 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4676 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4677 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004678 if (likely(p))
4679 return -NFS4ERR_DENIED;
4680out_overflow:
4681 print_overflow_msg(__func__, xdr);
4682 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004683}
4684
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004685static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004687 int status;
4688
4689 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004690 if (status == -EIO)
4691 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004692 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004693 status = decode_stateid(xdr, &res->stateid);
4694 if (unlikely(status))
4695 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004697 status = decode_lock_denied(xdr, NULL);
4698 if (res->open_seqid != NULL)
4699 nfs_increment_open_seqid(status, res->open_seqid);
4700 nfs_increment_lock_seqid(status, res->lock_seqid);
4701out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004702 return status;
4703}
4704
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004705static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706{
4707 int status;
4708 status = decode_op_hdr(xdr, OP_LOCKT);
4709 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004710 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711 return status;
4712}
4713
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004714static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716 int status;
4717
4718 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004719 if (status != -EIO)
4720 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004721 if (status == 0)
4722 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723 return status;
4724}
4725
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004726static int decode_release_lockowner(struct xdr_stream *xdr)
4727{
4728 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4729}
4730
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731static int decode_lookup(struct xdr_stream *xdr)
4732{
4733 return decode_op_hdr(xdr, OP_LOOKUP);
4734}
4735
4736/* This is too sick! */
4737static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4738{
Andy Adamson05d564f2008-12-23 16:06:15 -05004739 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740 uint32_t limit_type, nblocks, blocksize;
4741
Benny Halevyc0eae662009-08-14 17:20:14 +03004742 p = xdr_inline_decode(xdr, 12);
4743 if (unlikely(!p))
4744 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004745 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004747 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004748 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004749 break;
4750 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004751 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004752 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004753 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 }
4755 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004756out_overflow:
4757 print_overflow_msg(__func__, xdr);
4758 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759}
4760
4761static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4762{
Andy Adamson05d564f2008-12-23 16:06:15 -05004763 __be32 *p;
4764 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004765 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766
Benny Halevyc0eae662009-08-14 17:20:14 +03004767 p = xdr_inline_decode(xdr, 4);
4768 if (unlikely(!p))
4769 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004770 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4772 res->delegation_type = 0;
4773 return 0;
4774 }
Benny Halevy07d30432009-08-14 17:19:52 +03004775 status = decode_stateid(xdr, &res->delegation);
4776 if (unlikely(status))
4777 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004778 p = xdr_inline_decode(xdr, 4);
4779 if (unlikely(!p))
4780 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004781 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004782
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004784 case NFS4_OPEN_DELEGATE_READ:
4785 res->delegation_type = FMODE_READ;
4786 break;
4787 case NFS4_OPEN_DELEGATE_WRITE:
4788 res->delegation_type = FMODE_WRITE|FMODE_READ;
4789 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790 return -EIO;
4791 }
David Howells7539bba2006-08-22 20:06:09 -04004792 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004793out_overflow:
4794 print_overflow_msg(__func__, xdr);
4795 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004796}
4797
4798static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4799{
Andy Adamson05d564f2008-12-23 16:06:15 -05004800 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004801 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004802 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803
Andy Adamson05d564f2008-12-23 16:06:15 -05004804 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004805 if (status != -EIO)
4806 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004807 if (!status)
4808 status = decode_stateid(xdr, &res->stateid);
4809 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004810 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811
Andy Adamson05d564f2008-12-23 16:06:15 -05004812 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813
Benny Halevyc0eae662009-08-14 17:20:14 +03004814 p = xdr_inline_decode(xdr, 8);
4815 if (unlikely(!p))
4816 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004817 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004818 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004819 if (bmlen > 10)
4820 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821
Benny Halevyc0eae662009-08-14 17:20:14 +03004822 p = xdr_inline_decode(xdr, bmlen << 2);
4823 if (unlikely(!p))
4824 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004825 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4826 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004827 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004828 for (; i < NFS4_BITMAP_SIZE; i++)
4829 res->attrset[i] = 0;
4830
Linus Torvalds1da177e2005-04-16 15:20:36 -07004831 return decode_delegation(xdr, res);
4832xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004833 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004834 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004835out_overflow:
4836 print_overflow_msg(__func__, xdr);
4837 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838}
4839
4840static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4841{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842 int status;
4843
Andy Adamson05d564f2008-12-23 16:06:15 -05004844 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004845 if (status != -EIO)
4846 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004847 if (!status)
4848 status = decode_stateid(xdr, &res->stateid);
4849 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850}
4851
4852static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4853{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854 int status;
4855
4856 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004857 if (status != -EIO)
4858 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004859 if (!status)
4860 status = decode_stateid(xdr, &res->stateid);
4861 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862}
4863
4864static int decode_putfh(struct xdr_stream *xdr)
4865{
4866 return decode_op_hdr(xdr, OP_PUTFH);
4867}
4868
4869static int decode_putrootfh(struct xdr_stream *xdr)
4870{
4871 return decode_op_hdr(xdr, OP_PUTROOTFH);
4872}
4873
4874static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4875{
4876 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004877 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 uint32_t count, eof, recvd, hdrlen;
4879 int status;
4880
4881 status = decode_op_hdr(xdr, OP_READ);
4882 if (status)
4883 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004884 p = xdr_inline_decode(xdr, 8);
4885 if (unlikely(!p))
4886 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004887 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004888 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004889 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 recvd = req->rq_rcv_buf.len - hdrlen;
4891 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004892 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893 "count %u > recvd %u\n", count, recvd);
4894 count = recvd;
4895 eof = 0;
4896 }
4897 xdr_read_pages(xdr, count);
4898 res->eof = eof;
4899 res->count = count;
4900 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004901out_overflow:
4902 print_overflow_msg(__func__, xdr);
4903 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904}
4905
4906static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4907{
4908 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004909 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004910 size_t hdrlen;
4911 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004912 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913
4914 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004915 if (!status)
4916 status = decode_verifier(xdr, readdir->verifier.data);
4917 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004919 dprintk("%s: verifier = %08x:%08x\n",
4920 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004921 ((u32 *)readdir->verifier.data)[0],
4922 ((u32 *)readdir->verifier.data)[1]);
4923
Linus Torvalds1da177e2005-04-16 15:20:36 -07004924
Benny Halevydb942bb2009-08-14 17:19:56 +03004925 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926 recvd = rcvbuf->len - hdrlen;
4927 if (pglen > recvd)
4928 pglen = recvd;
4929 xdr_read_pages(xdr, pglen);
4930
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004931
Trond Myklebustac396122010-11-15 20:26:22 -05004932 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004933}
4934
4935static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4936{
4937 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4938 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004939 size_t hdrlen;
4940 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004941 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942 int status;
4943
4944 status = decode_op_hdr(xdr, OP_READLINK);
4945 if (status)
4946 return status;
4947
4948 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004949 p = xdr_inline_decode(xdr, 4);
4950 if (unlikely(!p))
4951 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004952 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004953 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004954 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004955 return -ENAMETOOLONG;
4956 }
4957 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4958 recvd = req->rq_rcv_buf.len - hdrlen;
4959 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004960 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961 "count %u > recvd %u\n", len, recvd);
4962 return -EIO;
4963 }
4964 xdr_read_pages(xdr, len);
4965 /*
4966 * The XDR encode routine has set things up so that
4967 * the link text will be copied directly into the
4968 * buffer. We just have to do overflow-checking,
4969 * and and null-terminate the text (the VFS expects
4970 * null-termination).
4971 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004972 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004974out_overflow:
4975 print_overflow_msg(__func__, xdr);
4976 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977}
4978
4979static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4980{
4981 int status;
4982
4983 status = decode_op_hdr(xdr, OP_REMOVE);
4984 if (status)
4985 goto out;
4986 status = decode_change_info(xdr, cinfo);
4987out:
4988 return status;
4989}
4990
4991static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4992 struct nfs4_change_info *new_cinfo)
4993{
4994 int status;
4995
4996 status = decode_op_hdr(xdr, OP_RENAME);
4997 if (status)
4998 goto out;
4999 if ((status = decode_change_info(xdr, old_cinfo)))
5000 goto out;
5001 status = decode_change_info(xdr, new_cinfo);
5002out:
5003 return status;
5004}
5005
5006static int decode_renew(struct xdr_stream *xdr)
5007{
5008 return decode_op_hdr(xdr, OP_RENEW);
5009}
5010
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005011static int
5012decode_restorefh(struct xdr_stream *xdr)
5013{
5014 return decode_op_hdr(xdr, OP_RESTOREFH);
5015}
5016
J. Bruce Fields029d1052005-06-22 17:16:22 +00005017static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005018 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005019{
Andy Adamsonbf118a32011-12-07 11:55:27 -05005020 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005021 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005022 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005023 struct kvec *iov = req->rq_rcv_buf.head;
5024 int status;
5025
Andy Adamsonbf118a32011-12-07 11:55:27 -05005026 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005027 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5028 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005029 bm_p = xdr->p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005030 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5031 goto out;
5032 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5033 goto out;
5034
5035 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5036 return -EIO;
5037 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04005038 size_t hdrlen;
5039 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005040
Andy Adamsonbf118a32011-12-07 11:55:27 -05005041 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5042 * are stored with the acl data to handle the problem of
5043 * variable length bitmaps.*/
5044 xdr->p = bm_p;
5045 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
5046 res->acl_data_offset <<= 2;
5047
J. Bruce Fields029d1052005-06-22 17:16:22 +00005048 /* We ignore &savep and don't do consistency checks on
5049 * the attr length. Let userspace figure it out.... */
5050 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005051 attrlen += res->acl_data_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005052 recvd = req->rq_rcv_buf.len - hdrlen;
5053 if (attrlen > recvd) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05005054 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
5055 /* getxattr interface called with a NULL buf */
5056 res->acl_len = attrlen;
5057 goto out;
5058 }
5059 dprintk("NFS: acl reply: attrlen %u > recvd %u\n",
J. Bruce Fields029d1052005-06-22 17:16:22 +00005060 attrlen, recvd);
5061 return -EINVAL;
5062 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04005063 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05005064 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005065 } else
5066 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005067
5068out:
5069 return status;
5070}
5071
Linus Torvalds1da177e2005-04-16 15:20:36 -07005072static int
5073decode_savefh(struct xdr_stream *xdr)
5074{
5075 return decode_op_hdr(xdr, OP_SAVEFH);
5076}
5077
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005078static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079{
Al Viro8687b632006-10-19 23:28:48 -07005080 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081 uint32_t bmlen;
5082 int status;
5083
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084 status = decode_op_hdr(xdr, OP_SETATTR);
5085 if (status)
5086 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005087 p = xdr_inline_decode(xdr, 4);
5088 if (unlikely(!p))
5089 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005090 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005091 p = xdr_inline_decode(xdr, bmlen << 2);
5092 if (likely(p))
5093 return 0;
5094out_overflow:
5095 print_overflow_msg(__func__, xdr);
5096 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005097}
5098
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005099static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005100{
Al Viro8687b632006-10-19 23:28:48 -07005101 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102 uint32_t opnum;
5103 int32_t nfserr;
5104
Benny Halevyc0eae662009-08-14 17:20:14 +03005105 p = xdr_inline_decode(xdr, 8);
5106 if (unlikely(!p))
5107 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005108 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005110 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005111 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112 return -EIO;
5113 }
Benny Halevycccddf42009-08-14 17:20:19 +03005114 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005116 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5117 if (unlikely(!p))
5118 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005119 p = xdr_decode_hyper(p, &res->clientid);
5120 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005121 } else if (nfserr == NFSERR_CLID_INUSE) {
5122 uint32_t len;
5123
5124 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005125 p = xdr_inline_decode(xdr, 4);
5126 if (unlikely(!p))
5127 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005128 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005129 p = xdr_inline_decode(xdr, len);
5130 if (unlikely(!p))
5131 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132
5133 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005134 p = xdr_inline_decode(xdr, 4);
5135 if (unlikely(!p))
5136 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005137 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005138 p = xdr_inline_decode(xdr, len);
5139 if (unlikely(!p))
5140 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005141 return -NFSERR_CLID_INUSE;
5142 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005143 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144
5145 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005146out_overflow:
5147 print_overflow_msg(__func__, xdr);
5148 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005149}
5150
5151static int decode_setclientid_confirm(struct xdr_stream *xdr)
5152{
5153 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5154}
5155
5156static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5157{
Al Viro8687b632006-10-19 23:28:48 -07005158 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005159 int status;
5160
5161 status = decode_op_hdr(xdr, OP_WRITE);
5162 if (status)
5163 return status;
5164
Benny Halevyc0eae662009-08-14 17:20:14 +03005165 p = xdr_inline_decode(xdr, 16);
5166 if (unlikely(!p))
5167 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005168 res->count = be32_to_cpup(p++);
5169 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03005170 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005171 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005172out_overflow:
5173 print_overflow_msg(__func__, xdr);
5174 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175}
5176
5177static int decode_delegreturn(struct xdr_stream *xdr)
5178{
5179 return decode_op_hdr(xdr, OP_DELEGRETURN);
5180}
5181
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005182static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5183{
5184 __be32 *p;
5185
5186 p = xdr_inline_decode(xdr, 4);
5187 if (unlikely(!p))
5188 goto out_overflow;
5189 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5190 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5191 goto out_err;
5192
5193 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5194 if (unlikely(!p))
5195 goto out_overflow;
5196 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5197
5198 p = xdr_inline_decode(xdr, 8);
5199 if (unlikely(!p))
5200 goto out_overflow;
5201 flavor->gss.qop4 = be32_to_cpup(p++);
5202 flavor->gss.service = be32_to_cpup(p);
5203
5204 return 0;
5205
5206out_overflow:
5207 print_overflow_msg(__func__, xdr);
5208 return -EIO;
5209out_err:
5210 return -EINVAL;
5211}
5212
5213static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5214{
5215 struct nfs4_secinfo_flavor *sec_flavor;
5216 int status;
5217 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005218 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005219
5220 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04005221 if (status)
5222 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005223 p = xdr_inline_decode(xdr, 4);
5224 if (unlikely(!p))
5225 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005226
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005227 res->flavors->num_flavors = 0;
5228 num_flavors = be32_to_cpup(p);
5229
5230 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005231 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005232 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005233 break;
5234
5235 p = xdr_inline_decode(xdr, 4);
5236 if (unlikely(!p))
5237 goto out_overflow;
5238 sec_flavor->flavor = be32_to_cpup(p);
5239
5240 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005241 status = decode_secinfo_gss(xdr, sec_flavor);
5242 if (status)
5243 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005244 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005245 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005246 }
5247
Bryan Schumaker613e9012011-04-27 15:28:44 -04005248out:
5249 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005250out_overflow:
5251 print_overflow_msg(__func__, xdr);
5252 return -EIO;
5253}
5254
Benny Halevy99fe60d2009-04-01 09:22:29 -04005255#if defined(CONFIG_NFS_V4_1)
5256static int decode_exchange_id(struct xdr_stream *xdr,
5257 struct nfs41_exchange_id_res *res)
5258{
5259 __be32 *p;
5260 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005261 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005262 int status;
5263 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005264 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005265
5266 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5267 if (status)
5268 return status;
5269
Benny Halevyc0eae662009-08-14 17:20:14 +03005270 p = xdr_inline_decode(xdr, 8);
5271 if (unlikely(!p))
5272 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005273 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005274 p = xdr_inline_decode(xdr, 12);
5275 if (unlikely(!p))
5276 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005277 clp->cl_seqid = be32_to_cpup(p++);
5278 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005279
5280 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005281 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005282 if (dummy != SP4_NONE)
5283 return -EIO;
5284
5285 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005286 p = xdr_inline_decode(xdr, 8);
5287 if (unlikely(!p))
5288 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005289
5290 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005291 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5292 if (unlikely(status))
5293 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005294
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005295 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005296 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5297 if (unlikely(status))
5298 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005299
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005300 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5301 return -EIO;
5302
5303 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5304 res->server_scope->server_scope_sz = dummy;
5305
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005306 /* Implementation Id */
5307 p = xdr_inline_decode(xdr, 4);
5308 if (unlikely(!p))
5309 goto out_overflow;
5310 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005311
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005312 if (impl_id_count) {
5313 /* nii_domain */
5314 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5315 if (unlikely(status))
5316 return status;
5317 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5318 return -EIO;
5319 memcpy(res->impl_id->domain, dummy_str, dummy);
5320
5321 /* nii_name */
5322 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5323 if (unlikely(status))
5324 return status;
5325 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5326 return -EIO;
5327 memcpy(res->impl_id->name, dummy_str, dummy);
5328
5329 /* nii_date */
5330 p = xdr_inline_decode(xdr, 12);
5331 if (unlikely(!p))
5332 goto out_overflow;
5333 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5334 res->impl_id->date.nseconds = be32_to_cpup(p);
5335
5336 /* if there's more than one entry, ignore the rest */
5337 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005338 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005339out_overflow:
5340 print_overflow_msg(__func__, xdr);
5341 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005342}
Andy Adamsonfc931582009-04-01 09:22:31 -04005343
5344static int decode_chan_attrs(struct xdr_stream *xdr,
5345 struct nfs4_channel_attrs *attrs)
5346{
5347 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005348 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005349
Benny Halevyc0eae662009-08-14 17:20:14 +03005350 p = xdr_inline_decode(xdr, 28);
5351 if (unlikely(!p))
5352 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005353 val = be32_to_cpup(p++); /* headerpadsz */
5354 if (val)
5355 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005356 attrs->max_rqst_sz = be32_to_cpup(p++);
5357 attrs->max_resp_sz = be32_to_cpup(p++);
5358 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5359 attrs->max_ops = be32_to_cpup(p++);
5360 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005361 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005362 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005363 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5364 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005365 return -EINVAL;
5366 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005367 if (nr_attrs == 1) {
5368 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5369 if (unlikely(!p))
5370 goto out_overflow;
5371 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005372 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005373out_overflow:
5374 print_overflow_msg(__func__, xdr);
5375 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005376}
5377
Benny Halevye78291e2009-08-14 17:20:00 +03005378static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5379{
5380 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005381}
5382
5383static int decode_create_session(struct xdr_stream *xdr,
5384 struct nfs41_create_session_res *res)
5385{
5386 __be32 *p;
5387 int status;
5388 struct nfs_client *clp = res->client;
5389 struct nfs4_session *session = clp->cl_session;
5390
5391 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005392 if (!status)
5393 status = decode_sessionid(xdr, &session->sess_id);
5394 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005395 return status;
5396
Andy Adamsonfc931582009-04-01 09:22:31 -04005397 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005398 p = xdr_inline_decode(xdr, 8);
5399 if (unlikely(!p))
5400 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005401 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005402 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005403
5404 /* Channel attributes */
5405 status = decode_chan_attrs(xdr, &session->fc_attrs);
5406 if (!status)
5407 status = decode_chan_attrs(xdr, &session->bc_attrs);
5408 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005409out_overflow:
5410 print_overflow_msg(__func__, xdr);
5411 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005412}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005413
5414static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5415{
5416 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5417}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005418
5419static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5420{
5421 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5422}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005423#endif /* CONFIG_NFS_V4_1 */
5424
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005425static int decode_sequence(struct xdr_stream *xdr,
5426 struct nfs4_sequence_res *res,
5427 struct rpc_rqst *rqstp)
5428{
5429#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005430 struct nfs4_sessionid id;
5431 u32 dummy;
5432 int status;
5433 __be32 *p;
5434
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005435 if (!res->sr_session)
5436 return 0;
5437
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005438 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005439 if (!status)
5440 status = decode_sessionid(xdr, &id);
5441 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005442 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005443
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005444 /*
5445 * If the server returns different values for sessionID, slotID or
5446 * sequence number, the server is looney tunes.
5447 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005448 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005449
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005450 if (memcmp(id.data, res->sr_session->sess_id.data,
5451 NFS4_MAX_SESSIONID_LEN)) {
5452 dprintk("%s Invalid session id\n", __func__);
5453 goto out_err;
5454 }
Benny Halevye78291e2009-08-14 17:20:00 +03005455
Benny Halevyc0eae662009-08-14 17:20:14 +03005456 p = xdr_inline_decode(xdr, 20);
5457 if (unlikely(!p))
5458 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005459
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005460 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005461 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005462 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005463 dprintk("%s Invalid sequence number\n", __func__);
5464 goto out_err;
5465 }
5466 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005467 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005468 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005469 dprintk("%s Invalid slot id\n", __func__);
5470 goto out_err;
5471 }
5472 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005473 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005474 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005475 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005476 /* result flags */
5477 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005478 status = 0;
5479out_err:
5480 res->sr_status = status;
5481 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005482out_overflow:
5483 print_overflow_msg(__func__, xdr);
5484 status = -EIO;
5485 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005486#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005487 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005488#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005489}
5490
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005491#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005492/*
5493 * TODO: Need to handle case when EOF != true;
5494 */
5495static int decode_getdevicelist(struct xdr_stream *xdr,
5496 struct pnfs_devicelist *res)
5497{
5498 __be32 *p;
5499 int status, i;
5500 struct nfs_writeverf verftemp;
5501
5502 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5503 if (status)
5504 return status;
5505
5506 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5507 if (unlikely(!p))
5508 goto out_overflow;
5509
5510 /* TODO: Skip cookie for now */
5511 p += 2;
5512
5513 /* Read verifier */
5514 p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8);
5515
5516 res->num_devs = be32_to_cpup(p);
5517
5518 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5519
5520 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005521 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005522 __func__, res->num_devs);
5523 return -EIO;
5524 }
5525
5526 p = xdr_inline_decode(xdr,
5527 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5528 if (unlikely(!p))
5529 goto out_overflow;
5530 for (i = 0; i < res->num_devs; i++)
5531 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5532 NFS4_DEVICEID4_SIZE);
5533 res->eof = be32_to_cpup(p);
5534 return 0;
5535out_overflow:
5536 print_overflow_msg(__func__, xdr);
5537 return -EIO;
5538}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005539
5540static int decode_getdeviceinfo(struct xdr_stream *xdr,
5541 struct pnfs_device *pdev)
5542{
5543 __be32 *p;
5544 uint32_t len, type;
5545 int status;
5546
5547 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5548 if (status) {
5549 if (status == -ETOOSMALL) {
5550 p = xdr_inline_decode(xdr, 4);
5551 if (unlikely(!p))
5552 goto out_overflow;
5553 pdev->mincount = be32_to_cpup(p);
5554 dprintk("%s: Min count too small. mincnt = %u\n",
5555 __func__, pdev->mincount);
5556 }
5557 return status;
5558 }
5559
5560 p = xdr_inline_decode(xdr, 8);
5561 if (unlikely(!p))
5562 goto out_overflow;
5563 type = be32_to_cpup(p++);
5564 if (type != pdev->layout_type) {
5565 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5566 __func__, pdev->layout_type, type);
5567 return -EINVAL;
5568 }
5569 /*
5570 * Get the length of the opaque device_addr4. xdr_read_pages places
5571 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5572 * and places the remaining xdr data in xdr_buf->tail
5573 */
5574 pdev->mincount = be32_to_cpup(p);
5575 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5576
5577 /* Parse notification bitmap, verifying that it is zero. */
5578 p = xdr_inline_decode(xdr, 4);
5579 if (unlikely(!p))
5580 goto out_overflow;
5581 len = be32_to_cpup(p);
5582 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005583 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005584
5585 p = xdr_inline_decode(xdr, 4 * len);
5586 if (unlikely(!p))
5587 goto out_overflow;
5588 for (i = 0; i < len; i++, p++) {
5589 if (be32_to_cpup(p)) {
5590 dprintk("%s: notifications not supported\n",
5591 __func__);
5592 return -EIO;
5593 }
5594 }
5595 }
5596 return 0;
5597out_overflow:
5598 print_overflow_msg(__func__, xdr);
5599 return -EIO;
5600}
5601
5602static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5603 struct nfs4_layoutget_res *res)
5604{
5605 __be32 *p;
5606 int status;
5607 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005608 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5609 struct kvec *iov = rcvbuf->head;
5610 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005611
5612 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5613 if (status)
5614 return status;
5615 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5616 if (unlikely(!p))
5617 goto out_overflow;
5618 res->return_on_close = be32_to_cpup(p++);
5619 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5620 layout_count = be32_to_cpup(p);
5621 if (!layout_count) {
5622 dprintk("%s: server responded with empty layout array\n",
5623 __func__);
5624 return -EINVAL;
5625 }
5626
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005627 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005628 if (unlikely(!p))
5629 goto out_overflow;
5630 p = xdr_decode_hyper(p, &res->range.offset);
5631 p = xdr_decode_hyper(p, &res->range.length);
5632 res->range.iomode = be32_to_cpup(p++);
5633 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005634 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005635
5636 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5637 __func__,
5638 (unsigned long)res->range.offset,
5639 (unsigned long)res->range.length,
5640 res->range.iomode,
5641 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005642 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005643
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005644 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5645 recvd = req->rq_rcv_buf.len - hdrlen;
5646 if (res->layoutp->len > recvd) {
5647 dprintk("NFS: server cheating in layoutget reply: "
5648 "layout len %u > recvd %u\n",
5649 res->layoutp->len, recvd);
5650 return -EINVAL;
5651 }
5652
5653 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005654
5655 if (layout_count > 1) {
5656 /* We only handle a length one array at the moment. Any
5657 * further entries are just ignored. Note that this means
5658 * the client may see a response that is less than the
5659 * minimum it requested.
5660 */
5661 dprintk("%s: server responded with %d layouts, dropping tail\n",
5662 __func__, layout_count);
5663 }
5664
5665 return 0;
5666out_overflow:
5667 print_overflow_msg(__func__, xdr);
5668 return -EIO;
5669}
Andy Adamson863a3c62011-03-23 13:27:54 +00005670
Benny Halevycbe82602011-05-22 19:52:37 +03005671static int decode_layoutreturn(struct xdr_stream *xdr,
5672 struct nfs4_layoutreturn_res *res)
5673{
5674 __be32 *p;
5675 int status;
5676
5677 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5678 if (status)
5679 return status;
5680 p = xdr_inline_decode(xdr, 4);
5681 if (unlikely(!p))
5682 goto out_overflow;
5683 res->lrs_present = be32_to_cpup(p);
5684 if (res->lrs_present)
5685 status = decode_stateid(xdr, &res->stateid);
5686 return status;
5687out_overflow:
5688 print_overflow_msg(__func__, xdr);
5689 return -EIO;
5690}
5691
Andy Adamson863a3c62011-03-23 13:27:54 +00005692static int decode_layoutcommit(struct xdr_stream *xdr,
5693 struct rpc_rqst *req,
5694 struct nfs4_layoutcommit_res *res)
5695{
5696 __be32 *p;
5697 __u32 sizechanged;
5698 int status;
5699
5700 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005701 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005702 if (status)
5703 return status;
5704
5705 p = xdr_inline_decode(xdr, 4);
5706 if (unlikely(!p))
5707 goto out_overflow;
5708 sizechanged = be32_to_cpup(p);
5709
5710 if (sizechanged) {
5711 /* throw away new size */
5712 p = xdr_inline_decode(xdr, 8);
5713 if (unlikely(!p))
5714 goto out_overflow;
5715 }
5716 return 0;
5717out_overflow:
5718 print_overflow_msg(__func__, xdr);
5719 return -EIO;
5720}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005721
5722static int decode_test_stateid(struct xdr_stream *xdr,
5723 struct nfs41_test_stateid_res *res)
5724{
5725 __be32 *p;
5726 int status;
5727 int num_res;
5728
5729 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5730 if (status)
5731 return status;
5732
5733 p = xdr_inline_decode(xdr, 4);
5734 if (unlikely(!p))
5735 goto out_overflow;
5736 num_res = be32_to_cpup(p++);
5737 if (num_res != 1)
5738 goto out;
5739
5740 p = xdr_inline_decode(xdr, 4);
5741 if (unlikely(!p))
5742 goto out_overflow;
5743 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005744
5745 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005746out_overflow:
5747 print_overflow_msg(__func__, xdr);
5748out:
5749 return -EIO;
5750}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005751
5752static int decode_free_stateid(struct xdr_stream *xdr,
5753 struct nfs41_free_stateid_res *res)
5754{
5755 __be32 *p;
5756 int status;
5757
5758 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5759 if (status)
5760 return status;
5761
5762 p = xdr_inline_decode(xdr, 4);
5763 if (unlikely(!p))
5764 goto out_overflow;
5765 res->status = be32_to_cpup(p++);
5766 return res->status;
5767out_overflow:
5768 print_overflow_msg(__func__, xdr);
5769 return -EIO;
5770}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005771#endif /* CONFIG_NFS_V4_1 */
5772
Linus Torvalds1da177e2005-04-16 15:20:36 -07005773/*
Benny Halevy49c25592008-12-23 16:06:16 -05005774 * END OF "GENERIC" DECODE ROUTINES.
5775 */
5776
5777/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005778 * Decode OPEN_DOWNGRADE response
5779 */
Chuck Leverbf269552010-12-14 14:59:29 +00005780static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5781 struct xdr_stream *xdr,
5782 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005783{
Andy Adamson05d564f2008-12-23 16:06:15 -05005784 struct compound_hdr hdr;
5785 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005786
Chuck Leverbf269552010-12-14 14:59:29 +00005787 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005788 if (status)
5789 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005790 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005791 if (status)
5792 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005793 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005794 if (status)
5795 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005796 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005797 if (status != 0)
5798 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005799 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005800out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005801 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005802}
5803
5804/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005805 * Decode ACCESS response
5806 */
Chuck Leverbf269552010-12-14 14:59:29 +00005807static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5808 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005809{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005810 struct compound_hdr hdr;
5811 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005812
Chuck Leverbf269552010-12-14 14:59:29 +00005813 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005814 if (status)
5815 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005816 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005817 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005818 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005819 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005820 if (status != 0)
5821 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005822 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005823 if (status != 0)
5824 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005825 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005826out:
5827 return status;
5828}
5829
5830/*
5831 * Decode LOOKUP response
5832 */
Chuck Leverbf269552010-12-14 14:59:29 +00005833static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5834 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005835{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836 struct compound_hdr hdr;
5837 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005838
Chuck Leverbf269552010-12-14 14:59:29 +00005839 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005840 if (status)
5841 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005842 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005843 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005845 status = decode_putfh(xdr);
5846 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005847 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005848 status = decode_lookup(xdr);
5849 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005851 status = decode_getfh(xdr, res->fh);
5852 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005853 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005854 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005855out:
5856 return status;
5857}
5858
5859/*
5860 * Decode LOOKUP_ROOT response
5861 */
Chuck Leverbf269552010-12-14 14:59:29 +00005862static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5863 struct xdr_stream *xdr,
5864 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005865{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005866 struct compound_hdr hdr;
5867 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005868
Chuck Leverbf269552010-12-14 14:59:29 +00005869 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005870 if (status)
5871 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005872 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005873 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005874 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005875 status = decode_putrootfh(xdr);
5876 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005878 status = decode_getfh(xdr, res->fh);
5879 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005880 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005881out:
5882 return status;
5883}
5884
5885/*
5886 * Decode REMOVE response
5887 */
Chuck Leverbf269552010-12-14 14:59:29 +00005888static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5889 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005890{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005891 struct compound_hdr hdr;
5892 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005893
Chuck Leverbf269552010-12-14 14:59:29 +00005894 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005895 if (status)
5896 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005897 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005898 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005899 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005900 status = decode_putfh(xdr);
5901 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005902 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005903 status = decode_remove(xdr, &res->cinfo);
5904 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005905 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005906 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005907out:
5908 return status;
5909}
5910
5911/*
5912 * Decode RENAME response
5913 */
Chuck Leverbf269552010-12-14 14:59:29 +00005914static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5915 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005916{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005917 struct compound_hdr hdr;
5918 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005919
Chuck Leverbf269552010-12-14 14:59:29 +00005920 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005921 if (status)
5922 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005923 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005924 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005925 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005926 status = decode_putfh(xdr);
5927 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005928 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005929 status = decode_savefh(xdr);
5930 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005932 status = decode_putfh(xdr);
5933 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005934 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005935 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5936 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005937 goto out;
5938 /* Current FH is target directory */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005939 if (decode_getfattr(xdr, res->new_fattr, res->server))
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005940 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005941 status = decode_restorefh(xdr);
5942 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005943 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005944 decode_getfattr(xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005945out:
5946 return status;
5947}
5948
5949/*
5950 * Decode LINK response
5951 */
Chuck Leverbf269552010-12-14 14:59:29 +00005952static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5953 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005955 struct compound_hdr hdr;
5956 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005957
Chuck Leverbf269552010-12-14 14:59:29 +00005958 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005959 if (status)
5960 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005961 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005962 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005964 status = decode_putfh(xdr);
5965 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005966 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005967 status = decode_savefh(xdr);
5968 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005970 status = decode_putfh(xdr);
5971 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005973 status = decode_link(xdr, &res->cinfo);
5974 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005975 goto out;
5976 /*
5977 * Note order: OP_LINK leaves the directory as the current
5978 * filehandle.
5979 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005980 if (decode_getfattr(xdr, res->dir_attr, res->server))
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005981 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005982 status = decode_restorefh(xdr);
5983 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005984 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005985 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005986out:
5987 return status;
5988}
5989
5990/*
5991 * Decode CREATE response
5992 */
Chuck Leverbf269552010-12-14 14:59:29 +00005993static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5994 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005995{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005996 struct compound_hdr hdr;
5997 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005998
Chuck Leverbf269552010-12-14 14:59:29 +00005999 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006000 if (status)
6001 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006002 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006003 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006004 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006005 status = decode_putfh(xdr);
6006 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006007 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006008 status = decode_savefh(xdr);
6009 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006010 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006011 status = decode_create(xdr, &res->dir_cinfo);
6012 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006014 status = decode_getfh(xdr, res->fh);
6015 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006016 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006017 if (decode_getfattr(xdr, res->fattr, res->server))
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006018 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006019 status = decode_restorefh(xdr);
6020 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006021 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006022 decode_getfattr(xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006023out:
6024 return status;
6025}
6026
6027/*
6028 * Decode SYMLINK response
6029 */
Chuck Leverbf269552010-12-14 14:59:29 +00006030static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6031 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006032{
Chuck Leverbf269552010-12-14 14:59:29 +00006033 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006034}
6035
6036/*
6037 * Decode GETATTR response
6038 */
Chuck Leverbf269552010-12-14 14:59:29 +00006039static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6040 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006041{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006042 struct compound_hdr hdr;
6043 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006044
Chuck Leverbf269552010-12-14 14:59:29 +00006045 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006046 if (status)
6047 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006048 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006049 if (status)
6050 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006051 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006052 if (status)
6053 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006054 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006055out:
6056 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006057}
6058
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006059/*
6060 * Encode an SETACL request
6061 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006062static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6063 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006064{
Andy Adamson05d564f2008-12-23 16:06:15 -05006065 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006066 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006067 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006068
Chuck Lever9f06c712010-12-14 14:59:18 +00006069 encode_compound_hdr(xdr, req, &hdr);
6070 encode_sequence(xdr, &args->seq_args, &hdr);
6071 encode_putfh(xdr, args->fh, &hdr);
6072 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006073 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006074}
Andy Adamson05d564f2008-12-23 16:06:15 -05006075
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006076/*
6077 * Decode SETACL response
6078 */
6079static int
Chuck Leverbf269552010-12-14 14:59:29 +00006080nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006081 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006082{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006083 struct compound_hdr hdr;
6084 int status;
6085
Chuck Leverbf269552010-12-14 14:59:29 +00006086 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006087 if (status)
6088 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006089 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006090 if (status)
6091 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006092 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006093 if (status)
6094 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006095 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006096out:
6097 return status;
6098}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006099
6100/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006101 * Decode GETACL response
6102 */
6103static int
Chuck Leverbf269552010-12-14 14:59:29 +00006104nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006105 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006106{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006107 struct compound_hdr hdr;
6108 int status;
6109
Chuck Leverbf269552010-12-14 14:59:29 +00006110 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006111 if (status)
6112 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006113 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006114 if (status)
6115 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006116 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006117 if (status)
6118 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006119 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006120
6121out:
6122 return status;
6123}
6124
6125/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006126 * Decode CLOSE response
6127 */
Chuck Leverbf269552010-12-14 14:59:29 +00006128static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6129 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006130{
Andy Adamson05d564f2008-12-23 16:06:15 -05006131 struct compound_hdr hdr;
6132 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133
Chuck Leverbf269552010-12-14 14:59:29 +00006134 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006135 if (status)
6136 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006137 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006138 if (status)
6139 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006140 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006141 if (status)
6142 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006143 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006144 if (status != 0)
6145 goto out;
6146 /*
6147 * Note: Server may do delete on close for this file
6148 * in which case the getattr call will fail with
6149 * an ESTALE error. Shouldn't be a problem,
6150 * though, since fattr->valid will remain unset.
6151 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006152 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006153out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006154 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155}
6156
6157/*
6158 * Decode OPEN response
6159 */
Chuck Leverbf269552010-12-14 14:59:29 +00006160static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6161 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006162{
Andy Adamson05d564f2008-12-23 16:06:15 -05006163 struct compound_hdr hdr;
6164 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006165
Chuck Leverbf269552010-12-14 14:59:29 +00006166 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006167 if (status)
6168 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006169 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006170 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_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006176 if (status)
6177 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006178 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006179 if (status)
6180 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006181 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006183 if (decode_getfattr(xdr, res->f_attr, res->server) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006184 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006185 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006186 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006187 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006189 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006190}
6191
6192/*
6193 * Decode OPEN_CONFIRM response
6194 */
Chuck Leverbf269552010-12-14 14:59:29 +00006195static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6196 struct xdr_stream *xdr,
6197 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198{
Andy Adamson05d564f2008-12-23 16:06:15 -05006199 struct compound_hdr hdr;
6200 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006201
Chuck Leverbf269552010-12-14 14:59:29 +00006202 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006203 if (status)
6204 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006205 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006206 if (status)
6207 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006208 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006210 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006211}
6212
6213/*
6214 * Decode OPEN response
6215 */
Chuck Leverbf269552010-12-14 14:59:29 +00006216static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6217 struct xdr_stream *xdr,
6218 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219{
Andy Adamson05d564f2008-12-23 16:06:15 -05006220 struct compound_hdr hdr;
6221 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006222
Chuck Leverbf269552010-12-14 14:59:29 +00006223 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006224 if (status)
6225 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006226 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006227 if (status)
6228 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006229 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006230 if (status)
6231 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006232 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006233 if (status)
6234 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006235 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006236out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006237 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238}
6239
6240/*
6241 * Decode SETATTR response
6242 */
Chuck Leverbf269552010-12-14 14:59:29 +00006243static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6244 struct xdr_stream *xdr,
6245 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246{
Andy Adamson05d564f2008-12-23 16:06:15 -05006247 struct compound_hdr hdr;
6248 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006249
Chuck Leverbf269552010-12-14 14:59:29 +00006250 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006251 if (status)
6252 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006253 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006254 if (status)
6255 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006256 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006257 if (status)
6258 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006259 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006260 if (status)
6261 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006262 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006263out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006264 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006265}
6266
6267/*
6268 * Decode LOCK response
6269 */
Chuck Leverbf269552010-12-14 14:59:29 +00006270static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6271 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006272{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273 struct compound_hdr hdr;
6274 int status;
6275
Chuck Leverbf269552010-12-14 14:59:29 +00006276 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277 if (status)
6278 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006279 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006280 if (status)
6281 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006282 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006283 if (status)
6284 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006285 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006286out:
6287 return status;
6288}
6289
6290/*
6291 * Decode LOCKT response
6292 */
Chuck Leverbf269552010-12-14 14:59:29 +00006293static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6294 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006296 struct compound_hdr hdr;
6297 int status;
6298
Chuck Leverbf269552010-12-14 14:59:29 +00006299 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006300 if (status)
6301 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006302 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006303 if (status)
6304 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006305 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306 if (status)
6307 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006308 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006309out:
6310 return status;
6311}
6312
6313/*
6314 * Decode LOCKU response
6315 */
Chuck Leverbf269552010-12-14 14:59:29 +00006316static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6317 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006318{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006319 struct compound_hdr hdr;
6320 int status;
6321
Chuck Leverbf269552010-12-14 14:59:29 +00006322 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323 if (status)
6324 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006326 if (status)
6327 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006328 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006329 if (status)
6330 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006331 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332out:
6333 return status;
6334}
6335
Chuck Leverbf269552010-12-14 14:59:29 +00006336static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6337 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006338{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006339 struct compound_hdr hdr;
6340 int status;
6341
Chuck Leverbf269552010-12-14 14:59:29 +00006342 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006343 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006344 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006345 return status;
6346}
6347
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348/*
6349 * Decode READLINK response
6350 */
Chuck Leverbf269552010-12-14 14:59:29 +00006351static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6352 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006353 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006355 struct compound_hdr hdr;
6356 int status;
6357
Chuck Leverbf269552010-12-14 14:59:29 +00006358 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359 if (status)
6360 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006361 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006362 if (status)
6363 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006365 if (status)
6366 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368out:
6369 return status;
6370}
6371
6372/*
6373 * Decode READDIR response
6374 */
Chuck Leverbf269552010-12-14 14:59:29 +00006375static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6376 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378 struct compound_hdr hdr;
6379 int status;
6380
Chuck Leverbf269552010-12-14 14:59:29 +00006381 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006382 if (status)
6383 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006384 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006385 if (status)
6386 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006387 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006388 if (status)
6389 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006390 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391out:
6392 return status;
6393}
6394
6395/*
6396 * Decode Read response
6397 */
Chuck Leverbf269552010-12-14 14:59:29 +00006398static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6399 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006401 struct compound_hdr hdr;
6402 int status;
6403
Chuck Leverbf269552010-12-14 14:59:29 +00006404 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006405 if (status)
6406 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006407 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006408 if (status)
6409 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411 if (status)
6412 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006413 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006414 if (!status)
6415 status = res->count;
6416out:
6417 return status;
6418}
6419
6420/*
6421 * Decode WRITE response
6422 */
Chuck Leverbf269552010-12-14 14:59:29 +00006423static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6424 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006425{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426 struct compound_hdr hdr;
6427 int status;
6428
Chuck Leverbf269552010-12-14 14:59:29 +00006429 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006430 if (status)
6431 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006432 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006433 if (status)
6434 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006435 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006436 if (status)
6437 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006438 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006439 if (status)
6440 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006441 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006442 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443 if (!status)
6444 status = res->count;
6445out:
6446 return status;
6447}
6448
6449/*
6450 * Decode COMMIT response
6451 */
Chuck Leverbf269552010-12-14 14:59:29 +00006452static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6453 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006455 struct compound_hdr hdr;
6456 int status;
6457
Chuck Leverbf269552010-12-14 14:59:29 +00006458 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006459 if (status)
6460 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006461 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006462 if (status)
6463 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006464 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465 if (status)
6466 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006467 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006468 if (status)
6469 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006470 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006471 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472out:
6473 return status;
6474}
6475
6476/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006477 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006478 */
Chuck Leverbf269552010-12-14 14:59:29 +00006479static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006480 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006481{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482 struct compound_hdr hdr;
6483 int status;
6484
Chuck Leverbf269552010-12-14 14:59:29 +00006485 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006486 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006487 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006488 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006489 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006491 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006492 return status;
6493}
6494
6495/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006496 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497 */
Chuck Leverbf269552010-12-14 14:59:29 +00006498static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006499 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006500{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006501 struct compound_hdr hdr;
6502 int status;
6503
Chuck Leverbf269552010-12-14 14:59:29 +00006504 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006505 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006506 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006507 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006508 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006509 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006510 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006511 return status;
6512}
6513
6514/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006515 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516 */
Chuck Leverbf269552010-12-14 14:59:29 +00006517static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006518 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006519{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520 struct compound_hdr hdr;
6521 int status;
6522
Chuck Leverbf269552010-12-14 14:59:29 +00006523 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006525 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006526 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006527 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006528 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006529 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530 return status;
6531}
6532
6533/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006534 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535 */
Chuck Leverbf269552010-12-14 14:59:29 +00006536static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6537 struct xdr_stream *xdr,
6538 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006540 struct compound_hdr hdr;
6541 int status;
6542
Chuck Leverbf269552010-12-14 14:59:29 +00006543 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006544 if (status)
6545 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006546 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006547 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006549 status = decode_putfh(xdr);
6550 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006552 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006553out:
6554 return status;
6555}
6556
6557/*
6558 * Decode RENEW response
6559 */
Chuck Leverbf269552010-12-14 14:59:29 +00006560static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6561 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006562{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006563 struct compound_hdr hdr;
6564 int status;
6565
Chuck Leverbf269552010-12-14 14:59:29 +00006566 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006567 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006568 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006569 return status;
6570}
6571
6572/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006573 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574 */
Chuck Leverbf269552010-12-14 14:59:29 +00006575static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6576 struct xdr_stream *xdr,
6577 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006578{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006579 struct compound_hdr hdr;
6580 int status;
6581
Chuck Leverbf269552010-12-14 14:59:29 +00006582 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006584 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006585 return status;
6586}
6587
6588/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006589 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006590 */
Chuck Leverbf269552010-12-14 14:59:29 +00006591static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6592 struct xdr_stream *xdr,
6593 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006594{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595 struct compound_hdr hdr;
6596 int status;
6597
Chuck Leverbf269552010-12-14 14:59:29 +00006598 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006599 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006600 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006601 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006602 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006603 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006604 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006605 return status;
6606}
6607
6608/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006609 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006610 */
Chuck Leverbf269552010-12-14 14:59:29 +00006611static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6612 struct xdr_stream *xdr,
6613 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006614{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006615 struct compound_hdr hdr;
6616 int status;
6617
Chuck Leverbf269552010-12-14 14:59:29 +00006618 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006619 if (status)
6620 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006621 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006622 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006623 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006624 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006625 if (status != 0)
6626 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006627 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006628 if (status != 0)
6629 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006630 decode_getfattr(xdr, res->fattr, res->server);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006631out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006632 return status;
6633}
6634
Trond Myklebust683b57b2006-06-09 09:34:22 -04006635/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006636 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006637 */
Chuck Leverbf269552010-12-14 14:59:29 +00006638static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6639 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006640 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006641{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006642 struct compound_hdr hdr;
6643 int status;
6644
Chuck Leverbf269552010-12-14 14:59:29 +00006645 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006646 if (status)
6647 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006648 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006649 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006650 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006651 status = decode_putfh(xdr);
6652 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006653 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006654 status = decode_lookup(xdr);
6655 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006656 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006657 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006658 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6659 NULL, res->fs_locations,
6660 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006661out:
6662 return status;
6663}
6664
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006665/*
6666 * Decode SECINFO response
6667 */
6668static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6669 struct xdr_stream *xdr,
6670 struct nfs4_secinfo_res *res)
6671{
6672 struct compound_hdr hdr;
6673 int status;
6674
6675 status = decode_compound_hdr(xdr, &hdr);
6676 if (status)
6677 goto out;
6678 status = decode_sequence(xdr, &res->seq_res, rqstp);
6679 if (status)
6680 goto out;
6681 status = decode_putfh(xdr);
6682 if (status)
6683 goto out;
6684 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006685out:
6686 return status;
6687}
6688
Benny Halevy99fe60d2009-04-01 09:22:29 -04006689#if defined(CONFIG_NFS_V4_1)
6690/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006691 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006692 */
Chuck Leverbf269552010-12-14 14:59:29 +00006693static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6694 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006695 void *res)
6696{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006697 struct compound_hdr hdr;
6698 int status;
6699
Chuck Leverbf269552010-12-14 14:59:29 +00006700 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006701 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006702 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006703 return status;
6704}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006705
6706/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006707 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006708 */
Chuck Leverbf269552010-12-14 14:59:29 +00006709static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6710 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006711 struct nfs41_create_session_res *res)
6712{
Andy Adamsonfc931582009-04-01 09:22:31 -04006713 struct compound_hdr hdr;
6714 int status;
6715
Chuck Leverbf269552010-12-14 14:59:29 +00006716 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006717 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006718 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006719 return status;
6720}
6721
6722/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006723 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006724 */
Chuck Leverbf269552010-12-14 14:59:29 +00006725static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6726 struct xdr_stream *xdr,
6727 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006728{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006729 struct compound_hdr hdr;
6730 int status;
6731
Chuck Leverbf269552010-12-14 14:59:29 +00006732 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006733 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006734 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006735 return status;
6736}
6737
6738/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006739 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006740 */
Chuck Leverbf269552010-12-14 14:59:29 +00006741static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6742 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006743 struct nfs4_sequence_res *res)
6744{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006745 struct compound_hdr hdr;
6746 int status;
6747
Chuck Leverbf269552010-12-14 14:59:29 +00006748 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006749 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006750 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006751 return status;
6752}
6753
6754/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006755 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006756 */
Chuck Leverbf269552010-12-14 14:59:29 +00006757static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6758 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006759 struct nfs4_get_lease_time_res *res)
6760{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006761 struct compound_hdr hdr;
6762 int status;
6763
Chuck Leverbf269552010-12-14 14:59:29 +00006764 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006765 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006766 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006767 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006768 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006769 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006770 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006771 return status;
6772}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006773
6774/*
6775 * Decode RECLAIM_COMPLETE response
6776 */
Chuck Leverbf269552010-12-14 14:59:29 +00006777static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6778 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006779 struct nfs41_reclaim_complete_res *res)
6780{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006781 struct compound_hdr hdr;
6782 int status;
6783
Chuck Leverbf269552010-12-14 14:59:29 +00006784 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006785 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006786 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006787 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006788 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006789 return status;
6790}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006791
6792/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006793 * Decode GETDEVICELIST response
6794 */
6795static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6796 struct xdr_stream *xdr,
6797 struct nfs4_getdevicelist_res *res)
6798{
6799 struct compound_hdr hdr;
6800 int status;
6801
6802 dprintk("encoding getdevicelist!\n");
6803
6804 status = decode_compound_hdr(xdr, &hdr);
6805 if (status != 0)
6806 goto out;
6807 status = decode_sequence(xdr, &res->seq_res, rqstp);
6808 if (status != 0)
6809 goto out;
6810 status = decode_putfh(xdr);
6811 if (status != 0)
6812 goto out;
6813 status = decode_getdevicelist(xdr, res->devlist);
6814out:
6815 return status;
6816}
6817
6818/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006819 * Decode GETDEVINFO response
6820 */
Chuck Leverbf269552010-12-14 14:59:29 +00006821static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6822 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006823 struct nfs4_getdeviceinfo_res *res)
6824{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006825 struct compound_hdr hdr;
6826 int status;
6827
Chuck Leverbf269552010-12-14 14:59:29 +00006828 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006829 if (status != 0)
6830 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006831 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006832 if (status != 0)
6833 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006834 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006835out:
6836 return status;
6837}
6838
6839/*
6840 * Decode LAYOUTGET response
6841 */
Chuck Leverbf269552010-12-14 14:59:29 +00006842static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6843 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006844 struct nfs4_layoutget_res *res)
6845{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006846 struct compound_hdr hdr;
6847 int status;
6848
Chuck Leverbf269552010-12-14 14:59:29 +00006849 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006850 if (status)
6851 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006852 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006853 if (status)
6854 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006855 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006856 if (status)
6857 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006858 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006859out:
6860 return status;
6861}
Andy Adamson863a3c62011-03-23 13:27:54 +00006862
6863/*
Benny Halevycbe82602011-05-22 19:52:37 +03006864 * Decode LAYOUTRETURN response
6865 */
6866static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6867 struct xdr_stream *xdr,
6868 struct nfs4_layoutreturn_res *res)
6869{
6870 struct compound_hdr hdr;
6871 int status;
6872
6873 status = decode_compound_hdr(xdr, &hdr);
6874 if (status)
6875 goto out;
6876 status = decode_sequence(xdr, &res->seq_res, rqstp);
6877 if (status)
6878 goto out;
6879 status = decode_putfh(xdr);
6880 if (status)
6881 goto out;
6882 status = decode_layoutreturn(xdr, res);
6883out:
6884 return status;
6885}
6886
6887/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006888 * Decode LAYOUTCOMMIT response
6889 */
6890static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6891 struct xdr_stream *xdr,
6892 struct nfs4_layoutcommit_res *res)
6893{
6894 struct compound_hdr hdr;
6895 int status;
6896
6897 status = decode_compound_hdr(xdr, &hdr);
6898 if (status)
6899 goto out;
6900 status = decode_sequence(xdr, &res->seq_res, rqstp);
6901 if (status)
6902 goto out;
6903 status = decode_putfh(xdr);
6904 if (status)
6905 goto out;
6906 status = decode_layoutcommit(xdr, rqstp, res);
6907 if (status)
6908 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006909 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006910out:
6911 return status;
6912}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006913
6914/*
6915 * Decode SECINFO_NO_NAME response
6916 */
6917static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6918 struct xdr_stream *xdr,
6919 struct nfs4_secinfo_res *res)
6920{
6921 struct compound_hdr hdr;
6922 int status;
6923
6924 status = decode_compound_hdr(xdr, &hdr);
6925 if (status)
6926 goto out;
6927 status = decode_sequence(xdr, &res->seq_res, rqstp);
6928 if (status)
6929 goto out;
6930 status = decode_putrootfh(xdr);
6931 if (status)
6932 goto out;
6933 status = decode_secinfo(xdr, res);
6934out:
6935 return status;
6936}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006937
6938/*
6939 * Decode TEST_STATEID response
6940 */
6941static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6942 struct xdr_stream *xdr,
6943 struct nfs41_test_stateid_res *res)
6944{
6945 struct compound_hdr hdr;
6946 int status;
6947
6948 status = decode_compound_hdr(xdr, &hdr);
6949 if (status)
6950 goto out;
6951 status = decode_sequence(xdr, &res->seq_res, rqstp);
6952 if (status)
6953 goto out;
6954 status = decode_test_stateid(xdr, res);
6955out:
6956 return status;
6957}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006958
6959/*
6960 * Decode FREE_STATEID response
6961 */
6962static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6963 struct xdr_stream *xdr,
6964 struct nfs41_free_stateid_res *res)
6965{
6966 struct compound_hdr hdr;
6967 int status;
6968
6969 status = decode_compound_hdr(xdr, &hdr);
6970 if (status)
6971 goto out;
6972 status = decode_sequence(xdr, &res->seq_res, rqstp);
6973 if (status)
6974 goto out;
6975 status = decode_free_stateid(xdr, res);
6976out:
6977 return status;
6978}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006979#endif /* CONFIG_NFS_V4_1 */
6980
Chuck Lever573c4e12010-12-14 14:58:11 +00006981/**
6982 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6983 * the local page cache.
6984 * @xdr: XDR stream where entry resides
6985 * @entry: buffer to fill in with entry data
6986 * @plus: boolean indicating whether this should be a readdirplus entry
6987 *
6988 * Returns zero if successful, otherwise a negative errno value is
6989 * returned.
6990 *
6991 * This function is not invoked during READDIR reply decoding, but
6992 * rather whenever an application invokes the getdents(2) system call
6993 * on a directory already in our cache.
6994 */
6995int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6996 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006997{
Fred Isamandae100c2011-07-30 20:52:37 -04006998 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07006999 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007000 __be32 *p = xdr_inline_decode(xdr, 4);
7001 if (unlikely(!p))
7002 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007003 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007004 p = xdr_inline_decode(xdr, 4);
7005 if (unlikely(!p))
7006 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007007 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007008 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007009 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007010 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007011 }
7012
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007013 p = xdr_inline_decode(xdr, 12);
7014 if (unlikely(!p))
7015 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007016 entry->prev_cookie = entry->cookie;
7017 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007018 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007019
Trond Myklebust9af8c222010-10-24 11:52:55 -04007020 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007021 if (unlikely(!p))
7022 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007023 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007024
7025 /*
7026 * In case the server doesn't return an inode number,
7027 * we fake one here. (We don't use inode number 0,
7028 * since glibc seems to choke on it...)
7029 */
7030 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007031 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007032
Trond Myklebust9af8c222010-10-24 11:52:55 -04007033 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007034 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007035
7036 if (decode_attr_length(xdr, &len, &p) < 0)
7037 goto out_overflow;
7038
Chuck Lever573c4e12010-12-14 14:58:11 +00007039 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007040 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007041 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007042 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7043 entry->ino = entry->fattr->mounted_on_fileid;
7044 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007045 entry->ino = entry->fattr->fileid;
7046
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007047 entry->d_type = DT_UNKNOWN;
7048 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7049 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7050
Chuck Lever573c4e12010-12-14 14:58:11 +00007051 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007052
7053out_overflow:
7054 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007055 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007056}
7057
7058/*
7059 * We need to translate between nfs status return values and
7060 * the local errno values which may not be the same.
7061 */
7062static struct {
7063 int stat;
7064 int errno;
7065} nfs_errtbl[] = {
7066 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007067 { NFS4ERR_PERM, -EPERM },
7068 { NFS4ERR_NOENT, -ENOENT },
7069 { NFS4ERR_IO, -errno_NFSERR_IO},
7070 { NFS4ERR_NXIO, -ENXIO },
7071 { NFS4ERR_ACCESS, -EACCES },
7072 { NFS4ERR_EXIST, -EEXIST },
7073 { NFS4ERR_XDEV, -EXDEV },
7074 { NFS4ERR_NOTDIR, -ENOTDIR },
7075 { NFS4ERR_ISDIR, -EISDIR },
7076 { NFS4ERR_INVAL, -EINVAL },
7077 { NFS4ERR_FBIG, -EFBIG },
7078 { NFS4ERR_NOSPC, -ENOSPC },
7079 { NFS4ERR_ROFS, -EROFS },
7080 { NFS4ERR_MLINK, -EMLINK },
7081 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7082 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7083 { NFS4ERR_DQUOT, -EDQUOT },
7084 { NFS4ERR_STALE, -ESTALE },
7085 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007086 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7087 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7088 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007089 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007090 { NFS4ERR_BADTYPE, -EBADTYPE },
7091 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007092 { NFS4ERR_SYMLINK, -ELOOP },
7093 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7094 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007095 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007096};
7097
7098/*
7099 * Convert an NFS error code to a local one.
7100 * This one is used jointly by NFSv2 and NFSv3.
7101 */
7102static int
David Howells0a8ea432006-08-22 20:06:08 -04007103nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007104{
7105 int i;
7106 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7107 if (nfs_errtbl[i].stat == stat)
7108 return nfs_errtbl[i].errno;
7109 }
7110 if (stat <= 10000 || stat > 10100) {
7111 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007112 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007113 }
7114 /* If we cannot translate the error, the recovery routines should
7115 * handle it.
7116 * Note: remaining NFSv4 error codes have values > 10000, so should
7117 * not conflict with native Linux error codes.
7118 */
Benny Halevy856dff32008-03-31 17:39:06 +03007119 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007120}
7121
Linus Torvalds1da177e2005-04-16 15:20:36 -07007122#define PROC(proc, argtype, restype) \
7123[NFSPROC4_CLNT_##proc] = { \
7124 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007125 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007126 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007127 .p_arglen = NFS4_##argtype##_sz, \
7128 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007129 .p_statidx = NFSPROC4_CLNT_##proc, \
7130 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007131}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007132
7133struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007134 PROC(READ, enc_read, dec_read),
7135 PROC(WRITE, enc_write, dec_write),
7136 PROC(COMMIT, enc_commit, dec_commit),
7137 PROC(OPEN, enc_open, dec_open),
7138 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7139 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7140 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7141 PROC(CLOSE, enc_close, dec_close),
7142 PROC(SETATTR, enc_setattr, dec_setattr),
7143 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7144 PROC(RENEW, enc_renew, dec_renew),
7145 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7146 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7147 PROC(LOCK, enc_lock, dec_lock),
7148 PROC(LOCKT, enc_lockt, dec_lockt),
7149 PROC(LOCKU, enc_locku, dec_locku),
7150 PROC(ACCESS, enc_access, dec_access),
7151 PROC(GETATTR, enc_getattr, dec_getattr),
7152 PROC(LOOKUP, enc_lookup, dec_lookup),
7153 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7154 PROC(REMOVE, enc_remove, dec_remove),
7155 PROC(RENAME, enc_rename, dec_rename),
7156 PROC(LINK, enc_link, dec_link),
7157 PROC(SYMLINK, enc_symlink, dec_symlink),
7158 PROC(CREATE, enc_create, dec_create),
7159 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7160 PROC(STATFS, enc_statfs, dec_statfs),
7161 PROC(READLINK, enc_readlink, dec_readlink),
7162 PROC(READDIR, enc_readdir, dec_readdir),
7163 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7164 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7165 PROC(GETACL, enc_getacl, dec_getacl),
7166 PROC(SETACL, enc_setacl, dec_setacl),
7167 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7168 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007169 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007170#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007171 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7172 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7173 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7174 PROC(SEQUENCE, enc_sequence, dec_sequence),
7175 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7176 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7177 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7178 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007179 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007180 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007181 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007182 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007183 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007184 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007185#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007186};
7187
Trond Myklebusta613fa12012-01-20 13:53:56 -05007188const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007189 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007190 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007191 .procs = nfs4_procedures
7192};
7193
7194/*
7195 * Local variables:
7196 * c-basic-offset: 8
7197 * End:
7198 */