blob: 9d328777b4c1dbbca7e4a7ade0090333a514782d [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>
Chuck Leverf0920752012-05-21 22:45:41 -040056
Trond Myklebust4ce79712005-06-22 17:16:21 +000057#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050058#include "internal.h"
Trond Myklebust76e697b2012-11-26 14:20:49 -050059#include "nfs4session.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040060#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040061#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63#define NFSDBG_FACILITY NFSDBG_XDR
64
65/* Mapping from NFS error code to "errno" error code. */
66#define errno_NFSERR_IO EIO
67
David Howells0a8ea432006-08-22 20:06:08 -040068static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
71#ifdef DEBUG
72#define NFS4_MAXTAGLEN 20
73#else
74#define NFS4_MAXTAGLEN 0
75#endif
76
Andy Adamson6c0195a2008-12-23 16:06:15 -050077/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040078 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040080#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050081#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040082#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85#define op_encode_hdr_maxsz (1)
86#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040087#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
90#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
92 (NFS4_FHSIZE >> 2))
93#define decode_putfh_maxsz (op_decode_hdr_maxsz)
94#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
95#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
96#define encode_getfh_maxsz (op_encode_hdr_maxsz)
97#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
98 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040099#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +0000100#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
102#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400103#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
104#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Andy Adamson88034c32012-05-23 05:02:34 -0400105/* We support only one layout type per file system */
106#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000107/* This is based on getfattr, which uses the most attributes: */
108#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400109 3 + 3 + 3 + nfs4_owner_maxsz + \
110 nfs4_group_maxsz + decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000111#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
112 nfs4_fattr_value_maxsz)
113#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400114#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
115 1 + 2 + 1 + \
116 nfs4_owner_maxsz + \
117 nfs4_group_maxsz + \
118 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#define encode_savefh_maxsz (op_encode_hdr_maxsz)
120#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400121#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
122#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200123#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400124/* The 5 accounts for the PNFS attributes, and assumes that at most three
125 * layout types will be returned.
126 */
127#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
128 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
130#define decode_renew_maxsz (op_decode_hdr_maxsz)
131#define encode_setclientid_maxsz \
132 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500133 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
134 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
135 1 /* sc_prog */ + \
136 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
137 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
138 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#define decode_setclientid_maxsz \
140 (op_decode_hdr_maxsz + \
141 2 + \
142 1024) /* large value for CLID_INUSE */
143#define encode_setclientid_confirm_maxsz \
144 (op_encode_hdr_maxsz + \
145 3 + (NFS4_VERIFIER_SIZE >> 2))
146#define decode_setclientid_confirm_maxsz \
147 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400148#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
149#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400150#define encode_share_access_maxsz \
151 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500152#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400153#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
154#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
155#define encode_open_maxsz (op_encode_hdr_maxsz + \
156 2 + encode_share_access_maxsz + 2 + \
157 open_owner_id_maxsz + \
158 encode_opentype_maxsz + \
159 encode_claim_null_maxsz)
160#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400161#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400162 decode_ace_maxsz)
163#define decode_change_info_maxsz (5)
164#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400165 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400166 decode_change_info_maxsz + 1 + \
167 nfs4_fattr_bitmap_maxsz + \
168 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400169#define encode_open_confirm_maxsz \
170 (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + 1)
172#define decode_open_confirm_maxsz \
173 (op_decode_hdr_maxsz + \
174 decode_stateid_maxsz)
175#define encode_open_downgrade_maxsz \
176 (op_encode_hdr_maxsz + \
177 encode_stateid_maxsz + 1 + \
178 encode_share_access_maxsz)
179#define decode_open_downgrade_maxsz \
180 (op_decode_hdr_maxsz + \
181 decode_stateid_maxsz)
182#define encode_close_maxsz (op_encode_hdr_maxsz + \
183 1 + encode_stateid_maxsz)
184#define decode_close_maxsz (op_decode_hdr_maxsz + \
185 decode_stateid_maxsz)
186#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + \
188 encode_attrs_maxsz)
189#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
190 nfs4_fattr_bitmap_maxsz)
191#define encode_read_maxsz (op_encode_hdr_maxsz + \
192 encode_stateid_maxsz + 3)
193#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
194#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
195 2 + encode_verifier_maxsz + 5)
196#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
197 decode_verifier_maxsz)
198#define encode_readlink_maxsz (op_encode_hdr_maxsz)
199#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
200#define encode_write_maxsz (op_encode_hdr_maxsz + \
201 encode_stateid_maxsz + 4)
202#define decode_write_maxsz (op_decode_hdr_maxsz + \
203 2 + decode_verifier_maxsz)
204#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
205#define decode_commit_maxsz (op_decode_hdr_maxsz + \
206 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#define encode_remove_maxsz (op_encode_hdr_maxsz + \
208 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400209#define decode_remove_maxsz (op_decode_hdr_maxsz + \
210 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211#define encode_rename_maxsz (op_encode_hdr_maxsz + \
212 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400213#define decode_rename_maxsz (op_decode_hdr_maxsz + \
214 decode_change_info_maxsz + \
215 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#define encode_link_maxsz (op_encode_hdr_maxsz + \
217 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400218#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400219#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400220#define encode_lock_maxsz (op_encode_hdr_maxsz + \
221 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400222 1 + encode_stateid_maxsz + 1 + \
223 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400224#define decode_lock_denied_maxsz \
225 (8 + decode_lockowner_maxsz)
226#define decode_lock_maxsz (op_decode_hdr_maxsz + \
227 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400228#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
229 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400230#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
231 decode_lock_denied_maxsz)
232#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
233 encode_stateid_maxsz + \
234 4)
235#define decode_locku_maxsz (op_decode_hdr_maxsz + \
236 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400237#define encode_release_lockowner_maxsz \
238 (op_encode_hdr_maxsz + \
239 encode_lockowner_maxsz)
240#define decode_release_lockowner_maxsz \
241 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400242#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
243#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
245 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400246 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000247 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
249#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400250 1 + 2 + nfs4_name_maxsz + \
251 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400252#define decode_create_maxsz (op_decode_hdr_maxsz + \
253 decode_change_info_maxsz + \
254 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400255#define encode_statfs_maxsz (encode_getattr_maxsz)
256#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
258#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400259#define encode_getacl_maxsz (encode_getattr_maxsz)
260#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
261 nfs4_fattr_bitmap_maxsz + 1)
262#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
263 encode_stateid_maxsz + 3)
264#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400265#define encode_fs_locations_maxsz \
266 (encode_getattr_maxsz)
267#define decode_fs_locations_maxsz \
268 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000269#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400270#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 -0400271
272#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400273#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500274#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
275 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400276
Benny Halevy99fe60d2009-04-01 09:22:29 -0400277#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
278 encode_verifier_maxsz + \
279 1 /* co_ownerid.len */ + \
280 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
281 1 /* flags */ + \
282 1 /* spa_how */ + \
283 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500284 1 /* implementation id array of size 1 */ + \
285 1 /* nii_domain */ + \
286 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
287 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500288 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500289 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400290#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
291 2 /* eir_clientid */ + \
292 1 /* eir_sequenceid */ + \
293 1 /* eir_flags */ + \
294 1 /* spr_how */ + \
295 0 /* SP4_NONE (for now) */ + \
296 2 /* eir_server_owner.so_minor_id */ + \
297 /* eir_server_owner.so_major_id<> */ \
298 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
299 /* eir_server_scope<> */ \
300 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
301 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500302 1 /* nii_domain */ + \
303 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
304 1 /* nii_name */ + \
305 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
306 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400307#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
308#define decode_channel_attrs_maxsz (6 + \
309 1 /* ca_rdma_ird.len */ + \
310 1 /* ca_rdma_ird */)
311#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
312 2 /* csa_clientid */ + \
313 1 /* csa_sequence */ + \
314 1 /* csa_flags */ + \
315 encode_channel_attrs_maxsz + \
316 encode_channel_attrs_maxsz + \
317 1 /* csa_cb_program */ + \
318 1 /* csa_sec_parms.len (1) */ + \
319 1 /* cb_secflavor (AUTH_SYS) */ + \
320 1 /* stamp */ + \
321 1 /* machinename.len */ + \
322 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
323 1 /* uid */ + \
324 1 /* gid */ + \
325 1 /* gids.len (0) */)
326#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
327 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
328 1 /* csr_sequence */ + \
329 1 /* csr_flags */ + \
330 decode_channel_attrs_maxsz + \
331 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400332#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
333 /* bctsa_sessid */ \
334 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
335 1 /* bctsa_dir */ + \
336 1 /* bctsa_use_conn_in_rdma_mode */)
337#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
338 /* bctsr_sessid */ \
339 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
340 1 /* bctsr_dir */ + \
341 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400342#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
343#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400344#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
345#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400346#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
347 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
348#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
349 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500350#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
351#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400352#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
353 encode_verifier_maxsz)
354#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
355 2 /* nfs_cookie4 gdlr_cookie */ + \
356 decode_verifier_maxsz \
357 /* verifier4 gdlr_verifier */ + \
358 1 /* gdlr_deviceid_list count */ + \
359 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
360 NFS4_DEVICEID4_SIZE) \
361 /* gdlr_deviceid_list */ + \
362 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400363#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
364 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
365#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
366 1 /* layout type */ + \
367 1 /* opaque devaddr4 length */ + \
368 /* devaddr4 payload is read into page */ \
369 1 /* notification bitmap length */ + \
370 1 /* notification bitmap */)
371#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
372 encode_stateid_maxsz)
373#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
374 decode_stateid_maxsz + \
375 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000376#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
377 2 /* offset */ + \
378 2 /* length */ + \
379 1 /* reclaim */ + \
380 encode_stateid_maxsz + \
381 1 /* new offset (true) */ + \
382 2 /* last byte written */ + \
383 1 /* nt_timechanged (false) */ + \
384 1 /* layoutupdate4 layout type */ + \
385 1 /* NULL filelayout layoutupdate4 payload */)
386#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300387#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
388 encode_stateid_maxsz + \
389 1 /* FIXME: opaque lrf_body always empty at the moment */)
390#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
391 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400392#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
393#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400394#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
395 XDR_QUADLEN(NFS4_STATEID_SIZE))
396#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400397#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
398 XDR_QUADLEN(NFS4_STATEID_SIZE))
399#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400400#else /* CONFIG_NFS_V4_1 */
401#define encode_sequence_maxsz 0
402#define decode_sequence_maxsz 0
403#endif /* CONFIG_NFS_V4_1 */
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
406#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
407#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400410 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400412 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400416 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400418 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400420 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400422 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400424 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400426 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400428 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400430 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400434 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400435 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400439 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400440 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400444 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400446 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400448 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400450 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400451 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400452 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400453 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400454 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400455 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400457 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400458 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400459 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400460 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400461 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400462 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400463#define NFS4_enc_open_confirm_sz \
464 (compound_encode_hdr_maxsz + \
465 encode_putfh_maxsz + \
466 encode_open_confirm_maxsz)
467#define NFS4_dec_open_confirm_sz \
468 (compound_decode_hdr_maxsz + \
469 decode_putfh_maxsz + \
470 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400472 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400474 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400475 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400478 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400480 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400481 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400482 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483#define NFS4_enc_open_downgrade_sz \
484 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400486 encode_putfh_maxsz + \
487 encode_open_downgrade_maxsz + \
488 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489#define NFS4_dec_open_downgrade_sz \
490 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400491 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400492 decode_putfh_maxsz + \
493 decode_open_downgrade_maxsz + \
494 decode_getattr_maxsz)
495#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400497 encode_putfh_maxsz + \
498 encode_close_maxsz + \
499 encode_getattr_maxsz)
500#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400501 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400502 decode_putfh_maxsz + \
503 decode_close_maxsz + \
504 decode_getattr_maxsz)
505#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400506 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400507 encode_putfh_maxsz + \
508 encode_setattr_maxsz + \
509 encode_getattr_maxsz)
510#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400511 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400512 decode_putfh_maxsz + \
513 decode_setattr_maxsz + \
514 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400516 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 encode_putfh_maxsz + \
518 encode_fsinfo_maxsz)
519#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 decode_putfh_maxsz + \
522 decode_fsinfo_maxsz)
523#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
524 encode_renew_maxsz)
525#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
526 decode_renew_maxsz)
527#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
528 encode_setclientid_maxsz)
529#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
530 decode_setclientid_maxsz)
531#define NFS4_enc_setclientid_confirm_sz \
532 (compound_encode_hdr_maxsz + \
533 encode_setclientid_confirm_maxsz + \
534 encode_putrootfh_maxsz + \
535 encode_fsinfo_maxsz)
536#define NFS4_dec_setclientid_confirm_sz \
537 (compound_decode_hdr_maxsz + \
538 decode_setclientid_confirm_maxsz + \
539 decode_putrootfh_maxsz + \
540 decode_fsinfo_maxsz)
541#define NFS4_enc_lock_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_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#define NFS4_dec_lock_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_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400550 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400552 encode_lockt_maxsz)
553#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400554 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400555 decode_putfh_maxsz + \
556 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400558 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400560 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400564 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400565#define NFS4_enc_release_lockowner_sz \
566 (compound_encode_hdr_maxsz + \
567 encode_lockowner_maxsz)
568#define NFS4_dec_release_lockowner_sz \
569 (compound_decode_hdr_maxsz + \
570 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400574 encode_access_maxsz + \
575 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400577 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400579 decode_access_maxsz + \
580 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 encode_putfh_maxsz + \
584 encode_getattr_maxsz)
585#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 decode_putfh_maxsz + \
588 decode_getattr_maxsz)
589#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 encode_putfh_maxsz + \
592 encode_lookup_maxsz + \
593 encode_getattr_maxsz + \
594 encode_getfh_maxsz)
595#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400598 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 decode_getattr_maxsz + \
600 decode_getfh_maxsz)
601#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400602 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 encode_putrootfh_maxsz + \
604 encode_getattr_maxsz + \
605 encode_getfh_maxsz)
606#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400607 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 decode_putrootfh_maxsz + \
609 decode_getattr_maxsz + \
610 decode_getfh_maxsz)
611#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400612 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400614 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400616 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400618 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400620 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 encode_putfh_maxsz + \
622 encode_savefh_maxsz + \
623 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400624 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400626 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 decode_putfh_maxsz + \
628 decode_savefh_maxsz + \
629 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400630 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400632 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 encode_putfh_maxsz + \
634 encode_savefh_maxsz + \
635 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400636 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400637 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400638 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400640 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 decode_putfh_maxsz + \
642 decode_savefh_maxsz + \
643 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400644 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400645 decode_restorefh_maxsz + \
646 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 encode_putfh_maxsz + \
650 encode_symlink_maxsz + \
651 encode_getattr_maxsz + \
652 encode_getfh_maxsz)
653#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 decode_putfh_maxsz + \
656 decode_symlink_maxsz + \
657 decode_getattr_maxsz + \
658 decode_getfh_maxsz)
659#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400660 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 encode_putfh_maxsz + \
662 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400663 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400664 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400666 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 decode_putfh_maxsz + \
668 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400669 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400670 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)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400741#define NFS4_enc_bind_conn_to_session_sz \
742 (compound_encode_hdr_maxsz + \
743 encode_bind_conn_to_session_maxsz)
744#define NFS4_dec_bind_conn_to_session_sz \
745 (compound_decode_hdr_maxsz + \
746 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400747#define NFS4_enc_exchange_id_sz \
748 (compound_encode_hdr_maxsz + \
749 encode_exchange_id_maxsz)
750#define NFS4_dec_exchange_id_sz \
751 (compound_decode_hdr_maxsz + \
752 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400753#define NFS4_enc_create_session_sz \
754 (compound_encode_hdr_maxsz + \
755 encode_create_session_maxsz)
756#define NFS4_dec_create_session_sz \
757 (compound_decode_hdr_maxsz + \
758 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400759#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
760 encode_destroy_session_maxsz)
761#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
762 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400763#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
764 encode_destroy_clientid_maxsz)
765#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
766 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400767#define NFS4_enc_sequence_sz \
768 (compound_decode_hdr_maxsz + \
769 encode_sequence_maxsz)
770#define NFS4_dec_sequence_sz \
771 (compound_decode_hdr_maxsz + \
772 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400773#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
774 encode_sequence_maxsz + \
775 encode_putrootfh_maxsz + \
776 encode_fsinfo_maxsz)
777#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
778 decode_sequence_maxsz + \
779 decode_putrootfh_maxsz + \
780 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500781#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
782 encode_sequence_maxsz + \
783 encode_reclaim_complete_maxsz)
784#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
785 decode_sequence_maxsz + \
786 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400787#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
788 encode_sequence_maxsz + \
789 encode_putfh_maxsz + \
790 encode_getdevicelist_maxsz)
791#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
792 decode_sequence_maxsz + \
793 decode_putfh_maxsz + \
794 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400795#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
796 encode_sequence_maxsz +\
797 encode_getdeviceinfo_maxsz)
798#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
799 decode_sequence_maxsz + \
800 decode_getdeviceinfo_maxsz)
801#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
802 encode_sequence_maxsz + \
803 encode_putfh_maxsz + \
804 encode_layoutget_maxsz)
805#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
806 decode_sequence_maxsz + \
807 decode_putfh_maxsz + \
808 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000809#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz +\
811 encode_putfh_maxsz + \
812 encode_layoutcommit_maxsz + \
813 encode_getattr_maxsz)
814#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
815 decode_sequence_maxsz + \
816 decode_putfh_maxsz + \
817 decode_layoutcommit_maxsz + \
818 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300819#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
820 encode_sequence_maxsz + \
821 encode_putfh_maxsz + \
822 encode_layoutreturn_maxsz)
823#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
824 decode_sequence_maxsz + \
825 decode_putfh_maxsz + \
826 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400827#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
828 encode_sequence_maxsz + \
829 encode_putrootfh_maxsz +\
830 encode_secinfo_no_name_maxsz)
831#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
832 decode_sequence_maxsz + \
833 decode_putrootfh_maxsz + \
834 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400835#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
836 encode_sequence_maxsz + \
837 encode_test_stateid_maxsz)
838#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
839 decode_sequence_maxsz + \
840 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400841#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
842 encode_sequence_maxsz + \
843 encode_free_stateid_maxsz)
844#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
845 decode_sequence_maxsz + \
846 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500847
848const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
849 compound_encode_hdr_maxsz +
850 encode_sequence_maxsz +
851 encode_putfh_maxsz +
852 encode_getattr_maxsz) *
853 XDR_UNIT);
854
855const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
856 compound_decode_hdr_maxsz +
857 decode_sequence_maxsz +
858 decode_putfh_maxsz) *
859 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400860#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Trond Myklebustbca79472009-03-11 14:10:26 -0400862static const umode_t nfs_type2fmt[] = {
863 [NF4BAD] = 0,
864 [NF4REG] = S_IFREG,
865 [NF4DIR] = S_IFDIR,
866 [NF4BLK] = S_IFBLK,
867 [NF4CHR] = S_IFCHR,
868 [NF4LNK] = S_IFLNK,
869 [NF4SOCK] = S_IFSOCK,
870 [NF4FIFO] = S_IFIFO,
871 [NF4ATTRDIR] = 0,
872 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873};
874
875struct compound_hdr {
876 int32_t status;
877 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500878 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 uint32_t taglen;
880 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400881 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400882 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883};
884
Benny Halevy13c65ce2009-08-14 17:19:25 +0300885static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
886{
887 __be32 *p = xdr_reserve_space(xdr, nbytes);
888 BUG_ON(!p);
889 return p;
890}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Trond Myklebustcb17e552012-03-04 18:13:56 -0500892static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
893{
894 __be32 *p;
895
896 p = xdr_reserve_space(xdr, len);
897 xdr_encode_opaque_fixed(p, buf, len);
898}
899
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
901{
Al Viro8687b632006-10-19 23:28:48 -0700902 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500904 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 xdr_encode_opaque(p, str, len);
906}
907
Trond Myklebust4ade9822012-03-04 18:13:57 -0500908static void encode_uint32(struct xdr_stream *xdr, u32 n)
909{
910 __be32 *p;
911
912 p = reserve_space(xdr, 4);
913 *p = cpu_to_be32(n);
914}
915
Trond Myklebustff2eb682012-03-05 11:40:12 -0500916static void encode_uint64(struct xdr_stream *xdr, u64 n)
917{
918 __be32 *p;
919
920 p = reserve_space(xdr, 8);
921 xdr_encode_hyper(p, n);
922}
923
Trond Myklebust4ade9822012-03-04 18:13:57 -0500924static void encode_nfs4_seqid(struct xdr_stream *xdr,
925 const struct nfs_seqid *seqid)
926{
927 encode_uint32(xdr, seqid->sequence->counter);
928}
929
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400930static void encode_compound_hdr(struct xdr_stream *xdr,
931 struct rpc_rqst *req,
932 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933{
Al Viro8687b632006-10-19 23:28:48 -0700934 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400935 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400936
937 /* initialize running count of expected bytes in reply.
938 * NOTE: the replied tag SHOULD be the same is the one sent,
939 * but this is not required as a MUST for the server to do so. */
940 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Trond Myklebust7fc38842012-10-15 11:51:21 -0400942 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500943 encode_string(xdr, hdr->taglen, hdr->tag);
944 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300945 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500946 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300947 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500948}
949
Trond Myklebustab19b482012-03-04 18:13:57 -0500950static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
951 uint32_t replen,
952 struct compound_hdr *hdr)
953{
954 encode_uint32(xdr, op);
955 hdr->nops++;
956 hdr->replen += replen;
957}
958
Andy Adamsond0179312008-12-23 16:06:17 -0500959static void encode_nops(struct compound_hdr *hdr)
960{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400961 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500962 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963}
964
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500965static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
966{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500967 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500968}
969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
971{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500972 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973}
974
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500975static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976{
977 char owner_name[IDMAP_NAMESZ];
978 char owner_group[IDMAP_NAMESZ];
979 int owner_namelen = 0;
980 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700981 __be32 *p;
982 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 int len;
984 uint32_t bmval0 = 0;
985 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
987 /*
988 * We reserve enough space to write the entire attribute buffer at once.
989 * In the worst-case, this would be
990 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
991 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000992 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 */
994 len = 16;
995
996 /* Sigh */
997 if (iap->ia_valid & ATTR_SIZE)
998 len += 8;
999 if (iap->ia_valid & ATTR_MODE)
1000 len += 4;
1001 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001002 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001004 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001005 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 /* XXX */
1007 strcpy(owner_name, "nobody");
1008 owner_namelen = sizeof("nobody") - 1;
1009 /* goto out; */
1010 }
1011 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1012 }
1013 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001014 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001016 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001017 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 strcpy(owner_group, "nobody");
1019 owner_grouplen = sizeof("nobody") - 1;
1020 /* goto out; */
1021 }
1022 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1023 }
1024 if (iap->ia_valid & ATTR_ATIME_SET)
1025 len += 16;
1026 else if (iap->ia_valid & ATTR_ATIME)
1027 len += 4;
1028 if (iap->ia_valid & ATTR_MTIME_SET)
1029 len += 16;
1030 else if (iap->ia_valid & ATTR_MTIME)
1031 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001032 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
1034 /*
1035 * We write the bitmap length now, but leave the bitmap and the attribute
1036 * buffer length to be backfilled at the end of this routine.
1037 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001038 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 q = p;
1040 p += 3;
1041
1042 if (iap->ia_valid & ATTR_SIZE) {
1043 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001044 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 }
1046 if (iap->ia_valid & ATTR_MODE) {
1047 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001048 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 }
1050 if (iap->ia_valid & ATTR_UID) {
1051 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001052 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
1054 if (iap->ia_valid & ATTR_GID) {
1055 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001056 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 }
1058 if (iap->ia_valid & ATTR_ATIME_SET) {
1059 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001060 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1061 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001062 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1063 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 }
1065 else if (iap->ia_valid & ATTR_ATIME) {
1066 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001067 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
1069 if (iap->ia_valid & ATTR_MTIME_SET) {
1070 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001071 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1072 *p++ = cpu_to_be32(0);
1073 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1074 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 }
1076 else if (iap->ia_valid & ATTR_MTIME) {
1077 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001078 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001080
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 /*
1082 * Now we backfill the bitmap and the attribute buffer length.
1083 */
1084 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001085 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 len, ((char *)p - (char *)q) + 4);
1087 BUG();
1088 }
1089 len = (char *)p - (char *)q - 12;
1090 *q++ = htonl(bmval0);
1091 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001092 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095}
1096
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001097static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001099 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1100 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101}
1102
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001103static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104{
Trond Myklebustab19b482012-03-04 18:13:57 -05001105 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001106 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001107 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108}
1109
Fred Isaman0b7c0152012-04-20 14:47:39 -04001110static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111{
Al Viro8687b632006-10-19 23:28:48 -07001112 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001113
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001114 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1115 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001116 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001117 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118}
1119
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001120static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121{
Al Viro8687b632006-10-19 23:28:48 -07001122 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001123
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001124 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1125 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
1127 switch (create->ftype) {
1128 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001129 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001130 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001131 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 break;
1133
1134 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001135 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001136 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001137 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 break;
1139
1140 default:
1141 break;
1142 }
1143
Benny Halevy811652b2009-08-14 17:19:34 +03001144 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001145 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146}
1147
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001148static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149{
Andy Adamson05d564f2008-12-23 16:06:15 -05001150 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001152 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1153 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001154 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001155 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156}
1157
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001158static 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 -07001159{
Andy Adamson05d564f2008-12-23 16:06:15 -05001160 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001162 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1163 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001164 *p++ = cpu_to_be32(2);
1165 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001166 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167}
1168
Fred Isamandae100c2011-07-30 20:52:37 -04001169static void
1170encode_getattr_three(struct xdr_stream *xdr,
1171 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1172 struct compound_hdr *hdr)
1173{
1174 __be32 *p;
1175
Trond Myklebustab19b482012-03-04 18:13:57 -05001176 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001177 if (bm2) {
1178 p = reserve_space(xdr, 16);
1179 *p++ = cpu_to_be32(3);
1180 *p++ = cpu_to_be32(bm0);
1181 *p++ = cpu_to_be32(bm1);
1182 *p = cpu_to_be32(bm2);
1183 } else if (bm1) {
1184 p = reserve_space(xdr, 12);
1185 *p++ = cpu_to_be32(2);
1186 *p++ = cpu_to_be32(bm0);
1187 *p = cpu_to_be32(bm1);
1188 } else {
1189 p = reserve_space(xdr, 8);
1190 *p++ = cpu_to_be32(1);
1191 *p = cpu_to_be32(bm0);
1192 }
Fred Isamandae100c2011-07-30 20:52:37 -04001193}
1194
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001195static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001197 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1198 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199}
1200
Andy Adamson88034c32012-05-23 05:02:34 -04001201static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001202 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001203 struct compound_hdr *hdr)
1204{
1205 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001206 bitmask[0] & open_bitmap[0],
1207 bitmask[1] & open_bitmap[1],
1208 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001209 hdr);
1210}
1211
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001212static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
Fred Isamandae100c2011-07-30 20:52:37 -04001214 encode_getattr_three(xdr,
1215 bitmask[0] & nfs4_fsinfo_bitmap[0],
1216 bitmask[1] & nfs4_fsinfo_bitmap[1],
1217 bitmask[2] & nfs4_fsinfo_bitmap[2],
1218 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219}
1220
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001221static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001222{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001223 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1224 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001225}
1226
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001227static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228{
Trond Myklebustab19b482012-03-04 18:13:57 -05001229 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230}
1231
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001232static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233{
Trond Myklebustab19b482012-03-04 18:13:57 -05001234 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001235 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236}
1237
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001238static inline int nfs4_lock_type(struct file_lock *fl, int block)
1239{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001240 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001241 return block ? NFS4_READW_LT : NFS4_READ_LT;
1242 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1243}
1244
1245static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1246{
1247 if (fl->fl_end == OFFSET_MAX)
1248 return ~(uint64_t)0;
1249 return fl->fl_end - fl->fl_start + 1;
1250}
1251
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001252static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1253{
1254 __be32 *p;
1255
Trond Myklebustd035c362010-12-21 10:45:27 -05001256 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001257 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001258 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001259 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001260 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001261 xdr_encode_hyper(p, lowner->id);
1262}
1263
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264/*
1265 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1266 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1267 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001268static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269{
Al Viro8687b632006-10-19 23:28:48 -07001270 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001272 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1273 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001274 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1275 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001276 p = xdr_encode_hyper(p, args->fl->fl_start);
1277 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001278 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001279 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001280 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001281 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001282 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001283 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 }
1285 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001286 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001287 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289}
1290
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001291static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
Al Viro8687b632006-10-19 23:28:48 -07001293 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001295 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1296 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001297 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001298 p = xdr_encode_hyper(p, args->fl->fl_start);
1299 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001300 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301}
1302
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001303static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304{
Al Viro8687b632006-10-19 23:28:48 -07001305 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001307 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1308 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001309 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001310 encode_nfs4_stateid(xdr, args->stateid);
1311 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001312 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001313 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314}
1315
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001316static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1317{
Trond Myklebustab19b482012-03-04 18:13:57 -05001318 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001319 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001320}
1321
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001322static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323{
Trond Myklebustab19b482012-03-04 18:13:57 -05001324 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001325 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326}
1327
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001328static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329{
Al Viro8687b632006-10-19 23:28:48 -07001330 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Benny Halevy13c65ce2009-08-14 17:19:25 +03001332 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001333 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001334 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001335 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001336 break;
1337 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001338 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001339 break;
1340 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001341 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001342 break;
1343 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001344 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 }
Benny Halevy34558512009-08-14 17:19:30 +03001346 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
1349static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1350{
Al Viro8687b632006-10-19 23:28:48 -07001351 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 /*
1353 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1354 * owner 4 = 32
1355 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001356 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001357 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001358 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001359 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001360 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001361 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001362 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001363 *p++ = cpu_to_be32(arg->id.uniquifier);
1364 xdr_encode_hyper(p, arg->id.create_time);
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:
Benny Halevy34558512009-08-14 17:19:30 +03001409 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001410 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 }
1412}
1413
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001414static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415{
Al Viro8687b632006-10-19 23:28:48 -07001416 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Benny Halevy13c65ce2009-08-14 17:19:25 +03001418 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001420 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001421 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001422 break;
1423 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001424 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001425 break;
1426 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001427 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001428 break;
1429 default:
1430 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 }
1432}
1433
1434static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1435{
Al Viro8687b632006-10-19 23:28:48 -07001436 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
Benny Halevy13c65ce2009-08-14 17:19:25 +03001438 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001439 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 encode_string(xdr, name->len, name->name);
1441}
1442
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001443static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
Al Viro8687b632006-10-19 23:28:48 -07001445 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Benny Halevy13c65ce2009-08-14 17:19:25 +03001447 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001448 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 encode_delegation_type(xdr, type);
1450}
1451
1452static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1453{
Al Viro8687b632006-10-19 23:28:48 -07001454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001456 p = reserve_space(xdr, 4);
1457 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1458 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 encode_string(xdr, name->len, name->name);
1460}
1461
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001462static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463{
Trond Myklebustab19b482012-03-04 18:13:57 -05001464 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480}
1481
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001482static 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 -07001483{
Trond Myklebustab19b482012-03-04 18:13:57 -05001484 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001485 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001486 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487}
1488
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001489static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490{
Trond Myklebustab19b482012-03-04 18:13:57 -05001491 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001492 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001493 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001494 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495}
1496
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001497static void
Andy Adamsond0179312008-12-23 16:06:17 -05001498encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499{
Trond Myklebustab19b482012-03-04 18:13:57 -05001500 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001501 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502}
1503
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001504static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505{
Trond Myklebustab19b482012-03-04 18:13:57 -05001506 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507}
1508
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001509static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510{
Al Viro8687b632006-10-19 23:28:48 -07001511 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
Trond Myklebustab19b482012-03-04 18:13:57 -05001513 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001514 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
Benny Halevy13c65ce2009-08-14 17:19:25 +03001516 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001517 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001518 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519}
1520
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001521static 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 -07001522{
Trond Myklebust28331a42011-04-27 13:47:52 -04001523 uint32_t attrs[2] = {
1524 FATTR4_WORD0_RDATTR_ERROR,
1525 FATTR4_WORD1_MOUNTED_ON_FILEID,
1526 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001527 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001528 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001530 if (readdir->plus) {
1531 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001532 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001533 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1534 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1535 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1536 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001537 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001538 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001539 /* Use mounted_on_fileid only if the server supports it */
1540 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1541 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001542
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001543 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001544 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001545 encode_nfs4_verifier(xdr, &readdir->verifier);
1546 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001547 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001548 *p++ = cpu_to_be32(readdir->count);
1549 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001550
Benny Halevye75bc1c2009-08-14 17:18:54 +03001551 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001552 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Chuck Levercd937102012-03-02 17:14:31 -05001553 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001554 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1555 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001556 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001557 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001558 attrs[0] & readdir->bitmask[0],
1559 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560}
1561
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001562static 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 -07001563{
Trond Myklebustab19b482012-03-04 18:13:57 -05001564 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565}
1566
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001567static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568{
Trond Myklebustab19b482012-03-04 18:13:57 -05001569 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001570 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571}
1572
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001573static 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 -07001574{
Trond Myklebustab19b482012-03-04 18:13:57 -05001575 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001576 encode_string(xdr, oldname->len, oldname->name);
1577 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578}
1579
Chuck Leverbb4dae52012-03-01 17:01:48 -05001580static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1581 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001583 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001584 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585}
1586
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001587static void
Andy Adamsond0179312008-12-23 16:06:17 -05001588encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001589{
Trond Myklebustab19b482012-03-04 18:13:57 -05001590 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001591}
1592
Chuck Lever9f06c712010-12-14 14:59:18 +00001593static void
Andy Adamsond0179312008-12-23 16:06:17 -05001594encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001595{
Al Viro8687b632006-10-19 23:28:48 -07001596 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001597
Trond Myklebustab19b482012-03-04 18:13:57 -05001598 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001599 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001600 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001601 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001602 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001603 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001604 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001605 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001606}
1607
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001608static void
Andy Adamsond0179312008-12-23 16:06:17 -05001609encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610{
Trond Myklebustab19b482012-03-04 18:13:57 -05001611 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612}
1613
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001614static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615{
Trond Myklebustab19b482012-03-04 18:13:57 -05001616 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001617 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001618 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619}
1620
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001621static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622{
Al Viro8687b632006-10-19 23:28:48 -07001623 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
Trond Myklebust70019512012-03-04 20:49:32 -05001625 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001626 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
1628 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001629 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001630 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1632 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001633 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001634 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635}
1636
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001637static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001639 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1640 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001641 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001642 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643}
1644
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001645static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646{
Al Viro8687b632006-10-19 23:28:48 -07001647 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
Trond Myklebustab19b482012-03-04 18:13:57 -05001649 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001650 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
Benny Halevy13c65ce2009-08-14 17:19:25 +03001652 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001653 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001654 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001655 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
1657 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658}
1659
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001660static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
Trond Myklebustab19b482012-03-04 18:13:57 -05001662 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001663 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001665
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001666static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1667{
Trond Myklebustab19b482012-03-04 18:13:57 -05001668 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001669 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001670}
1671
Benny Halevy99fe60d2009-04-01 09:22:29 -04001672#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001673/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001674static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1675 struct nfs4_session *session,
1676 struct compound_hdr *hdr)
1677{
1678 __be32 *p;
1679
1680 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1681 decode_bind_conn_to_session_maxsz, hdr);
1682 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1683 p = xdr_reserve_space(xdr, 8);
1684 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1685 *p = 0; /* use_conn_in_rdma_mode = False */
1686}
1687
Benny Halevy99fe60d2009-04-01 09:22:29 -04001688static void encode_exchange_id(struct xdr_stream *xdr,
1689 struct nfs41_exchange_id_args *args,
1690 struct compound_hdr *hdr)
1691{
1692 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001693 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001694 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001695
Trond Myklebust70019512012-03-04 20:49:32 -05001696 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001697 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001698
1699 encode_string(xdr, args->id_len, args->id);
1700
Benny Halevy13c65ce2009-08-14 17:19:25 +03001701 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001702 *p++ = cpu_to_be32(args->flags);
1703 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001704
1705 if (send_implementation_id &&
1706 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1707 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001708 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001709 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1710 utsname()->sysname, utsname()->release,
1711 utsname()->version, utsname()->machine);
1712
1713 if (len > 0) {
1714 *p = cpu_to_be32(1); /* implementation id array length=1 */
1715
1716 encode_string(xdr,
1717 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1718 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1719 encode_string(xdr, len, impl_name);
1720 /* just send zeros for nii_date - the date is in nii_name */
1721 p = reserve_space(xdr, 12);
1722 p = xdr_encode_hyper(p, 0);
1723 *p = cpu_to_be32(0);
1724 } else
1725 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001726}
Andy Adamsonfc931582009-04-01 09:22:31 -04001727
1728static void encode_create_session(struct xdr_stream *xdr,
1729 struct nfs41_create_session_args *args,
1730 struct compound_hdr *hdr)
1731{
1732 __be32 *p;
1733 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1734 uint32_t len;
1735 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001736 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001737 u32 max_resp_sz_cached;
1738
1739 /*
1740 * Assumes OPEN is the biggest non-idempotent compound.
1741 * 2 is the verifier.
1742 */
1743 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1744 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001745
Andy Adamsonfc931582009-04-01 09:22:31 -04001746 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1747 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001748
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001749 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1750 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001751 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001752 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1753 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001754
Andy Adamsonfc931582009-04-01 09:22:31 -04001755 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001756 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001757 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1758 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001759 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001760 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1761 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1762 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001763
1764 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001765 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001766 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1767 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1768 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1769 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1770 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1771 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001772
Benny Halevye75bc1c2009-08-14 17:18:54 +03001773 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001774 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001775 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001776
1777 /* authsys_parms rfc1831 */
Chuck Leverf0920752012-05-21 22:45:41 -04001778 *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001779 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001780 *p++ = cpu_to_be32(0); /* UID */
1781 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001782 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001783}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001784
1785static void encode_destroy_session(struct xdr_stream *xdr,
1786 struct nfs4_session *session,
1787 struct compound_hdr *hdr)
1788{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001789 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1790 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001791}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001792
Trond Myklebust66245532012-05-25 17:18:09 -04001793static void encode_destroy_clientid(struct xdr_stream *xdr,
1794 uint64_t clientid,
1795 struct compound_hdr *hdr)
1796{
1797 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1798 encode_uint64(xdr, clientid);
1799}
1800
Ricardo Labiaga180197532009-12-05 16:08:40 -05001801static void encode_reclaim_complete(struct xdr_stream *xdr,
1802 struct nfs41_reclaim_complete_args *args,
1803 struct compound_hdr *hdr)
1804{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001805 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1806 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001807}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001808#endif /* CONFIG_NFS_V4_1 */
1809
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001810static void encode_sequence(struct xdr_stream *xdr,
1811 const struct nfs4_sequence_args *args,
1812 struct compound_hdr *hdr)
1813{
1814#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001815 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001816 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001817 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001818 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001819
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001820 if (slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001821 return;
1822
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001823 tp = slot->table;
1824 session = tp->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001825
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001826 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001827
1828 /*
1829 * Sessionid + seqid + slotid + max slotid + cache_this
1830 */
1831 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1832 "max_slotid=%d cache_this=%d\n",
1833 __func__,
1834 ((u32 *)session->sess_id.data)[0],
1835 ((u32 *)session->sess_id.data)[1],
1836 ((u32 *)session->sess_id.data)[2],
1837 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001838 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001839 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001840 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001841 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001842 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001843 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001844 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001845 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001846#endif /* CONFIG_NFS_V4_1 */
1847}
1848
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001849#ifdef CONFIG_NFS_V4_1
1850static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001851encode_getdevicelist(struct xdr_stream *xdr,
1852 const struct nfs4_getdevicelist_args *args,
1853 struct compound_hdr *hdr)
1854{
1855 __be32 *p;
1856 nfs4_verifier dummy = {
1857 .data = "dummmmmy",
1858 };
1859
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001860 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1861 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001862 *p++ = cpu_to_be32(args->layoutclass);
1863 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1864 xdr_encode_hyper(p, 0ULL); /* cookie */
1865 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001866}
1867
1868static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001869encode_getdeviceinfo(struct xdr_stream *xdr,
1870 const struct nfs4_getdeviceinfo_args *args,
1871 struct compound_hdr *hdr)
1872{
1873 __be32 *p;
1874
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001875 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1876 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001877 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1878 NFS4_DEVICEID4_SIZE);
1879 *p++ = cpu_to_be32(args->pdev->layout_type);
1880 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1881 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001882}
1883
1884static void
1885encode_layoutget(struct xdr_stream *xdr,
1886 const struct nfs4_layoutget_args *args,
1887 struct compound_hdr *hdr)
1888{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001889 __be32 *p;
1890
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001891 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1892 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001893 *p++ = cpu_to_be32(0); /* Signal layout available */
1894 *p++ = cpu_to_be32(args->type);
1895 *p++ = cpu_to_be32(args->range.iomode);
1896 p = xdr_encode_hyper(p, args->range.offset);
1897 p = xdr_encode_hyper(p, args->range.length);
1898 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001899 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001900 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001901
1902 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1903 __func__,
1904 args->type,
1905 args->range.iomode,
1906 (unsigned long)args->range.offset,
1907 (unsigned long)args->range.length,
1908 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001909}
Andy Adamson863a3c62011-03-23 13:27:54 +00001910
1911static int
1912encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001913 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001914 const struct nfs4_layoutcommit_args *args,
1915 struct compound_hdr *hdr)
1916{
1917 __be32 *p;
1918
1919 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1920 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1921
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001922 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1923 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001924 /* Only whole file layouts */
1925 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001926 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001927 *p = cpu_to_be32(0); /* reclaim */
1928 encode_nfs4_stateid(xdr, &args->stateid);
1929 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001930 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1931 p = xdr_encode_hyper(p, args->lastbytewritten);
1932 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1933 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001934
1935 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1936 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1937 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001938 else
1939 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001940
Andy Adamson863a3c62011-03-23 13:27:54 +00001941 return 0;
1942}
Benny Halevycbe82602011-05-22 19:52:37 +03001943
1944static void
1945encode_layoutreturn(struct xdr_stream *xdr,
1946 const struct nfs4_layoutreturn_args *args,
1947 struct compound_hdr *hdr)
1948{
1949 __be32 *p;
1950
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001951 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1952 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001953 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1954 *p++ = cpu_to_be32(args->layout_type);
1955 *p++ = cpu_to_be32(IOMODE_ANY);
1956 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001957 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001958 p = xdr_encode_hyper(p, 0);
1959 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1960 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001961 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001962 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001963 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1964 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1965 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001966 } else
1967 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03001968}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001969
1970static int
1971encode_secinfo_no_name(struct xdr_stream *xdr,
1972 const struct nfs41_secinfo_no_name_args *args,
1973 struct compound_hdr *hdr)
1974{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001975 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1976 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001977 return 0;
1978}
Bryan Schumaker7d974792011-06-02 14:59:08 -04001979
1980static void encode_test_stateid(struct xdr_stream *xdr,
1981 struct nfs41_test_stateid_args *args,
1982 struct compound_hdr *hdr)
1983{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001984 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
1985 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001986 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04001987}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001988
1989static void encode_free_stateid(struct xdr_stream *xdr,
1990 struct nfs41_free_stateid_args *args,
1991 struct compound_hdr *hdr)
1992{
Trond Myklebustab19b482012-03-04 18:13:57 -05001993 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001994 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001995}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001996#endif /* CONFIG_NFS_V4_1 */
1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998/*
1999 * END OF "GENERIC" ENCODE ROUTINES.
2000 */
2001
Benny Halevy66cc0422009-04-01 09:22:10 -04002002static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2003{
2004#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05002005
2006 if (args->sa_slot)
2007 return args->sa_slot->table->session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002008#endif /* CONFIG_NFS_V4_1 */
2009 return 0;
2010}
2011
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012/*
2013 * Encode an ACCESS request
2014 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002015static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2016 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002019 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021
Chuck Lever9f06c712010-12-14 14:59:18 +00002022 encode_compound_hdr(xdr, req, &hdr);
2023 encode_sequence(xdr, &args->seq_args, &hdr);
2024 encode_putfh(xdr, args->fh, &hdr);
2025 encode_access(xdr, args->access, &hdr);
2026 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002027 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028}
2029
2030/*
2031 * Encode LOOKUP request
2032 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002033static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2034 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002037 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039
Chuck Lever9f06c712010-12-14 14:59:18 +00002040 encode_compound_hdr(xdr, req, &hdr);
2041 encode_sequence(xdr, &args->seq_args, &hdr);
2042 encode_putfh(xdr, args->dir_fh, &hdr);
2043 encode_lookup(xdr, args->name, &hdr);
2044 encode_getfh(xdr, &hdr);
2045 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002046 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047}
2048
2049/*
2050 * Encode LOOKUP_ROOT request
2051 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002052static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2053 struct xdr_stream *xdr,
2054 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002057 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Chuck Lever9f06c712010-12-14 14:59:18 +00002060 encode_compound_hdr(xdr, req, &hdr);
2061 encode_sequence(xdr, &args->seq_args, &hdr);
2062 encode_putrootfh(xdr, &hdr);
2063 encode_getfh(xdr, &hdr);
2064 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002065 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066}
2067
2068/*
2069 * Encode REMOVE request
2070 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002071static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2072 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002075 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
Chuck Lever9f06c712010-12-14 14:59:18 +00002078 encode_compound_hdr(xdr, req, &hdr);
2079 encode_sequence(xdr, &args->seq_args, &hdr);
2080 encode_putfh(xdr, args->fh, &hdr);
2081 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002082 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083}
2084
2085/*
2086 * Encode RENAME request
2087 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002088static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2089 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002092 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094
Chuck Lever9f06c712010-12-14 14:59:18 +00002095 encode_compound_hdr(xdr, req, &hdr);
2096 encode_sequence(xdr, &args->seq_args, &hdr);
2097 encode_putfh(xdr, args->old_dir, &hdr);
2098 encode_savefh(xdr, &hdr);
2099 encode_putfh(xdr, args->new_dir, &hdr);
2100 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002101 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102}
2103
2104/*
2105 * Encode LINK request
2106 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002107static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2108 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002111 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
Chuck Lever9f06c712010-12-14 14:59:18 +00002114 encode_compound_hdr(xdr, req, &hdr);
2115 encode_sequence(xdr, &args->seq_args, &hdr);
2116 encode_putfh(xdr, args->fh, &hdr);
2117 encode_savefh(xdr, &hdr);
2118 encode_putfh(xdr, args->dir_fh, &hdr);
2119 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002120 encode_restorefh(xdr, &hdr);
2121 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002122 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123}
2124
2125/*
2126 * Encode CREATE request
2127 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002128static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2129 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002132 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
Chuck Lever9f06c712010-12-14 14:59:18 +00002135 encode_compound_hdr(xdr, req, &hdr);
2136 encode_sequence(xdr, &args->seq_args, &hdr);
2137 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002138 encode_create(xdr, args, &hdr);
2139 encode_getfh(xdr, &hdr);
2140 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002141 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142}
2143
2144/*
2145 * Encode SYMLINK request
2146 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002147static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2148 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149{
Chuck Lever9f06c712010-12-14 14:59:18 +00002150 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151}
2152
2153/*
2154 * Encode GETATTR request
2155 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002156static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2157 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002160 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
Chuck Lever9f06c712010-12-14 14:59:18 +00002163 encode_compound_hdr(xdr, req, &hdr);
2164 encode_sequence(xdr, &args->seq_args, &hdr);
2165 encode_putfh(xdr, args->fh, &hdr);
2166 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002167 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168}
2169
2170/*
2171 * Encode a CLOSE request
2172 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002173static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2174 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175{
Andy Adamson05d564f2008-12-23 16:06:15 -05002176 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002177 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002178 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179
Chuck Lever9f06c712010-12-14 14:59:18 +00002180 encode_compound_hdr(xdr, req, &hdr);
2181 encode_sequence(xdr, &args->seq_args, &hdr);
2182 encode_putfh(xdr, args->fh, &hdr);
2183 encode_close(xdr, args, &hdr);
2184 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002185 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186}
2187
2188/*
2189 * Encode an OPEN request
2190 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002191static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2192 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002195 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
Chuck Lever9f06c712010-12-14 14:59:18 +00002198 encode_compound_hdr(xdr, req, &hdr);
2199 encode_sequence(xdr, &args->seq_args, &hdr);
2200 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002201 encode_open(xdr, args, &hdr);
2202 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002203 if (args->access)
2204 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002205 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002206 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207}
2208
2209/*
2210 * Encode an OPEN_CONFIRM request
2211 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002212static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2213 struct xdr_stream *xdr,
2214 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002217 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219
Chuck Lever9f06c712010-12-14 14:59:18 +00002220 encode_compound_hdr(xdr, req, &hdr);
2221 encode_putfh(xdr, args->fh, &hdr);
2222 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002223 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224}
2225
2226/*
2227 * Encode an OPEN request with no attributes.
2228 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002229static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2230 struct xdr_stream *xdr,
2231 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002234 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
Chuck Lever9f06c712010-12-14 14:59:18 +00002237 encode_compound_hdr(xdr, req, &hdr);
2238 encode_sequence(xdr, &args->seq_args, &hdr);
2239 encode_putfh(xdr, args->fh, &hdr);
2240 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002241 if (args->access)
2242 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002243 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002244 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245}
2246
2247/*
2248 * Encode an OPEN_DOWNGRADE request
2249 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002250static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2251 struct xdr_stream *xdr,
2252 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002255 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257
Chuck Lever9f06c712010-12-14 14:59:18 +00002258 encode_compound_hdr(xdr, req, &hdr);
2259 encode_sequence(xdr, &args->seq_args, &hdr);
2260 encode_putfh(xdr, args->fh, &hdr);
2261 encode_open_downgrade(xdr, args, &hdr);
2262 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002263 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264}
2265
2266/*
2267 * Encode a LOCK request
2268 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002269static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2270 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002273 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
Chuck Lever9f06c712010-12-14 14:59:18 +00002276 encode_compound_hdr(xdr, req, &hdr);
2277 encode_sequence(xdr, &args->seq_args, &hdr);
2278 encode_putfh(xdr, args->fh, &hdr);
2279 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002280 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281}
2282
2283/*
2284 * Encode a LOCKT request
2285 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002286static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2287 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002290 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
Chuck Lever9f06c712010-12-14 14:59:18 +00002293 encode_compound_hdr(xdr, req, &hdr);
2294 encode_sequence(xdr, &args->seq_args, &hdr);
2295 encode_putfh(xdr, args->fh, &hdr);
2296 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002297 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298}
2299
2300/*
2301 * Encode a LOCKU request
2302 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002303static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2304 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002307 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309
Chuck Lever9f06c712010-12-14 14:59:18 +00002310 encode_compound_hdr(xdr, req, &hdr);
2311 encode_sequence(xdr, &args->seq_args, &hdr);
2312 encode_putfh(xdr, args->fh, &hdr);
2313 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002314 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315}
2316
Chuck Lever9f06c712010-12-14 14:59:18 +00002317static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2318 struct xdr_stream *xdr,
2319 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002320{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002321 struct compound_hdr hdr = {
2322 .minorversion = 0,
2323 };
2324
Chuck Lever9f06c712010-12-14 14:59:18 +00002325 encode_compound_hdr(xdr, req, &hdr);
2326 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002327 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002328}
2329
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330/*
2331 * Encode a READLINK request
2332 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002333static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2334 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002337 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339
Chuck Lever9f06c712010-12-14 14:59:18 +00002340 encode_compound_hdr(xdr, req, &hdr);
2341 encode_sequence(xdr, &args->seq_args, &hdr);
2342 encode_putfh(xdr, args->fh, &hdr);
2343 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002344
Benny Halevy28f56692009-04-01 09:22:09 -04002345 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002346 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002347 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348}
2349
2350/*
2351 * Encode a READDIR request
2352 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002353static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2354 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002357 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359
Chuck Lever9f06c712010-12-14 14:59:18 +00002360 encode_compound_hdr(xdr, req, &hdr);
2361 encode_sequence(xdr, &args->seq_args, &hdr);
2362 encode_putfh(xdr, args->fh, &hdr);
2363 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002364
Benny Halevy28f56692009-04-01 09:22:09 -04002365 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002366 args->pgbase, args->count);
2367 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002368 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002369 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002370 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371}
2372
2373/*
2374 * Encode a READ request
2375 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002376static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2377 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002380 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382
Chuck Lever9f06c712010-12-14 14:59:18 +00002383 encode_compound_hdr(xdr, req, &hdr);
2384 encode_sequence(xdr, &args->seq_args, &hdr);
2385 encode_putfh(xdr, args->fh, &hdr);
2386 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387
Benny Halevy28f56692009-04-01 09:22:09 -04002388 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002390 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002391 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392}
2393
2394/*
2395 * Encode an SETATTR request
2396 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002397static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2398 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399{
Andy Adamson05d564f2008-12-23 16:06:15 -05002400 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002401 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002402 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403
Chuck Lever9f06c712010-12-14 14:59:18 +00002404 encode_compound_hdr(xdr, req, &hdr);
2405 encode_sequence(xdr, &args->seq_args, &hdr);
2406 encode_putfh(xdr, args->fh, &hdr);
2407 encode_setattr(xdr, args, args->server, &hdr);
2408 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002409 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410}
2411
2412/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002413 * Encode a GETACL request
2414 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002415static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2416 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002417{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002418 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002419 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002420 };
Benny Halevy28f56692009-04-01 09:22:09 -04002421 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002422
Chuck Lever9f06c712010-12-14 14:59:18 +00002423 encode_compound_hdr(xdr, req, &hdr);
2424 encode_sequence(xdr, &args->seq_args, &hdr);
2425 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002426 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002427 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002428
Benny Halevy28f56692009-04-01 09:22:09 -04002429 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002430 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002431
Andy Adamsond0179312008-12-23 16:06:17 -05002432 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002433}
2434
2435/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 * Encode a WRITE request
2437 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002438static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2439 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002442 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
Chuck Lever9f06c712010-12-14 14:59:18 +00002445 encode_compound_hdr(xdr, req, &hdr);
2446 encode_sequence(xdr, &args->seq_args, &hdr);
2447 encode_putfh(xdr, args->fh, &hdr);
2448 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002449 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002450 if (args->bitmask)
2451 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002452 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453}
2454
2455/*
2456 * a COMMIT request
2457 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002458static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002459 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002462 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464
Chuck Lever9f06c712010-12-14 14:59:18 +00002465 encode_compound_hdr(xdr, req, &hdr);
2466 encode_sequence(xdr, &args->seq_args, &hdr);
2467 encode_putfh(xdr, args->fh, &hdr);
2468 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002469 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470}
2471
2472/*
2473 * FSINFO request
2474 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002475static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2476 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002479 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481
Chuck Lever9f06c712010-12-14 14:59:18 +00002482 encode_compound_hdr(xdr, req, &hdr);
2483 encode_sequence(xdr, &args->seq_args, &hdr);
2484 encode_putfh(xdr, args->fh, &hdr);
2485 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002486 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487}
2488
2489/*
2490 * a PATHCONF request
2491 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002492static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2493 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002496 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498
Chuck Lever9f06c712010-12-14 14:59:18 +00002499 encode_compound_hdr(xdr, req, &hdr);
2500 encode_sequence(xdr, &args->seq_args, &hdr);
2501 encode_putfh(xdr, args->fh, &hdr);
2502 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002503 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002504 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505}
2506
2507/*
2508 * a STATFS request
2509 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002510static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2511 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002514 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516
Chuck Lever9f06c712010-12-14 14:59:18 +00002517 encode_compound_hdr(xdr, req, &hdr);
2518 encode_sequence(xdr, &args->seq_args, &hdr);
2519 encode_putfh(xdr, args->fh, &hdr);
2520 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002521 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002522 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523}
2524
2525/*
2526 * GETATTR_BITMAP request
2527 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002528static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2529 struct xdr_stream *xdr,
2530 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002533 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535
Chuck Lever9f06c712010-12-14 14:59:18 +00002536 encode_compound_hdr(xdr, req, &hdr);
2537 encode_sequence(xdr, &args->seq_args, &hdr);
2538 encode_putfh(xdr, args->fhandle, &hdr);
2539 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002540 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002541 FATTR4_WORD0_LINK_SUPPORT|
2542 FATTR4_WORD0_SYMLINK_SUPPORT|
2543 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002544 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545}
2546
2547/*
2548 * a RENEW request
2549 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002550static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2551 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002554 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 };
2556
Chuck Lever9f06c712010-12-14 14:59:18 +00002557 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002558 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002559 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560}
2561
2562/*
2563 * a SETCLIENTID request
2564 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002565static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2566 struct xdr_stream *xdr,
2567 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002570 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 };
2572
Chuck Lever9f06c712010-12-14 14:59:18 +00002573 encode_compound_hdr(xdr, req, &hdr);
2574 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002575 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576}
2577
2578/*
2579 * a SETCLIENTID_CONFIRM request
2580 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002581static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2582 struct xdr_stream *xdr,
2583 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002586 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 };
Fred Isamandae100c2011-07-30 20:52:37 -04002588 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589
Chuck Lever9f06c712010-12-14 14:59:18 +00002590 encode_compound_hdr(xdr, req, &hdr);
2591 encode_setclientid_confirm(xdr, arg, &hdr);
2592 encode_putrootfh(xdr, &hdr);
2593 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002594 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595}
2596
2597/*
2598 * DELEGRETURN request
2599 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002600static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2601 struct xdr_stream *xdr,
2602 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002605 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607
Chuck Lever9f06c712010-12-14 14:59:18 +00002608 encode_compound_hdr(xdr, req, &hdr);
2609 encode_sequence(xdr, &args->seq_args, &hdr);
2610 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002611 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002612 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002613 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614}
2615
2616/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002617 * Encode FS_LOCATIONS request
2618 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002619static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2620 struct xdr_stream *xdr,
2621 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002622{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002623 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002624 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002625 };
Benny Halevy28f56692009-04-01 09:22:09 -04002626 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002627
Chuck Lever9f06c712010-12-14 14:59:18 +00002628 encode_compound_hdr(xdr, req, &hdr);
2629 encode_sequence(xdr, &args->seq_args, &hdr);
2630 encode_putfh(xdr, args->dir_fh, &hdr);
2631 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002632 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002633 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002634
Benny Halevy28f56692009-04-01 09:22:09 -04002635 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002636 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002637 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002638}
2639
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002640/*
2641 * Encode SECINFO request
2642 */
2643static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2644 struct xdr_stream *xdr,
2645 struct nfs4_secinfo_arg *args)
2646{
2647 struct compound_hdr hdr = {
2648 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2649 };
2650
2651 encode_compound_hdr(xdr, req, &hdr);
2652 encode_sequence(xdr, &args->seq_args, &hdr);
2653 encode_putfh(xdr, args->dir_fh, &hdr);
2654 encode_secinfo(xdr, args->name, &hdr);
2655 encode_nops(&hdr);
2656}
2657
Benny Halevy99fe60d2009-04-01 09:22:29 -04002658#if defined(CONFIG_NFS_V4_1)
2659/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002660 * BIND_CONN_TO_SESSION request
2661 */
2662static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2663 struct xdr_stream *xdr,
2664 struct nfs_client *clp)
2665{
2666 struct compound_hdr hdr = {
2667 .minorversion = clp->cl_mvops->minor_version,
2668 };
2669
2670 encode_compound_hdr(xdr, req, &hdr);
2671 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2672 encode_nops(&hdr);
2673}
2674
2675/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002676 * EXCHANGE_ID request
2677 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002678static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2679 struct xdr_stream *xdr,
2680 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002681{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002682 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002683 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002684 };
2685
Chuck Lever9f06c712010-12-14 14:59:18 +00002686 encode_compound_hdr(xdr, req, &hdr);
2687 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002688 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002689}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002690
2691/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002692 * a CREATE_SESSION request
2693 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002694static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2695 struct xdr_stream *xdr,
2696 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002697{
Andy Adamsonfc931582009-04-01 09:22:31 -04002698 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002699 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002700 };
2701
Chuck Lever9f06c712010-12-14 14:59:18 +00002702 encode_compound_hdr(xdr, req, &hdr);
2703 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002704 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002705}
2706
2707/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002708 * a DESTROY_SESSION request
2709 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002710static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2711 struct xdr_stream *xdr,
2712 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002713{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002714 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002715 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002716 };
2717
Chuck Lever9f06c712010-12-14 14:59:18 +00002718 encode_compound_hdr(xdr, req, &hdr);
2719 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002720 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002721}
2722
2723/*
Trond Myklebust66245532012-05-25 17:18:09 -04002724 * a DESTROY_CLIENTID request
2725 */
2726static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2727 struct xdr_stream *xdr,
2728 struct nfs_client *clp)
2729{
2730 struct compound_hdr hdr = {
2731 .minorversion = clp->cl_mvops->minor_version,
2732 };
2733
2734 encode_compound_hdr(xdr, req, &hdr);
2735 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2736 encode_nops(&hdr);
2737}
2738
2739/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002740 * a SEQUENCE request
2741 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002742static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2743 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002744{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002745 struct compound_hdr hdr = {
2746 .minorversion = nfs4_xdr_minorversion(args),
2747 };
2748
Chuck Lever9f06c712010-12-14 14:59:18 +00002749 encode_compound_hdr(xdr, req, &hdr);
2750 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002751 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002752}
2753
2754/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002755 * a GET_LEASE_TIME request
2756 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002757static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2758 struct xdr_stream *xdr,
2759 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002760{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002761 struct compound_hdr hdr = {
2762 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2763 };
Fred Isamandae100c2011-07-30 20:52:37 -04002764 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002765
Chuck Lever9f06c712010-12-14 14:59:18 +00002766 encode_compound_hdr(xdr, req, &hdr);
2767 encode_sequence(xdr, &args->la_seq_args, &hdr);
2768 encode_putrootfh(xdr, &hdr);
2769 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002770 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002771}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002772
2773/*
2774 * a RECLAIM_COMPLETE request
2775 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002776static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2777 struct xdr_stream *xdr,
2778 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002779{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002780 struct compound_hdr hdr = {
2781 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2782 };
2783
Chuck Lever9f06c712010-12-14 14:59:18 +00002784 encode_compound_hdr(xdr, req, &hdr);
2785 encode_sequence(xdr, &args->seq_args, &hdr);
2786 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002787 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002788}
2789
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002790/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002791 * Encode GETDEVICELIST request
2792 */
2793static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2794 struct xdr_stream *xdr,
2795 struct nfs4_getdevicelist_args *args)
2796{
2797 struct compound_hdr hdr = {
2798 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2799 };
2800
2801 encode_compound_hdr(xdr, req, &hdr);
2802 encode_sequence(xdr, &args->seq_args, &hdr);
2803 encode_putfh(xdr, args->fh, &hdr);
2804 encode_getdevicelist(xdr, args, &hdr);
2805 encode_nops(&hdr);
2806}
2807
2808/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002809 * Encode GETDEVICEINFO request
2810 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002811static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2812 struct xdr_stream *xdr,
2813 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002814{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002815 struct compound_hdr hdr = {
2816 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2817 };
2818
Chuck Lever9f06c712010-12-14 14:59:18 +00002819 encode_compound_hdr(xdr, req, &hdr);
2820 encode_sequence(xdr, &args->seq_args, &hdr);
2821 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002822
2823 /* set up reply kvec. Subtract notification bitmap max size (2)
2824 * so that notification bitmap is put in xdr_buf tail */
2825 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2826 args->pdev->pages, args->pdev->pgbase,
2827 args->pdev->pglen);
2828
2829 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002830}
2831
2832/*
2833 * Encode LAYOUTGET request
2834 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002835static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2836 struct xdr_stream *xdr,
2837 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002838{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002839 struct compound_hdr hdr = {
2840 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2841 };
2842
Chuck Lever9f06c712010-12-14 14:59:18 +00002843 encode_compound_hdr(xdr, req, &hdr);
2844 encode_sequence(xdr, &args->seq_args, &hdr);
2845 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2846 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002847
2848 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2849 args->layout.pages, 0, args->layout.pglen);
2850
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002851 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002852}
Andy Adamson863a3c62011-03-23 13:27:54 +00002853
2854/*
2855 * Encode LAYOUTCOMMIT request
2856 */
Benny Halevycbe82602011-05-22 19:52:37 +03002857static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2858 struct xdr_stream *xdr,
2859 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002860{
Benny Halevyac7db722011-05-22 19:53:48 +03002861 struct nfs4_layoutcommit_data *data =
2862 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002863 struct compound_hdr hdr = {
2864 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2865 };
2866
2867 encode_compound_hdr(xdr, req, &hdr);
2868 encode_sequence(xdr, &args->seq_args, &hdr);
2869 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002870 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002871 encode_getfattr(xdr, args->bitmask, &hdr);
2872 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002873}
2874
2875/*
2876 * Encode LAYOUTRETURN request
2877 */
2878static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2879 struct xdr_stream *xdr,
2880 struct nfs4_layoutreturn_args *args)
2881{
2882 struct compound_hdr hdr = {
2883 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2884 };
2885
2886 encode_compound_hdr(xdr, req, &hdr);
2887 encode_sequence(xdr, &args->seq_args, &hdr);
2888 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2889 encode_layoutreturn(xdr, args, &hdr);
2890 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002891}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002892
2893/*
2894 * Encode SECINFO_NO_NAME request
2895 */
2896static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2897 struct xdr_stream *xdr,
2898 struct nfs41_secinfo_no_name_args *args)
2899{
2900 struct compound_hdr hdr = {
2901 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2902 };
2903
2904 encode_compound_hdr(xdr, req, &hdr);
2905 encode_sequence(xdr, &args->seq_args, &hdr);
2906 encode_putrootfh(xdr, &hdr);
2907 encode_secinfo_no_name(xdr, args, &hdr);
2908 encode_nops(&hdr);
2909 return 0;
2910}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002911
2912/*
2913 * Encode TEST_STATEID request
2914 */
2915static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2916 struct xdr_stream *xdr,
2917 struct nfs41_test_stateid_args *args)
2918{
2919 struct compound_hdr hdr = {
2920 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2921 };
2922
2923 encode_compound_hdr(xdr, req, &hdr);
2924 encode_sequence(xdr, &args->seq_args, &hdr);
2925 encode_test_stateid(xdr, args, &hdr);
2926 encode_nops(&hdr);
2927}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002928
2929/*
2930 * Encode FREE_STATEID request
2931 */
2932static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2933 struct xdr_stream *xdr,
2934 struct nfs41_free_stateid_args *args)
2935{
2936 struct compound_hdr hdr = {
2937 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2938 };
2939
2940 encode_compound_hdr(xdr, req, &hdr);
2941 encode_sequence(xdr, &args->seq_args, &hdr);
2942 encode_free_stateid(xdr, args, &hdr);
2943 encode_nops(&hdr);
2944}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002945#endif /* CONFIG_NFS_V4_1 */
2946
Benny Halevy686841b2009-08-14 17:19:48 +03002947static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2948{
2949 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2950 "Remaining buffer length is %tu words.\n",
2951 func, xdr->end - xdr->p);
2952}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953
Trond Myklebust683b57b2006-06-09 09:34:22 -04002954static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955{
Al Viro8687b632006-10-19 23:28:48 -07002956 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957
Benny Halevyc0eae662009-08-14 17:20:14 +03002958 p = xdr_inline_decode(xdr, 4);
2959 if (unlikely(!p))
2960 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002961 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002962 p = xdr_inline_decode(xdr, *len);
2963 if (unlikely(!p))
2964 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 *string = (char *)p;
2966 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002967out_overflow:
2968 print_overflow_msg(__func__, xdr);
2969 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970}
2971
2972static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2973{
Al Viro8687b632006-10-19 23:28:48 -07002974 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975
Benny Halevyc0eae662009-08-14 17:20:14 +03002976 p = xdr_inline_decode(xdr, 8);
2977 if (unlikely(!p))
2978 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002979 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002980 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002981
Benny Halevyc0eae662009-08-14 17:20:14 +03002982 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2983 if (unlikely(!p))
2984 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 hdr->tag = (char *)p;
2986 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002987 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002988 if (unlikely(hdr->nops < 1))
2989 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002991out_overflow:
2992 print_overflow_msg(__func__, xdr);
2993 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994}
2995
2996static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2997{
Al Viro8687b632006-10-19 23:28:48 -07002998 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 uint32_t opnum;
3000 int32_t nfserr;
3001
Benny Halevyc0eae662009-08-14 17:20:14 +03003002 p = xdr_inline_decode(xdr, 8);
3003 if (unlikely(!p))
3004 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003005 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003007 dprintk("nfs: Server returned operation"
3008 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 opnum, expected);
3010 return -EIO;
3011 }
Benny Halevycccddf42009-08-14 17:20:19 +03003012 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003014 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003016out_overflow:
3017 print_overflow_msg(__func__, xdr);
3018 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019}
3020
3021/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003022static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023{
Al Viro8687b632006-10-19 23:28:48 -07003024 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003025 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 char *str;
3027
Benny Halevyc0eae662009-08-14 17:20:14 +03003028 p = xdr_inline_decode(xdr, 12);
3029 if (likely(p))
3030 return decode_opaque_inline(xdr, &strlen, &str);
3031 print_overflow_msg(__func__, xdr);
3032 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033}
3034
3035static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3036{
Al Viro8687b632006-10-19 23:28:48 -07003037 uint32_t bmlen;
3038 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039
Benny Halevyc0eae662009-08-14 17:20:14 +03003040 p = xdr_inline_decode(xdr, 4);
3041 if (unlikely(!p))
3042 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003043 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044
Fred Isamandae100c2011-07-30 20:52:37 -04003045 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003046 p = xdr_inline_decode(xdr, (bmlen << 2));
3047 if (unlikely(!p))
3048 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003050 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003051 if (bmlen > 1) {
3052 bitmap[1] = be32_to_cpup(p++);
3053 if (bmlen > 2)
3054 bitmap[2] = be32_to_cpup(p);
3055 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 }
3057 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003058out_overflow:
3059 print_overflow_msg(__func__, xdr);
3060 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061}
3062
Trond Myklebust256e48b2012-06-21 11:18:13 -04003063static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064{
Al Viro8687b632006-10-19 23:28:48 -07003065 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066
Benny Halevyc0eae662009-08-14 17:20:14 +03003067 p = xdr_inline_decode(xdr, 4);
3068 if (unlikely(!p))
3069 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003070 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003071 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 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_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3079{
3080 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003081 int ret;
3082 ret = decode_attr_bitmap(xdr, bitmask);
3083 if (unlikely(ret < 0))
3084 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3086 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003087 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3088 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3089 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 return 0;
3091}
3092
3093static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3094{
Al Viro8687b632006-10-19 23:28:48 -07003095 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003096 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097
3098 *type = 0;
3099 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3100 return -EIO;
3101 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003102 p = xdr_inline_decode(xdr, 4);
3103 if (unlikely(!p))
3104 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003105 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003107 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 return -EIO;
3109 }
3110 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003111 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003113 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003114 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003115out_overflow:
3116 print_overflow_msg(__func__, xdr);
3117 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118}
3119
Chuck Lever264e6352012-03-01 17:02:05 -05003120static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3121 uint32_t *bitmap, uint32_t *type)
3122{
3123 __be32 *p;
3124
3125 *type = 0;
3126 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3127 return -EIO;
3128 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3129 p = xdr_inline_decode(xdr, 4);
3130 if (unlikely(!p))
3131 goto out_overflow;
3132 *type = be32_to_cpup(p);
3133 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3134 }
3135 dprintk("%s: expire type=0x%x\n", __func__, *type);
3136 return 0;
3137out_overflow:
3138 print_overflow_msg(__func__, xdr);
3139 return -EIO;
3140}
3141
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3143{
Al Viro8687b632006-10-19 23:28:48 -07003144 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003145 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146
3147 *change = 0;
3148 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3149 return -EIO;
3150 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003151 p = xdr_inline_decode(xdr, 8);
3152 if (unlikely(!p))
3153 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003154 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003156 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003158 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003160 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003161out_overflow:
3162 print_overflow_msg(__func__, xdr);
3163 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164}
3165
3166static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3167{
Al Viro8687b632006-10-19 23:28:48 -07003168 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003169 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170
3171 *size = 0;
3172 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3173 return -EIO;
3174 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003175 p = xdr_inline_decode(xdr, 8);
3176 if (unlikely(!p))
3177 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003178 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003180 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003182 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003183 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003184out_overflow:
3185 print_overflow_msg(__func__, xdr);
3186 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187}
3188
3189static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3190{
Al Viro8687b632006-10-19 23:28:48 -07003191 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192
3193 *res = 0;
3194 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3195 return -EIO;
3196 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003197 p = xdr_inline_decode(xdr, 4);
3198 if (unlikely(!p))
3199 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003200 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3202 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003203 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003205out_overflow:
3206 print_overflow_msg(__func__, xdr);
3207 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208}
3209
3210static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3211{
Al Viro8687b632006-10-19 23:28:48 -07003212 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213
3214 *res = 0;
3215 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3216 return -EIO;
3217 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003218 p = xdr_inline_decode(xdr, 4);
3219 if (unlikely(!p))
3220 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003221 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3223 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003224 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003226out_overflow:
3227 print_overflow_msg(__func__, xdr);
3228 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229}
3230
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003231static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232{
Al Viro8687b632006-10-19 23:28:48 -07003233 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003234 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235
3236 fsid->major = 0;
3237 fsid->minor = 0;
3238 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3239 return -EIO;
3240 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003241 p = xdr_inline_decode(xdr, 16);
3242 if (unlikely(!p))
3243 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003244 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003245 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003247 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003249 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 (unsigned long long)fsid->major,
3251 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003252 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003253out_overflow:
3254 print_overflow_msg(__func__, xdr);
3255 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256}
3257
3258static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3259{
Al Viro8687b632006-10-19 23:28:48 -07003260 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261
3262 *res = 60;
3263 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3264 return -EIO;
3265 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003266 p = xdr_inline_decode(xdr, 4);
3267 if (unlikely(!p))
3268 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003269 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3271 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003272 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003274out_overflow:
3275 print_overflow_msg(__func__, xdr);
3276 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277}
3278
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003279static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003280{
3281 __be32 *p;
3282
3283 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3284 return -EIO;
3285 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3286 p = xdr_inline_decode(xdr, 4);
3287 if (unlikely(!p))
3288 goto out_overflow;
3289 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003290 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003291 }
3292 return 0;
3293out_overflow:
3294 print_overflow_msg(__func__, xdr);
3295 return -EIO;
3296}
3297
3298static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3299{
3300 __be32 *p;
3301 int len;
3302
Trond Myklebust7ad07352010-10-23 15:34:20 -04003303 if (fh != NULL)
3304 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003305
3306 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3307 return -EIO;
3308 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3309 p = xdr_inline_decode(xdr, 4);
3310 if (unlikely(!p))
3311 goto out_overflow;
3312 len = be32_to_cpup(p);
3313 if (len > NFS4_FHSIZE)
3314 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003315 p = xdr_inline_decode(xdr, len);
3316 if (unlikely(!p))
3317 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003318 if (fh != NULL) {
3319 memcpy(fh->data, p, len);
3320 fh->size = len;
3321 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003322 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3323 }
3324 return 0;
3325out_overflow:
3326 print_overflow_msg(__func__, xdr);
3327 return -EIO;
3328}
3329
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3331{
Al Viro8687b632006-10-19 23:28:48 -07003332 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333
3334 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3335 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3336 return -EIO;
3337 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003338 p = xdr_inline_decode(xdr, 4);
3339 if (unlikely(!p))
3340 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003341 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3343 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003344 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003346out_overflow:
3347 print_overflow_msg(__func__, xdr);
3348 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349}
3350
3351static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3352{
Al Viro8687b632006-10-19 23:28:48 -07003353 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003354 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355
3356 *fileid = 0;
3357 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3358 return -EIO;
3359 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003360 p = xdr_inline_decode(xdr, 8);
3361 if (unlikely(!p))
3362 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003363 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003365 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003367 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003368 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003369out_overflow:
3370 print_overflow_msg(__func__, xdr);
3371 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372}
3373
Manoj Naik99baf622006-06-09 09:34:24 -04003374static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3375{
Al Viro8687b632006-10-19 23:28:48 -07003376 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003377 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003378
3379 *fileid = 0;
3380 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3381 return -EIO;
3382 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003383 p = xdr_inline_decode(xdr, 8);
3384 if (unlikely(!p))
3385 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003386 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003387 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003388 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003389 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003390 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003391 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003392out_overflow:
3393 print_overflow_msg(__func__, xdr);
3394 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003395}
3396
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3398{
Al Viro8687b632006-10-19 23:28:48 -07003399 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 int status = 0;
3401
3402 *res = 0;
3403 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3404 return -EIO;
3405 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003406 p = xdr_inline_decode(xdr, 8);
3407 if (unlikely(!p))
3408 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003409 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3411 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003412 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003414out_overflow:
3415 print_overflow_msg(__func__, xdr);
3416 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417}
3418
3419static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3420{
Al Viro8687b632006-10-19 23:28:48 -07003421 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 int status = 0;
3423
3424 *res = 0;
3425 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3426 return -EIO;
3427 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003428 p = xdr_inline_decode(xdr, 8);
3429 if (unlikely(!p))
3430 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003431 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3433 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003434 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003436out_overflow:
3437 print_overflow_msg(__func__, xdr);
3438 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439}
3440
3441static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3442{
Al Viro8687b632006-10-19 23:28:48 -07003443 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 int status = 0;
3445
3446 *res = 0;
3447 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3448 return -EIO;
3449 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003450 p = xdr_inline_decode(xdr, 8);
3451 if (unlikely(!p))
3452 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003453 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3455 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003456 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003458out_overflow:
3459 print_overflow_msg(__func__, xdr);
3460 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461}
3462
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003463static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3464{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003465 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003466 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003467 int status = 0;
3468
Benny Halevyc0eae662009-08-14 17:20:14 +03003469 p = xdr_inline_decode(xdr, 4);
3470 if (unlikely(!p))
3471 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003472 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003473 if (n == 0)
3474 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003475 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003476 path->ncomponents = 0;
3477 while (path->ncomponents < n) {
3478 struct nfs4_string *component = &path->components[path->ncomponents];
3479 status = decode_opaque_inline(xdr, &component->len, &component->data);
3480 if (unlikely(status != 0))
3481 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003482 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003483 pr_cont("%s%.*s ",
3484 (path->ncomponents != n ? "/ " : ""),
3485 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003486 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3487 path->ncomponents++;
3488 else {
3489 dprintk("cannot parse %d components in path\n", n);
3490 goto out_eio;
3491 }
3492 }
3493out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003494 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003495root_path:
3496/* a root pathname is sent as a zero component4 */
3497 path->ncomponents = 1;
3498 path->components[0].len=0;
3499 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003500 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003501 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003502out_eio:
3503 dprintk(" status %d", status);
3504 status = -EIO;
3505 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003506out_overflow:
3507 print_overflow_msg(__func__, xdr);
3508 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003509}
3510
3511static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003512{
3513 int n;
Al Viro8687b632006-10-19 23:28:48 -07003514 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003515 int status = -EIO;
3516
3517 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3518 goto out;
3519 status = 0;
3520 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3521 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003522 status = -EIO;
3523 /* Ignore borken servers that return unrequested attrs */
3524 if (unlikely(res == NULL))
3525 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003526 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003527 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003528 if (unlikely(status != 0))
3529 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003530 p = xdr_inline_decode(xdr, 4);
3531 if (unlikely(!p))
3532 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003533 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003534 if (n <= 0)
3535 goto out_eio;
3536 res->nlocations = 0;
3537 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003538 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003539 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003540
Benny Halevyc0eae662009-08-14 17:20:14 +03003541 p = xdr_inline_decode(xdr, 4);
3542 if (unlikely(!p))
3543 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003544 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003545
3546 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003547 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003548 while (loc->nservers < m) {
3549 struct nfs4_string *server = &loc->servers[loc->nservers];
3550 status = decode_opaque_inline(xdr, &server->len, &server->data);
3551 if (unlikely(status != 0))
3552 goto out_eio;
3553 dprintk("%s ", server->data);
3554 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3555 loc->nservers++;
3556 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003557 unsigned int i;
3558 dprintk("%s: using first %u of %u servers "
3559 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003560 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003561 NFS4_FS_LOCATION_MAXSERVERS,
3562 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003563 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003564 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003565 char *data;
3566 status = decode_opaque_inline(xdr, &len, &data);
3567 if (unlikely(status != 0))
3568 goto out_eio;
3569 }
3570 }
3571 }
3572 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003573 if (unlikely(status != 0))
3574 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003575 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003576 res->nlocations++;
3577 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003578 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003579 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003580out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003581 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003582 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003583out_overflow:
3584 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003585out_eio:
3586 status = -EIO;
3587 goto out;
3588}
3589
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3591{
Al Viro8687b632006-10-19 23:28:48 -07003592 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 int status = 0;
3594
3595 *res = 0;
3596 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3597 return -EIO;
3598 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003599 p = xdr_inline_decode(xdr, 8);
3600 if (unlikely(!p))
3601 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003602 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3604 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003605 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003607out_overflow:
3608 print_overflow_msg(__func__, xdr);
3609 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610}
3611
3612static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3613{
Al Viro8687b632006-10-19 23:28:48 -07003614 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 int status = 0;
3616
3617 *maxlink = 1;
3618 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3619 return -EIO;
3620 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003621 p = xdr_inline_decode(xdr, 4);
3622 if (unlikely(!p))
3623 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003624 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3626 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003627 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003629out_overflow:
3630 print_overflow_msg(__func__, xdr);
3631 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632}
3633
3634static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3635{
Al Viro8687b632006-10-19 23:28:48 -07003636 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 int status = 0;
3638
3639 *maxname = 1024;
3640 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3641 return -EIO;
3642 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003643 p = xdr_inline_decode(xdr, 4);
3644 if (unlikely(!p))
3645 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003646 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3648 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003649 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003651out_overflow:
3652 print_overflow_msg(__func__, xdr);
3653 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654}
3655
3656static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3657{
Al Viro8687b632006-10-19 23:28:48 -07003658 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 int status = 0;
3660
3661 *res = 1024;
3662 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3663 return -EIO;
3664 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3665 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003666 p = xdr_inline_decode(xdr, 8);
3667 if (unlikely(!p))
3668 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003669 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 if (maxread > 0x7FFFFFFF)
3671 maxread = 0x7FFFFFFF;
3672 *res = (uint32_t)maxread;
3673 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3674 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003675 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003677out_overflow:
3678 print_overflow_msg(__func__, xdr);
3679 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680}
3681
3682static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3683{
Al Viro8687b632006-10-19 23:28:48 -07003684 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 int status = 0;
3686
3687 *res = 1024;
3688 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3689 return -EIO;
3690 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3691 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003692 p = xdr_inline_decode(xdr, 8);
3693 if (unlikely(!p))
3694 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003695 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 if (maxwrite > 0x7FFFFFFF)
3697 maxwrite = 0x7FFFFFFF;
3698 *res = (uint32_t)maxwrite;
3699 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3700 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003701 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003703out_overflow:
3704 print_overflow_msg(__func__, xdr);
3705 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706}
3707
Trond Myklebustbca79472009-03-11 14:10:26 -04003708static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709{
Trond Myklebustbca79472009-03-11 14:10:26 -04003710 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003711 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003712 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713
3714 *mode = 0;
3715 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3716 return -EIO;
3717 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003718 p = xdr_inline_decode(xdr, 4);
3719 if (unlikely(!p))
3720 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003721 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003722 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003724 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003726 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003727 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003728out_overflow:
3729 print_overflow_msg(__func__, xdr);
3730 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731}
3732
3733static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3734{
Al Viro8687b632006-10-19 23:28:48 -07003735 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003736 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737
3738 *nlink = 1;
3739 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3740 return -EIO;
3741 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003742 p = xdr_inline_decode(xdr, 4);
3743 if (unlikely(!p))
3744 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003745 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003747 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003749 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003750 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003751out_overflow:
3752 print_overflow_msg(__func__, xdr);
3753 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754}
3755
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003756static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003757 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003758 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759{
Al Viro8687b632006-10-19 23:28:48 -07003760 uint32_t len;
3761 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003762 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763
Eric W. Biedermane5782072013-02-01 14:22:02 -08003764 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3766 return -EIO;
3767 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003768 p = xdr_inline_decode(xdr, 4);
3769 if (unlikely(!p))
3770 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003771 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003772 p = xdr_inline_decode(xdr, len);
3773 if (unlikely(!p))
3774 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003775 if (owner_name != NULL) {
3776 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3777 if (owner_name->data != NULL) {
3778 owner_name->len = len;
3779 ret = NFS_ATTR_FATTR_OWNER_NAME;
3780 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003781 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003782 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003783 ret = NFS_ATTR_FATTR_OWNER;
3784 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003786 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003788 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003789 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3791 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003792 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003793 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003794out_overflow:
3795 print_overflow_msg(__func__, xdr);
3796 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797}
3798
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003799static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003800 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003801 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802{
Al Viro8687b632006-10-19 23:28:48 -07003803 uint32_t len;
3804 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003805 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806
Eric W. Biedermane5782072013-02-01 14:22:02 -08003807 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3809 return -EIO;
3810 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003811 p = xdr_inline_decode(xdr, 4);
3812 if (unlikely(!p))
3813 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003814 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003815 p = xdr_inline_decode(xdr, len);
3816 if (unlikely(!p))
3817 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003818 if (group_name != NULL) {
3819 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3820 if (group_name->data != NULL) {
3821 group_name->len = len;
3822 ret = NFS_ATTR_FATTR_GROUP_NAME;
3823 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003824 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003825 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003826 ret = NFS_ATTR_FATTR_GROUP;
3827 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003829 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003831 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003832 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3834 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003835 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003836 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003837out_overflow:
3838 print_overflow_msg(__func__, xdr);
3839 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840}
3841
3842static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3843{
Al Viro8687b632006-10-19 23:28:48 -07003844 uint32_t major = 0, minor = 0;
3845 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003846 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847
3848 *rdev = MKDEV(0,0);
3849 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3850 return -EIO;
3851 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3852 dev_t tmp;
3853
Benny Halevyc0eae662009-08-14 17:20:14 +03003854 p = xdr_inline_decode(xdr, 8);
3855 if (unlikely(!p))
3856 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003857 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003858 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 tmp = MKDEV(major, minor);
3860 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3861 *rdev = tmp;
3862 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003863 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003865 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003866 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003867out_overflow:
3868 print_overflow_msg(__func__, xdr);
3869 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870}
3871
3872static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3873{
Al Viro8687b632006-10-19 23:28:48 -07003874 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875 int status = 0;
3876
3877 *res = 0;
3878 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3879 return -EIO;
3880 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003881 p = xdr_inline_decode(xdr, 8);
3882 if (unlikely(!p))
3883 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003884 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3886 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003887 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003889out_overflow:
3890 print_overflow_msg(__func__, xdr);
3891 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892}
3893
3894static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3895{
Al Viro8687b632006-10-19 23:28:48 -07003896 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 int status = 0;
3898
3899 *res = 0;
3900 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3901 return -EIO;
3902 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003903 p = xdr_inline_decode(xdr, 8);
3904 if (unlikely(!p))
3905 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003906 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3908 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003909 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003911out_overflow:
3912 print_overflow_msg(__func__, xdr);
3913 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914}
3915
3916static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3917{
Al Viro8687b632006-10-19 23:28:48 -07003918 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 int status = 0;
3920
3921 *res = 0;
3922 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3923 return -EIO;
3924 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003925 p = xdr_inline_decode(xdr, 8);
3926 if (unlikely(!p))
3927 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003928 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3930 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003931 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003933out_overflow:
3934 print_overflow_msg(__func__, xdr);
3935 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936}
3937
3938static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3939{
Al Viro8687b632006-10-19 23:28:48 -07003940 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003941 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942
3943 *used = 0;
3944 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3945 return -EIO;
3946 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003947 p = xdr_inline_decode(xdr, 8);
3948 if (unlikely(!p))
3949 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003950 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003952 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003954 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003956 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003957out_overflow:
3958 print_overflow_msg(__func__, xdr);
3959 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960}
3961
3962static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3963{
Al Viro8687b632006-10-19 23:28:48 -07003964 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 uint64_t sec;
3966 uint32_t nsec;
3967
Benny Halevyc0eae662009-08-14 17:20:14 +03003968 p = xdr_inline_decode(xdr, 12);
3969 if (unlikely(!p))
3970 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003971 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003972 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 time->tv_sec = (time_t)sec;
3974 time->tv_nsec = (long)nsec;
3975 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003976out_overflow:
3977 print_overflow_msg(__func__, xdr);
3978 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979}
3980
3981static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3982{
3983 int status = 0;
3984
3985 time->tv_sec = 0;
3986 time->tv_nsec = 0;
3987 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3988 return -EIO;
3989 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3990 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003991 if (status == 0)
3992 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3994 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003995 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 return status;
3997}
3998
3999static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4000{
4001 int status = 0;
4002
4003 time->tv_sec = 0;
4004 time->tv_nsec = 0;
4005 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4006 return -EIO;
4007 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4008 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004009 if (status == 0)
4010 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4012 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004013 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 return status;
4015}
4016
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004017static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4018 struct timespec *time)
4019{
4020 int status = 0;
4021
4022 time->tv_sec = 0;
4023 time->tv_nsec = 0;
4024 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4025 return -EIO;
4026 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4027 status = decode_attr_time(xdr, time);
4028 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4029 }
4030 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4031 (long)time->tv_nsec);
4032 return status;
4033}
4034
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4036{
4037 int status = 0;
4038
4039 time->tv_sec = 0;
4040 time->tv_nsec = 0;
4041 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4042 return -EIO;
4043 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4044 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004045 if (status == 0)
4046 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4048 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004049 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 return status;
4051}
4052
Trond Myklebust256e48b2012-06-21 11:18:13 -04004053static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054{
4055 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004056 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057
4058 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004059 dprintk("%s: server returned incorrect attribute length: "
4060 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004061 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062 attrwords << 2,
4063 (attrwords < nwords) ? '<' : '>',
4064 nwords << 2);
4065 return -EIO;
4066 }
4067 return 0;
4068}
4069
4070static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4071{
Al Viro8687b632006-10-19 23:28:48 -07004072 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073
Benny Halevyc0eae662009-08-14 17:20:14 +03004074 p = xdr_inline_decode(xdr, 20);
4075 if (unlikely(!p))
4076 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004077 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004078 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004079 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004081out_overflow:
4082 print_overflow_msg(__func__, xdr);
4083 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084}
4085
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004086static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087{
Al Viro8687b632006-10-19 23:28:48 -07004088 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 uint32_t supp, acc;
4090 int status;
4091
4092 status = decode_op_hdr(xdr, OP_ACCESS);
4093 if (status)
4094 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004095 p = xdr_inline_decode(xdr, 8);
4096 if (unlikely(!p))
4097 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004098 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004099 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004100 *supported = supp;
4101 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004103out_overflow:
4104 print_overflow_msg(__func__, xdr);
4105 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106}
4107
Benny Halevy07d30432009-08-14 17:19:52 +03004108static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109{
Al Viro8687b632006-10-19 23:28:48 -07004110 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004111
4112 p = xdr_inline_decode(xdr, len);
4113 if (likely(p)) {
4114 memcpy(buf, p, len);
4115 return 0;
4116 }
4117 print_overflow_msg(__func__, xdr);
4118 return -EIO;
4119}
4120
4121static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4122{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004123 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124}
4125
4126static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4127{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128 int status;
4129
4130 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004131 if (status != -EIO)
4132 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004133 if (!status)
4134 status = decode_stateid(xdr, &res->stateid);
4135 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136}
4137
Benny Halevydb942bb2009-08-14 17:19:56 +03004138static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4139{
Chuck Levercd937102012-03-02 17:14:31 -05004140 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141}
4142
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004143static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4144{
4145 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4146}
4147
Fred Isaman0b7c0152012-04-20 14:47:39 -04004148static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150 int status;
4151
4152 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004153 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004154 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004155 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156}
4157
4158static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4159{
Al Viro8687b632006-10-19 23:28:48 -07004160 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161 uint32_t bmlen;
4162 int status;
4163
4164 status = decode_op_hdr(xdr, OP_CREATE);
4165 if (status)
4166 return status;
4167 if ((status = decode_change_info(xdr, cinfo)))
4168 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004169 p = xdr_inline_decode(xdr, 4);
4170 if (unlikely(!p))
4171 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004172 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004173 p = xdr_inline_decode(xdr, bmlen << 2);
4174 if (likely(p))
4175 return 0;
4176out_overflow:
4177 print_overflow_msg(__func__, xdr);
4178 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179}
4180
4181static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4182{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004183 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004184 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 int status;
4186
4187 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4188 goto xdr_error;
4189 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4190 goto xdr_error;
4191 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4192 goto xdr_error;
4193 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4194 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004195 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4196 &res->fh_expire_type)) != 0)
4197 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4199 goto xdr_error;
4200 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4201 goto xdr_error;
4202 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4203 goto xdr_error;
4204 status = verify_attr_len(xdr, savep, attrlen);
4205xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004206 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 return status;
4208}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004209
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4211{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004212 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004213 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004215
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4217 goto xdr_error;
4218 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4219 goto xdr_error;
4220 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4221 goto xdr_error;
4222
4223 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4224 goto xdr_error;
4225 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4226 goto xdr_error;
4227 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4228 goto xdr_error;
4229 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4230 goto xdr_error;
4231 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4232 goto xdr_error;
4233 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4234 goto xdr_error;
4235
4236 status = verify_attr_len(xdr, savep, attrlen);
4237xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004238 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004239 return status;
4240}
4241
4242static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4243{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004244 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004245 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004247
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4249 goto xdr_error;
4250 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4251 goto xdr_error;
4252 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4253 goto xdr_error;
4254
4255 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4256 goto xdr_error;
4257 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4258 goto xdr_error;
4259
4260 status = verify_attr_len(xdr, savep, attrlen);
4261xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004262 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 return status;
4264}
4265
Andy Adamson88034c32012-05-23 05:02:34 -04004266static int decode_threshold_hint(struct xdr_stream *xdr,
4267 uint32_t *bitmap,
4268 uint64_t *res,
4269 uint32_t hint_bit)
4270{
4271 __be32 *p;
4272
4273 *res = 0;
4274 if (likely(bitmap[0] & hint_bit)) {
4275 p = xdr_inline_decode(xdr, 8);
4276 if (unlikely(!p))
4277 goto out_overflow;
4278 xdr_decode_hyper(p, res);
4279 }
4280 return 0;
4281out_overflow:
4282 print_overflow_msg(__func__, xdr);
4283 return -EIO;
4284}
4285
4286static int decode_first_threshold_item4(struct xdr_stream *xdr,
4287 struct nfs4_threshold *res)
4288{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004289 __be32 *p;
4290 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004291 uint32_t bitmap[3] = {0,}, attrlen;
4292 int status;
4293
4294 /* layout type */
4295 p = xdr_inline_decode(xdr, 4);
4296 if (unlikely(!p)) {
4297 print_overflow_msg(__func__, xdr);
4298 return -EIO;
4299 }
4300 res->l_type = be32_to_cpup(p);
4301
4302 /* thi_hintset bitmap */
4303 status = decode_attr_bitmap(xdr, bitmap);
4304 if (status < 0)
4305 goto xdr_error;
4306
4307 /* thi_hintlist length */
4308 status = decode_attr_length(xdr, &attrlen, &savep);
4309 if (status < 0)
4310 goto xdr_error;
4311 /* thi_hintlist */
4312 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4313 if (status < 0)
4314 goto xdr_error;
4315 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4316 if (status < 0)
4317 goto xdr_error;
4318 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4319 THRESHOLD_RD_IO);
4320 if (status < 0)
4321 goto xdr_error;
4322 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4323 THRESHOLD_WR_IO);
4324 if (status < 0)
4325 goto xdr_error;
4326
4327 status = verify_attr_len(xdr, savep, attrlen);
4328 res->bm = bitmap[0];
4329
4330 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4331 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4332 res->wr_io_sz);
4333xdr_error:
4334 dprintk("%s ret=%d!\n", __func__, status);
4335 return status;
4336}
4337
4338/*
4339 * Thresholds on pNFS direct I/O vrs MDS I/O
4340 */
4341static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4342 uint32_t *bitmap,
4343 struct nfs4_threshold *res)
4344{
4345 __be32 *p;
4346 int status = 0;
4347 uint32_t num;
4348
4349 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4350 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004351 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004352 /* Did the server return an unrequested attribute? */
4353 if (unlikely(res == NULL))
4354 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004355 p = xdr_inline_decode(xdr, 4);
4356 if (unlikely(!p))
4357 goto out_overflow;
4358 num = be32_to_cpup(p);
4359 if (num == 0)
4360 return 0;
4361 if (num > 1)
4362 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4363 "drivers per filesystem not supported\n",
4364 __func__);
4365
4366 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004367 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004368 }
4369 return status;
4370out_overflow:
4371 print_overflow_msg(__func__, xdr);
4372 return -EIO;
4373}
4374
Bryan Schumakerae42c702010-10-21 16:33:17 -04004375static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4376 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004377 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004378 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004379{
Trond Myklebustbca79472009-03-11 14:10:26 -04004380 int status;
4381 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004382 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004383 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004385 status = decode_attr_type(xdr, bitmap, &type);
4386 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004388 fattr->mode = 0;
4389 if (status != 0) {
4390 fattr->mode |= nfs_type2fmt[type];
4391 fattr->valid |= status;
4392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004394 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4395 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004397 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004398
4399 status = decode_attr_size(xdr, bitmap, &fattr->size);
4400 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004402 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004403
4404 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4405 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004407 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004408
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004409 err = 0;
4410 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004411 if (status < 0)
4412 goto xdr_error;
4413
4414 status = decode_attr_filehandle(xdr, bitmap, fh);
4415 if (status < 0)
4416 goto xdr_error;
4417
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004418 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4419 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004421 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004422
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004423 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004424 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004425 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004426 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004427
4428 status = decode_attr_mode(xdr, bitmap, &fmode);
4429 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004431 if (status != 0) {
4432 fattr->mode |= fmode;
4433 fattr->valid |= status;
4434 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004435
4436 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4437 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004439 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004440
Trond Myklebust6926afd2012-01-07 13:22:46 -05004441 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004442 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004444 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004445
Trond Myklebust6926afd2012-01-07 13:22:46 -05004446 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004447 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004449 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004450
4451 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4452 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004454 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004455
4456 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4457 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004459 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004460
4461 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4462 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004464 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004465
4466 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4467 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004469 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004470
4471 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4472 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004474 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004475
Trond Myklebust28331a42011-04-27 13:47:52 -04004476 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004477 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004478 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004479 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004480
Andy Adamson88034c32012-05-23 05:02:34 -04004481 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4482 if (status < 0)
4483 goto xdr_error;
4484
Bryan Schumakerae42c702010-10-21 16:33:17 -04004485xdr_error:
4486 dprintk("%s: xdr returned %d\n", __func__, -status);
4487 return status;
4488}
4489
4490static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004491 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4492 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004493{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004494 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004495 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004496 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004497 int status;
4498
4499 status = decode_op_hdr(xdr, OP_GETATTR);
4500 if (status < 0)
4501 goto xdr_error;
4502
4503 status = decode_attr_bitmap(xdr, bitmap);
4504 if (status < 0)
4505 goto xdr_error;
4506
4507 status = decode_attr_length(xdr, &attrlen, &savep);
4508 if (status < 0)
4509 goto xdr_error;
4510
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004511 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004512 if (status < 0)
4513 goto xdr_error;
4514
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004515 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004517 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004518 return status;
4519}
4520
Bryan Schumakerae42c702010-10-21 16:33:17 -04004521static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004522 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004523{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004524 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004525}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004526
Andy Adamson504913f2010-10-20 00:17:57 -04004527/*
4528 * Decode potentially multiple layout types. Currently we only support
4529 * one layout driver per file system.
4530 */
4531static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4532 uint32_t *layouttype)
4533{
4534 uint32_t *p;
4535 int num;
4536
4537 p = xdr_inline_decode(xdr, 4);
4538 if (unlikely(!p))
4539 goto out_overflow;
4540 num = be32_to_cpup(p);
4541
4542 /* pNFS is not supported by the underlying file system */
4543 if (num == 0) {
4544 *layouttype = 0;
4545 return 0;
4546 }
4547 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004548 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4549 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004550
4551 /* Decode and set first layout type, move xdr->p past unused types */
4552 p = xdr_inline_decode(xdr, num * 4);
4553 if (unlikely(!p))
4554 goto out_overflow;
4555 *layouttype = be32_to_cpup(p);
4556 return 0;
4557out_overflow:
4558 print_overflow_msg(__func__, xdr);
4559 return -EIO;
4560}
4561
4562/*
4563 * The type of file system exported.
4564 * Note we must ensure that layouttype is set in any non-error case.
4565 */
4566static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4567 uint32_t *layouttype)
4568{
4569 int status = 0;
4570
4571 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4572 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4573 return -EIO;
4574 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4575 status = decode_first_pnfs_layout_type(xdr, layouttype);
4576 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4577 } else
4578 *layouttype = 0;
4579 return status;
4580}
4581
Fred Isamandae100c2011-07-30 20:52:37 -04004582/*
4583 * The prefered block size for layout directed io
4584 */
4585static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4586 uint32_t *res)
4587{
4588 __be32 *p;
4589
4590 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4591 *res = 0;
4592 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4593 p = xdr_inline_decode(xdr, 4);
4594 if (unlikely(!p)) {
4595 print_overflow_msg(__func__, xdr);
4596 return -EIO;
4597 }
4598 *res = be32_to_cpup(p);
4599 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4600 }
4601 return 0;
4602}
4603
Linus Torvalds1da177e2005-04-16 15:20:36 -07004604static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4605{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004606 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004607 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 int status;
4609
4610 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4611 goto xdr_error;
4612 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4613 goto xdr_error;
4614 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4615 goto xdr_error;
4616
4617 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4618
4619 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4620 goto xdr_error;
4621 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4622 goto xdr_error;
4623 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4624 goto xdr_error;
4625 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4626 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4627 goto xdr_error;
4628 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004629 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4630 if (status != 0)
4631 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004632 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4633 if (status != 0)
4634 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004635 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4636 if (status)
4637 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638
4639 status = verify_attr_len(xdr, savep, attrlen);
4640xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004641 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642 return status;
4643}
4644
4645static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4646{
Al Viro8687b632006-10-19 23:28:48 -07004647 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648 uint32_t len;
4649 int status;
4650
Trond Myklebust99367812007-07-17 21:52:41 -04004651 /* Zero handle first to allow comparisons */
4652 memset(fh, 0, sizeof(*fh));
4653
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654 status = decode_op_hdr(xdr, OP_GETFH);
4655 if (status)
4656 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657
Benny Halevyc0eae662009-08-14 17:20:14 +03004658 p = xdr_inline_decode(xdr, 4);
4659 if (unlikely(!p))
4660 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004661 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 if (len > NFS4_FHSIZE)
4663 return -EIO;
4664 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004665 p = xdr_inline_decode(xdr, len);
4666 if (unlikely(!p))
4667 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004668 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004670out_overflow:
4671 print_overflow_msg(__func__, xdr);
4672 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004673}
4674
4675static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4676{
4677 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004678
Linus Torvalds1da177e2005-04-16 15:20:36 -07004679 status = decode_op_hdr(xdr, OP_LINK);
4680 if (status)
4681 return status;
4682 return decode_change_info(xdr, cinfo);
4683}
4684
4685/*
4686 * We create the owner, so we know a proper owner.id length is 4.
4687 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004688static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004689{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004690 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004691 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004692 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004694 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004695 if (unlikely(!p))
4696 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004697 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004698 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004699 type = be32_to_cpup(p++); /* 4 byte read */
4700 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004701 fl->fl_start = (loff_t)offset;
4702 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4703 if (length == ~(uint64_t)0)
4704 fl->fl_end = OFFSET_MAX;
4705 fl->fl_type = F_WRLCK;
4706 if (type & 1)
4707 fl->fl_type = F_RDLCK;
4708 fl->fl_pid = 0;
4709 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004710 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4711 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4712 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004713 if (likely(p))
4714 return -NFS4ERR_DENIED;
4715out_overflow:
4716 print_overflow_msg(__func__, xdr);
4717 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718}
4719
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004720static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004722 int status;
4723
4724 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004725 if (status == -EIO)
4726 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004727 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004728 status = decode_stateid(xdr, &res->stateid);
4729 if (unlikely(status))
4730 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004732 status = decode_lock_denied(xdr, NULL);
4733 if (res->open_seqid != NULL)
4734 nfs_increment_open_seqid(status, res->open_seqid);
4735 nfs_increment_lock_seqid(status, res->lock_seqid);
4736out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737 return status;
4738}
4739
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004740static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741{
4742 int status;
4743 status = decode_op_hdr(xdr, OP_LOCKT);
4744 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004745 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746 return status;
4747}
4748
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004749static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751 int status;
4752
4753 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004754 if (status != -EIO)
4755 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004756 if (status == 0)
4757 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004758 return status;
4759}
4760
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004761static int decode_release_lockowner(struct xdr_stream *xdr)
4762{
4763 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4764}
4765
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766static int decode_lookup(struct xdr_stream *xdr)
4767{
4768 return decode_op_hdr(xdr, OP_LOOKUP);
4769}
4770
4771/* This is too sick! */
4772static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4773{
Andy Adamson05d564f2008-12-23 16:06:15 -05004774 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004775 uint32_t limit_type, nblocks, blocksize;
4776
Benny Halevyc0eae662009-08-14 17:20:14 +03004777 p = xdr_inline_decode(xdr, 12);
4778 if (unlikely(!p))
4779 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004780 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004781 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004782 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004783 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004784 break;
4785 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004786 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004787 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004788 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789 }
4790 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004791out_overflow:
4792 print_overflow_msg(__func__, xdr);
4793 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794}
4795
4796static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4797{
Andy Adamson05d564f2008-12-23 16:06:15 -05004798 __be32 *p;
4799 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004800 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801
Benny Halevyc0eae662009-08-14 17:20:14 +03004802 p = xdr_inline_decode(xdr, 4);
4803 if (unlikely(!p))
4804 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004805 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4807 res->delegation_type = 0;
4808 return 0;
4809 }
Benny Halevy07d30432009-08-14 17:19:52 +03004810 status = decode_stateid(xdr, &res->delegation);
4811 if (unlikely(status))
4812 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004813 p = xdr_inline_decode(xdr, 4);
4814 if (unlikely(!p))
4815 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004816 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004817
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004819 case NFS4_OPEN_DELEGATE_READ:
4820 res->delegation_type = FMODE_READ;
4821 break;
4822 case NFS4_OPEN_DELEGATE_WRITE:
4823 res->delegation_type = FMODE_WRITE|FMODE_READ;
4824 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825 return -EIO;
4826 }
David Howells7539bba2006-08-22 20:06:09 -04004827 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004828out_overflow:
4829 print_overflow_msg(__func__, xdr);
4830 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004831}
4832
4833static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4834{
Andy Adamson05d564f2008-12-23 16:06:15 -05004835 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004836 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004837 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838
Andy Adamson05d564f2008-12-23 16:06:15 -05004839 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004840 if (status != -EIO)
4841 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004842 if (!status)
4843 status = decode_stateid(xdr, &res->stateid);
4844 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004845 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846
Andy Adamson05d564f2008-12-23 16:06:15 -05004847 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848
Benny Halevyc0eae662009-08-14 17:20:14 +03004849 p = xdr_inline_decode(xdr, 8);
4850 if (unlikely(!p))
4851 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004852 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004853 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004854 if (bmlen > 10)
4855 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004856
Benny Halevyc0eae662009-08-14 17:20:14 +03004857 p = xdr_inline_decode(xdr, bmlen << 2);
4858 if (unlikely(!p))
4859 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004860 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4861 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004862 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004863 for (; i < NFS4_BITMAP_SIZE; i++)
4864 res->attrset[i] = 0;
4865
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866 return decode_delegation(xdr, res);
4867xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004868 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004869 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004870out_overflow:
4871 print_overflow_msg(__func__, xdr);
4872 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873}
4874
4875static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4876{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004877 int status;
4878
Andy Adamson05d564f2008-12-23 16:06:15 -05004879 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004880 if (status != -EIO)
4881 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004882 if (!status)
4883 status = decode_stateid(xdr, &res->stateid);
4884 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885}
4886
4887static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4888{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889 int status;
4890
4891 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004892 if (status != -EIO)
4893 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004894 if (!status)
4895 status = decode_stateid(xdr, &res->stateid);
4896 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004897}
4898
4899static int decode_putfh(struct xdr_stream *xdr)
4900{
4901 return decode_op_hdr(xdr, OP_PUTFH);
4902}
4903
4904static int decode_putrootfh(struct xdr_stream *xdr)
4905{
4906 return decode_op_hdr(xdr, OP_PUTROOTFH);
4907}
4908
4909static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4910{
Al Viro8687b632006-10-19 23:28:48 -07004911 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04004912 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913 int status;
4914
4915 status = decode_op_hdr(xdr, OP_READ);
4916 if (status)
4917 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004918 p = xdr_inline_decode(xdr, 8);
4919 if (unlikely(!p))
4920 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004921 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004922 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04004923 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004924 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004925 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926 "count %u > recvd %u\n", count, recvd);
4927 count = recvd;
4928 eof = 0;
4929 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930 res->eof = eof;
4931 res->count = count;
4932 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004933out_overflow:
4934 print_overflow_msg(__func__, xdr);
4935 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936}
4937
4938static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4939{
Chuck Leverbcecff72007-10-26 13:32:03 -04004940 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004941 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942
4943 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004944 if (!status)
4945 status = decode_verifier(xdr, readdir->verifier.data);
4946 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004948 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004949 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004950 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04004951 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952}
4953
4954static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4955{
4956 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04004957 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004958 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004959 int status;
4960
4961 status = decode_op_hdr(xdr, OP_READLINK);
4962 if (status)
4963 return status;
4964
4965 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004966 p = xdr_inline_decode(xdr, 4);
4967 if (unlikely(!p))
4968 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004969 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004971 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972 return -ENAMETOOLONG;
4973 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04004974 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004976 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977 "count %u > recvd %u\n", len, recvd);
4978 return -EIO;
4979 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980 /*
4981 * The XDR encode routine has set things up so that
4982 * the link text will be copied directly into the
4983 * buffer. We just have to do overflow-checking,
4984 * and and null-terminate the text (the VFS expects
4985 * null-termination).
4986 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004987 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004989out_overflow:
4990 print_overflow_msg(__func__, xdr);
4991 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992}
4993
4994static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4995{
4996 int status;
4997
4998 status = decode_op_hdr(xdr, OP_REMOVE);
4999 if (status)
5000 goto out;
5001 status = decode_change_info(xdr, cinfo);
5002out:
5003 return status;
5004}
5005
5006static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5007 struct nfs4_change_info *new_cinfo)
5008{
5009 int status;
5010
5011 status = decode_op_hdr(xdr, OP_RENAME);
5012 if (status)
5013 goto out;
5014 if ((status = decode_change_info(xdr, old_cinfo)))
5015 goto out;
5016 status = decode_change_info(xdr, new_cinfo);
5017out:
5018 return status;
5019}
5020
5021static int decode_renew(struct xdr_stream *xdr)
5022{
5023 return decode_op_hdr(xdr, OP_RENEW);
5024}
5025
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005026static int
5027decode_restorefh(struct xdr_stream *xdr)
5028{
5029 return decode_op_hdr(xdr, OP_RESTOREFH);
5030}
5031
J. Bruce Fields029d1052005-06-22 17:16:22 +00005032static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005033 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005034{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005035 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005036 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005037 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005038 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005039 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005040
Andy Adamsonbf118a32011-12-07 11:55:27 -05005041 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005042 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5043 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005044
Trond Myklebust519d3952012-08-14 17:30:10 -04005045 xdr_enter_page(xdr, xdr->buf->page_len);
5046
Trond Myklebustcff298c2012-08-14 17:14:17 -04005047 /* Calculate the offset of the page data */
5048 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005049
J. Bruce Fields029d1052005-06-22 17:16:22 +00005050 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5051 goto out;
5052 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5053 goto out;
5054
5055 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5056 return -EIO;
5057 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005058
Andy Adamsonbf118a32011-12-07 11:55:27 -05005059 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5060 * are stored with the acl data to handle the problem of
5061 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005062 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005063 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005064
5065 /* Check for receive buffer overflow */
5066 if (res->acl_len > (xdr->nwords << 2) ||
5067 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5068 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005069 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005070 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005071 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005072 } else
5073 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005074
5075out:
5076 return status;
5077}
5078
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079static int
5080decode_savefh(struct xdr_stream *xdr)
5081{
5082 return decode_op_hdr(xdr, OP_SAVEFH);
5083}
5084
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005085static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086{
Al Viro8687b632006-10-19 23:28:48 -07005087 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088 uint32_t bmlen;
5089 int status;
5090
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091 status = decode_op_hdr(xdr, OP_SETATTR);
5092 if (status)
5093 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005094 p = xdr_inline_decode(xdr, 4);
5095 if (unlikely(!p))
5096 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005097 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005098 p = xdr_inline_decode(xdr, bmlen << 2);
5099 if (likely(p))
5100 return 0;
5101out_overflow:
5102 print_overflow_msg(__func__, xdr);
5103 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104}
5105
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005106static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107{
Al Viro8687b632006-10-19 23:28:48 -07005108 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109 uint32_t opnum;
5110 int32_t nfserr;
5111
Benny Halevyc0eae662009-08-14 17:20:14 +03005112 p = xdr_inline_decode(xdr, 8);
5113 if (unlikely(!p))
5114 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005115 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005117 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005118 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119 return -EIO;
5120 }
Benny Halevycccddf42009-08-14 17:20:19 +03005121 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005122 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005123 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5124 if (unlikely(!p))
5125 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005126 p = xdr_decode_hyper(p, &res->clientid);
5127 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128 } else if (nfserr == NFSERR_CLID_INUSE) {
5129 uint32_t len;
5130
5131 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005132 p = xdr_inline_decode(xdr, 4);
5133 if (unlikely(!p))
5134 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005135 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005136 p = xdr_inline_decode(xdr, len);
5137 if (unlikely(!p))
5138 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139
5140 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005141 p = xdr_inline_decode(xdr, 4);
5142 if (unlikely(!p))
5143 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005144 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005145 p = xdr_inline_decode(xdr, len);
5146 if (unlikely(!p))
5147 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005148 return -NFSERR_CLID_INUSE;
5149 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005150 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005151
5152 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005153out_overflow:
5154 print_overflow_msg(__func__, xdr);
5155 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156}
5157
5158static int decode_setclientid_confirm(struct xdr_stream *xdr)
5159{
5160 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5161}
5162
5163static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5164{
Al Viro8687b632006-10-19 23:28:48 -07005165 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005166 int status;
5167
5168 status = decode_op_hdr(xdr, OP_WRITE);
5169 if (status)
5170 return status;
5171
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005172 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005173 if (unlikely(!p))
5174 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005175 res->count = be32_to_cpup(p++);
5176 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005177 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005178out_overflow:
5179 print_overflow_msg(__func__, xdr);
5180 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181}
5182
5183static int decode_delegreturn(struct xdr_stream *xdr)
5184{
5185 return decode_op_hdr(xdr, OP_DELEGRETURN);
5186}
5187
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005188static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5189{
5190 __be32 *p;
5191
5192 p = xdr_inline_decode(xdr, 4);
5193 if (unlikely(!p))
5194 goto out_overflow;
5195 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5196 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5197 goto out_err;
5198
5199 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5200 if (unlikely(!p))
5201 goto out_overflow;
5202 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5203
5204 p = xdr_inline_decode(xdr, 8);
5205 if (unlikely(!p))
5206 goto out_overflow;
5207 flavor->gss.qop4 = be32_to_cpup(p++);
5208 flavor->gss.service = be32_to_cpup(p);
5209
5210 return 0;
5211
5212out_overflow:
5213 print_overflow_msg(__func__, xdr);
5214 return -EIO;
5215out_err:
5216 return -EINVAL;
5217}
5218
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005219static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005220{
5221 struct nfs4_secinfo_flavor *sec_flavor;
5222 int status;
5223 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005224 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005225
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005226 p = xdr_inline_decode(xdr, 4);
5227 if (unlikely(!p))
5228 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005229
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005230 res->flavors->num_flavors = 0;
5231 num_flavors = be32_to_cpup(p);
5232
5233 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005234 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005235 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005236 break;
5237
5238 p = xdr_inline_decode(xdr, 4);
5239 if (unlikely(!p))
5240 goto out_overflow;
5241 sec_flavor->flavor = be32_to_cpup(p);
5242
5243 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005244 status = decode_secinfo_gss(xdr, sec_flavor);
5245 if (status)
5246 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005247 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005248 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005249 }
5250
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005251 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005252out:
5253 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005254out_overflow:
5255 print_overflow_msg(__func__, xdr);
5256 return -EIO;
5257}
5258
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005259static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5260{
5261 int status = decode_op_hdr(xdr, OP_SECINFO);
5262 if (status)
5263 return status;
5264 return decode_secinfo_common(xdr, res);
5265}
5266
Benny Halevy99fe60d2009-04-01 09:22:29 -04005267#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005268static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5269{
5270 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5271 if (status)
5272 return status;
5273 return decode_secinfo_common(xdr, res);
5274}
5275
Benny Halevy99fe60d2009-04-01 09:22:29 -04005276static int decode_exchange_id(struct xdr_stream *xdr,
5277 struct nfs41_exchange_id_res *res)
5278{
5279 __be32 *p;
5280 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005281 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005282 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005283 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005284
5285 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5286 if (status)
5287 return status;
5288
Benny Halevyc0eae662009-08-14 17:20:14 +03005289 p = xdr_inline_decode(xdr, 8);
5290 if (unlikely(!p))
5291 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005292 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005293 p = xdr_inline_decode(xdr, 12);
5294 if (unlikely(!p))
5295 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005296 res->seqid = be32_to_cpup(p++);
5297 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005298
5299 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005300 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005301 if (dummy != SP4_NONE)
5302 return -EIO;
5303
Chuck Leveracdeb692012-05-21 22:46:16 -04005304 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005305 p = xdr_inline_decode(xdr, 8);
5306 if (unlikely(!p))
5307 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005308 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005309
Chuck Leveracdeb692012-05-21 22:46:16 -04005310 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005311 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5312 if (unlikely(status))
5313 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005314 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5315 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005316 memcpy(res->server_owner->major_id, dummy_str, dummy);
5317 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005318
Chuck Leveracdeb692012-05-21 22:46:16 -04005319 /* server_scope4 */
5320 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5321 if (unlikely(status))
5322 return status;
5323 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5324 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005325 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5326 res->server_scope->server_scope_sz = dummy;
5327
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005328 /* Implementation Id */
5329 p = xdr_inline_decode(xdr, 4);
5330 if (unlikely(!p))
5331 goto out_overflow;
5332 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005333
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005334 if (impl_id_count) {
5335 /* nii_domain */
5336 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5337 if (unlikely(status))
5338 return status;
5339 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5340 return -EIO;
5341 memcpy(res->impl_id->domain, dummy_str, dummy);
5342
5343 /* nii_name */
5344 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5345 if (unlikely(status))
5346 return status;
5347 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5348 return -EIO;
5349 memcpy(res->impl_id->name, dummy_str, dummy);
5350
5351 /* nii_date */
5352 p = xdr_inline_decode(xdr, 12);
5353 if (unlikely(!p))
5354 goto out_overflow;
5355 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5356 res->impl_id->date.nseconds = be32_to_cpup(p);
5357
5358 /* if there's more than one entry, ignore the rest */
5359 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005360 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005361out_overflow:
5362 print_overflow_msg(__func__, xdr);
5363 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005364}
Andy Adamsonfc931582009-04-01 09:22:31 -04005365
5366static int decode_chan_attrs(struct xdr_stream *xdr,
5367 struct nfs4_channel_attrs *attrs)
5368{
5369 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005370 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005371
Benny Halevyc0eae662009-08-14 17:20:14 +03005372 p = xdr_inline_decode(xdr, 28);
5373 if (unlikely(!p))
5374 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005375 val = be32_to_cpup(p++); /* headerpadsz */
5376 if (val)
5377 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005378 attrs->max_rqst_sz = be32_to_cpup(p++);
5379 attrs->max_resp_sz = be32_to_cpup(p++);
5380 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5381 attrs->max_ops = be32_to_cpup(p++);
5382 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005383 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005384 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005385 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5386 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005387 return -EINVAL;
5388 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005389 if (nr_attrs == 1) {
5390 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5391 if (unlikely(!p))
5392 goto out_overflow;
5393 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005394 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005395out_overflow:
5396 print_overflow_msg(__func__, xdr);
5397 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005398}
5399
Benny Halevye78291e2009-08-14 17:20:00 +03005400static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5401{
5402 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005403}
5404
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005405static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5406 struct nfs41_bind_conn_to_session_res *res)
5407{
5408 __be32 *p;
5409 int status;
5410
5411 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5412 if (!status)
5413 status = decode_sessionid(xdr, &res->session->sess_id);
5414 if (unlikely(status))
5415 return status;
5416
5417 /* dir flags, rdma mode bool */
5418 p = xdr_inline_decode(xdr, 8);
5419 if (unlikely(!p))
5420 goto out_overflow;
5421
5422 res->dir = be32_to_cpup(p++);
5423 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5424 return -EIO;
5425 if (be32_to_cpup(p) == 0)
5426 res->use_conn_in_rdma_mode = false;
5427 else
5428 res->use_conn_in_rdma_mode = true;
5429
5430 return 0;
5431out_overflow:
5432 print_overflow_msg(__func__, xdr);
5433 return -EIO;
5434}
5435
Andy Adamsonfc931582009-04-01 09:22:31 -04005436static int decode_create_session(struct xdr_stream *xdr,
5437 struct nfs41_create_session_res *res)
5438{
5439 __be32 *p;
5440 int status;
5441 struct nfs_client *clp = res->client;
5442 struct nfs4_session *session = clp->cl_session;
5443
5444 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005445 if (!status)
5446 status = decode_sessionid(xdr, &session->sess_id);
5447 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005448 return status;
5449
Andy Adamsonfc931582009-04-01 09:22:31 -04005450 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005451 p = xdr_inline_decode(xdr, 8);
5452 if (unlikely(!p))
5453 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005454 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005455 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005456
5457 /* Channel attributes */
5458 status = decode_chan_attrs(xdr, &session->fc_attrs);
5459 if (!status)
5460 status = decode_chan_attrs(xdr, &session->bc_attrs);
5461 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005462out_overflow:
5463 print_overflow_msg(__func__, xdr);
5464 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005465}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005466
5467static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5468{
5469 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5470}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005471
Trond Myklebust66245532012-05-25 17:18:09 -04005472static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5473{
5474 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5475}
5476
Ricardo Labiaga180197532009-12-05 16:08:40 -05005477static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5478{
5479 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5480}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005481#endif /* CONFIG_NFS_V4_1 */
5482
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005483static int decode_sequence(struct xdr_stream *xdr,
5484 struct nfs4_sequence_res *res,
5485 struct rpc_rqst *rqstp)
5486{
5487#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005488 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005489 struct nfs4_sessionid id;
5490 u32 dummy;
5491 int status;
5492 __be32 *p;
5493
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005494 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005495 return 0;
5496
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005497 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005498 if (!status)
5499 status = decode_sessionid(xdr, &id);
5500 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005501 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005502
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005503 /*
5504 * If the server returns different values for sessionID, slotID or
5505 * sequence number, the server is looney tunes.
5506 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005507 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005508 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005509
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005510 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005511 NFS4_MAX_SESSIONID_LEN)) {
5512 dprintk("%s Invalid session id\n", __func__);
5513 goto out_err;
5514 }
Benny Halevye78291e2009-08-14 17:20:00 +03005515
Benny Halevyc0eae662009-08-14 17:20:14 +03005516 p = xdr_inline_decode(xdr, 20);
5517 if (unlikely(!p))
5518 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005519
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005520 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005521 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005522 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005523 dprintk("%s Invalid sequence number\n", __func__);
5524 goto out_err;
5525 }
5526 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005527 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005528 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005529 dprintk("%s Invalid slot id\n", __func__);
5530 goto out_err;
5531 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005532 /* highest slot id */
5533 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005534 /* target highest slot id */
5535 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005536 /* result flags */
5537 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005538 status = 0;
5539out_err:
5540 res->sr_status = status;
5541 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005542out_overflow:
5543 print_overflow_msg(__func__, xdr);
5544 status = -EIO;
5545 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005546#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005547 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005548#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005549}
5550
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005551#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005552/*
5553 * TODO: Need to handle case when EOF != true;
5554 */
5555static int decode_getdevicelist(struct xdr_stream *xdr,
5556 struct pnfs_devicelist *res)
5557{
5558 __be32 *p;
5559 int status, i;
Trond Myklebust98d94522012-06-08 12:01:14 -04005560 nfs4_verifier verftemp;
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005561
5562 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5563 if (status)
5564 return status;
5565
5566 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5567 if (unlikely(!p))
5568 goto out_overflow;
5569
5570 /* TODO: Skip cookie for now */
5571 p += 2;
5572
5573 /* Read verifier */
Trond Myklebust98d94522012-06-08 12:01:14 -04005574 p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005575
5576 res->num_devs = be32_to_cpup(p);
5577
5578 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5579
5580 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005581 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005582 __func__, res->num_devs);
5583 return -EIO;
5584 }
5585
5586 p = xdr_inline_decode(xdr,
5587 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5588 if (unlikely(!p))
5589 goto out_overflow;
5590 for (i = 0; i < res->num_devs; i++)
5591 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5592 NFS4_DEVICEID4_SIZE);
5593 res->eof = be32_to_cpup(p);
5594 return 0;
5595out_overflow:
5596 print_overflow_msg(__func__, xdr);
5597 return -EIO;
5598}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005599
5600static int decode_getdeviceinfo(struct xdr_stream *xdr,
5601 struct pnfs_device *pdev)
5602{
5603 __be32 *p;
5604 uint32_t len, type;
5605 int status;
5606
5607 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5608 if (status) {
5609 if (status == -ETOOSMALL) {
5610 p = xdr_inline_decode(xdr, 4);
5611 if (unlikely(!p))
5612 goto out_overflow;
5613 pdev->mincount = be32_to_cpup(p);
5614 dprintk("%s: Min count too small. mincnt = %u\n",
5615 __func__, pdev->mincount);
5616 }
5617 return status;
5618 }
5619
5620 p = xdr_inline_decode(xdr, 8);
5621 if (unlikely(!p))
5622 goto out_overflow;
5623 type = be32_to_cpup(p++);
5624 if (type != pdev->layout_type) {
5625 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5626 __func__, pdev->layout_type, type);
5627 return -EINVAL;
5628 }
5629 /*
5630 * Get the length of the opaque device_addr4. xdr_read_pages places
5631 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5632 * and places the remaining xdr data in xdr_buf->tail
5633 */
5634 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005635 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5636 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005637
5638 /* Parse notification bitmap, verifying that it is zero. */
5639 p = xdr_inline_decode(xdr, 4);
5640 if (unlikely(!p))
5641 goto out_overflow;
5642 len = be32_to_cpup(p);
5643 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005644 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005645
5646 p = xdr_inline_decode(xdr, 4 * len);
5647 if (unlikely(!p))
5648 goto out_overflow;
5649 for (i = 0; i < len; i++, p++) {
5650 if (be32_to_cpup(p)) {
5651 dprintk("%s: notifications not supported\n",
5652 __func__);
5653 return -EIO;
5654 }
5655 }
5656 }
5657 return 0;
5658out_overflow:
5659 print_overflow_msg(__func__, xdr);
5660 return -EIO;
5661}
5662
5663static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5664 struct nfs4_layoutget_res *res)
5665{
5666 __be32 *p;
5667 int status;
5668 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005669 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005670
5671 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5672 if (status)
5673 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005674 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005675 if (unlikely(!p))
5676 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005677 res->return_on_close = be32_to_cpup(p);
5678 decode_stateid(xdr, &res->stateid);
5679 p = xdr_inline_decode(xdr, 4);
5680 if (unlikely(!p))
5681 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005682 layout_count = be32_to_cpup(p);
5683 if (!layout_count) {
5684 dprintk("%s: server responded with empty layout array\n",
5685 __func__);
5686 return -EINVAL;
5687 }
5688
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005689 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005690 if (unlikely(!p))
5691 goto out_overflow;
5692 p = xdr_decode_hyper(p, &res->range.offset);
5693 p = xdr_decode_hyper(p, &res->range.length);
5694 res->range.iomode = be32_to_cpup(p++);
5695 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005696 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005697
5698 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5699 __func__,
5700 (unsigned long)res->range.offset,
5701 (unsigned long)res->range.length,
5702 res->range.iomode,
5703 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005704 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005705
Trond Myklebust64bd5772012-06-20 22:35:05 -04005706 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005707 if (res->layoutp->len > recvd) {
5708 dprintk("NFS: server cheating in layoutget reply: "
5709 "layout len %u > recvd %u\n",
5710 res->layoutp->len, recvd);
5711 return -EINVAL;
5712 }
5713
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005714 if (layout_count > 1) {
5715 /* We only handle a length one array at the moment. Any
5716 * further entries are just ignored. Note that this means
5717 * the client may see a response that is less than the
5718 * minimum it requested.
5719 */
5720 dprintk("%s: server responded with %d layouts, dropping tail\n",
5721 __func__, layout_count);
5722 }
5723
5724 return 0;
5725out_overflow:
5726 print_overflow_msg(__func__, xdr);
5727 return -EIO;
5728}
Andy Adamson863a3c62011-03-23 13:27:54 +00005729
Benny Halevycbe82602011-05-22 19:52:37 +03005730static int decode_layoutreturn(struct xdr_stream *xdr,
5731 struct nfs4_layoutreturn_res *res)
5732{
5733 __be32 *p;
5734 int status;
5735
5736 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5737 if (status)
5738 return status;
5739 p = xdr_inline_decode(xdr, 4);
5740 if (unlikely(!p))
5741 goto out_overflow;
5742 res->lrs_present = be32_to_cpup(p);
5743 if (res->lrs_present)
5744 status = decode_stateid(xdr, &res->stateid);
5745 return status;
5746out_overflow:
5747 print_overflow_msg(__func__, xdr);
5748 return -EIO;
5749}
5750
Andy Adamson863a3c62011-03-23 13:27:54 +00005751static int decode_layoutcommit(struct xdr_stream *xdr,
5752 struct rpc_rqst *req,
5753 struct nfs4_layoutcommit_res *res)
5754{
5755 __be32 *p;
5756 __u32 sizechanged;
5757 int status;
5758
5759 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005760 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005761 if (status)
5762 return status;
5763
5764 p = xdr_inline_decode(xdr, 4);
5765 if (unlikely(!p))
5766 goto out_overflow;
5767 sizechanged = be32_to_cpup(p);
5768
5769 if (sizechanged) {
5770 /* throw away new size */
5771 p = xdr_inline_decode(xdr, 8);
5772 if (unlikely(!p))
5773 goto out_overflow;
5774 }
5775 return 0;
5776out_overflow:
5777 print_overflow_msg(__func__, xdr);
5778 return -EIO;
5779}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005780
5781static int decode_test_stateid(struct xdr_stream *xdr,
5782 struct nfs41_test_stateid_res *res)
5783{
5784 __be32 *p;
5785 int status;
5786 int num_res;
5787
5788 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5789 if (status)
5790 return status;
5791
5792 p = xdr_inline_decode(xdr, 4);
5793 if (unlikely(!p))
5794 goto out_overflow;
5795 num_res = be32_to_cpup(p++);
5796 if (num_res != 1)
5797 goto out;
5798
5799 p = xdr_inline_decode(xdr, 4);
5800 if (unlikely(!p))
5801 goto out_overflow;
5802 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005803
5804 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005805out_overflow:
5806 print_overflow_msg(__func__, xdr);
5807out:
5808 return -EIO;
5809}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005810
5811static int decode_free_stateid(struct xdr_stream *xdr,
5812 struct nfs41_free_stateid_res *res)
5813{
5814 __be32 *p;
5815 int status;
5816
5817 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5818 if (status)
5819 return status;
5820
5821 p = xdr_inline_decode(xdr, 4);
5822 if (unlikely(!p))
5823 goto out_overflow;
5824 res->status = be32_to_cpup(p++);
5825 return res->status;
5826out_overflow:
5827 print_overflow_msg(__func__, xdr);
5828 return -EIO;
5829}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005830#endif /* CONFIG_NFS_V4_1 */
5831
Linus Torvalds1da177e2005-04-16 15:20:36 -07005832/*
Benny Halevy49c25592008-12-23 16:06:16 -05005833 * END OF "GENERIC" DECODE ROUTINES.
5834 */
5835
5836/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005837 * Decode OPEN_DOWNGRADE response
5838 */
Chuck Leverbf269552010-12-14 14:59:29 +00005839static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5840 struct xdr_stream *xdr,
5841 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005842{
Andy Adamson05d564f2008-12-23 16:06:15 -05005843 struct compound_hdr hdr;
5844 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845
Chuck Leverbf269552010-12-14 14:59:29 +00005846 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005847 if (status)
5848 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005849 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005850 if (status)
5851 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005852 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005853 if (status)
5854 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005855 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005856 if (status != 0)
5857 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005858 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005859out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005860 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005861}
5862
5863/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005864 * Decode ACCESS response
5865 */
Chuck Leverbf269552010-12-14 14:59:29 +00005866static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5867 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005869 struct compound_hdr hdr;
5870 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005871
Chuck Leverbf269552010-12-14 14:59:29 +00005872 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005873 if (status)
5874 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005875 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005876 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005878 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005879 if (status != 0)
5880 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04005881 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04005882 if (status != 0)
5883 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005884 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005885out:
5886 return status;
5887}
5888
5889/*
5890 * Decode LOOKUP response
5891 */
Chuck Leverbf269552010-12-14 14:59:29 +00005892static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5893 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005894{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005895 struct compound_hdr hdr;
5896 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005897
Chuck Leverbf269552010-12-14 14:59:29 +00005898 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005899 if (status)
5900 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005901 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005902 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005903 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005904 status = decode_putfh(xdr);
5905 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005906 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005907 status = decode_lookup(xdr);
5908 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005910 status = decode_getfh(xdr, res->fh);
5911 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005912 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005913 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005914out:
5915 return status;
5916}
5917
5918/*
5919 * Decode LOOKUP_ROOT response
5920 */
Chuck Leverbf269552010-12-14 14:59:29 +00005921static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5922 struct xdr_stream *xdr,
5923 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005924{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005925 struct compound_hdr hdr;
5926 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005927
Chuck Leverbf269552010-12-14 14:59:29 +00005928 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005929 if (status)
5930 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005931 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005932 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005933 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005934 status = decode_putrootfh(xdr);
5935 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005936 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005937 status = decode_getfh(xdr, res->fh);
5938 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005939 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940out:
5941 return status;
5942}
5943
5944/*
5945 * Decode REMOVE response
5946 */
Chuck Leverbf269552010-12-14 14:59:29 +00005947static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5948 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005949{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005950 struct compound_hdr hdr;
5951 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005952
Chuck Leverbf269552010-12-14 14:59:29 +00005953 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005954 if (status)
5955 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005956 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005957 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005958 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005959 status = decode_putfh(xdr);
5960 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005961 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005962 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963out:
5964 return status;
5965}
5966
5967/*
5968 * Decode RENAME response
5969 */
Chuck Leverbf269552010-12-14 14:59:29 +00005970static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5971 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005973 struct compound_hdr hdr;
5974 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005975
Chuck Leverbf269552010-12-14 14:59:29 +00005976 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005977 if (status)
5978 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005979 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005980 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005981 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005982 status = decode_putfh(xdr);
5983 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005985 status = decode_savefh(xdr);
5986 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005987 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005988 status = decode_putfh(xdr);
5989 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005990 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005991 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005992out:
5993 return status;
5994}
5995
5996/*
5997 * Decode LINK response
5998 */
Chuck Leverbf269552010-12-14 14:59:29 +00005999static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6000 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006001{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006002 struct compound_hdr hdr;
6003 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006004
Chuck Leverbf269552010-12-14 14:59:29 +00006005 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006006 if (status)
6007 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006008 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006009 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006011 status = decode_putfh(xdr);
6012 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006014 status = decode_savefh(xdr);
6015 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006016 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006017 status = decode_putfh(xdr);
6018 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006019 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006020 status = decode_link(xdr, &res->cinfo);
6021 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006022 goto out;
6023 /*
6024 * Note order: OP_LINK leaves the directory as the current
6025 * filehandle.
6026 */
Chuck Leverbf269552010-12-14 14:59:29 +00006027 status = decode_restorefh(xdr);
6028 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006029 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006030 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006031out:
6032 return status;
6033}
6034
6035/*
6036 * Decode CREATE response
6037 */
Chuck Leverbf269552010-12-14 14:59:29 +00006038static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6039 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006040{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006041 struct compound_hdr hdr;
6042 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006043
Chuck Leverbf269552010-12-14 14:59:29 +00006044 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006045 if (status)
6046 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006047 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006048 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006049 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006050 status = decode_putfh(xdr);
6051 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006052 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006053 status = decode_create(xdr, &res->dir_cinfo);
6054 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006055 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006056 status = decode_getfh(xdr, res->fh);
6057 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006058 goto out;
Trond Myklebust7c317fc2012-04-27 13:48:18 -04006059 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006060out:
6061 return status;
6062}
6063
6064/*
6065 * Decode SYMLINK response
6066 */
Chuck Leverbf269552010-12-14 14:59:29 +00006067static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6068 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006069{
Chuck Leverbf269552010-12-14 14:59:29 +00006070 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006071}
6072
6073/*
6074 * Decode GETATTR response
6075 */
Chuck Leverbf269552010-12-14 14:59:29 +00006076static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6077 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006079 struct compound_hdr hdr;
6080 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006081
Chuck Leverbf269552010-12-14 14:59:29 +00006082 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083 if (status)
6084 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006085 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006086 if (status)
6087 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006088 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089 if (status)
6090 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006091 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092out:
6093 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006094}
6095
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006096/*
6097 * Encode an SETACL request
6098 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006099static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6100 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006101{
Andy Adamson05d564f2008-12-23 16:06:15 -05006102 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006103 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006104 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006105
Chuck Lever9f06c712010-12-14 14:59:18 +00006106 encode_compound_hdr(xdr, req, &hdr);
6107 encode_sequence(xdr, &args->seq_args, &hdr);
6108 encode_putfh(xdr, args->fh, &hdr);
6109 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006110 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006111}
Andy Adamson05d564f2008-12-23 16:06:15 -05006112
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006113/*
6114 * Decode SETACL response
6115 */
6116static int
Chuck Leverbf269552010-12-14 14:59:29 +00006117nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006118 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006119{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006120 struct compound_hdr hdr;
6121 int status;
6122
Chuck Leverbf269552010-12-14 14:59:29 +00006123 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006124 if (status)
6125 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006126 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006127 if (status)
6128 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006129 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006130 if (status)
6131 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006132 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006133out:
6134 return status;
6135}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006136
6137/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006138 * Decode GETACL response
6139 */
6140static int
Chuck Leverbf269552010-12-14 14:59:29 +00006141nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006142 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006143{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006144 struct compound_hdr hdr;
6145 int status;
6146
Trond Myklebust331818f2012-02-03 18:30:53 -05006147 if (res->acl_scratch != NULL) {
6148 void *p = page_address(res->acl_scratch);
6149 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6150 }
Chuck Leverbf269552010-12-14 14:59:29 +00006151 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006152 if (status)
6153 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006154 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006155 if (status)
6156 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006157 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006158 if (status)
6159 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006160 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006161
6162out:
6163 return status;
6164}
6165
6166/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006167 * Decode CLOSE response
6168 */
Chuck Leverbf269552010-12-14 14:59:29 +00006169static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6170 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006171{
Andy Adamson05d564f2008-12-23 16:06:15 -05006172 struct compound_hdr hdr;
6173 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006174
Chuck Leverbf269552010-12-14 14:59:29 +00006175 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006176 if (status)
6177 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006178 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006179 if (status)
6180 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006181 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006182 if (status)
6183 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006184 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006185 if (status != 0)
6186 goto out;
6187 /*
6188 * Note: Server may do delete on close for this file
6189 * in which case the getattr call will fail with
6190 * an ESTALE error. Shouldn't be a problem,
6191 * though, since fattr->valid will remain unset.
6192 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006193 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006195 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196}
6197
6198/*
6199 * Decode OPEN response
6200 */
Chuck Leverbf269552010-12-14 14:59:29 +00006201static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6202 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203{
Andy Adamson05d564f2008-12-23 16:06:15 -05006204 struct compound_hdr hdr;
6205 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206
Chuck Leverbf269552010-12-14 14:59:29 +00006207 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006208 if (status)
6209 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006210 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006211 if (status)
6212 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006213 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006214 if (status)
6215 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006216 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006217 if (status)
6218 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006219 status = decode_getfh(xdr, &res->fh);
6220 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006222 if (res->access_request)
6223 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust90ff0c52012-04-27 13:48:18 -04006224 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006226 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227}
6228
6229/*
6230 * Decode OPEN_CONFIRM response
6231 */
Chuck Leverbf269552010-12-14 14:59:29 +00006232static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6233 struct xdr_stream *xdr,
6234 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235{
Andy Adamson05d564f2008-12-23 16:06:15 -05006236 struct compound_hdr hdr;
6237 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238
Chuck Leverbf269552010-12-14 14:59:29 +00006239 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006240 if (status)
6241 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006242 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006243 if (status)
6244 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006245 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006247 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248}
6249
6250/*
6251 * Decode OPEN response
6252 */
Chuck Leverbf269552010-12-14 14:59:29 +00006253static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6254 struct xdr_stream *xdr,
6255 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006256{
Andy Adamson05d564f2008-12-23 16:06:15 -05006257 struct compound_hdr hdr;
6258 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006259
Chuck Leverbf269552010-12-14 14:59:29 +00006260 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006261 if (status)
6262 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006263 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006264 if (status)
6265 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006266 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006267 if (status)
6268 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006269 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006270 if (status)
6271 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006272 if (res->access_request)
6273 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006274 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006275out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006276 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277}
6278
6279/*
6280 * Decode SETATTR response
6281 */
Chuck Leverbf269552010-12-14 14:59:29 +00006282static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6283 struct xdr_stream *xdr,
6284 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285{
Andy Adamson05d564f2008-12-23 16:06:15 -05006286 struct compound_hdr hdr;
6287 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006288
Chuck Leverbf269552010-12-14 14:59:29 +00006289 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006290 if (status)
6291 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006292 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006293 if (status)
6294 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006295 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006296 if (status)
6297 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006298 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006299 if (status)
6300 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006301 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006302out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006303 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006304}
6305
6306/*
6307 * Decode LOCK response
6308 */
Chuck Leverbf269552010-12-14 14:59:29 +00006309static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6310 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006312 struct compound_hdr hdr;
6313 int status;
6314
Chuck Leverbf269552010-12-14 14:59:29 +00006315 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006316 if (status)
6317 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006318 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006319 if (status)
6320 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006321 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006322 if (status)
6323 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006324 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325out:
6326 return status;
6327}
6328
6329/*
6330 * Decode LOCKT response
6331 */
Chuck Leverbf269552010-12-14 14:59:29 +00006332static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6333 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006334{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335 struct compound_hdr hdr;
6336 int status;
6337
Chuck Leverbf269552010-12-14 14:59:29 +00006338 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339 if (status)
6340 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006341 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006342 if (status)
6343 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006344 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 if (status)
6346 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006347 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348out:
6349 return status;
6350}
6351
6352/*
6353 * Decode LOCKU response
6354 */
Chuck Leverbf269552010-12-14 14:59:29 +00006355static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6356 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358 struct compound_hdr hdr;
6359 int status;
6360
Chuck Leverbf269552010-12-14 14:59:29 +00006361 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 if (status)
6363 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006365 if (status)
6366 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368 if (status)
6369 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006370 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371out:
6372 return status;
6373}
6374
Chuck Leverbf269552010-12-14 14:59:29 +00006375static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6376 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006377{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006378 struct compound_hdr hdr;
6379 int status;
6380
Chuck Leverbf269552010-12-14 14:59:29 +00006381 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006382 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006383 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006384 return status;
6385}
6386
Linus Torvalds1da177e2005-04-16 15:20:36 -07006387/*
6388 * Decode READLINK response
6389 */
Chuck Leverbf269552010-12-14 14:59:29 +00006390static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6391 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006392 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006393{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006394 struct compound_hdr hdr;
6395 int status;
6396
Chuck Leverbf269552010-12-14 14:59:29 +00006397 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006398 if (status)
6399 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006400 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006401 if (status)
6402 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006403 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006404 if (status)
6405 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006406 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407out:
6408 return status;
6409}
6410
6411/*
6412 * Decode READDIR response
6413 */
Chuck Leverbf269552010-12-14 14:59:29 +00006414static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6415 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006417 struct compound_hdr hdr;
6418 int status;
6419
Chuck Leverbf269552010-12-14 14:59:29 +00006420 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006421 if (status)
6422 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006423 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006424 if (status)
6425 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006426 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427 if (status)
6428 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006429 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006430out:
6431 return status;
6432}
6433
6434/*
6435 * Decode Read response
6436 */
Chuck Leverbf269552010-12-14 14:59:29 +00006437static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6438 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440 struct compound_hdr hdr;
6441 int status;
6442
Chuck Leverbf269552010-12-14 14:59:29 +00006443 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 if (status)
6445 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006446 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006447 if (status)
6448 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006449 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450 if (status)
6451 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006452 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453 if (!status)
6454 status = res->count;
6455out:
6456 return status;
6457}
6458
6459/*
6460 * Decode WRITE response
6461 */
Chuck Leverbf269552010-12-14 14:59:29 +00006462static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6463 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465 struct compound_hdr hdr;
6466 int status;
6467
Chuck Leverbf269552010-12-14 14:59:29 +00006468 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006469 if (status)
6470 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006471 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006472 if (status)
6473 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006474 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475 if (status)
6476 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006477 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006478 if (status)
6479 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006480 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006481 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482 if (!status)
6483 status = res->count;
6484out:
6485 return status;
6486}
6487
6488/*
6489 * Decode COMMIT response
6490 */
Chuck Leverbf269552010-12-14 14:59:29 +00006491static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006492 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006493{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006494 struct compound_hdr hdr;
6495 int status;
6496
Chuck Leverbf269552010-12-14 14:59:29 +00006497 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006498 if (status)
6499 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006500 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006501 if (status)
6502 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006503 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006504 if (status)
6505 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006506 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507out:
6508 return status;
6509}
6510
6511/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006512 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513 */
Chuck Leverbf269552010-12-14 14:59:29 +00006514static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006515 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006517 struct compound_hdr hdr;
6518 int status;
6519
Chuck Leverbf269552010-12-14 14:59:29 +00006520 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006521 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006522 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006523 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006524 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006525 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527 return status;
6528}
6529
6530/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006531 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006532 */
Chuck Leverbf269552010-12-14 14:59:29 +00006533static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006534 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536 struct compound_hdr hdr;
6537 int status;
6538
Chuck Leverbf269552010-12-14 14:59:29 +00006539 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006540 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006541 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006542 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006543 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006545 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006546 return status;
6547}
6548
6549/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006550 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551 */
Chuck Leverbf269552010-12-14 14:59:29 +00006552static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006553 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006555 struct compound_hdr hdr;
6556 int status;
6557
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006560 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006561 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006562 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006563 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006564 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006565 return status;
6566}
6567
6568/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006569 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006570 */
Chuck Leverbf269552010-12-14 14:59:29 +00006571static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6572 struct xdr_stream *xdr,
6573 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006575 struct compound_hdr hdr;
6576 int status;
6577
Chuck Leverbf269552010-12-14 14:59:29 +00006578 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006579 if (status)
6580 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006581 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006582 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006584 status = decode_putfh(xdr);
6585 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006586 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006587 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006588out:
6589 return status;
6590}
6591
6592/*
6593 * Decode RENEW response
6594 */
Chuck Leverbf269552010-12-14 14:59:29 +00006595static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6596 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006598 struct compound_hdr hdr;
6599 int status;
6600
Chuck Leverbf269552010-12-14 14:59:29 +00006601 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006602 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006603 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006604 return status;
6605}
6606
6607/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006608 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006609 */
Chuck Leverbf269552010-12-14 14:59:29 +00006610static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6611 struct xdr_stream *xdr,
6612 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006614 struct compound_hdr hdr;
6615 int status;
6616
Chuck Leverbf269552010-12-14 14:59:29 +00006617 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006618 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006619 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006620 return status;
6621}
6622
6623/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006624 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006625 */
Chuck Leverbf269552010-12-14 14:59:29 +00006626static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6627 struct xdr_stream *xdr,
6628 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006630 struct compound_hdr hdr;
6631 int status;
6632
Chuck Leverbf269552010-12-14 14:59:29 +00006633 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006635 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006637 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006639 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640 return status;
6641}
6642
6643/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006644 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006645 */
Chuck Leverbf269552010-12-14 14:59:29 +00006646static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6647 struct xdr_stream *xdr,
6648 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650 struct compound_hdr hdr;
6651 int status;
6652
Chuck Leverbf269552010-12-14 14:59:29 +00006653 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006654 if (status)
6655 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006656 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006657 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006658 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006659 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006660 if (status != 0)
6661 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006662 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006663 if (status != 0)
6664 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006665 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006666out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006667 return status;
6668}
6669
Trond Myklebust683b57b2006-06-09 09:34:22 -04006670/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006671 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006672 */
Chuck Leverbf269552010-12-14 14:59:29 +00006673static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6674 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006675 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006676{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006677 struct compound_hdr hdr;
6678 int status;
6679
Chuck Leverbf269552010-12-14 14:59:29 +00006680 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006681 if (status)
6682 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006683 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006684 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006685 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006686 status = decode_putfh(xdr);
6687 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006688 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006689 status = decode_lookup(xdr);
6690 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006691 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006692 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006693 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6694 NULL, res->fs_locations,
6695 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006696out:
6697 return status;
6698}
6699
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006700/*
6701 * Decode SECINFO response
6702 */
6703static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6704 struct xdr_stream *xdr,
6705 struct nfs4_secinfo_res *res)
6706{
6707 struct compound_hdr hdr;
6708 int status;
6709
6710 status = decode_compound_hdr(xdr, &hdr);
6711 if (status)
6712 goto out;
6713 status = decode_sequence(xdr, &res->seq_res, rqstp);
6714 if (status)
6715 goto out;
6716 status = decode_putfh(xdr);
6717 if (status)
6718 goto out;
6719 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006720out:
6721 return status;
6722}
6723
Benny Halevy99fe60d2009-04-01 09:22:29 -04006724#if defined(CONFIG_NFS_V4_1)
6725/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006726 * Decode BIND_CONN_TO_SESSION response
6727 */
6728static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6729 struct xdr_stream *xdr,
6730 void *res)
6731{
6732 struct compound_hdr hdr;
6733 int status;
6734
6735 status = decode_compound_hdr(xdr, &hdr);
6736 if (!status)
6737 status = decode_bind_conn_to_session(xdr, res);
6738 return status;
6739}
6740
6741/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006742 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006743 */
Chuck Leverbf269552010-12-14 14:59:29 +00006744static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6745 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006746 void *res)
6747{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006748 struct compound_hdr hdr;
6749 int status;
6750
Chuck Leverbf269552010-12-14 14:59:29 +00006751 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006752 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006753 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006754 return status;
6755}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006756
6757/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006758 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006759 */
Chuck Leverbf269552010-12-14 14:59:29 +00006760static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6761 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006762 struct nfs41_create_session_res *res)
6763{
Andy Adamsonfc931582009-04-01 09:22:31 -04006764 struct compound_hdr hdr;
6765 int status;
6766
Chuck Leverbf269552010-12-14 14:59:29 +00006767 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006768 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006769 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006770 return status;
6771}
6772
6773/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006774 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006775 */
Chuck Leverbf269552010-12-14 14:59:29 +00006776static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6777 struct xdr_stream *xdr,
6778 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006779{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006780 struct compound_hdr hdr;
6781 int status;
6782
Chuck Leverbf269552010-12-14 14:59:29 +00006783 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006784 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006785 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006786 return status;
6787}
6788
6789/*
Trond Myklebust66245532012-05-25 17:18:09 -04006790 * Decode DESTROY_CLIENTID response
6791 */
6792static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6793 struct xdr_stream *xdr,
6794 void *res)
6795{
6796 struct compound_hdr hdr;
6797 int status;
6798
6799 status = decode_compound_hdr(xdr, &hdr);
6800 if (!status)
6801 status = decode_destroy_clientid(xdr, res);
6802 return status;
6803}
6804
6805/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006806 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006807 */
Chuck Leverbf269552010-12-14 14:59:29 +00006808static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6809 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006810 struct nfs4_sequence_res *res)
6811{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006812 struct compound_hdr hdr;
6813 int status;
6814
Chuck Leverbf269552010-12-14 14:59:29 +00006815 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006816 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006817 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006818 return status;
6819}
6820
6821/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006822 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006823 */
Chuck Leverbf269552010-12-14 14:59:29 +00006824static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6825 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006826 struct nfs4_get_lease_time_res *res)
6827{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006828 struct compound_hdr hdr;
6829 int status;
6830
Chuck Leverbf269552010-12-14 14:59:29 +00006831 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006832 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006833 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006834 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006835 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006836 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006837 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006838 return status;
6839}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006840
6841/*
6842 * Decode RECLAIM_COMPLETE response
6843 */
Chuck Leverbf269552010-12-14 14:59:29 +00006844static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6845 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006846 struct nfs41_reclaim_complete_res *res)
6847{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006848 struct compound_hdr hdr;
6849 int status;
6850
Chuck Leverbf269552010-12-14 14:59:29 +00006851 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006852 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006853 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006854 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006855 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006856 return status;
6857}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006858
6859/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006860 * Decode GETDEVICELIST response
6861 */
6862static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6863 struct xdr_stream *xdr,
6864 struct nfs4_getdevicelist_res *res)
6865{
6866 struct compound_hdr hdr;
6867 int status;
6868
6869 dprintk("encoding getdevicelist!\n");
6870
6871 status = decode_compound_hdr(xdr, &hdr);
6872 if (status != 0)
6873 goto out;
6874 status = decode_sequence(xdr, &res->seq_res, rqstp);
6875 if (status != 0)
6876 goto out;
6877 status = decode_putfh(xdr);
6878 if (status != 0)
6879 goto out;
6880 status = decode_getdevicelist(xdr, res->devlist);
6881out:
6882 return status;
6883}
6884
6885/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006886 * Decode GETDEVINFO response
6887 */
Chuck Leverbf269552010-12-14 14:59:29 +00006888static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6889 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006890 struct nfs4_getdeviceinfo_res *res)
6891{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006892 struct compound_hdr hdr;
6893 int status;
6894
Chuck Leverbf269552010-12-14 14:59:29 +00006895 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006896 if (status != 0)
6897 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006898 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006899 if (status != 0)
6900 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006901 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006902out:
6903 return status;
6904}
6905
6906/*
6907 * Decode LAYOUTGET response
6908 */
Chuck Leverbf269552010-12-14 14:59:29 +00006909static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6910 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006911 struct nfs4_layoutget_res *res)
6912{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006913 struct compound_hdr hdr;
6914 int status;
6915
Chuck Leverbf269552010-12-14 14:59:29 +00006916 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006917 if (status)
6918 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006919 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006920 if (status)
6921 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006922 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006923 if (status)
6924 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006925 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006926out:
6927 return status;
6928}
Andy Adamson863a3c62011-03-23 13:27:54 +00006929
6930/*
Benny Halevycbe82602011-05-22 19:52:37 +03006931 * Decode LAYOUTRETURN response
6932 */
6933static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6934 struct xdr_stream *xdr,
6935 struct nfs4_layoutreturn_res *res)
6936{
6937 struct compound_hdr hdr;
6938 int status;
6939
6940 status = decode_compound_hdr(xdr, &hdr);
6941 if (status)
6942 goto out;
6943 status = decode_sequence(xdr, &res->seq_res, rqstp);
6944 if (status)
6945 goto out;
6946 status = decode_putfh(xdr);
6947 if (status)
6948 goto out;
6949 status = decode_layoutreturn(xdr, res);
6950out:
6951 return status;
6952}
6953
6954/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006955 * Decode LAYOUTCOMMIT response
6956 */
6957static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6958 struct xdr_stream *xdr,
6959 struct nfs4_layoutcommit_res *res)
6960{
6961 struct compound_hdr hdr;
6962 int status;
6963
6964 status = decode_compound_hdr(xdr, &hdr);
6965 if (status)
6966 goto out;
6967 status = decode_sequence(xdr, &res->seq_res, rqstp);
6968 if (status)
6969 goto out;
6970 status = decode_putfh(xdr);
6971 if (status)
6972 goto out;
6973 status = decode_layoutcommit(xdr, rqstp, res);
6974 if (status)
6975 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006976 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006977out:
6978 return status;
6979}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006980
6981/*
6982 * Decode SECINFO_NO_NAME response
6983 */
6984static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6985 struct xdr_stream *xdr,
6986 struct nfs4_secinfo_res *res)
6987{
6988 struct compound_hdr hdr;
6989 int status;
6990
6991 status = decode_compound_hdr(xdr, &hdr);
6992 if (status)
6993 goto out;
6994 status = decode_sequence(xdr, &res->seq_res, rqstp);
6995 if (status)
6996 goto out;
6997 status = decode_putrootfh(xdr);
6998 if (status)
6999 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007000 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007001out:
7002 return status;
7003}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007004
7005/*
7006 * Decode TEST_STATEID response
7007 */
7008static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7009 struct xdr_stream *xdr,
7010 struct nfs41_test_stateid_res *res)
7011{
7012 struct compound_hdr hdr;
7013 int status;
7014
7015 status = decode_compound_hdr(xdr, &hdr);
7016 if (status)
7017 goto out;
7018 status = decode_sequence(xdr, &res->seq_res, rqstp);
7019 if (status)
7020 goto out;
7021 status = decode_test_stateid(xdr, res);
7022out:
7023 return status;
7024}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007025
7026/*
7027 * Decode FREE_STATEID response
7028 */
7029static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7030 struct xdr_stream *xdr,
7031 struct nfs41_free_stateid_res *res)
7032{
7033 struct compound_hdr hdr;
7034 int status;
7035
7036 status = decode_compound_hdr(xdr, &hdr);
7037 if (status)
7038 goto out;
7039 status = decode_sequence(xdr, &res->seq_res, rqstp);
7040 if (status)
7041 goto out;
7042 status = decode_free_stateid(xdr, res);
7043out:
7044 return status;
7045}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007046#endif /* CONFIG_NFS_V4_1 */
7047
Chuck Lever573c4e12010-12-14 14:58:11 +00007048/**
7049 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7050 * the local page cache.
7051 * @xdr: XDR stream where entry resides
7052 * @entry: buffer to fill in with entry data
7053 * @plus: boolean indicating whether this should be a readdirplus entry
7054 *
7055 * Returns zero if successful, otherwise a negative errno value is
7056 * returned.
7057 *
7058 * This function is not invoked during READDIR reply decoding, but
7059 * rather whenever an application invokes the getdents(2) system call
7060 * on a directory already in our cache.
7061 */
7062int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7063 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007064{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007065 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007066 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007067 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007068 __be32 *p = xdr_inline_decode(xdr, 4);
7069 if (unlikely(!p))
7070 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007071 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007072 p = xdr_inline_decode(xdr, 4);
7073 if (unlikely(!p))
7074 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007075 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007076 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007077 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007078 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007079 }
7080
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007081 p = xdr_inline_decode(xdr, 12);
7082 if (unlikely(!p))
7083 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007084 entry->prev_cookie = entry->cookie;
7085 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007086 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007087
Trond Myklebust9af8c222010-10-24 11:52:55 -04007088 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007089 if (unlikely(!p))
7090 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007091 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007092
7093 /*
7094 * In case the server doesn't return an inode number,
7095 * we fake one here. (We don't use inode number 0,
7096 * since glibc seems to choke on it...)
7097 */
7098 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007099 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007100
Trond Myklebust9af8c222010-10-24 11:52:55 -04007101 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007102 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007103
Trond Myklebust256e48b2012-06-21 11:18:13 -04007104 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007105 goto out_overflow;
7106
Chuck Lever573c4e12010-12-14 14:58:11 +00007107 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007108 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007109 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007110 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7111 entry->ino = entry->fattr->mounted_on_fileid;
7112 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007113 entry->ino = entry->fattr->fileid;
7114
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007115 entry->d_type = DT_UNKNOWN;
7116 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7117 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7118
Chuck Lever573c4e12010-12-14 14:58:11 +00007119 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007120
7121out_overflow:
7122 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007123 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007124}
7125
7126/*
7127 * We need to translate between nfs status return values and
7128 * the local errno values which may not be the same.
7129 */
7130static struct {
7131 int stat;
7132 int errno;
7133} nfs_errtbl[] = {
7134 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007135 { NFS4ERR_PERM, -EPERM },
7136 { NFS4ERR_NOENT, -ENOENT },
7137 { NFS4ERR_IO, -errno_NFSERR_IO},
7138 { NFS4ERR_NXIO, -ENXIO },
7139 { NFS4ERR_ACCESS, -EACCES },
7140 { NFS4ERR_EXIST, -EEXIST },
7141 { NFS4ERR_XDEV, -EXDEV },
7142 { NFS4ERR_NOTDIR, -ENOTDIR },
7143 { NFS4ERR_ISDIR, -EISDIR },
7144 { NFS4ERR_INVAL, -EINVAL },
7145 { NFS4ERR_FBIG, -EFBIG },
7146 { NFS4ERR_NOSPC, -ENOSPC },
7147 { NFS4ERR_ROFS, -EROFS },
7148 { NFS4ERR_MLINK, -EMLINK },
7149 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7150 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7151 { NFS4ERR_DQUOT, -EDQUOT },
7152 { NFS4ERR_STALE, -ESTALE },
7153 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007154 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7155 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7156 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007157 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007158 { NFS4ERR_BADTYPE, -EBADTYPE },
7159 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007160 { NFS4ERR_SYMLINK, -ELOOP },
7161 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7162 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007163 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007164};
7165
7166/*
7167 * Convert an NFS error code to a local one.
7168 * This one is used jointly by NFSv2 and NFSv3.
7169 */
7170static int
David Howells0a8ea432006-08-22 20:06:08 -04007171nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007172{
7173 int i;
7174 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7175 if (nfs_errtbl[i].stat == stat)
7176 return nfs_errtbl[i].errno;
7177 }
7178 if (stat <= 10000 || stat > 10100) {
7179 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007180 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007181 }
7182 /* If we cannot translate the error, the recovery routines should
7183 * handle it.
7184 * Note: remaining NFSv4 error codes have values > 10000, so should
7185 * not conflict with native Linux error codes.
7186 */
Benny Halevy856dff32008-03-31 17:39:06 +03007187 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007188}
7189
Linus Torvalds1da177e2005-04-16 15:20:36 -07007190#define PROC(proc, argtype, restype) \
7191[NFSPROC4_CLNT_##proc] = { \
7192 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007193 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007194 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007195 .p_arglen = NFS4_##argtype##_sz, \
7196 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007197 .p_statidx = NFSPROC4_CLNT_##proc, \
7198 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007199}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007200
7201struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007202 PROC(READ, enc_read, dec_read),
7203 PROC(WRITE, enc_write, dec_write),
7204 PROC(COMMIT, enc_commit, dec_commit),
7205 PROC(OPEN, enc_open, dec_open),
7206 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7207 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7208 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7209 PROC(CLOSE, enc_close, dec_close),
7210 PROC(SETATTR, enc_setattr, dec_setattr),
7211 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7212 PROC(RENEW, enc_renew, dec_renew),
7213 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7214 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7215 PROC(LOCK, enc_lock, dec_lock),
7216 PROC(LOCKT, enc_lockt, dec_lockt),
7217 PROC(LOCKU, enc_locku, dec_locku),
7218 PROC(ACCESS, enc_access, dec_access),
7219 PROC(GETATTR, enc_getattr, dec_getattr),
7220 PROC(LOOKUP, enc_lookup, dec_lookup),
7221 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7222 PROC(REMOVE, enc_remove, dec_remove),
7223 PROC(RENAME, enc_rename, dec_rename),
7224 PROC(LINK, enc_link, dec_link),
7225 PROC(SYMLINK, enc_symlink, dec_symlink),
7226 PROC(CREATE, enc_create, dec_create),
7227 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7228 PROC(STATFS, enc_statfs, dec_statfs),
7229 PROC(READLINK, enc_readlink, dec_readlink),
7230 PROC(READDIR, enc_readdir, dec_readdir),
7231 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7232 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7233 PROC(GETACL, enc_getacl, dec_getacl),
7234 PROC(SETACL, enc_setacl, dec_setacl),
7235 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7236 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007237 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007238#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007239 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7240 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7241 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7242 PROC(SEQUENCE, enc_sequence, dec_sequence),
7243 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7244 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7245 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7246 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007247 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007248 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007249 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007250 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007251 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007252 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007253 PROC(BIND_CONN_TO_SESSION,
7254 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007255 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007256#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007257};
7258
Trond Myklebusta613fa12012-01-20 13:53:56 -05007259const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007260 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007261 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007262 .procs = nfs4_procedures
7263};
7264
7265/*
7266 * Local variables:
7267 * c-basic-offset: 8
7268 * End:
7269 */