blob: 1a4a3bd415ed6c6b29e7cedf7809f9c1970288d4 [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))
David Quigleyaa9c2662013-05-22 12:50:44 -0400105#ifdef CONFIG_NFS_V4_SECURITY_LABEL
106/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
107#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
108#define encode_readdir_space 24
109#define encode_readdir_bitmask_sz 3
110#else
111#define nfs4_label_maxsz 0
112#define encode_readdir_space 20
113#define encode_readdir_bitmask_sz 2
114#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400115/* We support only one layout type per file system */
116#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000117/* This is based on getfattr, which uses the most attributes: */
118#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400119 3 + 3 + 3 + nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400120 nfs4_group_maxsz + nfs4_label_maxsz + \
121 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000122#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
123 nfs4_fattr_value_maxsz)
124#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400125#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
126 1 + 2 + 1 + \
127 nfs4_owner_maxsz + \
128 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400129 nfs4_label_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400130 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#define encode_savefh_maxsz (op_encode_hdr_maxsz)
132#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400133#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
134#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200135#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400136/* The 5 accounts for the PNFS attributes, and assumes that at most three
137 * layout types will be returned.
138 */
139#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
140 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
142#define decode_renew_maxsz (op_decode_hdr_maxsz)
143#define encode_setclientid_maxsz \
144 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500145 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
146 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
147 1 /* sc_prog */ + \
148 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
149 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
150 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#define decode_setclientid_maxsz \
152 (op_decode_hdr_maxsz + \
153 2 + \
154 1024) /* large value for CLID_INUSE */
155#define encode_setclientid_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 3 + (NFS4_VERIFIER_SIZE >> 2))
158#define decode_setclientid_confirm_maxsz \
159 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400160#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
161#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400162#define encode_share_access_maxsz \
163 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500164#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400165#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
166#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
167#define encode_open_maxsz (op_encode_hdr_maxsz + \
168 2 + encode_share_access_maxsz + 2 + \
169 open_owner_id_maxsz + \
170 encode_opentype_maxsz + \
171 encode_claim_null_maxsz)
172#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400173#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400174 decode_ace_maxsz)
175#define decode_change_info_maxsz (5)
176#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400177 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400178 decode_change_info_maxsz + 1 + \
179 nfs4_fattr_bitmap_maxsz + \
180 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400181#define encode_open_confirm_maxsz \
182 (op_encode_hdr_maxsz + \
183 encode_stateid_maxsz + 1)
184#define decode_open_confirm_maxsz \
185 (op_decode_hdr_maxsz + \
186 decode_stateid_maxsz)
187#define encode_open_downgrade_maxsz \
188 (op_encode_hdr_maxsz + \
189 encode_stateid_maxsz + 1 + \
190 encode_share_access_maxsz)
191#define decode_open_downgrade_maxsz \
192 (op_decode_hdr_maxsz + \
193 decode_stateid_maxsz)
194#define encode_close_maxsz (op_encode_hdr_maxsz + \
195 1 + encode_stateid_maxsz)
196#define decode_close_maxsz (op_decode_hdr_maxsz + \
197 decode_stateid_maxsz)
198#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
199 encode_stateid_maxsz + \
200 encode_attrs_maxsz)
201#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
202 nfs4_fattr_bitmap_maxsz)
203#define encode_read_maxsz (op_encode_hdr_maxsz + \
204 encode_stateid_maxsz + 3)
205#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
206#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400207 2 + encode_verifier_maxsz + 5 + \
208 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400209#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400210 decode_verifier_maxsz + \
211 nfs4_label_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400212#define encode_readlink_maxsz (op_encode_hdr_maxsz)
213#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
214#define encode_write_maxsz (op_encode_hdr_maxsz + \
215 encode_stateid_maxsz + 4)
216#define decode_write_maxsz (op_decode_hdr_maxsz + \
217 2 + decode_verifier_maxsz)
218#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
219#define decode_commit_maxsz (op_decode_hdr_maxsz + \
220 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221#define encode_remove_maxsz (op_encode_hdr_maxsz + \
222 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400223#define decode_remove_maxsz (op_decode_hdr_maxsz + \
224 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#define encode_rename_maxsz (op_encode_hdr_maxsz + \
226 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400227#define decode_rename_maxsz (op_decode_hdr_maxsz + \
228 decode_change_info_maxsz + \
229 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230#define encode_link_maxsz (op_encode_hdr_maxsz + \
231 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400232#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400233#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400234#define encode_lock_maxsz (op_encode_hdr_maxsz + \
235 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400236 1 + encode_stateid_maxsz + 1 + \
237 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400238#define decode_lock_denied_maxsz \
239 (8 + decode_lockowner_maxsz)
240#define decode_lock_maxsz (op_decode_hdr_maxsz + \
241 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400242#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
243 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400244#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
245 decode_lock_denied_maxsz)
246#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
247 encode_stateid_maxsz + \
248 4)
249#define decode_locku_maxsz (op_decode_hdr_maxsz + \
250 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400251#define encode_release_lockowner_maxsz \
252 (op_encode_hdr_maxsz + \
253 encode_lockowner_maxsz)
254#define decode_release_lockowner_maxsz \
255 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400256#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
257#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
259 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400260 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000261 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
263#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400264 1 + 2 + nfs4_name_maxsz + \
265 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400266#define decode_create_maxsz (op_decode_hdr_maxsz + \
267 decode_change_info_maxsz + \
268 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400269#define encode_statfs_maxsz (encode_getattr_maxsz)
270#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
272#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400273#define encode_getacl_maxsz (encode_getattr_maxsz)
274#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
275 nfs4_fattr_bitmap_maxsz + 1)
276#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
277 encode_stateid_maxsz + 3)
278#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400279#define encode_fs_locations_maxsz \
280 (encode_getattr_maxsz)
281#define decode_fs_locations_maxsz \
282 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000283#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400284#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 -0400285
286#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400287#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500288#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
289 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400290
Benny Halevy99fe60d2009-04-01 09:22:29 -0400291#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
292 encode_verifier_maxsz + \
293 1 /* co_ownerid.len */ + \
294 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
295 1 /* flags */ + \
296 1 /* spa_how */ + \
297 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500298 1 /* implementation id array of size 1 */ + \
299 1 /* nii_domain */ + \
300 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
301 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500302 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500303 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400304#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
305 2 /* eir_clientid */ + \
306 1 /* eir_sequenceid */ + \
307 1 /* eir_flags */ + \
308 1 /* spr_how */ + \
309 0 /* SP4_NONE (for now) */ + \
310 2 /* eir_server_owner.so_minor_id */ + \
311 /* eir_server_owner.so_major_id<> */ \
312 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
313 /* eir_server_scope<> */ \
314 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
315 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500316 1 /* nii_domain */ + \
317 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
318 1 /* nii_name */ + \
319 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
320 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400321#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
322#define decode_channel_attrs_maxsz (6 + \
323 1 /* ca_rdma_ird.len */ + \
324 1 /* ca_rdma_ird */)
325#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
326 2 /* csa_clientid */ + \
327 1 /* csa_sequence */ + \
328 1 /* csa_flags */ + \
329 encode_channel_attrs_maxsz + \
330 encode_channel_attrs_maxsz + \
331 1 /* csa_cb_program */ + \
332 1 /* csa_sec_parms.len (1) */ + \
333 1 /* cb_secflavor (AUTH_SYS) */ + \
334 1 /* stamp */ + \
335 1 /* machinename.len */ + \
336 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
337 1 /* uid */ + \
338 1 /* gid */ + \
339 1 /* gids.len (0) */)
340#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
341 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
342 1 /* csr_sequence */ + \
343 1 /* csr_flags */ + \
344 decode_channel_attrs_maxsz + \
345 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400346#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
347 /* bctsa_sessid */ \
348 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
349 1 /* bctsa_dir */ + \
350 1 /* bctsa_use_conn_in_rdma_mode */)
351#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
352 /* bctsr_sessid */ \
353 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
354 1 /* bctsr_dir */ + \
355 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400356#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
357#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400358#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
359#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400360#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
361 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
362#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
363 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500364#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
365#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400366#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
367 encode_verifier_maxsz)
368#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
369 2 /* nfs_cookie4 gdlr_cookie */ + \
370 decode_verifier_maxsz \
371 /* verifier4 gdlr_verifier */ + \
372 1 /* gdlr_deviceid_list count */ + \
373 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
374 NFS4_DEVICEID4_SIZE) \
375 /* gdlr_deviceid_list */ + \
376 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400377#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
378 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
379#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
380 1 /* layout type */ + \
381 1 /* opaque devaddr4 length */ + \
382 /* devaddr4 payload is read into page */ \
383 1 /* notification bitmap length */ + \
384 1 /* notification bitmap */)
385#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
386 encode_stateid_maxsz)
387#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
388 decode_stateid_maxsz + \
389 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000390#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
391 2 /* offset */ + \
392 2 /* length */ + \
393 1 /* reclaim */ + \
394 encode_stateid_maxsz + \
395 1 /* new offset (true) */ + \
396 2 /* last byte written */ + \
397 1 /* nt_timechanged (false) */ + \
398 1 /* layoutupdate4 layout type */ + \
399 1 /* NULL filelayout layoutupdate4 payload */)
400#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300401#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
402 encode_stateid_maxsz + \
403 1 /* FIXME: opaque lrf_body always empty at the moment */)
404#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
405 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400406#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
407#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400408#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
409 XDR_QUADLEN(NFS4_STATEID_SIZE))
410#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400411#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
412 XDR_QUADLEN(NFS4_STATEID_SIZE))
413#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400414#else /* CONFIG_NFS_V4_1 */
415#define encode_sequence_maxsz 0
416#define decode_sequence_maxsz 0
417#endif /* CONFIG_NFS_V4_1 */
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
420#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
421#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400426 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400428 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400432 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400434 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400436 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400438 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400440 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400444 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400446 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400448 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400449 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400451 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400453 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400454 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400456 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400458 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400460 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400462 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400464 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400465 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400466 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400467 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400468 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400469 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400471 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400472 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400473 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400474 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400475 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400477#define NFS4_enc_open_confirm_sz \
478 (compound_encode_hdr_maxsz + \
479 encode_putfh_maxsz + \
480 encode_open_confirm_maxsz)
481#define NFS4_dec_open_confirm_sz \
482 (compound_decode_hdr_maxsz + \
483 decode_putfh_maxsz + \
484 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400486 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400488 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400489 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400490 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400494 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400495 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400496 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497#define NFS4_enc_open_downgrade_sz \
498 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400499 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400500 encode_putfh_maxsz + \
501 encode_open_downgrade_maxsz + \
502 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#define NFS4_dec_open_downgrade_sz \
504 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400505 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400506 decode_putfh_maxsz + \
507 decode_open_downgrade_maxsz + \
508 decode_getattr_maxsz)
509#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400510 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400511 encode_putfh_maxsz + \
512 encode_close_maxsz + \
513 encode_getattr_maxsz)
514#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400515 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400516 decode_putfh_maxsz + \
517 decode_close_maxsz + \
518 decode_getattr_maxsz)
519#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400521 encode_putfh_maxsz + \
522 encode_setattr_maxsz + \
523 encode_getattr_maxsz)
524#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400525 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400526 decode_putfh_maxsz + \
527 decode_setattr_maxsz + \
528 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 encode_putfh_maxsz + \
532 encode_fsinfo_maxsz)
533#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 decode_putfh_maxsz + \
536 decode_fsinfo_maxsz)
537#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
538 encode_renew_maxsz)
539#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
540 decode_renew_maxsz)
541#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
542 encode_setclientid_maxsz)
543#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
544 decode_setclientid_maxsz)
545#define NFS4_enc_setclientid_confirm_sz \
546 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400547 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548#define NFS4_dec_setclientid_confirm_sz \
549 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400550 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400552 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400554 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400558 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400560 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400562 encode_lockt_maxsz)
563#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400565 decode_putfh_maxsz + \
566 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400570 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400574 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400575#define NFS4_enc_release_lockowner_sz \
576 (compound_encode_hdr_maxsz + \
577 encode_lockowner_maxsz)
578#define NFS4_dec_release_lockowner_sz \
579 (compound_decode_hdr_maxsz + \
580 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581#define NFS4_enc_access_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 + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400584 encode_access_maxsz + \
585 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400587 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400589 decode_access_maxsz + \
590 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400592 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 encode_putfh_maxsz + \
594 encode_getattr_maxsz)
595#define NFS4_dec_getattr_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 + \
598 decode_getattr_maxsz)
599#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400600 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 encode_putfh_maxsz + \
602 encode_lookup_maxsz + \
603 encode_getattr_maxsz + \
604 encode_getfh_maxsz)
605#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400608 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 decode_getattr_maxsz + \
610 decode_getfh_maxsz)
611#define NFS4_enc_lookup_root_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_putrootfh_maxsz + \
614 encode_getattr_maxsz + \
615 encode_getfh_maxsz)
616#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400617 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 decode_putrootfh_maxsz + \
619 decode_getattr_maxsz + \
620 decode_getfh_maxsz)
621#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400624 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#define NFS4_dec_remove_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 + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400628 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400630 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 encode_putfh_maxsz + \
632 encode_savefh_maxsz + \
633 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400634 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400636 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 decode_putfh_maxsz + \
638 decode_savefh_maxsz + \
639 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400640 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 encode_putfh_maxsz + \
644 encode_savefh_maxsz + \
645 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400646 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400647 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400648 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 decode_putfh_maxsz + \
652 decode_savefh_maxsz + \
653 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400654 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400655 decode_restorefh_maxsz + \
656 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400658 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 encode_putfh_maxsz + \
660 encode_symlink_maxsz + \
661 encode_getattr_maxsz + \
662 encode_getfh_maxsz)
663#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400664 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 decode_putfh_maxsz + \
666 decode_symlink_maxsz + \
667 decode_getattr_maxsz + \
668 decode_getfh_maxsz)
669#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400670 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 encode_putfh_maxsz + \
672 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400673 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400674 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675#define NFS4_dec_create_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_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400679 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400680 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400682 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 encode_putfh_maxsz + \
684 encode_getattr_maxsz)
685#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400686 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 decode_putfh_maxsz + \
688 decode_getattr_maxsz)
689#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400690 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400692 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400694 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400696 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400698 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800699 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 encode_getattr_maxsz)
701#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400702 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800703 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 decode_getattr_maxsz)
705#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400706 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100708 encode_delegreturn_maxsz + \
709 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400711 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100712 decode_delegreturn_maxsz + \
713 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000714#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400715 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000716 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400717 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000718#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400719 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000720 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400721 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000722#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400723 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000724 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400725 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000726#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400727 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000728 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400729 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400730#define NFS4_enc_fs_locations_sz \
731 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400732 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400733 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400734 encode_lookup_maxsz + \
735 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400736#define NFS4_dec_fs_locations_sz \
737 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400738 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400739 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400740 decode_lookup_maxsz + \
741 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000742#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
743 encode_sequence_maxsz + \
744 encode_putfh_maxsz + \
745 encode_secinfo_maxsz)
746#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
747 decode_sequence_maxsz + \
748 decode_putfh_maxsz + \
749 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400750#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400751#define NFS4_enc_bind_conn_to_session_sz \
752 (compound_encode_hdr_maxsz + \
753 encode_bind_conn_to_session_maxsz)
754#define NFS4_dec_bind_conn_to_session_sz \
755 (compound_decode_hdr_maxsz + \
756 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400757#define NFS4_enc_exchange_id_sz \
758 (compound_encode_hdr_maxsz + \
759 encode_exchange_id_maxsz)
760#define NFS4_dec_exchange_id_sz \
761 (compound_decode_hdr_maxsz + \
762 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400763#define NFS4_enc_create_session_sz \
764 (compound_encode_hdr_maxsz + \
765 encode_create_session_maxsz)
766#define NFS4_dec_create_session_sz \
767 (compound_decode_hdr_maxsz + \
768 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400769#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
770 encode_destroy_session_maxsz)
771#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
772 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400773#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
774 encode_destroy_clientid_maxsz)
775#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
776 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400777#define NFS4_enc_sequence_sz \
778 (compound_decode_hdr_maxsz + \
779 encode_sequence_maxsz)
780#define NFS4_dec_sequence_sz \
781 (compound_decode_hdr_maxsz + \
782 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400783#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
784 encode_sequence_maxsz + \
785 encode_putrootfh_maxsz + \
786 encode_fsinfo_maxsz)
787#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
788 decode_sequence_maxsz + \
789 decode_putrootfh_maxsz + \
790 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500791#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
792 encode_sequence_maxsz + \
793 encode_reclaim_complete_maxsz)
794#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
795 decode_sequence_maxsz + \
796 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400797#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
798 encode_sequence_maxsz + \
799 encode_putfh_maxsz + \
800 encode_getdevicelist_maxsz)
801#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
802 decode_sequence_maxsz + \
803 decode_putfh_maxsz + \
804 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400805#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
806 encode_sequence_maxsz +\
807 encode_getdeviceinfo_maxsz)
808#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
809 decode_sequence_maxsz + \
810 decode_getdeviceinfo_maxsz)
811#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
812 encode_sequence_maxsz + \
813 encode_putfh_maxsz + \
814 encode_layoutget_maxsz)
815#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
816 decode_sequence_maxsz + \
817 decode_putfh_maxsz + \
818 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000819#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
820 encode_sequence_maxsz +\
821 encode_putfh_maxsz + \
822 encode_layoutcommit_maxsz + \
823 encode_getattr_maxsz)
824#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
825 decode_sequence_maxsz + \
826 decode_putfh_maxsz + \
827 decode_layoutcommit_maxsz + \
828 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300829#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
830 encode_sequence_maxsz + \
831 encode_putfh_maxsz + \
832 encode_layoutreturn_maxsz)
833#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
834 decode_sequence_maxsz + \
835 decode_putfh_maxsz + \
836 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400837#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
838 encode_sequence_maxsz + \
839 encode_putrootfh_maxsz +\
840 encode_secinfo_no_name_maxsz)
841#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
842 decode_sequence_maxsz + \
843 decode_putrootfh_maxsz + \
844 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400845#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
846 encode_sequence_maxsz + \
847 encode_test_stateid_maxsz)
848#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
849 decode_sequence_maxsz + \
850 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400851#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
852 encode_sequence_maxsz + \
853 encode_free_stateid_maxsz)
854#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
855 decode_sequence_maxsz + \
856 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500857
858const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
859 compound_encode_hdr_maxsz +
860 encode_sequence_maxsz +
861 encode_putfh_maxsz +
862 encode_getattr_maxsz) *
863 XDR_UNIT);
864
865const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
866 compound_decode_hdr_maxsz +
867 decode_sequence_maxsz +
868 decode_putfh_maxsz) *
869 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400870
871const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
872 compound_decode_hdr_maxsz +
873 decode_sequence_maxsz) *
874 XDR_UNIT);
875EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400876#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Trond Myklebustbca79472009-03-11 14:10:26 -0400878static const umode_t nfs_type2fmt[] = {
879 [NF4BAD] = 0,
880 [NF4REG] = S_IFREG,
881 [NF4DIR] = S_IFDIR,
882 [NF4BLK] = S_IFBLK,
883 [NF4CHR] = S_IFCHR,
884 [NF4LNK] = S_IFLNK,
885 [NF4SOCK] = S_IFSOCK,
886 [NF4FIFO] = S_IFIFO,
887 [NF4ATTRDIR] = 0,
888 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889};
890
891struct compound_hdr {
892 int32_t status;
893 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500894 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 uint32_t taglen;
896 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400897 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400898 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899};
900
Benny Halevy13c65ce2009-08-14 17:19:25 +0300901static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
902{
903 __be32 *p = xdr_reserve_space(xdr, nbytes);
904 BUG_ON(!p);
905 return p;
906}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Trond Myklebustcb17e552012-03-04 18:13:56 -0500908static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
909{
910 __be32 *p;
911
912 p = xdr_reserve_space(xdr, len);
913 xdr_encode_opaque_fixed(p, buf, len);
914}
915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
917{
Al Viro8687b632006-10-19 23:28:48 -0700918 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500920 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 xdr_encode_opaque(p, str, len);
922}
923
Trond Myklebust4ade9822012-03-04 18:13:57 -0500924static void encode_uint32(struct xdr_stream *xdr, u32 n)
925{
926 __be32 *p;
927
928 p = reserve_space(xdr, 4);
929 *p = cpu_to_be32(n);
930}
931
Trond Myklebustff2eb682012-03-05 11:40:12 -0500932static void encode_uint64(struct xdr_stream *xdr, u64 n)
933{
934 __be32 *p;
935
936 p = reserve_space(xdr, 8);
937 xdr_encode_hyper(p, n);
938}
939
Trond Myklebust4ade9822012-03-04 18:13:57 -0500940static void encode_nfs4_seqid(struct xdr_stream *xdr,
941 const struct nfs_seqid *seqid)
942{
943 encode_uint32(xdr, seqid->sequence->counter);
944}
945
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400946static void encode_compound_hdr(struct xdr_stream *xdr,
947 struct rpc_rqst *req,
948 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949{
Al Viro8687b632006-10-19 23:28:48 -0700950 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400951 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400952
953 /* initialize running count of expected bytes in reply.
954 * NOTE: the replied tag SHOULD be the same is the one sent,
955 * but this is not required as a MUST for the server to do so. */
956 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Trond Myklebust7fc38842012-10-15 11:51:21 -0400958 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500959 encode_string(xdr, hdr->taglen, hdr->tag);
960 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300961 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500962 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300963 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500964}
965
Trond Myklebustab19b482012-03-04 18:13:57 -0500966static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
967 uint32_t replen,
968 struct compound_hdr *hdr)
969{
970 encode_uint32(xdr, op);
971 hdr->nops++;
972 hdr->replen += replen;
973}
974
Andy Adamsond0179312008-12-23 16:06:17 -0500975static void encode_nops(struct compound_hdr *hdr)
976{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400977 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500978 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979}
980
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500981static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
982{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500983 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500984}
985
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
987{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500988 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
David Quigleyaa9c2662013-05-22 12:50:44 -0400991static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
992 const struct nfs4_label *label,
993 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994{
995 char owner_name[IDMAP_NAMESZ];
996 char owner_group[IDMAP_NAMESZ];
997 int owner_namelen = 0;
998 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700999 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001000 unsigned i;
1001 uint32_t len = 0;
1002 uint32_t bmval_len;
1003 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
1005 /*
1006 * We reserve enough space to write the entire attribute buffer at once.
1007 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001008 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1009 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001010 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001012 if (iap->ia_valid & ATTR_SIZE) {
1013 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001015 }
1016 if (iap->ia_valid & ATTR_MODE) {
1017 bmval[1] |= FATTR4_WORD1_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 len += 4;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001019 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001021 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001023 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001024 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 /* XXX */
1026 strcpy(owner_name, "nobody");
1027 owner_namelen = sizeof("nobody") - 1;
1028 /* goto out; */
1029 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001030 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1032 }
1033 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001034 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001036 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001037 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 strcpy(owner_group, "nobody");
1039 owner_grouplen = sizeof("nobody") - 1;
1040 /* goto out; */
1041 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001042 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1044 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001046 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1047 len += 16;
1048 } else if (iap->ia_valid & ATTR_ATIME) {
1049 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1050 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 }
1052 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001053 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1054 len += 16;
1055 } else if (iap->ia_valid & ATTR_MTIME) {
1056 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1057 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001059 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001060 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1061 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1062 }
1063
1064 if (bmval[2] != 0)
1065 bmval_len = 3;
1066 else if (bmval[1] != 0)
1067 bmval_len = 2;
1068 else
1069 bmval_len = 1;
1070
1071 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1072
1073 *p++ = cpu_to_be32(bmval_len);
1074 for (i = 0; i < bmval_len; i++)
1075 *p++ = cpu_to_be32(bmval[i]);
1076 *p++ = cpu_to_be32(len);
1077
1078 if (bmval[0] & FATTR4_WORD0_SIZE)
1079 p = xdr_encode_hyper(p, iap->ia_size);
1080 if (bmval[1] & FATTR4_WORD1_MODE)
1081 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1082 if (bmval[1] & FATTR4_WORD1_OWNER)
1083 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1084 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1085 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1086 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1087 if (iap->ia_valid & ATTR_ATIME_SET) {
1088 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1089 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1090 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1091 } else
1092 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1093 }
1094 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1095 if (iap->ia_valid & ATTR_MTIME_SET) {
1096 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1097 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1098 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1099 } else
1100 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1101 }
1102 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001103 *p++ = cpu_to_be32(label->lfs);
1104 *p++ = cpu_to_be32(label->pi);
1105 *p++ = cpu_to_be32(label->len);
1106 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1107 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001108
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110}
1111
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001112static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001114 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1115 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001118static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
Trond Myklebustab19b482012-03-04 18:13:57 -05001120 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001121 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001122 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123}
1124
Fred Isaman0b7c0152012-04-20 14:47:39 -04001125static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126{
Al Viro8687b632006-10-19 23:28:48 -07001127 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001128
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001129 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1130 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001131 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001132 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133}
1134
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001135static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136{
Al Viro8687b632006-10-19 23:28:48 -07001137 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001138
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001139 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1140 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
1142 switch (create->ftype) {
1143 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001144 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001145 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001146 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 break;
1148
1149 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001150 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001151 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001152 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 break;
1154
1155 default:
1156 break;
1157 }
1158
Benny Halevy811652b2009-08-14 17:19:34 +03001159 encode_string(xdr, create->name->len, create->name->name);
David Quigleyaa9c2662013-05-22 12:50:44 -04001160 encode_attrs(xdr, create->attrs, create->label, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161}
1162
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001163static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164{
Andy Adamson05d564f2008-12-23 16:06:15 -05001165 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001167 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1168 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001169 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001170 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171}
1172
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001173static 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 -07001174{
Andy Adamson05d564f2008-12-23 16:06:15 -05001175 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001177 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1178 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001179 *p++ = cpu_to_be32(2);
1180 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001181 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182}
1183
Fred Isamandae100c2011-07-30 20:52:37 -04001184static void
1185encode_getattr_three(struct xdr_stream *xdr,
1186 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1187 struct compound_hdr *hdr)
1188{
1189 __be32 *p;
1190
Trond Myklebustab19b482012-03-04 18:13:57 -05001191 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001192 if (bm2) {
1193 p = reserve_space(xdr, 16);
1194 *p++ = cpu_to_be32(3);
1195 *p++ = cpu_to_be32(bm0);
1196 *p++ = cpu_to_be32(bm1);
1197 *p = cpu_to_be32(bm2);
1198 } else if (bm1) {
1199 p = reserve_space(xdr, 12);
1200 *p++ = cpu_to_be32(2);
1201 *p++ = cpu_to_be32(bm0);
1202 *p = cpu_to_be32(bm1);
1203 } else {
1204 p = reserve_space(xdr, 8);
1205 *p++ = cpu_to_be32(1);
1206 *p = cpu_to_be32(bm0);
1207 }
Fred Isamandae100c2011-07-30 20:52:37 -04001208}
1209
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001210static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211{
David Quigleya09df2c2013-05-22 12:50:41 -04001212 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1213 bitmask[1] & nfs4_fattr_bitmap[1],
1214 bitmask[2] & nfs4_fattr_bitmap[2],
1215 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216}
1217
Andy Adamson88034c32012-05-23 05:02:34 -04001218static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001219 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001220 struct compound_hdr *hdr)
1221{
1222 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001223 bitmask[0] & open_bitmap[0],
1224 bitmask[1] & open_bitmap[1],
1225 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001226 hdr);
1227}
1228
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001229static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230{
Fred Isamandae100c2011-07-30 20:52:37 -04001231 encode_getattr_three(xdr,
1232 bitmask[0] & nfs4_fsinfo_bitmap[0],
1233 bitmask[1] & nfs4_fsinfo_bitmap[1],
1234 bitmask[2] & nfs4_fsinfo_bitmap[2],
1235 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236}
1237
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001238static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001239{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001240 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1241 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001242}
1243
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001244static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245{
Trond Myklebustab19b482012-03-04 18:13:57 -05001246 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247}
1248
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001249static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250{
Trond Myklebustab19b482012-03-04 18:13:57 -05001251 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001252 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253}
1254
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001255static inline int nfs4_lock_type(struct file_lock *fl, int block)
1256{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001257 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001258 return block ? NFS4_READW_LT : NFS4_READ_LT;
1259 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1260}
1261
1262static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1263{
1264 if (fl->fl_end == OFFSET_MAX)
1265 return ~(uint64_t)0;
1266 return fl->fl_end - fl->fl_start + 1;
1267}
1268
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001269static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1270{
1271 __be32 *p;
1272
Trond Myklebustd035c362010-12-21 10:45:27 -05001273 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001274 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001275 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001276 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001277 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001278 xdr_encode_hyper(p, lowner->id);
1279}
1280
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281/*
1282 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1283 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1284 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001285static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286{
Al Viro8687b632006-10-19 23:28:48 -07001287 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001289 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1290 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001291 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1292 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001293 p = xdr_encode_hyper(p, args->fl->fl_start);
1294 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001295 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001296 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001297 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001298 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001299 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001300 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 }
1302 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001303 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001304 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306}
1307
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001308static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309{
Al Viro8687b632006-10-19 23:28:48 -07001310 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001312 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1313 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001314 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001315 p = xdr_encode_hyper(p, args->fl->fl_start);
1316 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001317 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318}
1319
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001320static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321{
Al Viro8687b632006-10-19 23:28:48 -07001322 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001324 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1325 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001326 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001327 encode_nfs4_stateid(xdr, args->stateid);
1328 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001329 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001330 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331}
1332
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001333static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1334{
Trond Myklebustab19b482012-03-04 18:13:57 -05001335 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001336 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001337}
1338
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001339static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340{
Trond Myklebustab19b482012-03-04 18:13:57 -05001341 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001342 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343}
1344
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001345static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346{
Al Viro8687b632006-10-19 23:28:48 -07001347 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Benny Halevy13c65ce2009-08-14 17:19:25 +03001349 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001350 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001351 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001352 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001353 break;
1354 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001355 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001356 break;
1357 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001358 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001359 break;
1360 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001361 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 }
Benny Halevy34558512009-08-14 17:19:30 +03001363 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364}
1365
1366static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1367{
Al Viro8687b632006-10-19 23:28:48 -07001368 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 /*
1370 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1371 * owner 4 = 32
1372 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001373 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001374 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001375 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001376 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001377 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001378 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001379 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001380 *p++ = cpu_to_be32(arg->id.uniquifier);
1381 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382}
1383
1384static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1385{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001386 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001387 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
Benny Halevy13c65ce2009-08-14 17:19:25 +03001389 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001390 switch(arg->createmode) {
1391 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001392 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001393 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Andy Adamson05d564f2008-12-23 16:06:15 -05001394 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001395 case NFS4_CREATE_GUARDED:
1396 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001397 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001398 break;
1399 case NFS4_CREATE_EXCLUSIVE:
1400 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1401 encode_nfs4_verifier(xdr, &arg->u.verifier);
1402 break;
1403 case NFS4_CREATE_EXCLUSIVE4_1:
1404 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1405 encode_nfs4_verifier(xdr, &arg->u.verifier);
1406 dummy.ia_valid = 0;
David Quigleyaa9c2662013-05-22 12:50:44 -04001407 encode_attrs(xdr, &dummy, arg->label, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 }
1409}
1410
1411static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1412{
Al Viro8687b632006-10-19 23:28:48 -07001413 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Benny Halevy13c65ce2009-08-14 17:19:25 +03001415 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001417 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001418 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001419 break;
1420 default:
Benny Halevy34558512009-08-14 17:19:30 +03001421 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001422 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 }
1424}
1425
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001426static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427{
Al Viro8687b632006-10-19 23:28:48 -07001428 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Benny Halevy13c65ce2009-08-14 17:19:25 +03001430 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001432 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001433 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001434 break;
1435 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001436 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001437 break;
1438 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001439 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001440 break;
1441 default:
1442 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 }
1444}
1445
1446static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1447{
Al Viro8687b632006-10-19 23:28:48 -07001448 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
Benny Halevy13c65ce2009-08-14 17:19:25 +03001450 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001451 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 encode_string(xdr, name->len, name->name);
1453}
1454
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001455static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456{
Al Viro8687b632006-10-19 23:28:48 -07001457 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Benny Halevy13c65ce2009-08-14 17:19:25 +03001459 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001460 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 encode_delegation_type(xdr, type);
1462}
1463
1464static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1465{
Al Viro8687b632006-10-19 23:28:48 -07001466 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001468 p = reserve_space(xdr, 4);
1469 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1470 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 encode_string(xdr, name->len, name->name);
1472}
1473
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001474static inline void encode_claim_fh(struct xdr_stream *xdr)
1475{
1476 __be32 *p;
1477
1478 p = reserve_space(xdr, 4);
1479 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1480}
1481
1482static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1483{
1484 __be32 *p;
1485
1486 p = reserve_space(xdr, 4);
1487 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1488 encode_nfs4_stateid(xdr, stateid);
1489}
1490
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001491static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492{
Trond Myklebustab19b482012-03-04 18:13:57 -05001493 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 encode_openhdr(xdr, arg);
1495 encode_opentype(xdr, arg);
1496 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001497 case NFS4_OPEN_CLAIM_NULL:
1498 encode_claim_null(xdr, arg->name);
1499 break;
1500 case NFS4_OPEN_CLAIM_PREVIOUS:
1501 encode_claim_previous(xdr, arg->u.delegation_type);
1502 break;
1503 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1504 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1505 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001506 case NFS4_OPEN_CLAIM_FH:
1507 encode_claim_fh(xdr);
1508 break;
1509 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1510 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1511 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001512 default:
1513 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515}
1516
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001517static 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 -07001518{
Trond Myklebustab19b482012-03-04 18:13:57 -05001519 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001520 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001521 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522}
1523
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001524static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525{
Trond Myklebustab19b482012-03-04 18:13:57 -05001526 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001527 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001528 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001529 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530}
1531
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001532static void
Andy Adamsond0179312008-12-23 16:06:17 -05001533encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534{
Trond Myklebustab19b482012-03-04 18:13:57 -05001535 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001536 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537}
1538
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001539static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540{
Trond Myklebustab19b482012-03-04 18:13:57 -05001541 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542}
1543
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001544static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545{
Al Viro8687b632006-10-19 23:28:48 -07001546 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Trond Myklebustab19b482012-03-04 18:13:57 -05001548 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001549 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Benny Halevy13c65ce2009-08-14 17:19:25 +03001551 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001552 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001553 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554}
1555
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001556static 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 -07001557{
David Quigleyaa9c2662013-05-22 12:50:44 -04001558 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001559 FATTR4_WORD0_RDATTR_ERROR,
1560 FATTR4_WORD1_MOUNTED_ON_FILEID,
1561 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001562 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001563 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001565 if (readdir->plus) {
1566 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001567 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001568 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1569 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1570 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1571 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001572 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001573 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001574 /* Use mounted_on_fileid only if the server supports it */
1575 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1576 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001577
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001578 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001579 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001580 encode_nfs4_verifier(xdr, &readdir->verifier);
David Quigleyaa9c2662013-05-22 12:50:44 -04001581 p = reserve_space(xdr, encode_readdir_space);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001582 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001583 *p++ = cpu_to_be32(readdir->count);
David Quigleyaa9c2662013-05-22 12:50:44 -04001584 *p++ = cpu_to_be32(encode_readdir_bitmask_sz);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001585 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
David Quigleyaa9c2662013-05-22 12:50:44 -04001586 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1587 if (encode_readdir_bitmask_sz > 2) {
1588 if (hdr->minorversion > 1)
1589 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1590 p++, *p++ = cpu_to_be32(attrs[2] & readdir->bitmask[2]);
1591 }
Chuck Levercd937102012-03-02 17:14:31 -05001592 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001593
1594 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001595 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001596 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001597 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001598 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001599 attrs[1] & readdir->bitmask[1],
1600 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601}
1602
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001603static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604{
Trond Myklebustab19b482012-03-04 18:13:57 -05001605 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606}
1607
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001608static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609{
Trond Myklebustab19b482012-03-04 18:13:57 -05001610 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001611 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612}
1613
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001614static 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 -07001615{
Trond Myklebustab19b482012-03-04 18:13:57 -05001616 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001617 encode_string(xdr, oldname->len, oldname->name);
1618 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619}
1620
Chuck Leverbb4dae52012-03-01 17:01:48 -05001621static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1622 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001624 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001625 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626}
1627
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001628static void
Andy Adamsond0179312008-12-23 16:06:17 -05001629encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001630{
Trond Myklebustab19b482012-03-04 18:13:57 -05001631 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001632}
1633
Chuck Lever9f06c712010-12-14 14:59:18 +00001634static void
Andy Adamsond0179312008-12-23 16:06:17 -05001635encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001636{
Al Viro8687b632006-10-19 23:28:48 -07001637 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001638
Trond Myklebustab19b482012-03-04 18:13:57 -05001639 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001640 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001641 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001642 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001643 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001644 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001645 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001646 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001647}
1648
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001649static void
Andy Adamsond0179312008-12-23 16:06:17 -05001650encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651{
Trond Myklebustab19b482012-03-04 18:13:57 -05001652 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653}
1654
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001655static 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 -07001656{
Trond Myklebustab19b482012-03-04 18:13:57 -05001657 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001658 encode_nfs4_stateid(xdr, &arg->stateid);
David Quigleyaa9c2662013-05-22 12:50:44 -04001659 encode_attrs(xdr, arg->iap, arg->label, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660}
1661
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001662static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663{
Al Viro8687b632006-10-19 23:28:48 -07001664 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
Trond Myklebust70019512012-03-04 20:49:32 -05001666 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001667 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
1669 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001670 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001671 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1673 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001674 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001675 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676}
1677
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001678static 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 -07001679{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001680 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1681 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001682 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001683 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684}
1685
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001686static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687{
Al Viro8687b632006-10-19 23:28:48 -07001688 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
Trond Myklebustab19b482012-03-04 18:13:57 -05001690 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001691 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
Benny Halevy13c65ce2009-08-14 17:19:25 +03001693 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001694 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001695 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001696 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
1698 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699}
1700
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001701static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702{
Trond Myklebustab19b482012-03-04 18:13:57 -05001703 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001704 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001706
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001707static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1708{
Trond Myklebustab19b482012-03-04 18:13:57 -05001709 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001710 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001711}
1712
Benny Halevy99fe60d2009-04-01 09:22:29 -04001713#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001714/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001715static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1716 struct nfs4_session *session,
1717 struct compound_hdr *hdr)
1718{
1719 __be32 *p;
1720
1721 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1722 decode_bind_conn_to_session_maxsz, hdr);
1723 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1724 p = xdr_reserve_space(xdr, 8);
1725 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1726 *p = 0; /* use_conn_in_rdma_mode = False */
1727}
1728
Benny Halevy99fe60d2009-04-01 09:22:29 -04001729static void encode_exchange_id(struct xdr_stream *xdr,
1730 struct nfs41_exchange_id_args *args,
1731 struct compound_hdr *hdr)
1732{
1733 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001734 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001735 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001736
Trond Myklebust70019512012-03-04 20:49:32 -05001737 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001738 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001739
1740 encode_string(xdr, args->id_len, args->id);
1741
Benny Halevy13c65ce2009-08-14 17:19:25 +03001742 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001743 *p++ = cpu_to_be32(args->flags);
1744 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001745
1746 if (send_implementation_id &&
1747 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1748 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001749 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001750 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1751 utsname()->sysname, utsname()->release,
1752 utsname()->version, utsname()->machine);
1753
1754 if (len > 0) {
1755 *p = cpu_to_be32(1); /* implementation id array length=1 */
1756
1757 encode_string(xdr,
1758 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1759 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1760 encode_string(xdr, len, impl_name);
1761 /* just send zeros for nii_date - the date is in nii_name */
1762 p = reserve_space(xdr, 12);
1763 p = xdr_encode_hyper(p, 0);
1764 *p = cpu_to_be32(0);
1765 } else
1766 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001767}
Andy Adamsonfc931582009-04-01 09:22:31 -04001768
1769static void encode_create_session(struct xdr_stream *xdr,
1770 struct nfs41_create_session_args *args,
1771 struct compound_hdr *hdr)
1772{
1773 __be32 *p;
1774 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1775 uint32_t len;
1776 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001777 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001778 u32 max_resp_sz_cached;
1779
1780 /*
1781 * Assumes OPEN is the biggest non-idempotent compound.
1782 * 2 is the verifier.
1783 */
1784 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1785 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001786
Andy Adamsonfc931582009-04-01 09:22:31 -04001787 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1788 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001789
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001790 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1791 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001792 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001793 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1794 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001795
Andy Adamsonfc931582009-04-01 09:22:31 -04001796 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001797 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001798 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1799 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001800 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001801 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1802 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1803 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001804
1805 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001806 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001807 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1808 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1809 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1810 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1811 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1812 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001813
Benny Halevye75bc1c2009-08-14 17:18:54 +03001814 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001815 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001816 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001817
1818 /* authsys_parms rfc1831 */
Chuck Leverf0920752012-05-21 22:45:41 -04001819 *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001820 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001821 *p++ = cpu_to_be32(0); /* UID */
1822 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001823 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001824}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001825
1826static void encode_destroy_session(struct xdr_stream *xdr,
1827 struct nfs4_session *session,
1828 struct compound_hdr *hdr)
1829{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001830 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1831 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001832}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001833
Trond Myklebust66245532012-05-25 17:18:09 -04001834static void encode_destroy_clientid(struct xdr_stream *xdr,
1835 uint64_t clientid,
1836 struct compound_hdr *hdr)
1837{
1838 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1839 encode_uint64(xdr, clientid);
1840}
1841
Ricardo Labiaga180197532009-12-05 16:08:40 -05001842static void encode_reclaim_complete(struct xdr_stream *xdr,
1843 struct nfs41_reclaim_complete_args *args,
1844 struct compound_hdr *hdr)
1845{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001846 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1847 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001848}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001849#endif /* CONFIG_NFS_V4_1 */
1850
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001851static void encode_sequence(struct xdr_stream *xdr,
1852 const struct nfs4_sequence_args *args,
1853 struct compound_hdr *hdr)
1854{
1855#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001856 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001857 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001858 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001859 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001860
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001861 if (slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001862 return;
1863
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001864 tp = slot->table;
1865 session = tp->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001866
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001867 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001868
1869 /*
1870 * Sessionid + seqid + slotid + max slotid + cache_this
1871 */
1872 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1873 "max_slotid=%d cache_this=%d\n",
1874 __func__,
1875 ((u32 *)session->sess_id.data)[0],
1876 ((u32 *)session->sess_id.data)[1],
1877 ((u32 *)session->sess_id.data)[2],
1878 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001879 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001880 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001881 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001882 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001883 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001884 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001885 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001886 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001887#endif /* CONFIG_NFS_V4_1 */
1888}
1889
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001890#ifdef CONFIG_NFS_V4_1
1891static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001892encode_getdevicelist(struct xdr_stream *xdr,
1893 const struct nfs4_getdevicelist_args *args,
1894 struct compound_hdr *hdr)
1895{
1896 __be32 *p;
1897 nfs4_verifier dummy = {
1898 .data = "dummmmmy",
1899 };
1900
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001901 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1902 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001903 *p++ = cpu_to_be32(args->layoutclass);
1904 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1905 xdr_encode_hyper(p, 0ULL); /* cookie */
1906 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001907}
1908
1909static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001910encode_getdeviceinfo(struct xdr_stream *xdr,
1911 const struct nfs4_getdeviceinfo_args *args,
1912 struct compound_hdr *hdr)
1913{
1914 __be32 *p;
1915
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001916 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1917 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001918 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1919 NFS4_DEVICEID4_SIZE);
1920 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001921 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001922 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001923}
1924
1925static void
1926encode_layoutget(struct xdr_stream *xdr,
1927 const struct nfs4_layoutget_args *args,
1928 struct compound_hdr *hdr)
1929{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001930 __be32 *p;
1931
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001932 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1933 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001934 *p++ = cpu_to_be32(0); /* Signal layout available */
1935 *p++ = cpu_to_be32(args->type);
1936 *p++ = cpu_to_be32(args->range.iomode);
1937 p = xdr_encode_hyper(p, args->range.offset);
1938 p = xdr_encode_hyper(p, args->range.length);
1939 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001940 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001941 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001942
1943 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1944 __func__,
1945 args->type,
1946 args->range.iomode,
1947 (unsigned long)args->range.offset,
1948 (unsigned long)args->range.length,
1949 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001950}
Andy Adamson863a3c62011-03-23 13:27:54 +00001951
1952static int
1953encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001954 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001955 const struct nfs4_layoutcommit_args *args,
1956 struct compound_hdr *hdr)
1957{
1958 __be32 *p;
1959
1960 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1961 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1962
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001963 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1964 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001965 /* Only whole file layouts */
1966 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001967 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001968 *p = cpu_to_be32(0); /* reclaim */
1969 encode_nfs4_stateid(xdr, &args->stateid);
1970 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001971 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1972 p = xdr_encode_hyper(p, args->lastbytewritten);
1973 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1974 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001975
1976 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1977 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1978 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001979 else
1980 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001981
Andy Adamson863a3c62011-03-23 13:27:54 +00001982 return 0;
1983}
Benny Halevycbe82602011-05-22 19:52:37 +03001984
1985static void
1986encode_layoutreturn(struct xdr_stream *xdr,
1987 const struct nfs4_layoutreturn_args *args,
1988 struct compound_hdr *hdr)
1989{
1990 __be32 *p;
1991
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001992 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1993 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001994 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1995 *p++ = cpu_to_be32(args->layout_type);
1996 *p++ = cpu_to_be32(IOMODE_ANY);
1997 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001998 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001999 p = xdr_encode_hyper(p, 0);
2000 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2001 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002002 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002003 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002004 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2005 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2006 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002007 } else
2008 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002009}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002010
2011static int
2012encode_secinfo_no_name(struct xdr_stream *xdr,
2013 const struct nfs41_secinfo_no_name_args *args,
2014 struct compound_hdr *hdr)
2015{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002016 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2017 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002018 return 0;
2019}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002020
2021static void encode_test_stateid(struct xdr_stream *xdr,
2022 struct nfs41_test_stateid_args *args,
2023 struct compound_hdr *hdr)
2024{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002025 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2026 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002027 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002028}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002029
2030static void encode_free_stateid(struct xdr_stream *xdr,
2031 struct nfs41_free_stateid_args *args,
2032 struct compound_hdr *hdr)
2033{
Trond Myklebustab19b482012-03-04 18:13:57 -05002034 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002035 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002036}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002037#endif /* CONFIG_NFS_V4_1 */
2038
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039/*
2040 * END OF "GENERIC" ENCODE ROUTINES.
2041 */
2042
Benny Halevy66cc0422009-04-01 09:22:10 -04002043static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2044{
2045#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05002046
2047 if (args->sa_slot)
2048 return args->sa_slot->table->session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002049#endif /* CONFIG_NFS_V4_1 */
2050 return 0;
2051}
2052
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053/*
2054 * Encode an ACCESS request
2055 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002056static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2057 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002060 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
Chuck Lever9f06c712010-12-14 14:59:18 +00002063 encode_compound_hdr(xdr, req, &hdr);
2064 encode_sequence(xdr, &args->seq_args, &hdr);
2065 encode_putfh(xdr, args->fh, &hdr);
2066 encode_access(xdr, args->access, &hdr);
2067 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002068 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069}
2070
2071/*
2072 * Encode LOOKUP request
2073 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002074static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2075 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002078 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
Chuck Lever9f06c712010-12-14 14:59:18 +00002081 encode_compound_hdr(xdr, req, &hdr);
2082 encode_sequence(xdr, &args->seq_args, &hdr);
2083 encode_putfh(xdr, args->dir_fh, &hdr);
2084 encode_lookup(xdr, args->name, &hdr);
2085 encode_getfh(xdr, &hdr);
2086 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002087 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088}
2089
2090/*
2091 * Encode LOOKUP_ROOT request
2092 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002093static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2094 struct xdr_stream *xdr,
2095 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002098 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Chuck Lever9f06c712010-12-14 14:59:18 +00002101 encode_compound_hdr(xdr, req, &hdr);
2102 encode_sequence(xdr, &args->seq_args, &hdr);
2103 encode_putrootfh(xdr, &hdr);
2104 encode_getfh(xdr, &hdr);
2105 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002106 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107}
2108
2109/*
2110 * Encode REMOVE request
2111 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002112static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2113 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002116 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
Chuck Lever9f06c712010-12-14 14:59:18 +00002119 encode_compound_hdr(xdr, req, &hdr);
2120 encode_sequence(xdr, &args->seq_args, &hdr);
2121 encode_putfh(xdr, args->fh, &hdr);
2122 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002123 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124}
2125
2126/*
2127 * Encode RENAME request
2128 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002129static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2130 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002133 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135
Chuck Lever9f06c712010-12-14 14:59:18 +00002136 encode_compound_hdr(xdr, req, &hdr);
2137 encode_sequence(xdr, &args->seq_args, &hdr);
2138 encode_putfh(xdr, args->old_dir, &hdr);
2139 encode_savefh(xdr, &hdr);
2140 encode_putfh(xdr, args->new_dir, &hdr);
2141 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002142 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143}
2144
2145/*
2146 * Encode LINK request
2147 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002148static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2149 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002152 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154
Chuck Lever9f06c712010-12-14 14:59:18 +00002155 encode_compound_hdr(xdr, req, &hdr);
2156 encode_sequence(xdr, &args->seq_args, &hdr);
2157 encode_putfh(xdr, args->fh, &hdr);
2158 encode_savefh(xdr, &hdr);
2159 encode_putfh(xdr, args->dir_fh, &hdr);
2160 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002161 encode_restorefh(xdr, &hdr);
2162 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002163 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164}
2165
2166/*
2167 * Encode CREATE request
2168 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002169static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2170 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002173 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
Chuck Lever9f06c712010-12-14 14:59:18 +00002176 encode_compound_hdr(xdr, req, &hdr);
2177 encode_sequence(xdr, &args->seq_args, &hdr);
2178 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002179 encode_create(xdr, args, &hdr);
2180 encode_getfh(xdr, &hdr);
2181 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002182 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183}
2184
2185/*
2186 * Encode SYMLINK request
2187 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002188static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2189 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190{
Chuck Lever9f06c712010-12-14 14:59:18 +00002191 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192}
2193
2194/*
2195 * Encode GETATTR request
2196 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002197static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2198 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002201 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203
Chuck Lever9f06c712010-12-14 14:59:18 +00002204 encode_compound_hdr(xdr, req, &hdr);
2205 encode_sequence(xdr, &args->seq_args, &hdr);
2206 encode_putfh(xdr, args->fh, &hdr);
2207 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002208 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209}
2210
2211/*
2212 * Encode a CLOSE request
2213 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002214static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2215 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216{
Andy Adamson05d564f2008-12-23 16:06:15 -05002217 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002218 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002219 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
Chuck Lever9f06c712010-12-14 14:59:18 +00002221 encode_compound_hdr(xdr, req, &hdr);
2222 encode_sequence(xdr, &args->seq_args, &hdr);
2223 encode_putfh(xdr, args->fh, &hdr);
2224 encode_close(xdr, args, &hdr);
2225 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002226 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227}
2228
2229/*
2230 * Encode an OPEN request
2231 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002232static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2233 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002236 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238
Chuck Lever9f06c712010-12-14 14:59:18 +00002239 encode_compound_hdr(xdr, req, &hdr);
2240 encode_sequence(xdr, &args->seq_args, &hdr);
2241 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002242 encode_open(xdr, args, &hdr);
2243 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002244 if (args->access)
2245 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002246 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002247 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248}
2249
2250/*
2251 * Encode an OPEN_CONFIRM request
2252 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002253static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2254 struct xdr_stream *xdr,
2255 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002258 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260
Chuck Lever9f06c712010-12-14 14:59:18 +00002261 encode_compound_hdr(xdr, req, &hdr);
2262 encode_putfh(xdr, args->fh, &hdr);
2263 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002264 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265}
2266
2267/*
2268 * Encode an OPEN request with no attributes.
2269 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002270static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2271 struct xdr_stream *xdr,
2272 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002275 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277
Chuck Lever9f06c712010-12-14 14:59:18 +00002278 encode_compound_hdr(xdr, req, &hdr);
2279 encode_sequence(xdr, &args->seq_args, &hdr);
2280 encode_putfh(xdr, args->fh, &hdr);
2281 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002282 if (args->access)
2283 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002284 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002285 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286}
2287
2288/*
2289 * Encode an OPEN_DOWNGRADE request
2290 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002291static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2292 struct xdr_stream *xdr,
2293 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002296 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
Chuck Lever9f06c712010-12-14 14:59:18 +00002299 encode_compound_hdr(xdr, req, &hdr);
2300 encode_sequence(xdr, &args->seq_args, &hdr);
2301 encode_putfh(xdr, args->fh, &hdr);
2302 encode_open_downgrade(xdr, args, &hdr);
2303 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002304 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305}
2306
2307/*
2308 * Encode a LOCK request
2309 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002310static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2311 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002314 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316
Chuck Lever9f06c712010-12-14 14:59:18 +00002317 encode_compound_hdr(xdr, req, &hdr);
2318 encode_sequence(xdr, &args->seq_args, &hdr);
2319 encode_putfh(xdr, args->fh, &hdr);
2320 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002321 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322}
2323
2324/*
2325 * Encode a LOCKT request
2326 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002327static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2328 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002331 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
Chuck Lever9f06c712010-12-14 14:59:18 +00002334 encode_compound_hdr(xdr, req, &hdr);
2335 encode_sequence(xdr, &args->seq_args, &hdr);
2336 encode_putfh(xdr, args->fh, &hdr);
2337 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002338 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339}
2340
2341/*
2342 * Encode a LOCKU request
2343 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002344static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2345 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002348 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350
Chuck Lever9f06c712010-12-14 14:59:18 +00002351 encode_compound_hdr(xdr, req, &hdr);
2352 encode_sequence(xdr, &args->seq_args, &hdr);
2353 encode_putfh(xdr, args->fh, &hdr);
2354 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002355 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356}
2357
Chuck Lever9f06c712010-12-14 14:59:18 +00002358static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2359 struct xdr_stream *xdr,
2360 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002361{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002362 struct compound_hdr hdr = {
2363 .minorversion = 0,
2364 };
2365
Chuck Lever9f06c712010-12-14 14:59:18 +00002366 encode_compound_hdr(xdr, req, &hdr);
2367 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002368 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002369}
2370
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371/*
2372 * Encode a READLINK request
2373 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002374static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2375 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002378 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380
Chuck Lever9f06c712010-12-14 14:59:18 +00002381 encode_compound_hdr(xdr, req, &hdr);
2382 encode_sequence(xdr, &args->seq_args, &hdr);
2383 encode_putfh(xdr, args->fh, &hdr);
2384 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002385
Benny Halevy28f56692009-04-01 09:22:09 -04002386 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002387 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002388 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389}
2390
2391/*
2392 * Encode a READDIR request
2393 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002394static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2395 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002398 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400
Chuck Lever9f06c712010-12-14 14:59:18 +00002401 encode_compound_hdr(xdr, req, &hdr);
2402 encode_sequence(xdr, &args->seq_args, &hdr);
2403 encode_putfh(xdr, args->fh, &hdr);
2404 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002405
Benny Halevy28f56692009-04-01 09:22:09 -04002406 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002407 args->pgbase, args->count);
2408 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002409 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002410 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002411 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412}
2413
2414/*
2415 * Encode a READ request
2416 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002417static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2418 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002421 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423
Chuck Lever9f06c712010-12-14 14:59:18 +00002424 encode_compound_hdr(xdr, req, &hdr);
2425 encode_sequence(xdr, &args->seq_args, &hdr);
2426 encode_putfh(xdr, args->fh, &hdr);
2427 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
Benny Halevy28f56692009-04-01 09:22:09 -04002429 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002431 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002432 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433}
2434
2435/*
2436 * Encode an SETATTR request
2437 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002438static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2439 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440{
Andy Adamson05d564f2008-12-23 16:06:15 -05002441 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002442 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002443 };
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_setattr(xdr, args, args->server, &hdr);
2449 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002450 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451}
2452
2453/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002454 * Encode a GETACL request
2455 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002456static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2457 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002458{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002459 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002460 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002461 };
Benny Halevy28f56692009-04-01 09:22:09 -04002462 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002463
Chuck Lever9f06c712010-12-14 14:59:18 +00002464 encode_compound_hdr(xdr, req, &hdr);
2465 encode_sequence(xdr, &args->seq_args, &hdr);
2466 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002467 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002468 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002469
Benny Halevy28f56692009-04-01 09:22:09 -04002470 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002471 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002472
Andy Adamsond0179312008-12-23 16:06:17 -05002473 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002474}
2475
2476/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 * Encode a WRITE request
2478 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002479static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2480 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002483 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485
Chuck Lever9f06c712010-12-14 14:59:18 +00002486 encode_compound_hdr(xdr, req, &hdr);
2487 encode_sequence(xdr, &args->seq_args, &hdr);
2488 encode_putfh(xdr, args->fh, &hdr);
2489 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002490 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002491 if (args->bitmask)
2492 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002493 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494}
2495
2496/*
2497 * a COMMIT request
2498 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002499static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002500 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002503 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505
Chuck Lever9f06c712010-12-14 14:59:18 +00002506 encode_compound_hdr(xdr, req, &hdr);
2507 encode_sequence(xdr, &args->seq_args, &hdr);
2508 encode_putfh(xdr, args->fh, &hdr);
2509 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002510 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511}
2512
2513/*
2514 * FSINFO request
2515 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002516static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2517 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002520 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522
Chuck Lever9f06c712010-12-14 14:59:18 +00002523 encode_compound_hdr(xdr, req, &hdr);
2524 encode_sequence(xdr, &args->seq_args, &hdr);
2525 encode_putfh(xdr, args->fh, &hdr);
2526 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002527 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528}
2529
2530/*
2531 * a PATHCONF request
2532 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002533static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2534 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002537 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539
Chuck Lever9f06c712010-12-14 14:59:18 +00002540 encode_compound_hdr(xdr, req, &hdr);
2541 encode_sequence(xdr, &args->seq_args, &hdr);
2542 encode_putfh(xdr, args->fh, &hdr);
2543 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002544 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002545 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546}
2547
2548/*
2549 * a STATFS request
2550 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002551static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2552 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002555 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557
Chuck Lever9f06c712010-12-14 14:59:18 +00002558 encode_compound_hdr(xdr, req, &hdr);
2559 encode_sequence(xdr, &args->seq_args, &hdr);
2560 encode_putfh(xdr, args->fh, &hdr);
2561 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002562 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002563 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564}
2565
2566/*
2567 * GETATTR_BITMAP request
2568 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002569static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2570 struct xdr_stream *xdr,
2571 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002574 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576
Chuck Lever9f06c712010-12-14 14:59:18 +00002577 encode_compound_hdr(xdr, req, &hdr);
2578 encode_sequence(xdr, &args->seq_args, &hdr);
2579 encode_putfh(xdr, args->fhandle, &hdr);
2580 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002581 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002582 FATTR4_WORD0_LINK_SUPPORT|
2583 FATTR4_WORD0_SYMLINK_SUPPORT|
2584 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002585 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586}
2587
2588/*
2589 * a RENEW request
2590 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002591static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2592 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002595 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 };
2597
Chuck Lever9f06c712010-12-14 14:59:18 +00002598 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002599 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002600 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601}
2602
2603/*
2604 * a SETCLIENTID request
2605 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002606static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2607 struct xdr_stream *xdr,
2608 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002611 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 };
2613
Chuck Lever9f06c712010-12-14 14:59:18 +00002614 encode_compound_hdr(xdr, req, &hdr);
2615 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002616 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617}
2618
2619/*
2620 * a SETCLIENTID_CONFIRM request
2621 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002622static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2623 struct xdr_stream *xdr,
2624 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002627 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629
Chuck Lever9f06c712010-12-14 14:59:18 +00002630 encode_compound_hdr(xdr, req, &hdr);
2631 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002632 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633}
2634
2635/*
2636 * DELEGRETURN request
2637 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002638static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2639 struct xdr_stream *xdr,
2640 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002643 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645
Chuck Lever9f06c712010-12-14 14:59:18 +00002646 encode_compound_hdr(xdr, req, &hdr);
2647 encode_sequence(xdr, &args->seq_args, &hdr);
2648 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002649 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002650 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002651 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652}
2653
2654/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002655 * Encode FS_LOCATIONS request
2656 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002657static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2658 struct xdr_stream *xdr,
2659 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002660{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002661 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002662 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002663 };
Benny Halevy28f56692009-04-01 09:22:09 -04002664 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002665
Chuck Lever9f06c712010-12-14 14:59:18 +00002666 encode_compound_hdr(xdr, req, &hdr);
2667 encode_sequence(xdr, &args->seq_args, &hdr);
2668 encode_putfh(xdr, args->dir_fh, &hdr);
2669 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002670 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002671 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002672
Benny Halevy28f56692009-04-01 09:22:09 -04002673 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002674 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002675 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002676}
2677
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002678/*
2679 * Encode SECINFO request
2680 */
2681static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2682 struct xdr_stream *xdr,
2683 struct nfs4_secinfo_arg *args)
2684{
2685 struct compound_hdr hdr = {
2686 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2687 };
2688
2689 encode_compound_hdr(xdr, req, &hdr);
2690 encode_sequence(xdr, &args->seq_args, &hdr);
2691 encode_putfh(xdr, args->dir_fh, &hdr);
2692 encode_secinfo(xdr, args->name, &hdr);
2693 encode_nops(&hdr);
2694}
2695
Benny Halevy99fe60d2009-04-01 09:22:29 -04002696#if defined(CONFIG_NFS_V4_1)
2697/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002698 * BIND_CONN_TO_SESSION request
2699 */
2700static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2701 struct xdr_stream *xdr,
2702 struct nfs_client *clp)
2703{
2704 struct compound_hdr hdr = {
2705 .minorversion = clp->cl_mvops->minor_version,
2706 };
2707
2708 encode_compound_hdr(xdr, req, &hdr);
2709 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2710 encode_nops(&hdr);
2711}
2712
2713/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002714 * EXCHANGE_ID request
2715 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002716static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2717 struct xdr_stream *xdr,
2718 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002719{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002720 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002721 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002722 };
2723
Chuck Lever9f06c712010-12-14 14:59:18 +00002724 encode_compound_hdr(xdr, req, &hdr);
2725 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002726 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002727}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002728
2729/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002730 * a CREATE_SESSION request
2731 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002732static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2733 struct xdr_stream *xdr,
2734 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002735{
Andy Adamsonfc931582009-04-01 09:22:31 -04002736 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002737 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002738 };
2739
Chuck Lever9f06c712010-12-14 14:59:18 +00002740 encode_compound_hdr(xdr, req, &hdr);
2741 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002742 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002743}
2744
2745/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002746 * a DESTROY_SESSION request
2747 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002748static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2749 struct xdr_stream *xdr,
2750 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002751{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002752 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002753 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002754 };
2755
Chuck Lever9f06c712010-12-14 14:59:18 +00002756 encode_compound_hdr(xdr, req, &hdr);
2757 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002758 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002759}
2760
2761/*
Trond Myklebust66245532012-05-25 17:18:09 -04002762 * a DESTROY_CLIENTID request
2763 */
2764static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2765 struct xdr_stream *xdr,
2766 struct nfs_client *clp)
2767{
2768 struct compound_hdr hdr = {
2769 .minorversion = clp->cl_mvops->minor_version,
2770 };
2771
2772 encode_compound_hdr(xdr, req, &hdr);
2773 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2774 encode_nops(&hdr);
2775}
2776
2777/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002778 * a SEQUENCE request
2779 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002780static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2781 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002782{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002783 struct compound_hdr hdr = {
2784 .minorversion = nfs4_xdr_minorversion(args),
2785 };
2786
Chuck Lever9f06c712010-12-14 14:59:18 +00002787 encode_compound_hdr(xdr, req, &hdr);
2788 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002789 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002790}
2791
2792/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002793 * a GET_LEASE_TIME request
2794 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002795static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2796 struct xdr_stream *xdr,
2797 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002798{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002799 struct compound_hdr hdr = {
2800 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2801 };
Fred Isamandae100c2011-07-30 20:52:37 -04002802 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002803
Chuck Lever9f06c712010-12-14 14:59:18 +00002804 encode_compound_hdr(xdr, req, &hdr);
2805 encode_sequence(xdr, &args->la_seq_args, &hdr);
2806 encode_putrootfh(xdr, &hdr);
2807 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002808 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002809}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002810
2811/*
2812 * a RECLAIM_COMPLETE request
2813 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002814static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2815 struct xdr_stream *xdr,
2816 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002817{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002818 struct compound_hdr hdr = {
2819 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2820 };
2821
Chuck Lever9f06c712010-12-14 14:59:18 +00002822 encode_compound_hdr(xdr, req, &hdr);
2823 encode_sequence(xdr, &args->seq_args, &hdr);
2824 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002825 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002826}
2827
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002828/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002829 * Encode GETDEVICELIST request
2830 */
2831static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2832 struct xdr_stream *xdr,
2833 struct nfs4_getdevicelist_args *args)
2834{
2835 struct compound_hdr hdr = {
2836 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2837 };
2838
2839 encode_compound_hdr(xdr, req, &hdr);
2840 encode_sequence(xdr, &args->seq_args, &hdr);
2841 encode_putfh(xdr, args->fh, &hdr);
2842 encode_getdevicelist(xdr, args, &hdr);
2843 encode_nops(&hdr);
2844}
2845
2846/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002847 * Encode GETDEVICEINFO request
2848 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002849static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2850 struct xdr_stream *xdr,
2851 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002852{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002853 struct compound_hdr hdr = {
2854 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2855 };
2856
Chuck Lever9f06c712010-12-14 14:59:18 +00002857 encode_compound_hdr(xdr, req, &hdr);
2858 encode_sequence(xdr, &args->seq_args, &hdr);
2859 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002860
2861 /* set up reply kvec. Subtract notification bitmap max size (2)
2862 * so that notification bitmap is put in xdr_buf tail */
2863 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2864 args->pdev->pages, args->pdev->pgbase,
2865 args->pdev->pglen);
2866
2867 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002868}
2869
2870/*
2871 * Encode LAYOUTGET request
2872 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002873static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2874 struct xdr_stream *xdr,
2875 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002876{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002877 struct compound_hdr hdr = {
2878 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2879 };
2880
Chuck Lever9f06c712010-12-14 14:59:18 +00002881 encode_compound_hdr(xdr, req, &hdr);
2882 encode_sequence(xdr, &args->seq_args, &hdr);
2883 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2884 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002885
2886 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2887 args->layout.pages, 0, args->layout.pglen);
2888
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002889 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002890}
Andy Adamson863a3c62011-03-23 13:27:54 +00002891
2892/*
2893 * Encode LAYOUTCOMMIT request
2894 */
Benny Halevycbe82602011-05-22 19:52:37 +03002895static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2896 struct xdr_stream *xdr,
2897 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002898{
Benny Halevyac7db722011-05-22 19:53:48 +03002899 struct nfs4_layoutcommit_data *data =
2900 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002901 struct compound_hdr hdr = {
2902 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2903 };
2904
2905 encode_compound_hdr(xdr, req, &hdr);
2906 encode_sequence(xdr, &args->seq_args, &hdr);
2907 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002908 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002909 encode_getfattr(xdr, args->bitmask, &hdr);
2910 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002911}
2912
2913/*
2914 * Encode LAYOUTRETURN request
2915 */
2916static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2917 struct xdr_stream *xdr,
2918 struct nfs4_layoutreturn_args *args)
2919{
2920 struct compound_hdr hdr = {
2921 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2922 };
2923
2924 encode_compound_hdr(xdr, req, &hdr);
2925 encode_sequence(xdr, &args->seq_args, &hdr);
2926 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2927 encode_layoutreturn(xdr, args, &hdr);
2928 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002929}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002930
2931/*
2932 * Encode SECINFO_NO_NAME request
2933 */
2934static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2935 struct xdr_stream *xdr,
2936 struct nfs41_secinfo_no_name_args *args)
2937{
2938 struct compound_hdr hdr = {
2939 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2940 };
2941
2942 encode_compound_hdr(xdr, req, &hdr);
2943 encode_sequence(xdr, &args->seq_args, &hdr);
2944 encode_putrootfh(xdr, &hdr);
2945 encode_secinfo_no_name(xdr, args, &hdr);
2946 encode_nops(&hdr);
2947 return 0;
2948}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002949
2950/*
2951 * Encode TEST_STATEID request
2952 */
2953static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2954 struct xdr_stream *xdr,
2955 struct nfs41_test_stateid_args *args)
2956{
2957 struct compound_hdr hdr = {
2958 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2959 };
2960
2961 encode_compound_hdr(xdr, req, &hdr);
2962 encode_sequence(xdr, &args->seq_args, &hdr);
2963 encode_test_stateid(xdr, args, &hdr);
2964 encode_nops(&hdr);
2965}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002966
2967/*
2968 * Encode FREE_STATEID request
2969 */
2970static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2971 struct xdr_stream *xdr,
2972 struct nfs41_free_stateid_args *args)
2973{
2974 struct compound_hdr hdr = {
2975 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2976 };
2977
2978 encode_compound_hdr(xdr, req, &hdr);
2979 encode_sequence(xdr, &args->seq_args, &hdr);
2980 encode_free_stateid(xdr, args, &hdr);
2981 encode_nops(&hdr);
2982}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002983#endif /* CONFIG_NFS_V4_1 */
2984
Benny Halevy686841b2009-08-14 17:19:48 +03002985static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2986{
2987 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2988 "Remaining buffer length is %tu words.\n",
2989 func, xdr->end - xdr->p);
2990}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991
Trond Myklebust683b57b2006-06-09 09:34:22 -04002992static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993{
Al Viro8687b632006-10-19 23:28:48 -07002994 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995
Benny Halevyc0eae662009-08-14 17:20:14 +03002996 p = xdr_inline_decode(xdr, 4);
2997 if (unlikely(!p))
2998 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002999 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003000 p = xdr_inline_decode(xdr, *len);
3001 if (unlikely(!p))
3002 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 *string = (char *)p;
3004 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003005out_overflow:
3006 print_overflow_msg(__func__, xdr);
3007 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008}
3009
3010static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3011{
Al Viro8687b632006-10-19 23:28:48 -07003012 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013
Benny Halevyc0eae662009-08-14 17:20:14 +03003014 p = xdr_inline_decode(xdr, 8);
3015 if (unlikely(!p))
3016 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003017 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003018 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003019
Benny Halevyc0eae662009-08-14 17:20:14 +03003020 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3021 if (unlikely(!p))
3022 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 hdr->tag = (char *)p;
3024 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003025 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003026 if (unlikely(hdr->nops < 1))
3027 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003029out_overflow:
3030 print_overflow_msg(__func__, xdr);
3031 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032}
3033
3034static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3035{
Al Viro8687b632006-10-19 23:28:48 -07003036 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 uint32_t opnum;
3038 int32_t nfserr;
3039
Benny Halevyc0eae662009-08-14 17:20:14 +03003040 p = xdr_inline_decode(xdr, 8);
3041 if (unlikely(!p))
3042 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003043 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003045 dprintk("nfs: Server returned operation"
3046 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 opnum, expected);
3048 return -EIO;
3049 }
Benny Halevycccddf42009-08-14 17:20:19 +03003050 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003052 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003054out_overflow:
3055 print_overflow_msg(__func__, xdr);
3056 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057}
3058
3059/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003060static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061{
Al Viro8687b632006-10-19 23:28:48 -07003062 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003063 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 char *str;
3065
Benny Halevyc0eae662009-08-14 17:20:14 +03003066 p = xdr_inline_decode(xdr, 12);
3067 if (likely(p))
3068 return decode_opaque_inline(xdr, &strlen, &str);
3069 print_overflow_msg(__func__, xdr);
3070 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071}
3072
3073static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3074{
Al Viro8687b632006-10-19 23:28:48 -07003075 uint32_t bmlen;
3076 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077
Benny Halevyc0eae662009-08-14 17:20:14 +03003078 p = xdr_inline_decode(xdr, 4);
3079 if (unlikely(!p))
3080 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003081 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082
Fred Isamandae100c2011-07-30 20:52:37 -04003083 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003084 p = xdr_inline_decode(xdr, (bmlen << 2));
3085 if (unlikely(!p))
3086 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003088 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003089 if (bmlen > 1) {
3090 bitmap[1] = be32_to_cpup(p++);
3091 if (bmlen > 2)
3092 bitmap[2] = be32_to_cpup(p);
3093 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 }
3095 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003096out_overflow:
3097 print_overflow_msg(__func__, xdr);
3098 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099}
3100
Trond Myklebust256e48b2012-06-21 11:18:13 -04003101static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102{
Al Viro8687b632006-10-19 23:28:48 -07003103 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104
Benny Halevyc0eae662009-08-14 17:20:14 +03003105 p = xdr_inline_decode(xdr, 4);
3106 if (unlikely(!p))
3107 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003108 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003109 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003111out_overflow:
3112 print_overflow_msg(__func__, xdr);
3113 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114}
3115
3116static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3117{
3118 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003119 int ret;
3120 ret = decode_attr_bitmap(xdr, bitmask);
3121 if (unlikely(ret < 0))
3122 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3124 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003125 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3126 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3127 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 return 0;
3129}
3130
3131static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3132{
Al Viro8687b632006-10-19 23:28:48 -07003133 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003134 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135
3136 *type = 0;
3137 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3138 return -EIO;
3139 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003140 p = xdr_inline_decode(xdr, 4);
3141 if (unlikely(!p))
3142 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003143 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003145 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 return -EIO;
3147 }
3148 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003149 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003151 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003152 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003153out_overflow:
3154 print_overflow_msg(__func__, xdr);
3155 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156}
3157
Chuck Lever264e6352012-03-01 17:02:05 -05003158static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3159 uint32_t *bitmap, uint32_t *type)
3160{
3161 __be32 *p;
3162
3163 *type = 0;
3164 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3165 return -EIO;
3166 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3167 p = xdr_inline_decode(xdr, 4);
3168 if (unlikely(!p))
3169 goto out_overflow;
3170 *type = be32_to_cpup(p);
3171 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3172 }
3173 dprintk("%s: expire type=0x%x\n", __func__, *type);
3174 return 0;
3175out_overflow:
3176 print_overflow_msg(__func__, xdr);
3177 return -EIO;
3178}
3179
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3181{
Al Viro8687b632006-10-19 23:28:48 -07003182 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003183 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184
3185 *change = 0;
3186 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3187 return -EIO;
3188 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003189 p = xdr_inline_decode(xdr, 8);
3190 if (unlikely(!p))
3191 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003192 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003194 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003196 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003198 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003199out_overflow:
3200 print_overflow_msg(__func__, xdr);
3201 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202}
3203
3204static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3205{
Al Viro8687b632006-10-19 23:28:48 -07003206 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003207 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208
3209 *size = 0;
3210 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3211 return -EIO;
3212 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003213 p = xdr_inline_decode(xdr, 8);
3214 if (unlikely(!p))
3215 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003216 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003218 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003220 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003221 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003222out_overflow:
3223 print_overflow_msg(__func__, xdr);
3224 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225}
3226
3227static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3228{
Al Viro8687b632006-10-19 23:28:48 -07003229 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230
3231 *res = 0;
3232 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3233 return -EIO;
3234 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003235 p = xdr_inline_decode(xdr, 4);
3236 if (unlikely(!p))
3237 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003238 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3240 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003241 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003243out_overflow:
3244 print_overflow_msg(__func__, xdr);
3245 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246}
3247
3248static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3249{
Al Viro8687b632006-10-19 23:28:48 -07003250 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251
3252 *res = 0;
3253 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3254 return -EIO;
3255 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003256 p = xdr_inline_decode(xdr, 4);
3257 if (unlikely(!p))
3258 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003259 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3261 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003262 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003264out_overflow:
3265 print_overflow_msg(__func__, xdr);
3266 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267}
3268
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003269static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270{
Al Viro8687b632006-10-19 23:28:48 -07003271 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003272 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273
3274 fsid->major = 0;
3275 fsid->minor = 0;
3276 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3277 return -EIO;
3278 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003279 p = xdr_inline_decode(xdr, 16);
3280 if (unlikely(!p))
3281 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003282 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003283 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003285 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003287 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 (unsigned long long)fsid->major,
3289 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003290 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003291out_overflow:
3292 print_overflow_msg(__func__, xdr);
3293 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294}
3295
3296static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3297{
Al Viro8687b632006-10-19 23:28:48 -07003298 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299
3300 *res = 60;
3301 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3302 return -EIO;
3303 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003304 p = xdr_inline_decode(xdr, 4);
3305 if (unlikely(!p))
3306 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003307 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3309 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003310 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003312out_overflow:
3313 print_overflow_msg(__func__, xdr);
3314 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315}
3316
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003317static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003318{
3319 __be32 *p;
3320
3321 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3322 return -EIO;
3323 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3324 p = xdr_inline_decode(xdr, 4);
3325 if (unlikely(!p))
3326 goto out_overflow;
3327 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003328 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003329 }
3330 return 0;
3331out_overflow:
3332 print_overflow_msg(__func__, xdr);
3333 return -EIO;
3334}
3335
3336static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3337{
3338 __be32 *p;
3339 int len;
3340
Trond Myklebust7ad07352010-10-23 15:34:20 -04003341 if (fh != NULL)
3342 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003343
3344 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3345 return -EIO;
3346 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3347 p = xdr_inline_decode(xdr, 4);
3348 if (unlikely(!p))
3349 goto out_overflow;
3350 len = be32_to_cpup(p);
3351 if (len > NFS4_FHSIZE)
3352 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003353 p = xdr_inline_decode(xdr, len);
3354 if (unlikely(!p))
3355 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003356 if (fh != NULL) {
3357 memcpy(fh->data, p, len);
3358 fh->size = len;
3359 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003360 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3361 }
3362 return 0;
3363out_overflow:
3364 print_overflow_msg(__func__, xdr);
3365 return -EIO;
3366}
3367
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3369{
Al Viro8687b632006-10-19 23:28:48 -07003370 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371
3372 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3373 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3374 return -EIO;
3375 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003376 p = xdr_inline_decode(xdr, 4);
3377 if (unlikely(!p))
3378 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003379 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3381 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003382 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003384out_overflow:
3385 print_overflow_msg(__func__, xdr);
3386 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387}
3388
3389static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3390{
Al Viro8687b632006-10-19 23:28:48 -07003391 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003392 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393
3394 *fileid = 0;
3395 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3396 return -EIO;
3397 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003398 p = xdr_inline_decode(xdr, 8);
3399 if (unlikely(!p))
3400 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003401 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003403 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003405 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003406 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003407out_overflow:
3408 print_overflow_msg(__func__, xdr);
3409 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410}
3411
Manoj Naik99baf622006-06-09 09:34:24 -04003412static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3413{
Al Viro8687b632006-10-19 23:28:48 -07003414 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003415 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003416
3417 *fileid = 0;
3418 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3419 return -EIO;
3420 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003421 p = xdr_inline_decode(xdr, 8);
3422 if (unlikely(!p))
3423 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003424 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003425 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003426 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003427 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003428 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003429 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003430out_overflow:
3431 print_overflow_msg(__func__, xdr);
3432 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003433}
3434
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3436{
Al Viro8687b632006-10-19 23:28:48 -07003437 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438 int status = 0;
3439
3440 *res = 0;
3441 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3442 return -EIO;
3443 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003444 p = xdr_inline_decode(xdr, 8);
3445 if (unlikely(!p))
3446 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003447 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3449 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003450 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003452out_overflow:
3453 print_overflow_msg(__func__, xdr);
3454 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455}
3456
3457static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3458{
Al Viro8687b632006-10-19 23:28:48 -07003459 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 int status = 0;
3461
3462 *res = 0;
3463 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3464 return -EIO;
3465 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003466 p = xdr_inline_decode(xdr, 8);
3467 if (unlikely(!p))
3468 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003469 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3471 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003472 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003474out_overflow:
3475 print_overflow_msg(__func__, xdr);
3476 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477}
3478
3479static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3480{
Al Viro8687b632006-10-19 23:28:48 -07003481 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 int status = 0;
3483
3484 *res = 0;
3485 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3486 return -EIO;
3487 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003488 p = xdr_inline_decode(xdr, 8);
3489 if (unlikely(!p))
3490 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003491 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3493 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003494 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003496out_overflow:
3497 print_overflow_msg(__func__, xdr);
3498 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499}
3500
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003501static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3502{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003503 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003504 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003505 int status = 0;
3506
Benny Halevyc0eae662009-08-14 17:20:14 +03003507 p = xdr_inline_decode(xdr, 4);
3508 if (unlikely(!p))
3509 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003510 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003511 if (n == 0)
3512 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003513 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003514 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3515 dprintk("cannot parse %d components in path\n", n);
3516 goto out_eio;
3517 }
3518 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003519 struct nfs4_string *component = &path->components[path->ncomponents];
3520 status = decode_opaque_inline(xdr, &component->len, &component->data);
3521 if (unlikely(status != 0))
3522 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003523 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003524 pr_cont("%s%.*s ",
3525 (path->ncomponents != n ? "/ " : ""),
3526 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003527 }
3528out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003529 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003530root_path:
3531/* a root pathname is sent as a zero component4 */
3532 path->ncomponents = 1;
3533 path->components[0].len=0;
3534 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003535 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003536 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003537out_eio:
3538 dprintk(" status %d", status);
3539 status = -EIO;
3540 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003541out_overflow:
3542 print_overflow_msg(__func__, xdr);
3543 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003544}
3545
3546static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003547{
3548 int n;
Al Viro8687b632006-10-19 23:28:48 -07003549 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003550 int status = -EIO;
3551
3552 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3553 goto out;
3554 status = 0;
3555 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3556 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003557 status = -EIO;
3558 /* Ignore borken servers that return unrequested attrs */
3559 if (unlikely(res == NULL))
3560 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003561 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003562 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003563 if (unlikely(status != 0))
3564 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003565 p = xdr_inline_decode(xdr, 4);
3566 if (unlikely(!p))
3567 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003568 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003569 if (n <= 0)
3570 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003571 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003572 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003573 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003574
Trond Myklebust809b4262013-03-27 11:54:45 -04003575 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3576 break;
3577 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003578 p = xdr_inline_decode(xdr, 4);
3579 if (unlikely(!p))
3580 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003581 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003582
Chuck Lever02a29762012-03-01 17:00:31 -05003583 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003584 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3585 struct nfs4_string *server;
3586
3587 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003588 unsigned int i;
3589 dprintk("%s: using first %u of %u servers "
3590 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003591 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003592 NFS4_FS_LOCATION_MAXSERVERS,
3593 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003594 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003595 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003596 char *data;
3597 status = decode_opaque_inline(xdr, &len, &data);
3598 if (unlikely(status != 0))
3599 goto out_eio;
3600 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003601 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003602 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003603 server = &loc->servers[loc->nservers];
3604 status = decode_opaque_inline(xdr, &server->len, &server->data);
3605 if (unlikely(status != 0))
3606 goto out_eio;
3607 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003608 }
3609 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003610 if (unlikely(status != 0))
3611 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003612 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003613 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003614 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003615out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003616 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003617 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003618out_overflow:
3619 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003620out_eio:
3621 status = -EIO;
3622 goto out;
3623}
3624
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3626{
Al Viro8687b632006-10-19 23:28:48 -07003627 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 int status = 0;
3629
3630 *res = 0;
3631 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3632 return -EIO;
3633 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003634 p = xdr_inline_decode(xdr, 8);
3635 if (unlikely(!p))
3636 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003637 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3639 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003640 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003642out_overflow:
3643 print_overflow_msg(__func__, xdr);
3644 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645}
3646
3647static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3648{
Al Viro8687b632006-10-19 23:28:48 -07003649 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650 int status = 0;
3651
3652 *maxlink = 1;
3653 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3654 return -EIO;
3655 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003656 p = xdr_inline_decode(xdr, 4);
3657 if (unlikely(!p))
3658 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003659 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3661 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003662 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003664out_overflow:
3665 print_overflow_msg(__func__, xdr);
3666 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667}
3668
3669static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3670{
Al Viro8687b632006-10-19 23:28:48 -07003671 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 int status = 0;
3673
3674 *maxname = 1024;
3675 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3676 return -EIO;
3677 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003678 p = xdr_inline_decode(xdr, 4);
3679 if (unlikely(!p))
3680 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003681 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3683 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003684 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003686out_overflow:
3687 print_overflow_msg(__func__, xdr);
3688 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689}
3690
3691static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3692{
Al Viro8687b632006-10-19 23:28:48 -07003693 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694 int status = 0;
3695
3696 *res = 1024;
3697 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3698 return -EIO;
3699 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3700 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003701 p = xdr_inline_decode(xdr, 8);
3702 if (unlikely(!p))
3703 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003704 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 if (maxread > 0x7FFFFFFF)
3706 maxread = 0x7FFFFFFF;
3707 *res = (uint32_t)maxread;
3708 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3709 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003710 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003712out_overflow:
3713 print_overflow_msg(__func__, xdr);
3714 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715}
3716
3717static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3718{
Al Viro8687b632006-10-19 23:28:48 -07003719 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 int status = 0;
3721
3722 *res = 1024;
3723 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3724 return -EIO;
3725 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3726 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003727 p = xdr_inline_decode(xdr, 8);
3728 if (unlikely(!p))
3729 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003730 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 if (maxwrite > 0x7FFFFFFF)
3732 maxwrite = 0x7FFFFFFF;
3733 *res = (uint32_t)maxwrite;
3734 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3735 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003736 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003738out_overflow:
3739 print_overflow_msg(__func__, xdr);
3740 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741}
3742
Trond Myklebustbca79472009-03-11 14:10:26 -04003743static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744{
Trond Myklebustbca79472009-03-11 14:10:26 -04003745 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003746 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003747 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748
3749 *mode = 0;
3750 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3751 return -EIO;
3752 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003753 p = xdr_inline_decode(xdr, 4);
3754 if (unlikely(!p))
3755 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003756 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003757 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003759 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003761 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003762 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003763out_overflow:
3764 print_overflow_msg(__func__, xdr);
3765 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766}
3767
3768static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3769{
Al Viro8687b632006-10-19 23:28:48 -07003770 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003771 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772
3773 *nlink = 1;
3774 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3775 return -EIO;
3776 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003777 p = xdr_inline_decode(xdr, 4);
3778 if (unlikely(!p))
3779 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003780 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003782 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003784 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003785 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003786out_overflow:
3787 print_overflow_msg(__func__, xdr);
3788 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789}
3790
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003791static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003792 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003793 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794{
Al Viro8687b632006-10-19 23:28:48 -07003795 uint32_t len;
3796 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003797 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798
Eric W. Biedermane5782072013-02-01 14:22:02 -08003799 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3801 return -EIO;
3802 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003803 p = xdr_inline_decode(xdr, 4);
3804 if (unlikely(!p))
3805 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003806 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003807 p = xdr_inline_decode(xdr, len);
3808 if (unlikely(!p))
3809 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003810 if (owner_name != NULL) {
3811 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3812 if (owner_name->data != NULL) {
3813 owner_name->len = len;
3814 ret = NFS_ATTR_FATTR_OWNER_NAME;
3815 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003816 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003817 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003818 ret = NFS_ATTR_FATTR_OWNER;
3819 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003821 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003823 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003824 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3826 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003827 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003828 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003829out_overflow:
3830 print_overflow_msg(__func__, xdr);
3831 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832}
3833
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003834static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003835 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003836 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837{
Al Viro8687b632006-10-19 23:28:48 -07003838 uint32_t len;
3839 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003840 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841
Eric W. Biedermane5782072013-02-01 14:22:02 -08003842 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3844 return -EIO;
3845 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003846 p = xdr_inline_decode(xdr, 4);
3847 if (unlikely(!p))
3848 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003849 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003850 p = xdr_inline_decode(xdr, len);
3851 if (unlikely(!p))
3852 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003853 if (group_name != NULL) {
3854 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3855 if (group_name->data != NULL) {
3856 group_name->len = len;
3857 ret = NFS_ATTR_FATTR_GROUP_NAME;
3858 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003859 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003860 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003861 ret = NFS_ATTR_FATTR_GROUP;
3862 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003864 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003866 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003867 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3869 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003870 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003871 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003872out_overflow:
3873 print_overflow_msg(__func__, xdr);
3874 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875}
3876
3877static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3878{
Al Viro8687b632006-10-19 23:28:48 -07003879 uint32_t major = 0, minor = 0;
3880 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003881 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882
3883 *rdev = MKDEV(0,0);
3884 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3885 return -EIO;
3886 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3887 dev_t tmp;
3888
Benny Halevyc0eae662009-08-14 17:20:14 +03003889 p = xdr_inline_decode(xdr, 8);
3890 if (unlikely(!p))
3891 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003892 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003893 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 tmp = MKDEV(major, minor);
3895 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3896 *rdev = tmp;
3897 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003898 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003900 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003901 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003902out_overflow:
3903 print_overflow_msg(__func__, xdr);
3904 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905}
3906
3907static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3908{
Al Viro8687b632006-10-19 23:28:48 -07003909 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 int status = 0;
3911
3912 *res = 0;
3913 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3914 return -EIO;
3915 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003916 p = xdr_inline_decode(xdr, 8);
3917 if (unlikely(!p))
3918 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003919 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3921 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003922 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003924out_overflow:
3925 print_overflow_msg(__func__, xdr);
3926 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927}
3928
3929static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3930{
Al Viro8687b632006-10-19 23:28:48 -07003931 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932 int status = 0;
3933
3934 *res = 0;
3935 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3936 return -EIO;
3937 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003938 p = xdr_inline_decode(xdr, 8);
3939 if (unlikely(!p))
3940 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003941 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3943 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003944 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003946out_overflow:
3947 print_overflow_msg(__func__, xdr);
3948 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949}
3950
3951static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3952{
Al Viro8687b632006-10-19 23:28:48 -07003953 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 int status = 0;
3955
3956 *res = 0;
3957 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3958 return -EIO;
3959 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003960 p = xdr_inline_decode(xdr, 8);
3961 if (unlikely(!p))
3962 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003963 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3965 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003966 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003968out_overflow:
3969 print_overflow_msg(__func__, xdr);
3970 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971}
3972
3973static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3974{
Al Viro8687b632006-10-19 23:28:48 -07003975 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003976 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977
3978 *used = 0;
3979 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3980 return -EIO;
3981 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003982 p = xdr_inline_decode(xdr, 8);
3983 if (unlikely(!p))
3984 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003985 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003987 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003989 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003991 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003992out_overflow:
3993 print_overflow_msg(__func__, xdr);
3994 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995}
3996
3997static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3998{
Al Viro8687b632006-10-19 23:28:48 -07003999 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 uint64_t sec;
4001 uint32_t nsec;
4002
Benny Halevyc0eae662009-08-14 17:20:14 +03004003 p = xdr_inline_decode(xdr, 12);
4004 if (unlikely(!p))
4005 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004006 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004007 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 time->tv_sec = (time_t)sec;
4009 time->tv_nsec = (long)nsec;
4010 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004011out_overflow:
4012 print_overflow_msg(__func__, xdr);
4013 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014}
4015
4016static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4017{
4018 int status = 0;
4019
4020 time->tv_sec = 0;
4021 time->tv_nsec = 0;
4022 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4023 return -EIO;
4024 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4025 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004026 if (status == 0)
4027 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4029 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004030 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031 return status;
4032}
4033
4034static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4035{
4036 int status = 0;
4037
4038 time->tv_sec = 0;
4039 time->tv_nsec = 0;
4040 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4041 return -EIO;
4042 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4043 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004044 if (status == 0)
4045 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4047 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004048 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049 return status;
4050}
4051
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004052static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4053 struct timespec *time)
4054{
4055 int status = 0;
4056
4057 time->tv_sec = 0;
4058 time->tv_nsec = 0;
4059 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4060 return -EIO;
4061 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4062 status = decode_attr_time(xdr, time);
4063 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4064 }
4065 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4066 (long)time->tv_nsec);
4067 return status;
4068}
4069
David Quigleyaa9c2662013-05-22 12:50:44 -04004070static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4071 struct nfs4_label *label)
4072{
4073 uint32_t pi = 0;
4074 uint32_t lfs = 0;
4075 __u32 len;
4076 __be32 *p;
4077 int status = 0;
4078
4079 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4080 return -EIO;
4081 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4082 p = xdr_inline_decode(xdr, 4);
4083 if (unlikely(!p))
4084 goto out_overflow;
4085 lfs = be32_to_cpup(p++);
4086 p = xdr_inline_decode(xdr, 4);
4087 if (unlikely(!p))
4088 goto out_overflow;
4089 pi = be32_to_cpup(p++);
4090 p = xdr_inline_decode(xdr, 4);
4091 if (unlikely(!p))
4092 goto out_overflow;
4093 len = be32_to_cpup(p++);
4094 p = xdr_inline_decode(xdr, len);
4095 if (unlikely(!p))
4096 goto out_overflow;
4097 if (len < NFS4_MAXLABELLEN) {
4098 if (label) {
4099 memcpy(label->label, p, len);
4100 label->len = len;
4101 label->pi = pi;
4102 label->lfs = lfs;
4103 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4104 }
4105 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4106 } else
4107 printk(KERN_WARNING "%s: label too long (%u)!\n",
4108 __func__, len);
4109 }
4110 if (label && label->label)
4111 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4112 (char *)label->label, label->len, label->pi, label->lfs);
4113 return status;
4114
4115out_overflow:
4116 print_overflow_msg(__func__, xdr);
4117 return -EIO;
4118}
4119
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4121{
4122 int status = 0;
4123
4124 time->tv_sec = 0;
4125 time->tv_nsec = 0;
4126 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4127 return -EIO;
4128 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4129 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004130 if (status == 0)
4131 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4133 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004134 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135 return status;
4136}
4137
Trond Myklebust256e48b2012-06-21 11:18:13 -04004138static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139{
4140 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004141 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142
4143 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004144 dprintk("%s: server returned incorrect attribute length: "
4145 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004146 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 attrwords << 2,
4148 (attrwords < nwords) ? '<' : '>',
4149 nwords << 2);
4150 return -EIO;
4151 }
4152 return 0;
4153}
4154
4155static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4156{
Al Viro8687b632006-10-19 23:28:48 -07004157 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158
Benny Halevyc0eae662009-08-14 17:20:14 +03004159 p = xdr_inline_decode(xdr, 20);
4160 if (unlikely(!p))
4161 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004162 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004163 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004164 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004165 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004166out_overflow:
4167 print_overflow_msg(__func__, xdr);
4168 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169}
4170
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004171static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172{
Al Viro8687b632006-10-19 23:28:48 -07004173 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174 uint32_t supp, acc;
4175 int status;
4176
4177 status = decode_op_hdr(xdr, OP_ACCESS);
4178 if (status)
4179 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004180 p = xdr_inline_decode(xdr, 8);
4181 if (unlikely(!p))
4182 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004183 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004184 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004185 *supported = supp;
4186 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004188out_overflow:
4189 print_overflow_msg(__func__, xdr);
4190 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191}
4192
Benny Halevy07d30432009-08-14 17:19:52 +03004193static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194{
Al Viro8687b632006-10-19 23:28:48 -07004195 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004196
4197 p = xdr_inline_decode(xdr, len);
4198 if (likely(p)) {
4199 memcpy(buf, p, len);
4200 return 0;
4201 }
4202 print_overflow_msg(__func__, xdr);
4203 return -EIO;
4204}
4205
4206static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4207{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004208 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209}
4210
4211static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4212{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 int status;
4214
4215 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004216 if (status != -EIO)
4217 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004218 if (!status)
4219 status = decode_stateid(xdr, &res->stateid);
4220 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221}
4222
Benny Halevydb942bb2009-08-14 17:19:56 +03004223static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4224{
Chuck Levercd937102012-03-02 17:14:31 -05004225 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226}
4227
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004228static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4229{
4230 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4231}
4232
Fred Isaman0b7c0152012-04-20 14:47:39 -04004233static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 int status;
4236
4237 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004238 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004239 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004240 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241}
4242
4243static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4244{
Al Viro8687b632006-10-19 23:28:48 -07004245 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246 uint32_t bmlen;
4247 int status;
4248
4249 status = decode_op_hdr(xdr, OP_CREATE);
4250 if (status)
4251 return status;
4252 if ((status = decode_change_info(xdr, cinfo)))
4253 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004254 p = xdr_inline_decode(xdr, 4);
4255 if (unlikely(!p))
4256 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004257 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004258 p = xdr_inline_decode(xdr, bmlen << 2);
4259 if (likely(p))
4260 return 0;
4261out_overflow:
4262 print_overflow_msg(__func__, xdr);
4263 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264}
4265
4266static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4267{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004268 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004269 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270 int status;
4271
4272 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4273 goto xdr_error;
4274 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4275 goto xdr_error;
4276 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4277 goto xdr_error;
4278 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4279 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004280 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4281 &res->fh_expire_type)) != 0)
4282 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4284 goto xdr_error;
4285 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4286 goto xdr_error;
4287 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4288 goto xdr_error;
4289 status = verify_attr_len(xdr, savep, attrlen);
4290xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004291 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 return status;
4293}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004294
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4296{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004297 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004298 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004300
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4302 goto xdr_error;
4303 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4304 goto xdr_error;
4305 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4306 goto xdr_error;
4307
4308 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4309 goto xdr_error;
4310 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4311 goto xdr_error;
4312 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4313 goto xdr_error;
4314 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4315 goto xdr_error;
4316 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4317 goto xdr_error;
4318 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4319 goto xdr_error;
4320
4321 status = verify_attr_len(xdr, savep, attrlen);
4322xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004323 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324 return status;
4325}
4326
4327static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4328{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004329 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004330 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004331 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004332
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4334 goto xdr_error;
4335 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4336 goto xdr_error;
4337 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4338 goto xdr_error;
4339
4340 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4341 goto xdr_error;
4342 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4343 goto xdr_error;
4344
4345 status = verify_attr_len(xdr, savep, attrlen);
4346xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004347 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348 return status;
4349}
4350
Andy Adamson88034c32012-05-23 05:02:34 -04004351static int decode_threshold_hint(struct xdr_stream *xdr,
4352 uint32_t *bitmap,
4353 uint64_t *res,
4354 uint32_t hint_bit)
4355{
4356 __be32 *p;
4357
4358 *res = 0;
4359 if (likely(bitmap[0] & hint_bit)) {
4360 p = xdr_inline_decode(xdr, 8);
4361 if (unlikely(!p))
4362 goto out_overflow;
4363 xdr_decode_hyper(p, res);
4364 }
4365 return 0;
4366out_overflow:
4367 print_overflow_msg(__func__, xdr);
4368 return -EIO;
4369}
4370
4371static int decode_first_threshold_item4(struct xdr_stream *xdr,
4372 struct nfs4_threshold *res)
4373{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004374 __be32 *p;
4375 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004376 uint32_t bitmap[3] = {0,}, attrlen;
4377 int status;
4378
4379 /* layout type */
4380 p = xdr_inline_decode(xdr, 4);
4381 if (unlikely(!p)) {
4382 print_overflow_msg(__func__, xdr);
4383 return -EIO;
4384 }
4385 res->l_type = be32_to_cpup(p);
4386
4387 /* thi_hintset bitmap */
4388 status = decode_attr_bitmap(xdr, bitmap);
4389 if (status < 0)
4390 goto xdr_error;
4391
4392 /* thi_hintlist length */
4393 status = decode_attr_length(xdr, &attrlen, &savep);
4394 if (status < 0)
4395 goto xdr_error;
4396 /* thi_hintlist */
4397 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4398 if (status < 0)
4399 goto xdr_error;
4400 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4401 if (status < 0)
4402 goto xdr_error;
4403 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4404 THRESHOLD_RD_IO);
4405 if (status < 0)
4406 goto xdr_error;
4407 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4408 THRESHOLD_WR_IO);
4409 if (status < 0)
4410 goto xdr_error;
4411
4412 status = verify_attr_len(xdr, savep, attrlen);
4413 res->bm = bitmap[0];
4414
4415 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4416 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4417 res->wr_io_sz);
4418xdr_error:
4419 dprintk("%s ret=%d!\n", __func__, status);
4420 return status;
4421}
4422
4423/*
4424 * Thresholds on pNFS direct I/O vrs MDS I/O
4425 */
4426static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4427 uint32_t *bitmap,
4428 struct nfs4_threshold *res)
4429{
4430 __be32 *p;
4431 int status = 0;
4432 uint32_t num;
4433
4434 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4435 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004436 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004437 /* Did the server return an unrequested attribute? */
4438 if (unlikely(res == NULL))
4439 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004440 p = xdr_inline_decode(xdr, 4);
4441 if (unlikely(!p))
4442 goto out_overflow;
4443 num = be32_to_cpup(p);
4444 if (num == 0)
4445 return 0;
4446 if (num > 1)
4447 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4448 "drivers per filesystem not supported\n",
4449 __func__);
4450
4451 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004452 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004453 }
4454 return status;
4455out_overflow:
4456 print_overflow_msg(__func__, xdr);
4457 return -EIO;
4458}
4459
Bryan Schumakerae42c702010-10-21 16:33:17 -04004460static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4461 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004462 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004463 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464{
Trond Myklebustbca79472009-03-11 14:10:26 -04004465 int status;
4466 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004467 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004468 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004470 status = decode_attr_type(xdr, bitmap, &type);
4471 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004473 fattr->mode = 0;
4474 if (status != 0) {
4475 fattr->mode |= nfs_type2fmt[type];
4476 fattr->valid |= status;
4477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004479 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4480 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004482 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004483
4484 status = decode_attr_size(xdr, bitmap, &fattr->size);
4485 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004487 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004488
4489 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4490 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004492 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004493
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004494 err = 0;
4495 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004496 if (status < 0)
4497 goto xdr_error;
4498
4499 status = decode_attr_filehandle(xdr, bitmap, fh);
4500 if (status < 0)
4501 goto xdr_error;
4502
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004503 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4504 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004505 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004506 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004507
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004508 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004509 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004510 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004511 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004512
4513 status = decode_attr_mode(xdr, bitmap, &fmode);
4514 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004516 if (status != 0) {
4517 fattr->mode |= fmode;
4518 fattr->valid |= status;
4519 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004520
4521 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4522 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004524 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004525
Trond Myklebust6926afd2012-01-07 13:22:46 -05004526 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004527 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004529 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004530
Trond Myklebust6926afd2012-01-07 13:22:46 -05004531 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004532 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004534 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004535
4536 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4537 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004539 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004540
4541 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4542 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004544 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004545
4546 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4547 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004549 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004550
4551 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4552 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004554 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004555
4556 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4557 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004558 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004559 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004560
Trond Myklebust28331a42011-04-27 13:47:52 -04004561 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004562 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004563 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004564 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004565
Andy Adamson88034c32012-05-23 05:02:34 -04004566 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4567 if (status < 0)
4568 goto xdr_error;
4569
David Quigleyaa9c2662013-05-22 12:50:44 -04004570 if (label) {
4571 status = decode_attr_security_label(xdr, bitmap, label);
4572 if (status < 0)
4573 goto xdr_error;
4574 fattr->valid |= status;
4575 }
4576
Bryan Schumakerae42c702010-10-21 16:33:17 -04004577xdr_error:
4578 dprintk("%s: xdr returned %d\n", __func__, -status);
4579 return status;
4580}
4581
4582static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004583 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004584 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004585{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004586 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004587 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004588 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004589 int status;
4590
4591 status = decode_op_hdr(xdr, OP_GETATTR);
4592 if (status < 0)
4593 goto xdr_error;
4594
4595 status = decode_attr_bitmap(xdr, bitmap);
4596 if (status < 0)
4597 goto xdr_error;
4598
4599 status = decode_attr_length(xdr, &attrlen, &savep);
4600 if (status < 0)
4601 goto xdr_error;
4602
David Quigleyaa9c2662013-05-22 12:50:44 -04004603 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4604 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004605 if (status < 0)
4606 goto xdr_error;
4607
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004608 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004609xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004610 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611 return status;
4612}
4613
David Quigleyaa9c2662013-05-22 12:50:44 -04004614static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4615 struct nfs4_label *label, const struct nfs_server *server)
4616{
4617 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4618}
4619
Bryan Schumakerae42c702010-10-21 16:33:17 -04004620static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004621 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004622{
David Quigleyaa9c2662013-05-22 12:50:44 -04004623 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004624}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625
Andy Adamson504913f2010-10-20 00:17:57 -04004626/*
4627 * Decode potentially multiple layout types. Currently we only support
4628 * one layout driver per file system.
4629 */
4630static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4631 uint32_t *layouttype)
4632{
4633 uint32_t *p;
4634 int num;
4635
4636 p = xdr_inline_decode(xdr, 4);
4637 if (unlikely(!p))
4638 goto out_overflow;
4639 num = be32_to_cpup(p);
4640
4641 /* pNFS is not supported by the underlying file system */
4642 if (num == 0) {
4643 *layouttype = 0;
4644 return 0;
4645 }
4646 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004647 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4648 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004649
4650 /* Decode and set first layout type, move xdr->p past unused types */
4651 p = xdr_inline_decode(xdr, num * 4);
4652 if (unlikely(!p))
4653 goto out_overflow;
4654 *layouttype = be32_to_cpup(p);
4655 return 0;
4656out_overflow:
4657 print_overflow_msg(__func__, xdr);
4658 return -EIO;
4659}
4660
4661/*
4662 * The type of file system exported.
4663 * Note we must ensure that layouttype is set in any non-error case.
4664 */
4665static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4666 uint32_t *layouttype)
4667{
4668 int status = 0;
4669
4670 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4671 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4672 return -EIO;
4673 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4674 status = decode_first_pnfs_layout_type(xdr, layouttype);
4675 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4676 } else
4677 *layouttype = 0;
4678 return status;
4679}
4680
Fred Isamandae100c2011-07-30 20:52:37 -04004681/*
4682 * The prefered block size for layout directed io
4683 */
4684static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4685 uint32_t *res)
4686{
4687 __be32 *p;
4688
4689 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4690 *res = 0;
4691 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4692 p = xdr_inline_decode(xdr, 4);
4693 if (unlikely(!p)) {
4694 print_overflow_msg(__func__, xdr);
4695 return -EIO;
4696 }
4697 *res = be32_to_cpup(p);
4698 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4699 }
4700 return 0;
4701}
4702
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4704{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004705 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004706 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004707 int status;
4708
4709 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4710 goto xdr_error;
4711 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4712 goto xdr_error;
4713 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4714 goto xdr_error;
4715
4716 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4717
4718 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4719 goto xdr_error;
4720 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4721 goto xdr_error;
4722 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4723 goto xdr_error;
4724 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4725 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4726 goto xdr_error;
4727 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004728 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4729 if (status != 0)
4730 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004731 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4732 if (status != 0)
4733 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004734 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4735 if (status)
4736 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737
4738 status = verify_attr_len(xdr, savep, attrlen);
4739xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004740 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741 return status;
4742}
4743
4744static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4745{
Al Viro8687b632006-10-19 23:28:48 -07004746 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747 uint32_t len;
4748 int status;
4749
Trond Myklebust99367812007-07-17 21:52:41 -04004750 /* Zero handle first to allow comparisons */
4751 memset(fh, 0, sizeof(*fh));
4752
Linus Torvalds1da177e2005-04-16 15:20:36 -07004753 status = decode_op_hdr(xdr, OP_GETFH);
4754 if (status)
4755 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756
Benny Halevyc0eae662009-08-14 17:20:14 +03004757 p = xdr_inline_decode(xdr, 4);
4758 if (unlikely(!p))
4759 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004760 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004761 if (len > NFS4_FHSIZE)
4762 return -EIO;
4763 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004764 p = xdr_inline_decode(xdr, len);
4765 if (unlikely(!p))
4766 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004767 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004769out_overflow:
4770 print_overflow_msg(__func__, xdr);
4771 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772}
4773
4774static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4775{
4776 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004777
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 status = decode_op_hdr(xdr, OP_LINK);
4779 if (status)
4780 return status;
4781 return decode_change_info(xdr, cinfo);
4782}
4783
4784/*
4785 * We create the owner, so we know a proper owner.id length is 4.
4786 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004787static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004789 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004790 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004791 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004793 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004794 if (unlikely(!p))
4795 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004796 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004797 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004798 type = be32_to_cpup(p++); /* 4 byte read */
4799 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004800 fl->fl_start = (loff_t)offset;
4801 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4802 if (length == ~(uint64_t)0)
4803 fl->fl_end = OFFSET_MAX;
4804 fl->fl_type = F_WRLCK;
4805 if (type & 1)
4806 fl->fl_type = F_RDLCK;
4807 fl->fl_pid = 0;
4808 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004809 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4810 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4811 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004812 if (likely(p))
4813 return -NFS4ERR_DENIED;
4814out_overflow:
4815 print_overflow_msg(__func__, xdr);
4816 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817}
4818
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004819static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821 int status;
4822
4823 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004824 if (status == -EIO)
4825 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004827 status = decode_stateid(xdr, &res->stateid);
4828 if (unlikely(status))
4829 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004831 status = decode_lock_denied(xdr, NULL);
4832 if (res->open_seqid != NULL)
4833 nfs_increment_open_seqid(status, res->open_seqid);
4834 nfs_increment_lock_seqid(status, res->lock_seqid);
4835out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836 return status;
4837}
4838
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004839static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840{
4841 int status;
4842 status = decode_op_hdr(xdr, OP_LOCKT);
4843 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004844 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845 return status;
4846}
4847
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004848static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850 int status;
4851
4852 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004853 if (status != -EIO)
4854 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004855 if (status == 0)
4856 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857 return status;
4858}
4859
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004860static int decode_release_lockowner(struct xdr_stream *xdr)
4861{
4862 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4863}
4864
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865static int decode_lookup(struct xdr_stream *xdr)
4866{
4867 return decode_op_hdr(xdr, OP_LOOKUP);
4868}
4869
4870/* This is too sick! */
4871static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4872{
Andy Adamson05d564f2008-12-23 16:06:15 -05004873 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874 uint32_t limit_type, nblocks, blocksize;
4875
Benny Halevyc0eae662009-08-14 17:20:14 +03004876 p = xdr_inline_decode(xdr, 12);
4877 if (unlikely(!p))
4878 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004879 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004881 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004882 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004883 break;
4884 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004885 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004886 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004887 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004888 }
4889 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004890out_overflow:
4891 print_overflow_msg(__func__, xdr);
4892 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893}
4894
4895static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4896{
Andy Adamson05d564f2008-12-23 16:06:15 -05004897 __be32 *p;
4898 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004899 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900
Benny Halevyc0eae662009-08-14 17:20:14 +03004901 p = xdr_inline_decode(xdr, 4);
4902 if (unlikely(!p))
4903 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004904 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4906 res->delegation_type = 0;
4907 return 0;
4908 }
Benny Halevy07d30432009-08-14 17:19:52 +03004909 status = decode_stateid(xdr, &res->delegation);
4910 if (unlikely(status))
4911 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004912 p = xdr_inline_decode(xdr, 4);
4913 if (unlikely(!p))
4914 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004915 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004916
Linus Torvalds1da177e2005-04-16 15:20:36 -07004917 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004918 case NFS4_OPEN_DELEGATE_READ:
4919 res->delegation_type = FMODE_READ;
4920 break;
4921 case NFS4_OPEN_DELEGATE_WRITE:
4922 res->delegation_type = FMODE_WRITE|FMODE_READ;
4923 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004924 return -EIO;
4925 }
David Howells7539bba2006-08-22 20:06:09 -04004926 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004927out_overflow:
4928 print_overflow_msg(__func__, xdr);
4929 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930}
4931
4932static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4933{
Andy Adamson05d564f2008-12-23 16:06:15 -05004934 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004935 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004936 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004937
Andy Adamson05d564f2008-12-23 16:06:15 -05004938 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004939 if (status != -EIO)
4940 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004941 if (!status)
4942 status = decode_stateid(xdr, &res->stateid);
4943 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004944 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945
Andy Adamson05d564f2008-12-23 16:06:15 -05004946 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947
Benny Halevyc0eae662009-08-14 17:20:14 +03004948 p = xdr_inline_decode(xdr, 8);
4949 if (unlikely(!p))
4950 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004951 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004952 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004953 if (bmlen > 10)
4954 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004955
Benny Halevyc0eae662009-08-14 17:20:14 +03004956 p = xdr_inline_decode(xdr, bmlen << 2);
4957 if (unlikely(!p))
4958 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004959 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4960 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004961 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004962 for (; i < NFS4_BITMAP_SIZE; i++)
4963 res->attrset[i] = 0;
4964
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965 return decode_delegation(xdr, res);
4966xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004967 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004968 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004969out_overflow:
4970 print_overflow_msg(__func__, xdr);
4971 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972}
4973
4974static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4975{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976 int status;
4977
Andy Adamson05d564f2008-12-23 16:06:15 -05004978 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004979 if (status != -EIO)
4980 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004981 if (!status)
4982 status = decode_stateid(xdr, &res->stateid);
4983 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984}
4985
4986static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4987{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988 int status;
4989
4990 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004991 if (status != -EIO)
4992 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004993 if (!status)
4994 status = decode_stateid(xdr, &res->stateid);
4995 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996}
4997
4998static int decode_putfh(struct xdr_stream *xdr)
4999{
5000 return decode_op_hdr(xdr, OP_PUTFH);
5001}
5002
5003static int decode_putrootfh(struct xdr_stream *xdr)
5004{
5005 return decode_op_hdr(xdr, OP_PUTROOTFH);
5006}
5007
5008static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
5009{
Al Viro8687b632006-10-19 23:28:48 -07005010 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005011 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005012 int status;
5013
5014 status = decode_op_hdr(xdr, OP_READ);
5015 if (status)
5016 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005017 p = xdr_inline_decode(xdr, 8);
5018 if (unlikely(!p))
5019 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005020 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005021 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005022 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005024 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 "count %u > recvd %u\n", count, recvd);
5026 count = recvd;
5027 eof = 0;
5028 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029 res->eof = eof;
5030 res->count = count;
5031 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005032out_overflow:
5033 print_overflow_msg(__func__, xdr);
5034 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035}
5036
5037static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5038{
Chuck Leverbcecff72007-10-26 13:32:03 -04005039 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005040 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041
5042 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005043 if (!status)
5044 status = decode_verifier(xdr, readdir->verifier.data);
5045 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005047 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005048 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005049 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005050 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005051}
5052
5053static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5054{
5055 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005056 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005057 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058 int status;
5059
5060 status = decode_op_hdr(xdr, OP_READLINK);
5061 if (status)
5062 return status;
5063
5064 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005065 p = xdr_inline_decode(xdr, 4);
5066 if (unlikely(!p))
5067 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005068 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005070 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071 return -ENAMETOOLONG;
5072 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005073 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005075 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005076 "count %u > recvd %u\n", len, recvd);
5077 return -EIO;
5078 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079 /*
5080 * The XDR encode routine has set things up so that
5081 * the link text will be copied directly into the
5082 * buffer. We just have to do overflow-checking,
5083 * and and null-terminate the text (the VFS expects
5084 * null-termination).
5085 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005086 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005088out_overflow:
5089 print_overflow_msg(__func__, xdr);
5090 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091}
5092
5093static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5094{
5095 int status;
5096
5097 status = decode_op_hdr(xdr, OP_REMOVE);
5098 if (status)
5099 goto out;
5100 status = decode_change_info(xdr, cinfo);
5101out:
5102 return status;
5103}
5104
5105static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5106 struct nfs4_change_info *new_cinfo)
5107{
5108 int status;
5109
5110 status = decode_op_hdr(xdr, OP_RENAME);
5111 if (status)
5112 goto out;
5113 if ((status = decode_change_info(xdr, old_cinfo)))
5114 goto out;
5115 status = decode_change_info(xdr, new_cinfo);
5116out:
5117 return status;
5118}
5119
5120static int decode_renew(struct xdr_stream *xdr)
5121{
5122 return decode_op_hdr(xdr, OP_RENEW);
5123}
5124
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005125static int
5126decode_restorefh(struct xdr_stream *xdr)
5127{
5128 return decode_op_hdr(xdr, OP_RESTOREFH);
5129}
5130
J. Bruce Fields029d1052005-06-22 17:16:22 +00005131static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005132 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005133{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005134 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005135 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005136 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005137 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005138 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005139
Andy Adamsonbf118a32011-12-07 11:55:27 -05005140 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005141 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5142 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005143
Trond Myklebust519d3952012-08-14 17:30:10 -04005144 xdr_enter_page(xdr, xdr->buf->page_len);
5145
Trond Myklebustcff298c2012-08-14 17:14:17 -04005146 /* Calculate the offset of the page data */
5147 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005148
J. Bruce Fields029d1052005-06-22 17:16:22 +00005149 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5150 goto out;
5151 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5152 goto out;
5153
5154 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5155 return -EIO;
5156 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005157
Andy Adamsonbf118a32011-12-07 11:55:27 -05005158 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5159 * are stored with the acl data to handle the problem of
5160 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005161 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005162 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005163
5164 /* Check for receive buffer overflow */
5165 if (res->acl_len > (xdr->nwords << 2) ||
5166 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5167 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005168 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005169 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005170 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005171 } else
5172 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005173
5174out:
5175 return status;
5176}
5177
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178static int
5179decode_savefh(struct xdr_stream *xdr)
5180{
5181 return decode_op_hdr(xdr, OP_SAVEFH);
5182}
5183
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005184static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185{
Al Viro8687b632006-10-19 23:28:48 -07005186 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005187 uint32_t bmlen;
5188 int status;
5189
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190 status = decode_op_hdr(xdr, OP_SETATTR);
5191 if (status)
5192 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005193 p = xdr_inline_decode(xdr, 4);
5194 if (unlikely(!p))
5195 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005196 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005197 p = xdr_inline_decode(xdr, bmlen << 2);
5198 if (likely(p))
5199 return 0;
5200out_overflow:
5201 print_overflow_msg(__func__, xdr);
5202 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005203}
5204
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005205static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005206{
Al Viro8687b632006-10-19 23:28:48 -07005207 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005208 uint32_t opnum;
5209 int32_t nfserr;
5210
Benny Halevyc0eae662009-08-14 17:20:14 +03005211 p = xdr_inline_decode(xdr, 8);
5212 if (unlikely(!p))
5213 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005214 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005216 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005217 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218 return -EIO;
5219 }
Benny Halevycccddf42009-08-14 17:20:19 +03005220 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005221 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005222 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5223 if (unlikely(!p))
5224 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005225 p = xdr_decode_hyper(p, &res->clientid);
5226 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227 } else if (nfserr == NFSERR_CLID_INUSE) {
5228 uint32_t len;
5229
5230 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005231 p = xdr_inline_decode(xdr, 4);
5232 if (unlikely(!p))
5233 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005234 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005235 p = xdr_inline_decode(xdr, len);
5236 if (unlikely(!p))
5237 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238
5239 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005240 p = xdr_inline_decode(xdr, 4);
5241 if (unlikely(!p))
5242 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005243 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005244 p = xdr_inline_decode(xdr, len);
5245 if (unlikely(!p))
5246 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005247 return -NFSERR_CLID_INUSE;
5248 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005249 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250
5251 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005252out_overflow:
5253 print_overflow_msg(__func__, xdr);
5254 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005255}
5256
5257static int decode_setclientid_confirm(struct xdr_stream *xdr)
5258{
5259 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5260}
5261
5262static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5263{
Al Viro8687b632006-10-19 23:28:48 -07005264 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005265 int status;
5266
5267 status = decode_op_hdr(xdr, OP_WRITE);
5268 if (status)
5269 return status;
5270
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005271 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005272 if (unlikely(!p))
5273 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005274 res->count = be32_to_cpup(p++);
5275 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005276 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005277out_overflow:
5278 print_overflow_msg(__func__, xdr);
5279 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005280}
5281
5282static int decode_delegreturn(struct xdr_stream *xdr)
5283{
5284 return decode_op_hdr(xdr, OP_DELEGRETURN);
5285}
5286
Chuck Leverfb15b262013-03-16 15:54:34 -04005287static int decode_secinfo_gss(struct xdr_stream *xdr,
5288 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005289{
Chuck Leverfb15b262013-03-16 15:54:34 -04005290 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005291 __be32 *p;
5292
5293 p = xdr_inline_decode(xdr, 4);
5294 if (unlikely(!p))
5295 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005296 oid_len = be32_to_cpup(p);
5297 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005298 goto out_err;
5299
Chuck Leverfb15b262013-03-16 15:54:34 -04005300 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005301 if (unlikely(!p))
5302 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005303 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5304 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005305
5306 p = xdr_inline_decode(xdr, 8);
5307 if (unlikely(!p))
5308 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005309 flavor->flavor_info.qop = be32_to_cpup(p++);
5310 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005311
5312 return 0;
5313
5314out_overflow:
5315 print_overflow_msg(__func__, xdr);
5316 return -EIO;
5317out_err:
5318 return -EINVAL;
5319}
5320
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005321static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005322{
Chuck Leverfb15b262013-03-16 15:54:34 -04005323 struct nfs4_secinfo4 *sec_flavor;
5324 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005325 int status;
5326 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005327
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005328 p = xdr_inline_decode(xdr, 4);
5329 if (unlikely(!p))
5330 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005331
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005332 res->flavors->num_flavors = 0;
5333 num_flavors = be32_to_cpup(p);
5334
5335 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005336 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005337 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005338 break;
5339
5340 p = xdr_inline_decode(xdr, 4);
5341 if (unlikely(!p))
5342 goto out_overflow;
5343 sec_flavor->flavor = be32_to_cpup(p);
5344
5345 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005346 status = decode_secinfo_gss(xdr, sec_flavor);
5347 if (status)
5348 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005349 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005350 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005351 }
5352
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005353 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005354out:
5355 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005356out_overflow:
5357 print_overflow_msg(__func__, xdr);
5358 return -EIO;
5359}
5360
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005361static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5362{
5363 int status = decode_op_hdr(xdr, OP_SECINFO);
5364 if (status)
5365 return status;
5366 return decode_secinfo_common(xdr, res);
5367}
5368
Benny Halevy99fe60d2009-04-01 09:22:29 -04005369#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005370static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5371{
5372 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5373 if (status)
5374 return status;
5375 return decode_secinfo_common(xdr, res);
5376}
5377
Benny Halevy99fe60d2009-04-01 09:22:29 -04005378static int decode_exchange_id(struct xdr_stream *xdr,
5379 struct nfs41_exchange_id_res *res)
5380{
5381 __be32 *p;
5382 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005383 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005384 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005385 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005386
5387 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5388 if (status)
5389 return status;
5390
Benny Halevyc0eae662009-08-14 17:20:14 +03005391 p = xdr_inline_decode(xdr, 8);
5392 if (unlikely(!p))
5393 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005394 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005395 p = xdr_inline_decode(xdr, 12);
5396 if (unlikely(!p))
5397 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005398 res->seqid = be32_to_cpup(p++);
5399 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005400
5401 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005402 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005403 if (dummy != SP4_NONE)
5404 return -EIO;
5405
Chuck Leveracdeb692012-05-21 22:46:16 -04005406 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005407 p = xdr_inline_decode(xdr, 8);
5408 if (unlikely(!p))
5409 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005410 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005411
Chuck Leveracdeb692012-05-21 22:46:16 -04005412 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005413 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5414 if (unlikely(status))
5415 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005416 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5417 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005418 memcpy(res->server_owner->major_id, dummy_str, dummy);
5419 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005420
Chuck Leveracdeb692012-05-21 22:46:16 -04005421 /* server_scope4 */
5422 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5423 if (unlikely(status))
5424 return status;
5425 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5426 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005427 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5428 res->server_scope->server_scope_sz = dummy;
5429
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005430 /* Implementation Id */
5431 p = xdr_inline_decode(xdr, 4);
5432 if (unlikely(!p))
5433 goto out_overflow;
5434 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005435
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005436 if (impl_id_count) {
5437 /* nii_domain */
5438 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5439 if (unlikely(status))
5440 return status;
5441 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5442 return -EIO;
5443 memcpy(res->impl_id->domain, dummy_str, dummy);
5444
5445 /* nii_name */
5446 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5447 if (unlikely(status))
5448 return status;
5449 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5450 return -EIO;
5451 memcpy(res->impl_id->name, dummy_str, dummy);
5452
5453 /* nii_date */
5454 p = xdr_inline_decode(xdr, 12);
5455 if (unlikely(!p))
5456 goto out_overflow;
5457 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5458 res->impl_id->date.nseconds = be32_to_cpup(p);
5459
5460 /* if there's more than one entry, ignore the rest */
5461 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005462 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005463out_overflow:
5464 print_overflow_msg(__func__, xdr);
5465 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005466}
Andy Adamsonfc931582009-04-01 09:22:31 -04005467
5468static int decode_chan_attrs(struct xdr_stream *xdr,
5469 struct nfs4_channel_attrs *attrs)
5470{
5471 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005472 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005473
Benny Halevyc0eae662009-08-14 17:20:14 +03005474 p = xdr_inline_decode(xdr, 28);
5475 if (unlikely(!p))
5476 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005477 val = be32_to_cpup(p++); /* headerpadsz */
5478 if (val)
5479 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005480 attrs->max_rqst_sz = be32_to_cpup(p++);
5481 attrs->max_resp_sz = be32_to_cpup(p++);
5482 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5483 attrs->max_ops = be32_to_cpup(p++);
5484 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005485 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005486 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005487 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5488 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005489 return -EINVAL;
5490 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005491 if (nr_attrs == 1) {
5492 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5493 if (unlikely(!p))
5494 goto out_overflow;
5495 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005496 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005497out_overflow:
5498 print_overflow_msg(__func__, xdr);
5499 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005500}
5501
Benny Halevye78291e2009-08-14 17:20:00 +03005502static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5503{
5504 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005505}
5506
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005507static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5508 struct nfs41_bind_conn_to_session_res *res)
5509{
5510 __be32 *p;
5511 int status;
5512
5513 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5514 if (!status)
5515 status = decode_sessionid(xdr, &res->session->sess_id);
5516 if (unlikely(status))
5517 return status;
5518
5519 /* dir flags, rdma mode bool */
5520 p = xdr_inline_decode(xdr, 8);
5521 if (unlikely(!p))
5522 goto out_overflow;
5523
5524 res->dir = be32_to_cpup(p++);
5525 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5526 return -EIO;
5527 if (be32_to_cpup(p) == 0)
5528 res->use_conn_in_rdma_mode = false;
5529 else
5530 res->use_conn_in_rdma_mode = true;
5531
5532 return 0;
5533out_overflow:
5534 print_overflow_msg(__func__, xdr);
5535 return -EIO;
5536}
5537
Andy Adamsonfc931582009-04-01 09:22:31 -04005538static int decode_create_session(struct xdr_stream *xdr,
5539 struct nfs41_create_session_res *res)
5540{
5541 __be32 *p;
5542 int status;
5543 struct nfs_client *clp = res->client;
5544 struct nfs4_session *session = clp->cl_session;
5545
5546 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005547 if (!status)
5548 status = decode_sessionid(xdr, &session->sess_id);
5549 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005550 return status;
5551
Andy Adamsonfc931582009-04-01 09:22:31 -04005552 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005553 p = xdr_inline_decode(xdr, 8);
5554 if (unlikely(!p))
5555 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005556 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005557 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005558
5559 /* Channel attributes */
5560 status = decode_chan_attrs(xdr, &session->fc_attrs);
5561 if (!status)
5562 status = decode_chan_attrs(xdr, &session->bc_attrs);
5563 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005564out_overflow:
5565 print_overflow_msg(__func__, xdr);
5566 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005567}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005568
5569static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5570{
5571 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5572}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005573
Trond Myklebust66245532012-05-25 17:18:09 -04005574static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5575{
5576 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5577}
5578
Ricardo Labiaga180197532009-12-05 16:08:40 -05005579static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5580{
5581 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5582}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005583#endif /* CONFIG_NFS_V4_1 */
5584
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005585static int decode_sequence(struct xdr_stream *xdr,
5586 struct nfs4_sequence_res *res,
5587 struct rpc_rqst *rqstp)
5588{
5589#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005590 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005591 struct nfs4_sessionid id;
5592 u32 dummy;
5593 int status;
5594 __be32 *p;
5595
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005596 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005597 return 0;
5598
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005599 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005600 if (!status)
5601 status = decode_sessionid(xdr, &id);
5602 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005603 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005604
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005605 /*
5606 * If the server returns different values for sessionID, slotID or
5607 * sequence number, the server is looney tunes.
5608 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005609 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005610 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005611
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005612 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005613 NFS4_MAX_SESSIONID_LEN)) {
5614 dprintk("%s Invalid session id\n", __func__);
5615 goto out_err;
5616 }
Benny Halevye78291e2009-08-14 17:20:00 +03005617
Benny Halevyc0eae662009-08-14 17:20:14 +03005618 p = xdr_inline_decode(xdr, 20);
5619 if (unlikely(!p))
5620 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005621
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005622 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005623 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005624 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005625 dprintk("%s Invalid sequence number\n", __func__);
5626 goto out_err;
5627 }
5628 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005629 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005630 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005631 dprintk("%s Invalid slot id\n", __func__);
5632 goto out_err;
5633 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005634 /* highest slot id */
5635 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005636 /* target highest slot id */
5637 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005638 /* result flags */
5639 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005640 status = 0;
5641out_err:
5642 res->sr_status = status;
5643 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005644out_overflow:
5645 print_overflow_msg(__func__, xdr);
5646 status = -EIO;
5647 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005648#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005649 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005650#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005651}
5652
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005653#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005654/*
5655 * TODO: Need to handle case when EOF != true;
5656 */
5657static int decode_getdevicelist(struct xdr_stream *xdr,
5658 struct pnfs_devicelist *res)
5659{
5660 __be32 *p;
5661 int status, i;
Trond Myklebust98d94522012-06-08 12:01:14 -04005662 nfs4_verifier verftemp;
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005663
5664 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5665 if (status)
5666 return status;
5667
5668 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5669 if (unlikely(!p))
5670 goto out_overflow;
5671
5672 /* TODO: Skip cookie for now */
5673 p += 2;
5674
5675 /* Read verifier */
Trond Myklebust98d94522012-06-08 12:01:14 -04005676 p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005677
5678 res->num_devs = be32_to_cpup(p);
5679
5680 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5681
5682 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005683 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005684 __func__, res->num_devs);
5685 return -EIO;
5686 }
5687
5688 p = xdr_inline_decode(xdr,
5689 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5690 if (unlikely(!p))
5691 goto out_overflow;
5692 for (i = 0; i < res->num_devs; i++)
5693 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5694 NFS4_DEVICEID4_SIZE);
5695 res->eof = be32_to_cpup(p);
5696 return 0;
5697out_overflow:
5698 print_overflow_msg(__func__, xdr);
5699 return -EIO;
5700}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005701
5702static int decode_getdeviceinfo(struct xdr_stream *xdr,
5703 struct pnfs_device *pdev)
5704{
5705 __be32 *p;
5706 uint32_t len, type;
5707 int status;
5708
5709 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5710 if (status) {
5711 if (status == -ETOOSMALL) {
5712 p = xdr_inline_decode(xdr, 4);
5713 if (unlikely(!p))
5714 goto out_overflow;
5715 pdev->mincount = be32_to_cpup(p);
5716 dprintk("%s: Min count too small. mincnt = %u\n",
5717 __func__, pdev->mincount);
5718 }
5719 return status;
5720 }
5721
5722 p = xdr_inline_decode(xdr, 8);
5723 if (unlikely(!p))
5724 goto out_overflow;
5725 type = be32_to_cpup(p++);
5726 if (type != pdev->layout_type) {
5727 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5728 __func__, pdev->layout_type, type);
5729 return -EINVAL;
5730 }
5731 /*
5732 * Get the length of the opaque device_addr4. xdr_read_pages places
5733 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5734 * and places the remaining xdr data in xdr_buf->tail
5735 */
5736 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005737 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5738 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005739
5740 /* Parse notification bitmap, verifying that it is zero. */
5741 p = xdr_inline_decode(xdr, 4);
5742 if (unlikely(!p))
5743 goto out_overflow;
5744 len = be32_to_cpup(p);
5745 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005746 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005747
5748 p = xdr_inline_decode(xdr, 4 * len);
5749 if (unlikely(!p))
5750 goto out_overflow;
5751 for (i = 0; i < len; i++, p++) {
5752 if (be32_to_cpup(p)) {
5753 dprintk("%s: notifications not supported\n",
5754 __func__);
5755 return -EIO;
5756 }
5757 }
5758 }
5759 return 0;
5760out_overflow:
5761 print_overflow_msg(__func__, xdr);
5762 return -EIO;
5763}
5764
5765static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5766 struct nfs4_layoutget_res *res)
5767{
5768 __be32 *p;
5769 int status;
5770 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005771 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005772
5773 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5774 if (status)
5775 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005776 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005777 if (unlikely(!p))
5778 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005779 res->return_on_close = be32_to_cpup(p);
5780 decode_stateid(xdr, &res->stateid);
5781 p = xdr_inline_decode(xdr, 4);
5782 if (unlikely(!p))
5783 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005784 layout_count = be32_to_cpup(p);
5785 if (!layout_count) {
5786 dprintk("%s: server responded with empty layout array\n",
5787 __func__);
5788 return -EINVAL;
5789 }
5790
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005791 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005792 if (unlikely(!p))
5793 goto out_overflow;
5794 p = xdr_decode_hyper(p, &res->range.offset);
5795 p = xdr_decode_hyper(p, &res->range.length);
5796 res->range.iomode = be32_to_cpup(p++);
5797 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005798 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005799
5800 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5801 __func__,
5802 (unsigned long)res->range.offset,
5803 (unsigned long)res->range.length,
5804 res->range.iomode,
5805 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005806 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005807
Trond Myklebust64bd5772012-06-20 22:35:05 -04005808 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005809 if (res->layoutp->len > recvd) {
5810 dprintk("NFS: server cheating in layoutget reply: "
5811 "layout len %u > recvd %u\n",
5812 res->layoutp->len, recvd);
5813 return -EINVAL;
5814 }
5815
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005816 if (layout_count > 1) {
5817 /* We only handle a length one array at the moment. Any
5818 * further entries are just ignored. Note that this means
5819 * the client may see a response that is less than the
5820 * minimum it requested.
5821 */
5822 dprintk("%s: server responded with %d layouts, dropping tail\n",
5823 __func__, layout_count);
5824 }
5825
5826 return 0;
5827out_overflow:
5828 print_overflow_msg(__func__, xdr);
5829 return -EIO;
5830}
Andy Adamson863a3c62011-03-23 13:27:54 +00005831
Benny Halevycbe82602011-05-22 19:52:37 +03005832static int decode_layoutreturn(struct xdr_stream *xdr,
5833 struct nfs4_layoutreturn_res *res)
5834{
5835 __be32 *p;
5836 int status;
5837
5838 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5839 if (status)
5840 return status;
5841 p = xdr_inline_decode(xdr, 4);
5842 if (unlikely(!p))
5843 goto out_overflow;
5844 res->lrs_present = be32_to_cpup(p);
5845 if (res->lrs_present)
5846 status = decode_stateid(xdr, &res->stateid);
5847 return status;
5848out_overflow:
5849 print_overflow_msg(__func__, xdr);
5850 return -EIO;
5851}
5852
Andy Adamson863a3c62011-03-23 13:27:54 +00005853static int decode_layoutcommit(struct xdr_stream *xdr,
5854 struct rpc_rqst *req,
5855 struct nfs4_layoutcommit_res *res)
5856{
5857 __be32 *p;
5858 __u32 sizechanged;
5859 int status;
5860
5861 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005862 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005863 if (status)
5864 return status;
5865
5866 p = xdr_inline_decode(xdr, 4);
5867 if (unlikely(!p))
5868 goto out_overflow;
5869 sizechanged = be32_to_cpup(p);
5870
5871 if (sizechanged) {
5872 /* throw away new size */
5873 p = xdr_inline_decode(xdr, 8);
5874 if (unlikely(!p))
5875 goto out_overflow;
5876 }
5877 return 0;
5878out_overflow:
5879 print_overflow_msg(__func__, xdr);
5880 return -EIO;
5881}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005882
5883static int decode_test_stateid(struct xdr_stream *xdr,
5884 struct nfs41_test_stateid_res *res)
5885{
5886 __be32 *p;
5887 int status;
5888 int num_res;
5889
5890 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5891 if (status)
5892 return status;
5893
5894 p = xdr_inline_decode(xdr, 4);
5895 if (unlikely(!p))
5896 goto out_overflow;
5897 num_res = be32_to_cpup(p++);
5898 if (num_res != 1)
5899 goto out;
5900
5901 p = xdr_inline_decode(xdr, 4);
5902 if (unlikely(!p))
5903 goto out_overflow;
5904 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005905
5906 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005907out_overflow:
5908 print_overflow_msg(__func__, xdr);
5909out:
5910 return -EIO;
5911}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005912
5913static int decode_free_stateid(struct xdr_stream *xdr,
5914 struct nfs41_free_stateid_res *res)
5915{
5916 __be32 *p;
5917 int status;
5918
5919 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5920 if (status)
5921 return status;
5922
5923 p = xdr_inline_decode(xdr, 4);
5924 if (unlikely(!p))
5925 goto out_overflow;
5926 res->status = be32_to_cpup(p++);
5927 return res->status;
5928out_overflow:
5929 print_overflow_msg(__func__, xdr);
5930 return -EIO;
5931}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005932#endif /* CONFIG_NFS_V4_1 */
5933
Linus Torvalds1da177e2005-04-16 15:20:36 -07005934/*
Benny Halevy49c25592008-12-23 16:06:16 -05005935 * END OF "GENERIC" DECODE ROUTINES.
5936 */
5937
5938/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005939 * Decode OPEN_DOWNGRADE response
5940 */
Chuck Leverbf269552010-12-14 14:59:29 +00005941static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5942 struct xdr_stream *xdr,
5943 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005944{
Andy Adamson05d564f2008-12-23 16:06:15 -05005945 struct compound_hdr hdr;
5946 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005947
Chuck Leverbf269552010-12-14 14:59:29 +00005948 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005949 if (status)
5950 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005951 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005952 if (status)
5953 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005954 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005955 if (status)
5956 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005957 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005958 if (status != 0)
5959 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005960 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005961out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005962 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963}
5964
5965/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005966 * Decode ACCESS response
5967 */
Chuck Leverbf269552010-12-14 14:59:29 +00005968static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5969 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005971 struct compound_hdr hdr;
5972 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005973
Chuck Leverbf269552010-12-14 14:59:29 +00005974 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005975 if (status)
5976 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005977 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005978 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005980 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005981 if (status != 0)
5982 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04005983 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04005984 if (status != 0)
5985 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005986 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005987out:
5988 return status;
5989}
5990
5991/*
5992 * Decode LOOKUP response
5993 */
Chuck Leverbf269552010-12-14 14:59:29 +00005994static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5995 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005996{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997 struct compound_hdr hdr;
5998 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005999
Chuck Leverbf269552010-12-14 14:59:29 +00006000 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006001 if (status)
6002 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006003 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006004 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006005 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006006 status = decode_putfh(xdr);
6007 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006009 status = decode_lookup(xdr);
6010 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006011 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006012 status = decode_getfh(xdr, res->fh);
6013 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006015 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006016out:
6017 return status;
6018}
6019
6020/*
6021 * Decode LOOKUP_ROOT response
6022 */
Chuck Leverbf269552010-12-14 14:59:29 +00006023static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6024 struct xdr_stream *xdr,
6025 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006026{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006027 struct compound_hdr hdr;
6028 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006029
Chuck Leverbf269552010-12-14 14:59:29 +00006030 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006031 if (status)
6032 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006033 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006034 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006035 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006036 status = decode_putrootfh(xdr);
6037 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006038 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006039 status = decode_getfh(xdr, res->fh);
6040 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006041 status = decode_getfattr_label(xdr, res->fattr,
6042 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006043out:
6044 return status;
6045}
6046
6047/*
6048 * Decode REMOVE response
6049 */
Chuck Leverbf269552010-12-14 14:59:29 +00006050static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6051 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006052{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006053 struct compound_hdr hdr;
6054 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006055
Chuck Leverbf269552010-12-14 14:59:29 +00006056 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006057 if (status)
6058 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006059 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006060 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006062 status = decode_putfh(xdr);
6063 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006064 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006065 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006066out:
6067 return status;
6068}
6069
6070/*
6071 * Decode RENAME response
6072 */
Chuck Leverbf269552010-12-14 14:59:29 +00006073static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6074 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006075{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006076 struct compound_hdr hdr;
6077 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006078
Chuck Leverbf269552010-12-14 14:59:29 +00006079 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006080 if (status)
6081 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006082 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006083 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006084 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006085 status = decode_putfh(xdr);
6086 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006087 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006088 status = decode_savefh(xdr);
6089 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006090 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006091 status = decode_putfh(xdr);
6092 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006093 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006094 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006095out:
6096 return status;
6097}
6098
6099/*
6100 * Decode LINK response
6101 */
Chuck Leverbf269552010-12-14 14:59:29 +00006102static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6103 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006105 struct compound_hdr hdr;
6106 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006107
Chuck Leverbf269552010-12-14 14:59:29 +00006108 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006109 if (status)
6110 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006111 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006112 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006114 status = decode_putfh(xdr);
6115 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006116 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006117 status = decode_savefh(xdr);
6118 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006119 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006120 status = decode_putfh(xdr);
6121 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006122 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006123 status = decode_link(xdr, &res->cinfo);
6124 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006125 goto out;
6126 /*
6127 * Note order: OP_LINK leaves the directory as the current
6128 * filehandle.
6129 */
Chuck Leverbf269552010-12-14 14:59:29 +00006130 status = decode_restorefh(xdr);
6131 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006132 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006133 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006134out:
6135 return status;
6136}
6137
6138/*
6139 * Decode CREATE response
6140 */
Chuck Leverbf269552010-12-14 14:59:29 +00006141static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6142 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006144 struct compound_hdr hdr;
6145 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006146
Chuck Leverbf269552010-12-14 14:59:29 +00006147 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006148 if (status)
6149 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006150 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006151 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_putfh(xdr);
6154 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_create(xdr, &res->dir_cinfo);
6157 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006158 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_getfh(xdr, res->fh);
6160 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006161 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006162 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006163out:
6164 return status;
6165}
6166
6167/*
6168 * Decode SYMLINK response
6169 */
Chuck Leverbf269552010-12-14 14:59:29 +00006170static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6171 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172{
Chuck Leverbf269552010-12-14 14:59:29 +00006173 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006174}
6175
6176/*
6177 * Decode GETATTR response
6178 */
Chuck Leverbf269552010-12-14 14:59:29 +00006179static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6180 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182 struct compound_hdr hdr;
6183 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006184
Chuck Leverbf269552010-12-14 14:59:29 +00006185 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006186 if (status)
6187 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006188 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006189 if (status)
6190 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006191 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192 if (status)
6193 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006194 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195out:
6196 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197}
6198
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006199/*
6200 * Encode an SETACL request
6201 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006202static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6203 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006204{
Andy Adamson05d564f2008-12-23 16:06:15 -05006205 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006206 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006207 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006208
Chuck Lever9f06c712010-12-14 14:59:18 +00006209 encode_compound_hdr(xdr, req, &hdr);
6210 encode_sequence(xdr, &args->seq_args, &hdr);
6211 encode_putfh(xdr, args->fh, &hdr);
6212 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006213 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006214}
Andy Adamson05d564f2008-12-23 16:06:15 -05006215
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006216/*
6217 * Decode SETACL response
6218 */
6219static int
Chuck Leverbf269552010-12-14 14:59:29 +00006220nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006221 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006222{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006223 struct compound_hdr hdr;
6224 int status;
6225
Chuck Leverbf269552010-12-14 14:59:29 +00006226 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006227 if (status)
6228 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006229 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006230 if (status)
6231 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006232 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006233 if (status)
6234 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006235 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006236out:
6237 return status;
6238}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239
6240/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006241 * Decode GETACL response
6242 */
6243static int
Chuck Leverbf269552010-12-14 14:59:29 +00006244nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006245 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006246{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006247 struct compound_hdr hdr;
6248 int status;
6249
Trond Myklebust331818f2012-02-03 18:30:53 -05006250 if (res->acl_scratch != NULL) {
6251 void *p = page_address(res->acl_scratch);
6252 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6253 }
Chuck Leverbf269552010-12-14 14:59:29 +00006254 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006255 if (status)
6256 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006257 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006258 if (status)
6259 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006260 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006261 if (status)
6262 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006263 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006264
6265out:
6266 return status;
6267}
6268
6269/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270 * Decode CLOSE response
6271 */
Chuck Leverbf269552010-12-14 14:59:29 +00006272static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6273 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006274{
Andy Adamson05d564f2008-12-23 16:06:15 -05006275 struct compound_hdr hdr;
6276 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277
Chuck Leverbf269552010-12-14 14:59:29 +00006278 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006279 if (status)
6280 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006281 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006282 if (status)
6283 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006284 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006285 if (status)
6286 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006287 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006288 if (status != 0)
6289 goto out;
6290 /*
6291 * Note: Server may do delete on close for this file
6292 * in which case the getattr call will fail with
6293 * an ESTALE error. Shouldn't be a problem,
6294 * though, since fattr->valid will remain unset.
6295 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006296 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006297out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006298 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299}
6300
6301/*
6302 * Decode OPEN response
6303 */
Chuck Leverbf269552010-12-14 14:59:29 +00006304static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6305 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306{
Andy Adamson05d564f2008-12-23 16:06:15 -05006307 struct compound_hdr hdr;
6308 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006309
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006311 if (status)
6312 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006313 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006314 if (status)
6315 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006316 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006317 if (status)
6318 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006319 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006320 if (status)
6321 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006322 status = decode_getfh(xdr, &res->fh);
6323 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006325 if (res->access_request)
6326 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006327 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006328out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006329 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006330}
6331
6332/*
6333 * Decode OPEN_CONFIRM response
6334 */
Chuck Leverbf269552010-12-14 14:59:29 +00006335static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6336 struct xdr_stream *xdr,
6337 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006338{
Andy Adamson05d564f2008-12-23 16:06:15 -05006339 struct compound_hdr hdr;
6340 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006341
Chuck Leverbf269552010-12-14 14:59:29 +00006342 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006343 if (status)
6344 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006345 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006346 if (status)
6347 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006348 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006349out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006350 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351}
6352
6353/*
6354 * Decode OPEN response
6355 */
Chuck Leverbf269552010-12-14 14:59:29 +00006356static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6357 struct xdr_stream *xdr,
6358 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359{
Andy Adamson05d564f2008-12-23 16:06:15 -05006360 struct compound_hdr hdr;
6361 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362
Chuck Leverbf269552010-12-14 14:59:29 +00006363 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006364 if (status)
6365 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006366 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006367 if (status)
6368 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006369 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006370 if (status)
6371 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006372 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006373 if (status)
6374 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006375 if (res->access_request)
6376 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006377 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006379 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006380}
6381
6382/*
6383 * Decode SETATTR response
6384 */
Chuck Leverbf269552010-12-14 14:59:29 +00006385static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6386 struct xdr_stream *xdr,
6387 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006388{
Andy Adamson05d564f2008-12-23 16:06:15 -05006389 struct compound_hdr hdr;
6390 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391
Chuck Leverbf269552010-12-14 14:59:29 +00006392 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006393 if (status)
6394 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006395 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006396 if (status)
6397 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006398 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006399 if (status)
6400 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006401 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006402 if (status)
6403 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006404 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006405out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006406 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407}
6408
6409/*
6410 * Decode LOCK response
6411 */
Chuck Leverbf269552010-12-14 14:59:29 +00006412static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6413 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006414{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006415 struct compound_hdr hdr;
6416 int status;
6417
Chuck Leverbf269552010-12-14 14:59:29 +00006418 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006419 if (status)
6420 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006421 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006422 if (status)
6423 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006424 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006425 if (status)
6426 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006427 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006428out:
6429 return status;
6430}
6431
6432/*
6433 * Decode LOCKT response
6434 */
Chuck Leverbf269552010-12-14 14:59:29 +00006435static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6436 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006438 struct compound_hdr hdr;
6439 int status;
6440
Chuck Leverbf269552010-12-14 14:59:29 +00006441 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006442 if (status)
6443 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006444 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006445 if (status)
6446 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006447 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448 if (status)
6449 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006450 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006451out:
6452 return status;
6453}
6454
6455/*
6456 * Decode LOCKU response
6457 */
Chuck Leverbf269552010-12-14 14:59:29 +00006458static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6459 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461 struct compound_hdr hdr;
6462 int status;
6463
Chuck Leverbf269552010-12-14 14:59:29 +00006464 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465 if (status)
6466 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006467 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006468 if (status)
6469 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006470 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471 if (status)
6472 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006473 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006474out:
6475 return status;
6476}
6477
Chuck Leverbf269552010-12-14 14:59:29 +00006478static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6479 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006480{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006481 struct compound_hdr hdr;
6482 int status;
6483
Chuck Leverbf269552010-12-14 14:59:29 +00006484 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006485 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006486 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006487 return status;
6488}
6489
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490/*
6491 * Decode READLINK response
6492 */
Chuck Leverbf269552010-12-14 14:59:29 +00006493static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6494 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006495 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006496{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497 struct compound_hdr hdr;
6498 int status;
6499
Chuck Leverbf269552010-12-14 14:59:29 +00006500 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006501 if (status)
6502 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006503 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006504 if (status)
6505 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006506 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507 if (status)
6508 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006509 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006510out:
6511 return status;
6512}
6513
6514/*
6515 * Decode READDIR response
6516 */
Chuck Leverbf269552010-12-14 14:59:29 +00006517static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6518 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006519{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520 struct compound_hdr hdr;
6521 int status;
6522
Chuck Leverbf269552010-12-14 14:59:29 +00006523 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524 if (status)
6525 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006527 if (status)
6528 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006529 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530 if (status)
6531 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006532 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006533out:
6534 return status;
6535}
6536
6537/*
6538 * Decode Read response
6539 */
Chuck Leverbf269552010-12-14 14:59:29 +00006540static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6541 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006542{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543 struct compound_hdr hdr;
6544 int status;
6545
Chuck Leverbf269552010-12-14 14:59:29 +00006546 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547 if (status)
6548 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006549 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006550 if (status)
6551 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006552 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006553 if (status)
6554 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006555 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556 if (!status)
6557 status = res->count;
6558out:
6559 return status;
6560}
6561
6562/*
6563 * Decode WRITE response
6564 */
Chuck Leverbf269552010-12-14 14:59:29 +00006565static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6566 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006567{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006568 struct compound_hdr hdr;
6569 int status;
6570
Chuck Leverbf269552010-12-14 14:59:29 +00006571 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006572 if (status)
6573 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006574 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006575 if (status)
6576 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006577 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006578 if (status)
6579 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006580 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006581 if (status)
6582 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006583 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006584 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006585 if (!status)
6586 status = res->count;
6587out:
6588 return status;
6589}
6590
6591/*
6592 * Decode COMMIT response
6593 */
Chuck Leverbf269552010-12-14 14:59:29 +00006594static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006595 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006596{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597 struct compound_hdr hdr;
6598 int status;
6599
Chuck Leverbf269552010-12-14 14:59:29 +00006600 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006601 if (status)
6602 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006603 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006604 if (status)
6605 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006606 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006607 if (status)
6608 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006609 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006610out:
6611 return status;
6612}
6613
6614/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006615 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006616 */
Chuck Leverbf269552010-12-14 14:59:29 +00006617static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006618 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006619{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006620 struct compound_hdr hdr;
6621 int status;
6622
Chuck Leverbf269552010-12-14 14:59:29 +00006623 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006624 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006625 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006626 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006627 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006628 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006629 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006630 return status;
6631}
6632
6633/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006634 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006635 */
Chuck Leverbf269552010-12-14 14:59:29 +00006636static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006637 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006639 struct compound_hdr hdr;
6640 int status;
6641
Chuck Leverbf269552010-12-14 14:59:29 +00006642 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006644 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006645 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006646 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006648 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649 return status;
6650}
6651
6652/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006653 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006654 */
Chuck Leverbf269552010-12-14 14:59:29 +00006655static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006656 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006657{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006658 struct compound_hdr hdr;
6659 int status;
6660
Chuck Leverbf269552010-12-14 14:59:29 +00006661 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006662 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006663 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006664 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006665 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006668 return status;
6669}
6670
6671/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006672 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006673 */
Chuck Leverbf269552010-12-14 14:59:29 +00006674static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6675 struct xdr_stream *xdr,
6676 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006677{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006678 struct compound_hdr hdr;
6679 int status;
6680
Chuck Leverbf269552010-12-14 14:59:29 +00006681 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006682 if (status)
6683 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006684 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006685 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006686 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006687 status = decode_putfh(xdr);
6688 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006689 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006690 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006691out:
6692 return status;
6693}
6694
6695/*
6696 * Decode RENEW response
6697 */
Chuck Leverbf269552010-12-14 14:59:29 +00006698static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6699 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006700{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006701 struct compound_hdr hdr;
6702 int status;
6703
Chuck Leverbf269552010-12-14 14:59:29 +00006704 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006705 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006706 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006707 return status;
6708}
6709
6710/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006711 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712 */
Chuck Leverbf269552010-12-14 14:59:29 +00006713static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6714 struct xdr_stream *xdr,
6715 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006716{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006717 struct compound_hdr hdr;
6718 int status;
6719
Chuck Leverbf269552010-12-14 14:59:29 +00006720 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006721 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006722 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006723 return status;
6724}
6725
6726/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006727 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006728 */
Chuck Leverbf269552010-12-14 14:59:29 +00006729static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006730 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006731{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006732 struct compound_hdr hdr;
6733 int status;
6734
Chuck Leverbf269552010-12-14 14:59:29 +00006735 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006737 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006738 return status;
6739}
6740
6741/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006742 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006743 */
Chuck Leverbf269552010-12-14 14:59:29 +00006744static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6745 struct xdr_stream *xdr,
6746 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006747{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006748 struct compound_hdr hdr;
6749 int status;
6750
Chuck Leverbf269552010-12-14 14:59:29 +00006751 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006752 if (status)
6753 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006754 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006755 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006756 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006757 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006758 if (status != 0)
6759 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006760 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006761 if (status != 0)
6762 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006763 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006764out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006765 return status;
6766}
6767
Trond Myklebust683b57b2006-06-09 09:34:22 -04006768/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006769 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006770 */
Chuck Leverbf269552010-12-14 14:59:29 +00006771static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6772 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006773 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006774{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006775 struct compound_hdr hdr;
6776 int status;
6777
Chuck Leverbf269552010-12-14 14:59:29 +00006778 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006779 if (status)
6780 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006781 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006782 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006783 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006784 status = decode_putfh(xdr);
6785 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006786 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006787 status = decode_lookup(xdr);
6788 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006789 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006790 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006791 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6792 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006793 NULL, res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006794out:
6795 return status;
6796}
6797
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006798/*
6799 * Decode SECINFO response
6800 */
6801static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6802 struct xdr_stream *xdr,
6803 struct nfs4_secinfo_res *res)
6804{
6805 struct compound_hdr hdr;
6806 int status;
6807
6808 status = decode_compound_hdr(xdr, &hdr);
6809 if (status)
6810 goto out;
6811 status = decode_sequence(xdr, &res->seq_res, rqstp);
6812 if (status)
6813 goto out;
6814 status = decode_putfh(xdr);
6815 if (status)
6816 goto out;
6817 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006818out:
6819 return status;
6820}
6821
Benny Halevy99fe60d2009-04-01 09:22:29 -04006822#if defined(CONFIG_NFS_V4_1)
6823/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006824 * Decode BIND_CONN_TO_SESSION response
6825 */
6826static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6827 struct xdr_stream *xdr,
6828 void *res)
6829{
6830 struct compound_hdr hdr;
6831 int status;
6832
6833 status = decode_compound_hdr(xdr, &hdr);
6834 if (!status)
6835 status = decode_bind_conn_to_session(xdr, res);
6836 return status;
6837}
6838
6839/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006840 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006841 */
Chuck Leverbf269552010-12-14 14:59:29 +00006842static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6843 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006844 void *res)
6845{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006846 struct compound_hdr hdr;
6847 int status;
6848
Chuck Leverbf269552010-12-14 14:59:29 +00006849 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006850 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006851 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006852 return status;
6853}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006854
6855/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006856 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006857 */
Chuck Leverbf269552010-12-14 14:59:29 +00006858static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6859 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006860 struct nfs41_create_session_res *res)
6861{
Andy Adamsonfc931582009-04-01 09:22:31 -04006862 struct compound_hdr hdr;
6863 int status;
6864
Chuck Leverbf269552010-12-14 14:59:29 +00006865 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006866 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006867 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006868 return status;
6869}
6870
6871/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006872 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006873 */
Chuck Leverbf269552010-12-14 14:59:29 +00006874static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6875 struct xdr_stream *xdr,
6876 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006877{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006878 struct compound_hdr hdr;
6879 int status;
6880
Chuck Leverbf269552010-12-14 14:59:29 +00006881 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006882 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006883 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006884 return status;
6885}
6886
6887/*
Trond Myklebust66245532012-05-25 17:18:09 -04006888 * Decode DESTROY_CLIENTID response
6889 */
6890static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6891 struct xdr_stream *xdr,
6892 void *res)
6893{
6894 struct compound_hdr hdr;
6895 int status;
6896
6897 status = decode_compound_hdr(xdr, &hdr);
6898 if (!status)
6899 status = decode_destroy_clientid(xdr, res);
6900 return status;
6901}
6902
6903/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006904 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006905 */
Chuck Leverbf269552010-12-14 14:59:29 +00006906static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6907 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006908 struct nfs4_sequence_res *res)
6909{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006910 struct compound_hdr hdr;
6911 int status;
6912
Chuck Leverbf269552010-12-14 14:59:29 +00006913 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006914 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006915 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006916 return status;
6917}
6918
6919/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006920 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006921 */
Chuck Leverbf269552010-12-14 14:59:29 +00006922static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6923 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006924 struct nfs4_get_lease_time_res *res)
6925{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006926 struct compound_hdr hdr;
6927 int status;
6928
Chuck Leverbf269552010-12-14 14:59:29 +00006929 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006930 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006931 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006932 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006933 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006934 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006935 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006936 return status;
6937}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006938
6939/*
6940 * Decode RECLAIM_COMPLETE response
6941 */
Chuck Leverbf269552010-12-14 14:59:29 +00006942static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6943 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006944 struct nfs41_reclaim_complete_res *res)
6945{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006946 struct compound_hdr hdr;
6947 int status;
6948
Chuck Leverbf269552010-12-14 14:59:29 +00006949 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006950 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006951 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006952 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006953 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006954 return status;
6955}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006956
6957/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006958 * Decode GETDEVICELIST response
6959 */
6960static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6961 struct xdr_stream *xdr,
6962 struct nfs4_getdevicelist_res *res)
6963{
6964 struct compound_hdr hdr;
6965 int status;
6966
6967 dprintk("encoding getdevicelist!\n");
6968
6969 status = decode_compound_hdr(xdr, &hdr);
6970 if (status != 0)
6971 goto out;
6972 status = decode_sequence(xdr, &res->seq_res, rqstp);
6973 if (status != 0)
6974 goto out;
6975 status = decode_putfh(xdr);
6976 if (status != 0)
6977 goto out;
6978 status = decode_getdevicelist(xdr, res->devlist);
6979out:
6980 return status;
6981}
6982
6983/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006984 * Decode GETDEVINFO response
6985 */
Chuck Leverbf269552010-12-14 14:59:29 +00006986static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6987 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006988 struct nfs4_getdeviceinfo_res *res)
6989{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006990 struct compound_hdr hdr;
6991 int status;
6992
Chuck Leverbf269552010-12-14 14:59:29 +00006993 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006994 if (status != 0)
6995 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006996 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006997 if (status != 0)
6998 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006999 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007000out:
7001 return status;
7002}
7003
7004/*
7005 * Decode LAYOUTGET response
7006 */
Chuck Leverbf269552010-12-14 14:59:29 +00007007static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7008 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007009 struct nfs4_layoutget_res *res)
7010{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007011 struct compound_hdr hdr;
7012 int status;
7013
Chuck Leverbf269552010-12-14 14:59:29 +00007014 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007015 if (status)
7016 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007017 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007018 if (status)
7019 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007020 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007021 if (status)
7022 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007023 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007024out:
7025 return status;
7026}
Andy Adamson863a3c62011-03-23 13:27:54 +00007027
7028/*
Benny Halevycbe82602011-05-22 19:52:37 +03007029 * Decode LAYOUTRETURN response
7030 */
7031static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7032 struct xdr_stream *xdr,
7033 struct nfs4_layoutreturn_res *res)
7034{
7035 struct compound_hdr hdr;
7036 int status;
7037
7038 status = decode_compound_hdr(xdr, &hdr);
7039 if (status)
7040 goto out;
7041 status = decode_sequence(xdr, &res->seq_res, rqstp);
7042 if (status)
7043 goto out;
7044 status = decode_putfh(xdr);
7045 if (status)
7046 goto out;
7047 status = decode_layoutreturn(xdr, res);
7048out:
7049 return status;
7050}
7051
7052/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007053 * Decode LAYOUTCOMMIT response
7054 */
7055static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7056 struct xdr_stream *xdr,
7057 struct nfs4_layoutcommit_res *res)
7058{
7059 struct compound_hdr hdr;
7060 int status;
7061
7062 status = decode_compound_hdr(xdr, &hdr);
7063 if (status)
7064 goto out;
7065 status = decode_sequence(xdr, &res->seq_res, rqstp);
7066 if (status)
7067 goto out;
7068 status = decode_putfh(xdr);
7069 if (status)
7070 goto out;
7071 status = decode_layoutcommit(xdr, rqstp, res);
7072 if (status)
7073 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007074 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007075out:
7076 return status;
7077}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007078
7079/*
7080 * Decode SECINFO_NO_NAME response
7081 */
7082static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7083 struct xdr_stream *xdr,
7084 struct nfs4_secinfo_res *res)
7085{
7086 struct compound_hdr hdr;
7087 int status;
7088
7089 status = decode_compound_hdr(xdr, &hdr);
7090 if (status)
7091 goto out;
7092 status = decode_sequence(xdr, &res->seq_res, rqstp);
7093 if (status)
7094 goto out;
7095 status = decode_putrootfh(xdr);
7096 if (status)
7097 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007098 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007099out:
7100 return status;
7101}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007102
7103/*
7104 * Decode TEST_STATEID response
7105 */
7106static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7107 struct xdr_stream *xdr,
7108 struct nfs41_test_stateid_res *res)
7109{
7110 struct compound_hdr hdr;
7111 int status;
7112
7113 status = decode_compound_hdr(xdr, &hdr);
7114 if (status)
7115 goto out;
7116 status = decode_sequence(xdr, &res->seq_res, rqstp);
7117 if (status)
7118 goto out;
7119 status = decode_test_stateid(xdr, res);
7120out:
7121 return status;
7122}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007123
7124/*
7125 * Decode FREE_STATEID response
7126 */
7127static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7128 struct xdr_stream *xdr,
7129 struct nfs41_free_stateid_res *res)
7130{
7131 struct compound_hdr hdr;
7132 int status;
7133
7134 status = decode_compound_hdr(xdr, &hdr);
7135 if (status)
7136 goto out;
7137 status = decode_sequence(xdr, &res->seq_res, rqstp);
7138 if (status)
7139 goto out;
7140 status = decode_free_stateid(xdr, res);
7141out:
7142 return status;
7143}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007144#endif /* CONFIG_NFS_V4_1 */
7145
Chuck Lever573c4e12010-12-14 14:58:11 +00007146/**
7147 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7148 * the local page cache.
7149 * @xdr: XDR stream where entry resides
7150 * @entry: buffer to fill in with entry data
7151 * @plus: boolean indicating whether this should be a readdirplus entry
7152 *
7153 * Returns zero if successful, otherwise a negative errno value is
7154 * returned.
7155 *
7156 * This function is not invoked during READDIR reply decoding, but
7157 * rather whenever an application invokes the getdents(2) system call
7158 * on a directory already in our cache.
7159 */
7160int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7161 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007162{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007163 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007164 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007165 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007166 __be32 *p = xdr_inline_decode(xdr, 4);
7167 if (unlikely(!p))
7168 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007169 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007170 p = xdr_inline_decode(xdr, 4);
7171 if (unlikely(!p))
7172 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007173 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007174 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007175 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007176 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007177 }
7178
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007179 p = xdr_inline_decode(xdr, 12);
7180 if (unlikely(!p))
7181 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007182 entry->prev_cookie = entry->cookie;
7183 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007184 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007185
Trond Myklebust9af8c222010-10-24 11:52:55 -04007186 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007187 if (unlikely(!p))
7188 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007189 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007190
7191 /*
7192 * In case the server doesn't return an inode number,
7193 * we fake one here. (We don't use inode number 0,
7194 * since glibc seems to choke on it...)
7195 */
7196 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007197 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007198
Trond Myklebust9af8c222010-10-24 11:52:55 -04007199 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007200 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007201
Trond Myklebust256e48b2012-06-21 11:18:13 -04007202 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007203 goto out_overflow;
7204
Chuck Lever573c4e12010-12-14 14:58:11 +00007205 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007206 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007207 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007208 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7209 entry->ino = entry->fattr->mounted_on_fileid;
7210 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007211 entry->ino = entry->fattr->fileid;
7212
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007213 entry->d_type = DT_UNKNOWN;
7214 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7215 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7216
Chuck Lever573c4e12010-12-14 14:58:11 +00007217 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007218
7219out_overflow:
7220 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007221 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007222}
7223
7224/*
7225 * We need to translate between nfs status return values and
7226 * the local errno values which may not be the same.
7227 */
7228static struct {
7229 int stat;
7230 int errno;
7231} nfs_errtbl[] = {
7232 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007233 { NFS4ERR_PERM, -EPERM },
7234 { NFS4ERR_NOENT, -ENOENT },
7235 { NFS4ERR_IO, -errno_NFSERR_IO},
7236 { NFS4ERR_NXIO, -ENXIO },
7237 { NFS4ERR_ACCESS, -EACCES },
7238 { NFS4ERR_EXIST, -EEXIST },
7239 { NFS4ERR_XDEV, -EXDEV },
7240 { NFS4ERR_NOTDIR, -ENOTDIR },
7241 { NFS4ERR_ISDIR, -EISDIR },
7242 { NFS4ERR_INVAL, -EINVAL },
7243 { NFS4ERR_FBIG, -EFBIG },
7244 { NFS4ERR_NOSPC, -ENOSPC },
7245 { NFS4ERR_ROFS, -EROFS },
7246 { NFS4ERR_MLINK, -EMLINK },
7247 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7248 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7249 { NFS4ERR_DQUOT, -EDQUOT },
7250 { NFS4ERR_STALE, -ESTALE },
7251 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007252 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7253 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7254 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007255 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007256 { NFS4ERR_BADTYPE, -EBADTYPE },
7257 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007258 { NFS4ERR_SYMLINK, -ELOOP },
7259 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7260 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007261 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007262};
7263
7264/*
7265 * Convert an NFS error code to a local one.
7266 * This one is used jointly by NFSv2 and NFSv3.
7267 */
7268static int
David Howells0a8ea432006-08-22 20:06:08 -04007269nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007270{
7271 int i;
7272 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7273 if (nfs_errtbl[i].stat == stat)
7274 return nfs_errtbl[i].errno;
7275 }
7276 if (stat <= 10000 || stat > 10100) {
7277 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007278 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007279 }
7280 /* If we cannot translate the error, the recovery routines should
7281 * handle it.
7282 * Note: remaining NFSv4 error codes have values > 10000, so should
7283 * not conflict with native Linux error codes.
7284 */
Benny Halevy856dff32008-03-31 17:39:06 +03007285 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007286}
7287
Linus Torvalds1da177e2005-04-16 15:20:36 -07007288#define PROC(proc, argtype, restype) \
7289[NFSPROC4_CLNT_##proc] = { \
7290 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007291 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007292 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007293 .p_arglen = NFS4_##argtype##_sz, \
7294 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007295 .p_statidx = NFSPROC4_CLNT_##proc, \
7296 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007297}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007298
7299struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007300 PROC(READ, enc_read, dec_read),
7301 PROC(WRITE, enc_write, dec_write),
7302 PROC(COMMIT, enc_commit, dec_commit),
7303 PROC(OPEN, enc_open, dec_open),
7304 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7305 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7306 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7307 PROC(CLOSE, enc_close, dec_close),
7308 PROC(SETATTR, enc_setattr, dec_setattr),
7309 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7310 PROC(RENEW, enc_renew, dec_renew),
7311 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7312 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7313 PROC(LOCK, enc_lock, dec_lock),
7314 PROC(LOCKT, enc_lockt, dec_lockt),
7315 PROC(LOCKU, enc_locku, dec_locku),
7316 PROC(ACCESS, enc_access, dec_access),
7317 PROC(GETATTR, enc_getattr, dec_getattr),
7318 PROC(LOOKUP, enc_lookup, dec_lookup),
7319 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7320 PROC(REMOVE, enc_remove, dec_remove),
7321 PROC(RENAME, enc_rename, dec_rename),
7322 PROC(LINK, enc_link, dec_link),
7323 PROC(SYMLINK, enc_symlink, dec_symlink),
7324 PROC(CREATE, enc_create, dec_create),
7325 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7326 PROC(STATFS, enc_statfs, dec_statfs),
7327 PROC(READLINK, enc_readlink, dec_readlink),
7328 PROC(READDIR, enc_readdir, dec_readdir),
7329 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7330 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7331 PROC(GETACL, enc_getacl, dec_getacl),
7332 PROC(SETACL, enc_setacl, dec_setacl),
7333 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7334 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007335 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007336#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007337 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7338 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7339 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7340 PROC(SEQUENCE, enc_sequence, dec_sequence),
7341 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7342 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7343 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7344 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007345 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007346 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007347 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007348 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007349 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007350 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007351 PROC(BIND_CONN_TO_SESSION,
7352 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007353 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007354#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007355};
7356
Trond Myklebusta613fa12012-01-20 13:53:56 -05007357const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007358 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007359 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007360 .procs = nfs4_procedures
7361};
7362
7363/*
7364 * Local variables:
7365 * c-basic-offset: 8
7366 * End:
7367 */