blob: 005d03c5d274615ea8af9e5eb529bcf3a1916222 [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))
David Quigleyaa9c2662013-05-22 12:50:44 -0400108#else
109#define nfs4_label_maxsz 0
David Quigleyaa9c2662013-05-22 12:50:44 -0400110#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400111/* We support only one layout type per file system */
112#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000113/* This is based on getfattr, which uses the most attributes: */
114#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400115 3 + 3 + 3 + nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400116 nfs4_group_maxsz + nfs4_label_maxsz + \
117 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000118#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
119 nfs4_fattr_value_maxsz)
120#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400121#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
122 1 + 2 + 1 + \
123 nfs4_owner_maxsz + \
124 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400125 nfs4_label_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400126 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define encode_savefh_maxsz (op_encode_hdr_maxsz)
128#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400129#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
130#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200131#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400132/* The 5 accounts for the PNFS attributes, and assumes that at most three
133 * layout types will be returned.
134 */
135#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
136 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
138#define decode_renew_maxsz (op_decode_hdr_maxsz)
139#define encode_setclientid_maxsz \
140 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500141 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
142 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
143 1 /* sc_prog */ + \
144 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
145 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
146 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#define decode_setclientid_maxsz \
148 (op_decode_hdr_maxsz + \
149 2 + \
150 1024) /* large value for CLID_INUSE */
151#define encode_setclientid_confirm_maxsz \
152 (op_encode_hdr_maxsz + \
153 3 + (NFS4_VERIFIER_SIZE >> 2))
154#define decode_setclientid_confirm_maxsz \
155 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400156#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
157#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400158#define encode_share_access_maxsz \
159 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500160#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400161#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
162#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
163#define encode_open_maxsz (op_encode_hdr_maxsz + \
164 2 + encode_share_access_maxsz + 2 + \
165 open_owner_id_maxsz + \
166 encode_opentype_maxsz + \
167 encode_claim_null_maxsz)
168#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400169#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400170 decode_ace_maxsz)
171#define decode_change_info_maxsz (5)
172#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400173 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400174 decode_change_info_maxsz + 1 + \
175 nfs4_fattr_bitmap_maxsz + \
176 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400177#define encode_open_confirm_maxsz \
178 (op_encode_hdr_maxsz + \
179 encode_stateid_maxsz + 1)
180#define decode_open_confirm_maxsz \
181 (op_decode_hdr_maxsz + \
182 decode_stateid_maxsz)
183#define encode_open_downgrade_maxsz \
184 (op_encode_hdr_maxsz + \
185 encode_stateid_maxsz + 1 + \
186 encode_share_access_maxsz)
187#define decode_open_downgrade_maxsz \
188 (op_decode_hdr_maxsz + \
189 decode_stateid_maxsz)
190#define encode_close_maxsz (op_encode_hdr_maxsz + \
191 1 + encode_stateid_maxsz)
192#define decode_close_maxsz (op_decode_hdr_maxsz + \
193 decode_stateid_maxsz)
194#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + \
196 encode_attrs_maxsz)
197#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
198 nfs4_fattr_bitmap_maxsz)
199#define encode_read_maxsz (op_encode_hdr_maxsz + \
200 encode_stateid_maxsz + 3)
201#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
202#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400203 2 + encode_verifier_maxsz + 5 + \
204 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400205#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Chuck Levera7697f62014-03-12 12:51:17 -0400206 decode_verifier_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400207#define encode_readlink_maxsz (op_encode_hdr_maxsz)
208#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
209#define encode_write_maxsz (op_encode_hdr_maxsz + \
210 encode_stateid_maxsz + 4)
211#define decode_write_maxsz (op_decode_hdr_maxsz + \
212 2 + decode_verifier_maxsz)
213#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
214#define decode_commit_maxsz (op_decode_hdr_maxsz + \
215 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#define encode_remove_maxsz (op_encode_hdr_maxsz + \
217 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400218#define decode_remove_maxsz (op_decode_hdr_maxsz + \
219 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#define encode_rename_maxsz (op_encode_hdr_maxsz + \
221 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400222#define decode_rename_maxsz (op_decode_hdr_maxsz + \
223 decode_change_info_maxsz + \
224 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#define encode_link_maxsz (op_encode_hdr_maxsz + \
226 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400227#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400228#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400229#define encode_lock_maxsz (op_encode_hdr_maxsz + \
230 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400231 1 + encode_stateid_maxsz + 1 + \
232 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400233#define decode_lock_denied_maxsz \
234 (8 + decode_lockowner_maxsz)
235#define decode_lock_maxsz (op_decode_hdr_maxsz + \
236 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400237#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
238 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400239#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
240 decode_lock_denied_maxsz)
241#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
242 encode_stateid_maxsz + \
243 4)
244#define decode_locku_maxsz (op_decode_hdr_maxsz + \
245 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400246#define encode_release_lockowner_maxsz \
247 (op_encode_hdr_maxsz + \
248 encode_lockowner_maxsz)
249#define decode_release_lockowner_maxsz \
250 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400251#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
252#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
254 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400255 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000256 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
258#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400259 1 + 2 + nfs4_name_maxsz + \
260 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400261#define decode_create_maxsz (op_decode_hdr_maxsz + \
262 decode_change_info_maxsz + \
263 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400264#define encode_statfs_maxsz (encode_getattr_maxsz)
265#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
267#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400268#define encode_getacl_maxsz (encode_getattr_maxsz)
269#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
270 nfs4_fattr_bitmap_maxsz + 1)
271#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
272 encode_stateid_maxsz + 3)
273#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400274#define encode_fs_locations_maxsz \
275 (encode_getattr_maxsz)
276#define decode_fs_locations_maxsz \
277 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000278#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400279#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 -0400280
281#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400282#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500283#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
284 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400285
Benny Halevy99fe60d2009-04-01 09:22:29 -0400286#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
287 encode_verifier_maxsz + \
288 1 /* co_ownerid.len */ + \
289 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
290 1 /* flags */ + \
291 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400292 /* max is SP4_MACH_CRED (for now) */ + \
293 1 + NFS4_OP_MAP_NUM_WORDS + \
294 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500295 1 /* implementation id array of size 1 */ + \
296 1 /* nii_domain */ + \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
298 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500299 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500300 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400301#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
302 2 /* eir_clientid */ + \
303 1 /* eir_sequenceid */ + \
304 1 /* eir_flags */ + \
305 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400306 /* max is SP4_MACH_CRED (for now) */ + \
307 1 + NFS4_OP_MAP_NUM_WORDS + \
308 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400309 2 /* eir_server_owner.so_minor_id */ + \
310 /* eir_server_owner.so_major_id<> */ \
311 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
312 /* eir_server_scope<> */ \
313 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
314 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500315 1 /* nii_domain */ + \
316 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
317 1 /* nii_name */ + \
318 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
319 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400320#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
321#define decode_channel_attrs_maxsz (6 + \
322 1 /* ca_rdma_ird.len */ + \
323 1 /* ca_rdma_ird */)
324#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
325 2 /* csa_clientid */ + \
326 1 /* csa_sequence */ + \
327 1 /* csa_flags */ + \
328 encode_channel_attrs_maxsz + \
329 encode_channel_attrs_maxsz + \
330 1 /* csa_cb_program */ + \
331 1 /* csa_sec_parms.len (1) */ + \
332 1 /* cb_secflavor (AUTH_SYS) */ + \
333 1 /* stamp */ + \
334 1 /* machinename.len */ + \
335 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
336 1 /* uid */ + \
337 1 /* gid */ + \
338 1 /* gids.len (0) */)
339#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
340 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
341 1 /* csr_sequence */ + \
342 1 /* csr_flags */ + \
343 decode_channel_attrs_maxsz + \
344 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400345#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
346 /* bctsa_sessid */ \
347 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
348 1 /* bctsa_dir */ + \
349 1 /* bctsa_use_conn_in_rdma_mode */)
350#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
351 /* bctsr_sessid */ \
352 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
353 1 /* bctsr_dir */ + \
354 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400355#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
356#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400357#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
358#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400359#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
360 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
361#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
362 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500363#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
364#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700365#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
366 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
367 1 /* layout type */ + \
368 1 /* maxcount */ + \
369 1 /* bitmap size */ + \
370 1 /* notification bitmap length */ + \
371 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400372#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
373 1 /* layout type */ + \
374 1 /* opaque devaddr4 length */ + \
375 /* devaddr4 payload is read into page */ \
376 1 /* notification bitmap length */ + \
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700377 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400378#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
379 encode_stateid_maxsz)
380#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
381 decode_stateid_maxsz + \
382 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000383#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
384 2 /* offset */ + \
385 2 /* length */ + \
386 1 /* reclaim */ + \
387 encode_stateid_maxsz + \
388 1 /* new offset (true) */ + \
389 2 /* last byte written */ + \
390 1 /* nt_timechanged (false) */ + \
391 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500392 1 /* layoutupdate4 opaqueue len */)
393 /* the actual content of layoutupdate4 should
394 be allocated by drivers and spliced in
395 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000396#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300397#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
398 encode_stateid_maxsz + \
399 1 /* FIXME: opaque lrf_body always empty at the moment */)
400#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
401 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400402#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
403#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400404#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
405 XDR_QUADLEN(NFS4_STATEID_SIZE))
406#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400407#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
408 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400409#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400410#else /* CONFIG_NFS_V4_1 */
411#define encode_sequence_maxsz 0
412#define decode_sequence_maxsz 0
413#endif /* CONFIG_NFS_V4_1 */
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
416#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
417#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400418 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400420 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400426 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400428 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400432 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400434 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400436 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400438 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400440 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400444 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400445 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400447 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400449 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400450 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400452 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400454 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400456 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400458 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400460 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400461 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400462 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400463 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400464 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400465 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400467 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400468 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400469 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400470 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400471 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400472 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400473#define NFS4_enc_open_confirm_sz \
474 (compound_encode_hdr_maxsz + \
475 encode_putfh_maxsz + \
476 encode_open_confirm_maxsz)
477#define NFS4_dec_open_confirm_sz \
478 (compound_decode_hdr_maxsz + \
479 decode_putfh_maxsz + \
480 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400482 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400484 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400485 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400486 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400488 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400490 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400491 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400492 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493#define NFS4_enc_open_downgrade_sz \
494 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400495 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400496 encode_putfh_maxsz + \
497 encode_open_downgrade_maxsz + \
498 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499#define NFS4_dec_open_downgrade_sz \
500 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400501 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400502 decode_putfh_maxsz + \
503 decode_open_downgrade_maxsz + \
504 decode_getattr_maxsz)
505#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400506 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400507 encode_putfh_maxsz + \
508 encode_close_maxsz + \
509 encode_getattr_maxsz)
510#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400511 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400512 decode_putfh_maxsz + \
513 decode_close_maxsz + \
514 decode_getattr_maxsz)
515#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400516 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400517 encode_putfh_maxsz + \
518 encode_setattr_maxsz + \
519 encode_getattr_maxsz)
520#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400521 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400522 decode_putfh_maxsz + \
523 decode_setattr_maxsz + \
524 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400526 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 encode_putfh_maxsz + \
528 encode_fsinfo_maxsz)
529#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 decode_putfh_maxsz + \
532 decode_fsinfo_maxsz)
533#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
534 encode_renew_maxsz)
535#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
536 decode_renew_maxsz)
537#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
538 encode_setclientid_maxsz)
539#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
540 decode_setclientid_maxsz)
541#define NFS4_enc_setclientid_confirm_sz \
542 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400543 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544#define NFS4_dec_setclientid_confirm_sz \
545 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400546 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400548 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400550 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400552 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400554 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400558 encode_lockt_maxsz)
559#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400560 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400561 decode_putfh_maxsz + \
562 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400566 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400570 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400571#define NFS4_enc_release_lockowner_sz \
572 (compound_encode_hdr_maxsz + \
573 encode_lockowner_maxsz)
574#define NFS4_dec_release_lockowner_sz \
575 (compound_decode_hdr_maxsz + \
576 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400578 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400580 encode_access_maxsz + \
581 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400583 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400585 decode_access_maxsz + \
586 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400588 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400590 encode_getattr_maxsz + \
591 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400593 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400595 decode_getattr_maxsz + \
596 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400598 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 encode_putfh_maxsz + \
600 encode_lookup_maxsz + \
601 encode_getattr_maxsz + \
602 encode_getfh_maxsz)
603#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400604 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400606 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 decode_getattr_maxsz + \
608 decode_getfh_maxsz)
609#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400610 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 encode_putrootfh_maxsz + \
612 encode_getattr_maxsz + \
613 encode_getfh_maxsz)
614#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400615 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 decode_putrootfh_maxsz + \
617 decode_getattr_maxsz + \
618 decode_getfh_maxsz)
619#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400620 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400622 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400624 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400626 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400628 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 encode_putfh_maxsz + \
630 encode_savefh_maxsz + \
631 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400632 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400634 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 decode_putfh_maxsz + \
636 decode_savefh_maxsz + \
637 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400638 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400640 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 encode_putfh_maxsz + \
642 encode_savefh_maxsz + \
643 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400644 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400645 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400646 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 decode_putfh_maxsz + \
650 decode_savefh_maxsz + \
651 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400652 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400653 decode_restorefh_maxsz + \
654 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400656 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 encode_putfh_maxsz + \
658 encode_symlink_maxsz + \
659 encode_getattr_maxsz + \
660 encode_getfh_maxsz)
661#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400662 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 decode_putfh_maxsz + \
664 decode_symlink_maxsz + \
665 decode_getattr_maxsz + \
666 decode_getfh_maxsz)
667#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400668 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 encode_putfh_maxsz + \
670 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400671 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400672 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400674 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 decode_putfh_maxsz + \
676 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400677 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400678 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 encode_putfh_maxsz + \
682 encode_getattr_maxsz)
683#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 decode_putfh_maxsz + \
686 decode_getattr_maxsz)
687#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400690 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400694 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800697 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 encode_getattr_maxsz)
699#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400700 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800701 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 decode_getattr_maxsz)
703#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400704 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100706 encode_delegreturn_maxsz + \
707 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400709 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100710 decode_delegreturn_maxsz + \
711 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000712#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000714 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400715 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000716#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000718 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400719 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000720#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400721 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000722 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400723 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000724#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400725 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000726 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400727 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400728#define NFS4_enc_fs_locations_sz \
729 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400730 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400731 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400732 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400733 encode_fs_locations_maxsz + \
734 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400735#define NFS4_dec_fs_locations_sz \
736 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400737 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400738 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400739 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400740 decode_fs_locations_maxsz + \
741 decode_renew_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)
Chuck Lever44c99932013-10-17 14:13:30 -0400750#define NFS4_enc_fsid_present_sz \
751 (compound_encode_hdr_maxsz + \
752 encode_sequence_maxsz + \
753 encode_putfh_maxsz + \
754 encode_getfh_maxsz + \
755 encode_renew_maxsz)
756#define NFS4_dec_fsid_present_sz \
757 (compound_decode_hdr_maxsz + \
758 decode_sequence_maxsz + \
759 decode_putfh_maxsz + \
760 decode_getfh_maxsz + \
761 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400762#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400763#define NFS4_enc_bind_conn_to_session_sz \
764 (compound_encode_hdr_maxsz + \
765 encode_bind_conn_to_session_maxsz)
766#define NFS4_dec_bind_conn_to_session_sz \
767 (compound_decode_hdr_maxsz + \
768 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400769#define NFS4_enc_exchange_id_sz \
770 (compound_encode_hdr_maxsz + \
771 encode_exchange_id_maxsz)
772#define NFS4_dec_exchange_id_sz \
773 (compound_decode_hdr_maxsz + \
774 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400775#define NFS4_enc_create_session_sz \
776 (compound_encode_hdr_maxsz + \
777 encode_create_session_maxsz)
778#define NFS4_dec_create_session_sz \
779 (compound_decode_hdr_maxsz + \
780 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400781#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
782 encode_destroy_session_maxsz)
783#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
784 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400785#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
786 encode_destroy_clientid_maxsz)
787#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
788 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400789#define NFS4_enc_sequence_sz \
790 (compound_decode_hdr_maxsz + \
791 encode_sequence_maxsz)
792#define NFS4_dec_sequence_sz \
793 (compound_decode_hdr_maxsz + \
794 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400795#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
796 encode_sequence_maxsz + \
797 encode_putrootfh_maxsz + \
798 encode_fsinfo_maxsz)
799#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
800 decode_sequence_maxsz + \
801 decode_putrootfh_maxsz + \
802 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500803#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
804 encode_sequence_maxsz + \
805 encode_reclaim_complete_maxsz)
806#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
807 decode_sequence_maxsz + \
808 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400809#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz +\
811 encode_getdeviceinfo_maxsz)
812#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
813 decode_sequence_maxsz + \
814 decode_getdeviceinfo_maxsz)
815#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
816 encode_sequence_maxsz + \
817 encode_putfh_maxsz + \
818 encode_layoutget_maxsz)
819#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
820 decode_sequence_maxsz + \
821 decode_putfh_maxsz + \
822 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000823#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
824 encode_sequence_maxsz +\
825 encode_putfh_maxsz + \
826 encode_layoutcommit_maxsz + \
827 encode_getattr_maxsz)
828#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
829 decode_sequence_maxsz + \
830 decode_putfh_maxsz + \
831 decode_layoutcommit_maxsz + \
832 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300833#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
834 encode_sequence_maxsz + \
835 encode_putfh_maxsz + \
836 encode_layoutreturn_maxsz)
837#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
838 decode_sequence_maxsz + \
839 decode_putfh_maxsz + \
840 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400841#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
842 encode_sequence_maxsz + \
843 encode_putrootfh_maxsz +\
844 encode_secinfo_no_name_maxsz)
845#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
846 decode_sequence_maxsz + \
847 decode_putrootfh_maxsz + \
848 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400849#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
850 encode_sequence_maxsz + \
851 encode_test_stateid_maxsz)
852#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
853 decode_sequence_maxsz + \
854 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400855#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
856 encode_sequence_maxsz + \
857 encode_free_stateid_maxsz)
858#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
859 decode_sequence_maxsz + \
860 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500861
862const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
863 compound_encode_hdr_maxsz +
864 encode_sequence_maxsz +
865 encode_putfh_maxsz +
866 encode_getattr_maxsz) *
867 XDR_UNIT);
868
869const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
870 compound_decode_hdr_maxsz +
871 decode_sequence_maxsz +
872 decode_putfh_maxsz) *
873 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400874
875const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
876 compound_decode_hdr_maxsz +
877 decode_sequence_maxsz) *
878 XDR_UNIT);
879EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400880#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Trond Myklebustbca79472009-03-11 14:10:26 -0400882static const umode_t nfs_type2fmt[] = {
883 [NF4BAD] = 0,
884 [NF4REG] = S_IFREG,
885 [NF4DIR] = S_IFDIR,
886 [NF4BLK] = S_IFBLK,
887 [NF4CHR] = S_IFCHR,
888 [NF4LNK] = S_IFLNK,
889 [NF4SOCK] = S_IFSOCK,
890 [NF4FIFO] = S_IFIFO,
891 [NF4ATTRDIR] = 0,
892 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893};
894
895struct compound_hdr {
896 int32_t status;
897 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500898 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 uint32_t taglen;
900 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400901 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400902 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903};
904
Benny Halevy13c65ce2009-08-14 17:19:25 +0300905static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
906{
907 __be32 *p = xdr_reserve_space(xdr, nbytes);
908 BUG_ON(!p);
909 return p;
910}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
Trond Myklebustcb17e552012-03-04 18:13:56 -0500912static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
913{
914 __be32 *p;
915
916 p = xdr_reserve_space(xdr, len);
917 xdr_encode_opaque_fixed(p, buf, len);
918}
919
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
921{
Al Viro8687b632006-10-19 23:28:48 -0700922 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500924 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 xdr_encode_opaque(p, str, len);
926}
927
Trond Myklebust4ade9822012-03-04 18:13:57 -0500928static void encode_uint32(struct xdr_stream *xdr, u32 n)
929{
930 __be32 *p;
931
932 p = reserve_space(xdr, 4);
933 *p = cpu_to_be32(n);
934}
935
Trond Myklebustff2eb682012-03-05 11:40:12 -0500936static void encode_uint64(struct xdr_stream *xdr, u64 n)
937{
938 __be32 *p;
939
940 p = reserve_space(xdr, 8);
941 xdr_encode_hyper(p, n);
942}
943
Trond Myklebust4ade9822012-03-04 18:13:57 -0500944static void encode_nfs4_seqid(struct xdr_stream *xdr,
945 const struct nfs_seqid *seqid)
946{
947 encode_uint32(xdr, seqid->sequence->counter);
948}
949
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400950static void encode_compound_hdr(struct xdr_stream *xdr,
951 struct rpc_rqst *req,
952 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953{
Al Viro8687b632006-10-19 23:28:48 -0700954 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400955 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400956
957 /* initialize running count of expected bytes in reply.
958 * NOTE: the replied tag SHOULD be the same is the one sent,
959 * but this is not required as a MUST for the server to do so. */
960 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Trond Myklebust7fc38842012-10-15 11:51:21 -0400962 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500963 encode_string(xdr, hdr->taglen, hdr->tag);
964 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300965 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500966 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300967 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500968}
969
Trond Myklebustab19b482012-03-04 18:13:57 -0500970static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
971 uint32_t replen,
972 struct compound_hdr *hdr)
973{
974 encode_uint32(xdr, op);
975 hdr->nops++;
976 hdr->replen += replen;
977}
978
Andy Adamsond0179312008-12-23 16:06:17 -0500979static void encode_nops(struct compound_hdr *hdr)
980{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400981 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500982 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983}
984
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500985static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
986{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500987 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500988}
989
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
991{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500992 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993}
994
David Quigleyaa9c2662013-05-22 12:50:44 -0400995static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
996 const struct nfs4_label *label,
997 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998{
999 char owner_name[IDMAP_NAMESZ];
1000 char owner_group[IDMAP_NAMESZ];
1001 int owner_namelen = 0;
1002 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001003 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001004 unsigned i;
1005 uint32_t len = 0;
1006 uint32_t bmval_len;
1007 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009 /*
1010 * We reserve enough space to write the entire attribute buffer at once.
1011 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001012 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1013 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001014 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001016 if (iap->ia_valid & ATTR_SIZE) {
1017 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001019 }
1020 if (iap->ia_valid & ATTR_MODE) {
1021 bmval[1] |= FATTR4_WORD1_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 len += 4;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001023 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001025 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001027 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001028 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 /* XXX */
1030 strcpy(owner_name, "nobody");
1031 owner_namelen = sizeof("nobody") - 1;
1032 /* goto out; */
1033 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001034 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1036 }
1037 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001038 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001040 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001041 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 strcpy(owner_group, "nobody");
1043 owner_grouplen = sizeof("nobody") - 1;
1044 /* goto out; */
1045 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001046 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1048 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001050 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1051 len += 16;
1052 } else if (iap->ia_valid & ATTR_ATIME) {
1053 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1054 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 }
1056 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001057 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1058 len += 16;
1059 } else if (iap->ia_valid & ATTR_MTIME) {
1060 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1061 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001063 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001064 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1065 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1066 }
1067
1068 if (bmval[2] != 0)
1069 bmval_len = 3;
1070 else if (bmval[1] != 0)
1071 bmval_len = 2;
1072 else
1073 bmval_len = 1;
1074
1075 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1076
1077 *p++ = cpu_to_be32(bmval_len);
1078 for (i = 0; i < bmval_len; i++)
1079 *p++ = cpu_to_be32(bmval[i]);
1080 *p++ = cpu_to_be32(len);
1081
1082 if (bmval[0] & FATTR4_WORD0_SIZE)
1083 p = xdr_encode_hyper(p, iap->ia_size);
1084 if (bmval[1] & FATTR4_WORD1_MODE)
1085 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1086 if (bmval[1] & FATTR4_WORD1_OWNER)
1087 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1088 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1089 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1090 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1091 if (iap->ia_valid & ATTR_ATIME_SET) {
1092 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1093 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1094 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1095 } else
1096 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1097 }
1098 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1099 if (iap->ia_valid & ATTR_MTIME_SET) {
1100 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1101 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1102 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1103 } else
1104 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1105 }
1106 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001107 *p++ = cpu_to_be32(label->lfs);
1108 *p++ = cpu_to_be32(label->pi);
1109 *p++ = cpu_to_be32(label->len);
1110 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1111 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001112
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114}
1115
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001116static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001118 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1119 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120}
1121
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001122static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123{
Trond Myklebustab19b482012-03-04 18:13:57 -05001124 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001125 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001126 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127}
1128
Fred Isaman0b7c0152012-04-20 14:47:39 -04001129static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130{
Al Viro8687b632006-10-19 23:28:48 -07001131 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001132
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001133 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1134 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001135 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001136 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137}
1138
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001139static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140{
Al Viro8687b632006-10-19 23:28:48 -07001141 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001142
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001143 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1144 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146 switch (create->ftype) {
1147 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001148 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001149 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001150 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 break;
1152
1153 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001154 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001155 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001156 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 break;
1158
1159 default:
1160 break;
1161 }
1162
Benny Halevy811652b2009-08-14 17:19:34 +03001163 encode_string(xdr, create->name->len, create->name->name);
David Quigleyaa9c2662013-05-22 12:50:44 -04001164 encode_attrs(xdr, create->attrs, create->label, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165}
1166
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001167static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
Andy Adamson05d564f2008-12-23 16:06:15 -05001169 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001171 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1172 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001173 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001174 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175}
1176
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001177static 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 -07001178{
Andy Adamson05d564f2008-12-23 16:06:15 -05001179 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001181 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1182 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001183 *p++ = cpu_to_be32(2);
1184 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001185 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186}
1187
Fred Isamandae100c2011-07-30 20:52:37 -04001188static void
1189encode_getattr_three(struct xdr_stream *xdr,
1190 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1191 struct compound_hdr *hdr)
1192{
1193 __be32 *p;
1194
Trond Myklebustab19b482012-03-04 18:13:57 -05001195 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001196 if (bm2) {
1197 p = reserve_space(xdr, 16);
1198 *p++ = cpu_to_be32(3);
1199 *p++ = cpu_to_be32(bm0);
1200 *p++ = cpu_to_be32(bm1);
1201 *p = cpu_to_be32(bm2);
1202 } else if (bm1) {
1203 p = reserve_space(xdr, 12);
1204 *p++ = cpu_to_be32(2);
1205 *p++ = cpu_to_be32(bm0);
1206 *p = cpu_to_be32(bm1);
1207 } else {
1208 p = reserve_space(xdr, 8);
1209 *p++ = cpu_to_be32(1);
1210 *p = cpu_to_be32(bm0);
1211 }
Fred Isamandae100c2011-07-30 20:52:37 -04001212}
1213
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001214static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215{
David Quigleya09df2c2013-05-22 12:50:41 -04001216 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1217 bitmask[1] & nfs4_fattr_bitmap[1],
1218 bitmask[2] & nfs4_fattr_bitmap[2],
1219 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220}
1221
Andy Adamson88034c32012-05-23 05:02:34 -04001222static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001223 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001224 struct compound_hdr *hdr)
1225{
1226 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001227 bitmask[0] & open_bitmap[0],
1228 bitmask[1] & open_bitmap[1],
1229 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001230 hdr);
1231}
1232
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001233static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234{
Fred Isamandae100c2011-07-30 20:52:37 -04001235 encode_getattr_three(xdr,
1236 bitmask[0] & nfs4_fsinfo_bitmap[0],
1237 bitmask[1] & nfs4_fsinfo_bitmap[1],
1238 bitmask[2] & nfs4_fsinfo_bitmap[2],
1239 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240}
1241
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001242static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001243{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001244 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1245 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001246}
1247
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001248static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Trond Myklebustab19b482012-03-04 18:13:57 -05001250 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251}
1252
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001253static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254{
Trond Myklebustab19b482012-03-04 18:13:57 -05001255 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001256 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257}
1258
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001259static inline int nfs4_lock_type(struct file_lock *fl, int block)
1260{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001261 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001262 return block ? NFS4_READW_LT : NFS4_READ_LT;
1263 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1264}
1265
1266static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1267{
1268 if (fl->fl_end == OFFSET_MAX)
1269 return ~(uint64_t)0;
1270 return fl->fl_end - fl->fl_start + 1;
1271}
1272
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001273static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1274{
1275 __be32 *p;
1276
Trond Myklebustd035c362010-12-21 10:45:27 -05001277 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001278 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001279 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001280 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001281 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001282 xdr_encode_hyper(p, lowner->id);
1283}
1284
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285/*
1286 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1287 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1288 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001289static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290{
Al Viro8687b632006-10-19 23:28:48 -07001291 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001293 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1294 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001295 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1296 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001297 p = xdr_encode_hyper(p, args->fl->fl_start);
1298 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001299 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001300 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001301 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001302 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001303 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001304 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 }
1306 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001307 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001308 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310}
1311
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001312static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313{
Al Viro8687b632006-10-19 23:28:48 -07001314 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001316 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1317 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001318 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001319 p = xdr_encode_hyper(p, args->fl->fl_start);
1320 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001321 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322}
1323
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001324static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325{
Al Viro8687b632006-10-19 23:28:48 -07001326 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001328 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1329 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001330 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001331 encode_nfs4_stateid(xdr, args->stateid);
1332 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001333 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001334 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335}
1336
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001337static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1338{
Trond Myklebustab19b482012-03-04 18:13:57 -05001339 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001340 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001341}
1342
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001343static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344{
Trond Myklebustab19b482012-03-04 18:13:57 -05001345 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001346 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001349static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350{
Al Viro8687b632006-10-19 23:28:48 -07001351 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Benny Halevy13c65ce2009-08-14 17:19:25 +03001353 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001354 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001355 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001356 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001357 break;
1358 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001359 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001360 break;
1361 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001362 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001363 break;
1364 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001365 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 }
Benny Halevy34558512009-08-14 17:19:30 +03001367 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368}
1369
1370static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1371{
Al Viro8687b632006-10-19 23:28:48 -07001372 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 /*
1374 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1375 * owner 4 = 32
1376 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001377 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001378 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001379 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001380 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001381 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001382 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001383 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001384 *p++ = cpu_to_be32(arg->id.uniquifier);
1385 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386}
1387
1388static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1389{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001390 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001391 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
Benny Halevy13c65ce2009-08-14 17:19:25 +03001393 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001394 switch(arg->createmode) {
1395 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001396 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001397 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Andy Adamson05d564f2008-12-23 16:06:15 -05001398 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001399 case NFS4_CREATE_GUARDED:
1400 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001401 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001402 break;
1403 case NFS4_CREATE_EXCLUSIVE:
1404 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1405 encode_nfs4_verifier(xdr, &arg->u.verifier);
1406 break;
1407 case NFS4_CREATE_EXCLUSIVE4_1:
1408 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1409 encode_nfs4_verifier(xdr, &arg->u.verifier);
1410 dummy.ia_valid = 0;
David Quigleyaa9c2662013-05-22 12:50:44 -04001411 encode_attrs(xdr, &dummy, arg->label, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 }
1413}
1414
1415static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1416{
Al Viro8687b632006-10-19 23:28:48 -07001417 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Benny Halevy13c65ce2009-08-14 17:19:25 +03001419 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001421 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001422 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001423 break;
1424 default:
Benny Halevy34558512009-08-14 17:19:30 +03001425 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001426 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 }
1428}
1429
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001430static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431{
Al Viro8687b632006-10-19 23:28:48 -07001432 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Benny Halevy13c65ce2009-08-14 17:19:25 +03001434 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001436 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001437 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001438 break;
1439 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001440 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001441 break;
1442 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001443 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001444 break;
1445 default:
1446 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 }
1448}
1449
1450static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1451{
Al Viro8687b632006-10-19 23:28:48 -07001452 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
Benny Halevy13c65ce2009-08-14 17:19:25 +03001454 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001455 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 encode_string(xdr, name->len, name->name);
1457}
1458
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001459static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460{
Al Viro8687b632006-10-19 23:28:48 -07001461 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Benny Halevy13c65ce2009-08-14 17:19:25 +03001463 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001464 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 encode_delegation_type(xdr, type);
1466}
1467
1468static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1469{
Al Viro8687b632006-10-19 23:28:48 -07001470 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001472 p = reserve_space(xdr, 4);
1473 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1474 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 encode_string(xdr, name->len, name->name);
1476}
1477
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001478static inline void encode_claim_fh(struct xdr_stream *xdr)
1479{
1480 __be32 *p;
1481
1482 p = reserve_space(xdr, 4);
1483 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1484}
1485
1486static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1487{
1488 __be32 *p;
1489
1490 p = reserve_space(xdr, 4);
1491 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1492 encode_nfs4_stateid(xdr, stateid);
1493}
1494
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001495static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496{
Trond Myklebustab19b482012-03-04 18:13:57 -05001497 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 encode_openhdr(xdr, arg);
1499 encode_opentype(xdr, arg);
1500 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001501 case NFS4_OPEN_CLAIM_NULL:
1502 encode_claim_null(xdr, arg->name);
1503 break;
1504 case NFS4_OPEN_CLAIM_PREVIOUS:
1505 encode_claim_previous(xdr, arg->u.delegation_type);
1506 break;
1507 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1508 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1509 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001510 case NFS4_OPEN_CLAIM_FH:
1511 encode_claim_fh(xdr);
1512 break;
1513 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1514 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1515 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001516 default:
1517 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519}
1520
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001521static 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 -07001522{
Trond Myklebustab19b482012-03-04 18:13:57 -05001523 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001524 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001525 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526}
1527
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001528static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529{
Trond Myklebustab19b482012-03-04 18:13:57 -05001530 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001531 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001532 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001533 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534}
1535
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001536static void
Andy Adamsond0179312008-12-23 16:06:17 -05001537encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538{
Trond Myklebustab19b482012-03-04 18:13:57 -05001539 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001540 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541}
1542
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001543static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544{
Trond Myklebustab19b482012-03-04 18:13:57 -05001545 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546}
1547
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001548static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1549 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550{
Al Viro8687b632006-10-19 23:28:48 -07001551 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Trond Myklebustab19b482012-03-04 18:13:57 -05001553 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001554 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
Benny Halevy13c65ce2009-08-14 17:19:25 +03001556 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001557 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001558 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559}
1560
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001561static 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 -07001562{
David Quigleyaa9c2662013-05-22 12:50:44 -04001563 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001564 FATTR4_WORD0_RDATTR_ERROR,
1565 FATTR4_WORD1_MOUNTED_ON_FILEID,
1566 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001567 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001568 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001569 uint32_t attrlen = 0;
1570 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001572 if (readdir->plus) {
1573 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001574 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001575 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1576 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1577 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1578 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001579 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001580 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001581 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001582 /* Use mounted_on_fileid only if the server supports it */
1583 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1584 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001585 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1586 attrs[i] &= readdir->bitmask[i];
1587 if (attrs[i] != 0)
1588 attrlen = i+1;
1589 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001590
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001591 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001592 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001593 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001594 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001595 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001596 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001597 *p++ = cpu_to_be32(attrlen);
1598 for (i = 0; i < attrlen; i++)
1599 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001600 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001601
1602 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001603 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001604 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001605 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001606 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001607 attrs[1] & readdir->bitmask[1],
1608 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609}
1610
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001611static 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 -07001612{
Trond Myklebustab19b482012-03-04 18:13:57 -05001613 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614}
1615
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001616static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617{
Trond Myklebustab19b482012-03-04 18:13:57 -05001618 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001619 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620}
1621
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001622static 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 -07001623{
Trond Myklebustab19b482012-03-04 18:13:57 -05001624 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001625 encode_string(xdr, oldname->len, oldname->name);
1626 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627}
1628
Chuck Leverbb4dae52012-03-01 17:01:48 -05001629static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1630 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001632 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001633 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634}
1635
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001636static void
Andy Adamsond0179312008-12-23 16:06:17 -05001637encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001638{
Trond Myklebustab19b482012-03-04 18:13:57 -05001639 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001640}
1641
Chuck Lever9f06c712010-12-14 14:59:18 +00001642static void
Andy Adamsond0179312008-12-23 16:06:17 -05001643encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001644{
Al Viro8687b632006-10-19 23:28:48 -07001645 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001646
Trond Myklebustab19b482012-03-04 18:13:57 -05001647 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001648 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001649 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001650 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001651 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001652 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001653 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001654 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001655}
1656
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001657static void
Andy Adamsond0179312008-12-23 16:06:17 -05001658encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659{
Trond Myklebustab19b482012-03-04 18:13:57 -05001660 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661}
1662
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001663static 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 -07001664{
Trond Myklebustab19b482012-03-04 18:13:57 -05001665 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001666 encode_nfs4_stateid(xdr, &arg->stateid);
David Quigleyaa9c2662013-05-22 12:50:44 -04001667 encode_attrs(xdr, arg->iap, arg->label, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668}
1669
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001670static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671{
Al Viro8687b632006-10-19 23:28:48 -07001672 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
Trond Myklebust70019512012-03-04 20:49:32 -05001674 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001675 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676
1677 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001678 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001679 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1681 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001682 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001683 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684}
1685
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001686static 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 -07001687{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001688 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1689 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001690 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001691 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692}
1693
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001694static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1695 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696{
Al Viro8687b632006-10-19 23:28:48 -07001697 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
Trond Myklebustab19b482012-03-04 18:13:57 -05001699 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001700 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Benny Halevy13c65ce2009-08-14 17:19:25 +03001702 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001703 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001704 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001705 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
1707 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708}
1709
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001710static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711{
Trond Myklebustab19b482012-03-04 18:13:57 -05001712 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001713 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001715
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001716static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1717{
Trond Myklebustab19b482012-03-04 18:13:57 -05001718 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001719 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001720}
1721
Benny Halevy99fe60d2009-04-01 09:22:29 -04001722#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001723/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001724static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1725 struct nfs4_session *session,
1726 struct compound_hdr *hdr)
1727{
1728 __be32 *p;
1729
1730 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1731 decode_bind_conn_to_session_maxsz, hdr);
1732 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1733 p = xdr_reserve_space(xdr, 8);
1734 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1735 *p = 0; /* use_conn_in_rdma_mode = False */
1736}
1737
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001738static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1739{
1740 unsigned int i;
1741 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1742 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1743 encode_uint32(xdr, op_map->u.words[i]);
1744}
1745
Benny Halevy99fe60d2009-04-01 09:22:29 -04001746static void encode_exchange_id(struct xdr_stream *xdr,
1747 struct nfs41_exchange_id_args *args,
1748 struct compound_hdr *hdr)
1749{
1750 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001751 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001752 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001753
Trond Myklebust70019512012-03-04 20:49:32 -05001754 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001755 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001756
1757 encode_string(xdr, args->id_len, args->id);
1758
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001759 encode_uint32(xdr, args->flags);
1760 encode_uint32(xdr, args->state_protect.how);
1761
1762 switch (args->state_protect.how) {
1763 case SP4_NONE:
1764 break;
1765 case SP4_MACH_CRED:
1766 encode_op_map(xdr, &args->state_protect.enforce);
1767 encode_op_map(xdr, &args->state_protect.allow);
1768 break;
1769 default:
1770 WARN_ON_ONCE(1);
1771 break;
1772 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001773
1774 if (send_implementation_id &&
1775 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1776 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001777 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001778 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1779 utsname()->sysname, utsname()->release,
1780 utsname()->version, utsname()->machine);
1781
1782 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001783 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001784
1785 encode_string(xdr,
1786 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1787 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1788 encode_string(xdr, len, impl_name);
1789 /* just send zeros for nii_date - the date is in nii_name */
1790 p = reserve_space(xdr, 12);
1791 p = xdr_encode_hyper(p, 0);
1792 *p = cpu_to_be32(0);
1793 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001794 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001795}
Andy Adamsonfc931582009-04-01 09:22:31 -04001796
1797static void encode_create_session(struct xdr_stream *xdr,
1798 struct nfs41_create_session_args *args,
1799 struct compound_hdr *hdr)
1800{
1801 __be32 *p;
1802 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1803 uint32_t len;
1804 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001805 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001806 u32 max_resp_sz_cached;
1807
1808 /*
1809 * Assumes OPEN is the biggest non-idempotent compound.
1810 * 2 is the verifier.
1811 */
1812 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1813 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001814
Andy Adamsonfc931582009-04-01 09:22:31 -04001815 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1816 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001817
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001818 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1819 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001820 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001821 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1822 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001823
Andy Adamsonfc931582009-04-01 09:22:31 -04001824 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001825 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001826 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1827 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001828 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001829 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1830 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1831 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001832
1833 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001834 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001835 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1836 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1837 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1838 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1839 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1840 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001841
Benny Halevye75bc1c2009-08-14 17:18:54 +03001842 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001843 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001844 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001845
1846 /* authsys_parms rfc1831 */
Trond Myklebust17f26b12013-08-21 15:48:42 -04001847 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001848 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001849 *p++ = cpu_to_be32(0); /* UID */
1850 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001851 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001852}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001853
1854static void encode_destroy_session(struct xdr_stream *xdr,
1855 struct nfs4_session *session,
1856 struct compound_hdr *hdr)
1857{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001858 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1859 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001860}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001861
Trond Myklebust66245532012-05-25 17:18:09 -04001862static void encode_destroy_clientid(struct xdr_stream *xdr,
1863 uint64_t clientid,
1864 struct compound_hdr *hdr)
1865{
1866 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1867 encode_uint64(xdr, clientid);
1868}
1869
Ricardo Labiaga180197532009-12-05 16:08:40 -05001870static void encode_reclaim_complete(struct xdr_stream *xdr,
1871 struct nfs41_reclaim_complete_args *args,
1872 struct compound_hdr *hdr)
1873{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001874 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1875 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001876}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001877#endif /* CONFIG_NFS_V4_1 */
1878
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001879static void encode_sequence(struct xdr_stream *xdr,
1880 const struct nfs4_sequence_args *args,
1881 struct compound_hdr *hdr)
1882{
1883#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001884 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001885 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001886 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001887 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001888
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001889 tp = slot->table;
1890 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001891 if (!session)
1892 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001893
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001894 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001895
1896 /*
1897 * Sessionid + seqid + slotid + max slotid + cache_this
1898 */
1899 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1900 "max_slotid=%d cache_this=%d\n",
1901 __func__,
1902 ((u32 *)session->sess_id.data)[0],
1903 ((u32 *)session->sess_id.data)[1],
1904 ((u32 *)session->sess_id.data)[2],
1905 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001906 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001907 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001908 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001909 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001910 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001911 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001912 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001913 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001914#endif /* CONFIG_NFS_V4_1 */
1915}
1916
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001917#ifdef CONFIG_NFS_V4_1
1918static void
1919encode_getdeviceinfo(struct xdr_stream *xdr,
1920 const struct nfs4_getdeviceinfo_args *args,
1921 struct compound_hdr *hdr)
1922{
1923 __be32 *p;
1924
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001925 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001926 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001927 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1928 NFS4_DEVICEID4_SIZE);
1929 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001930 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001931
1932 p = reserve_space(xdr, 4 + 4);
1933 *p++ = cpu_to_be32(1); /* bitmap length */
1934 *p++ = cpu_to_be32(NOTIFY_DEVICEID4_CHANGE | NOTIFY_DEVICEID4_DELETE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001935}
1936
1937static void
1938encode_layoutget(struct xdr_stream *xdr,
1939 const struct nfs4_layoutget_args *args,
1940 struct compound_hdr *hdr)
1941{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001942 __be32 *p;
1943
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001944 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1945 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001946 *p++ = cpu_to_be32(0); /* Signal layout available */
1947 *p++ = cpu_to_be32(args->type);
1948 *p++ = cpu_to_be32(args->range.iomode);
1949 p = xdr_encode_hyper(p, args->range.offset);
1950 p = xdr_encode_hyper(p, args->range.length);
1951 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001952 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001953 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001954
1955 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1956 __func__,
1957 args->type,
1958 args->range.iomode,
1959 (unsigned long)args->range.offset,
1960 (unsigned long)args->range.length,
1961 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001962}
Andy Adamson863a3c62011-03-23 13:27:54 +00001963
1964static int
1965encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001966 struct inode *inode,
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001967 struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001968 struct compound_hdr *hdr)
1969{
1970 __be32 *p;
1971
1972 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1973 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1974
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001975 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1976 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001977 /* Only whole file layouts */
1978 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001979 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001980 *p = cpu_to_be32(0); /* reclaim */
1981 encode_nfs4_stateid(xdr, &args->stateid);
1982 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001983 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1984 p = xdr_encode_hyper(p, args->lastbytewritten);
1985 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1986 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001987
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001988 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
Benny Halevyac7db722011-05-22 19:53:48 +03001989 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1990 NFS_I(inode)->layout, xdr, args);
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001991 } else {
1992 encode_uint32(xdr, args->layoutupdate_len);
1993 if (args->layoutupdate_pages) {
1994 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
1995 args->layoutupdate_len);
1996 }
1997 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001998
Andy Adamson863a3c62011-03-23 13:27:54 +00001999 return 0;
2000}
Benny Halevycbe82602011-05-22 19:52:37 +03002001
2002static void
2003encode_layoutreturn(struct xdr_stream *xdr,
2004 const struct nfs4_layoutreturn_args *args,
2005 struct compound_hdr *hdr)
2006{
2007 __be32 *p;
2008
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002009 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2010 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002011 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2012 *p++ = cpu_to_be32(args->layout_type);
2013 *p++ = cpu_to_be32(IOMODE_ANY);
2014 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002015 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002016 p = xdr_encode_hyper(p, 0);
2017 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2018 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002019 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002020 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002021 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2022 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2023 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002024 } else
2025 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002026}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002027
2028static int
2029encode_secinfo_no_name(struct xdr_stream *xdr,
2030 const struct nfs41_secinfo_no_name_args *args,
2031 struct compound_hdr *hdr)
2032{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002033 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2034 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002035 return 0;
2036}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002037
2038static void encode_test_stateid(struct xdr_stream *xdr,
2039 struct nfs41_test_stateid_args *args,
2040 struct compound_hdr *hdr)
2041{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002042 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2043 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002044 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002045}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002046
2047static void encode_free_stateid(struct xdr_stream *xdr,
2048 struct nfs41_free_stateid_args *args,
2049 struct compound_hdr *hdr)
2050{
Trond Myklebustab19b482012-03-04 18:13:57 -05002051 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002052 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002053}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002054#endif /* CONFIG_NFS_V4_1 */
2055
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056/*
2057 * END OF "GENERIC" ENCODE ROUTINES.
2058 */
2059
Benny Halevy66cc0422009-04-01 09:22:10 -04002060static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2061{
2062#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002063 struct nfs4_session *session = args->sa_slot->table->session;
2064 if (session)
2065 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002066#endif /* CONFIG_NFS_V4_1 */
2067 return 0;
2068}
2069
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070/*
2071 * Encode an ACCESS request
2072 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002073static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2074 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002077 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079
Chuck Lever9f06c712010-12-14 14:59:18 +00002080 encode_compound_hdr(xdr, req, &hdr);
2081 encode_sequence(xdr, &args->seq_args, &hdr);
2082 encode_putfh(xdr, args->fh, &hdr);
2083 encode_access(xdr, args->access, &hdr);
2084 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002085 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086}
2087
2088/*
2089 * Encode LOOKUP request
2090 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002091static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2092 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002095 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
Chuck Lever9f06c712010-12-14 14:59:18 +00002098 encode_compound_hdr(xdr, req, &hdr);
2099 encode_sequence(xdr, &args->seq_args, &hdr);
2100 encode_putfh(xdr, args->dir_fh, &hdr);
2101 encode_lookup(xdr, args->name, &hdr);
2102 encode_getfh(xdr, &hdr);
2103 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002104 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105}
2106
2107/*
2108 * Encode LOOKUP_ROOT request
2109 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002110static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2111 struct xdr_stream *xdr,
2112 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002115 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
Chuck Lever9f06c712010-12-14 14:59:18 +00002118 encode_compound_hdr(xdr, req, &hdr);
2119 encode_sequence(xdr, &args->seq_args, &hdr);
2120 encode_putrootfh(xdr, &hdr);
2121 encode_getfh(xdr, &hdr);
2122 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002123 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124}
2125
2126/*
2127 * Encode REMOVE request
2128 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002129static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2130 const struct nfs_removeargs *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->fh, &hdr);
2139 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002140 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141}
2142
2143/*
2144 * Encode RENAME request
2145 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002146static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2147 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002150 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152
Chuck Lever9f06c712010-12-14 14:59:18 +00002153 encode_compound_hdr(xdr, req, &hdr);
2154 encode_sequence(xdr, &args->seq_args, &hdr);
2155 encode_putfh(xdr, args->old_dir, &hdr);
2156 encode_savefh(xdr, &hdr);
2157 encode_putfh(xdr, args->new_dir, &hdr);
2158 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002159 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160}
2161
2162/*
2163 * Encode LINK request
2164 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002165static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2166 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002169 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171
Chuck Lever9f06c712010-12-14 14:59:18 +00002172 encode_compound_hdr(xdr, req, &hdr);
2173 encode_sequence(xdr, &args->seq_args, &hdr);
2174 encode_putfh(xdr, args->fh, &hdr);
2175 encode_savefh(xdr, &hdr);
2176 encode_putfh(xdr, args->dir_fh, &hdr);
2177 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002178 encode_restorefh(xdr, &hdr);
2179 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002180 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181}
2182
2183/*
2184 * Encode CREATE request
2185 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002186static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2187 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002190 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192
Chuck Lever9f06c712010-12-14 14:59:18 +00002193 encode_compound_hdr(xdr, req, &hdr);
2194 encode_sequence(xdr, &args->seq_args, &hdr);
2195 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002196 encode_create(xdr, args, &hdr);
2197 encode_getfh(xdr, &hdr);
2198 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002199 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200}
2201
2202/*
2203 * Encode SYMLINK request
2204 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002205static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2206 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207{
Chuck Lever9f06c712010-12-14 14:59:18 +00002208 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209}
2210
2211/*
2212 * Encode GETATTR request
2213 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002214static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2215 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002218 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 };
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_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002225 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226}
2227
2228/*
2229 * Encode a CLOSE request
2230 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002231static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2232 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233{
Andy Adamson05d564f2008-12-23 16:06:15 -05002234 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002235 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002236 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237
Chuck Lever9f06c712010-12-14 14:59:18 +00002238 encode_compound_hdr(xdr, req, &hdr);
2239 encode_sequence(xdr, &args->seq_args, &hdr);
2240 encode_putfh(xdr, args->fh, &hdr);
2241 encode_close(xdr, args, &hdr);
2242 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002243 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244}
2245
2246/*
2247 * Encode an OPEN request
2248 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002249static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2250 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002253 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
Chuck Lever9f06c712010-12-14 14:59:18 +00002256 encode_compound_hdr(xdr, req, &hdr);
2257 encode_sequence(xdr, &args->seq_args, &hdr);
2258 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002259 encode_open(xdr, args, &hdr);
2260 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002261 if (args->access)
2262 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002263 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &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_CONFIRM request
2269 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002270static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2271 struct xdr_stream *xdr,
2272 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002275 .nops = 0,
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_putfh(xdr, args->fh, &hdr);
2280 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002281 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282}
2283
2284/*
2285 * Encode an OPEN request with no attributes.
2286 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002287static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2288 struct xdr_stream *xdr,
2289 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002292 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
Chuck Lever9f06c712010-12-14 14:59:18 +00002295 encode_compound_hdr(xdr, req, &hdr);
2296 encode_sequence(xdr, &args->seq_args, &hdr);
2297 encode_putfh(xdr, args->fh, &hdr);
2298 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002299 if (args->access)
2300 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002301 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002302 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303}
2304
2305/*
2306 * Encode an OPEN_DOWNGRADE request
2307 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002308static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2309 struct xdr_stream *xdr,
2310 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002313 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
Chuck Lever9f06c712010-12-14 14:59:18 +00002316 encode_compound_hdr(xdr, req, &hdr);
2317 encode_sequence(xdr, &args->seq_args, &hdr);
2318 encode_putfh(xdr, args->fh, &hdr);
2319 encode_open_downgrade(xdr, args, &hdr);
2320 encode_getfattr(xdr, args->bitmask, &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 LOCK request
2326 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002327static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2328 struct nfs_lock_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_lock(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 LOCKT request
2343 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002344static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2345 struct nfs_lockt_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_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002355 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356}
2357
2358/*
2359 * Encode a LOCKU request
2360 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002361static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2362 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002365 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367
Chuck Lever9f06c712010-12-14 14:59:18 +00002368 encode_compound_hdr(xdr, req, &hdr);
2369 encode_sequence(xdr, &args->seq_args, &hdr);
2370 encode_putfh(xdr, args->fh, &hdr);
2371 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002372 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373}
2374
Chuck Lever9f06c712010-12-14 14:59:18 +00002375static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2376 struct xdr_stream *xdr,
2377 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002378{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002379 struct compound_hdr hdr = {
2380 .minorversion = 0,
2381 };
2382
Chuck Lever9f06c712010-12-14 14:59:18 +00002383 encode_compound_hdr(xdr, req, &hdr);
2384 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002385 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002386}
2387
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388/*
2389 * Encode a READLINK request
2390 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002391static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2392 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002395 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397
Chuck Lever9f06c712010-12-14 14:59:18 +00002398 encode_compound_hdr(xdr, req, &hdr);
2399 encode_sequence(xdr, &args->seq_args, &hdr);
2400 encode_putfh(xdr, args->fh, &hdr);
2401 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002402
Benny Halevy28f56692009-04-01 09:22:09 -04002403 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002404 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002405 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406}
2407
2408/*
2409 * Encode a READDIR request
2410 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002411static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2412 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002415 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
Chuck Lever9f06c712010-12-14 14:59:18 +00002418 encode_compound_hdr(xdr, req, &hdr);
2419 encode_sequence(xdr, &args->seq_args, &hdr);
2420 encode_putfh(xdr, args->fh, &hdr);
2421 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002422
Benny Halevy28f56692009-04-01 09:22:09 -04002423 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002424 args->pgbase, args->count);
2425 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002426 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002427 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002428 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429}
2430
2431/*
2432 * Encode a READ request
2433 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002434static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002435 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002438 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440
Chuck Lever9f06c712010-12-14 14:59:18 +00002441 encode_compound_hdr(xdr, req, &hdr);
2442 encode_sequence(xdr, &args->seq_args, &hdr);
2443 encode_putfh(xdr, args->fh, &hdr);
2444 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
Benny Halevy28f56692009-04-01 09:22:09 -04002446 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002448 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002449 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450}
2451
2452/*
2453 * Encode an SETATTR request
2454 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002455static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2456 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457{
Andy Adamson05d564f2008-12-23 16:06:15 -05002458 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002459 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002460 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461
Chuck Lever9f06c712010-12-14 14:59:18 +00002462 encode_compound_hdr(xdr, req, &hdr);
2463 encode_sequence(xdr, &args->seq_args, &hdr);
2464 encode_putfh(xdr, args->fh, &hdr);
2465 encode_setattr(xdr, args, args->server, &hdr);
2466 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002467 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468}
2469
2470/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002471 * Encode a GETACL request
2472 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002473static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2474 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002475{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002476 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002477 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002478 };
Benny Halevy28f56692009-04-01 09:22:09 -04002479 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002480
Chuck Lever9f06c712010-12-14 14:59:18 +00002481 encode_compound_hdr(xdr, req, &hdr);
2482 encode_sequence(xdr, &args->seq_args, &hdr);
2483 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002484 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002485 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002486
Benny Halevy28f56692009-04-01 09:22:09 -04002487 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002488 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002489
Andy Adamsond0179312008-12-23 16:06:17 -05002490 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002491}
2492
2493/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 * Encode a WRITE request
2495 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002496static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002497 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002500 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502
Chuck Lever9f06c712010-12-14 14:59:18 +00002503 encode_compound_hdr(xdr, req, &hdr);
2504 encode_sequence(xdr, &args->seq_args, &hdr);
2505 encode_putfh(xdr, args->fh, &hdr);
2506 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002507 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002508 if (args->bitmask)
2509 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002510 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511}
2512
2513/*
2514 * a COMMIT request
2515 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002516static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002517 struct nfs_commitargs *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_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002527 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528}
2529
2530/*
2531 * FSINFO request
2532 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002533static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2534 struct nfs4_fsinfo_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_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002544 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545}
2546
2547/*
2548 * a PATHCONF request
2549 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002550static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2551 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002554 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556
Chuck Lever9f06c712010-12-14 14:59:18 +00002557 encode_compound_hdr(xdr, req, &hdr);
2558 encode_sequence(xdr, &args->seq_args, &hdr);
2559 encode_putfh(xdr, args->fh, &hdr);
2560 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002561 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002562 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563}
2564
2565/*
2566 * a STATFS request
2567 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002568static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2569 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002572 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574
Chuck Lever9f06c712010-12-14 14:59:18 +00002575 encode_compound_hdr(xdr, req, &hdr);
2576 encode_sequence(xdr, &args->seq_args, &hdr);
2577 encode_putfh(xdr, args->fh, &hdr);
2578 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002579 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002580 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581}
2582
2583/*
2584 * GETATTR_BITMAP request
2585 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002586static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2587 struct xdr_stream *xdr,
2588 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002591 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593
Chuck Lever9f06c712010-12-14 14:59:18 +00002594 encode_compound_hdr(xdr, req, &hdr);
2595 encode_sequence(xdr, &args->seq_args, &hdr);
2596 encode_putfh(xdr, args->fhandle, &hdr);
2597 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002598 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002599 FATTR4_WORD0_LINK_SUPPORT|
2600 FATTR4_WORD0_SYMLINK_SUPPORT|
2601 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002602 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603}
2604
2605/*
2606 * a RENEW request
2607 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002608static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2609 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002612 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 };
2614
Chuck Lever9f06c712010-12-14 14:59:18 +00002615 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002616 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002617 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618}
2619
2620/*
2621 * a SETCLIENTID request
2622 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002623static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2624 struct xdr_stream *xdr,
2625 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002628 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 };
2630
Chuck Lever9f06c712010-12-14 14:59:18 +00002631 encode_compound_hdr(xdr, req, &hdr);
2632 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002633 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634}
2635
2636/*
2637 * a SETCLIENTID_CONFIRM request
2638 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002639static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2640 struct xdr_stream *xdr,
2641 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002644 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646
Chuck Lever9f06c712010-12-14 14:59:18 +00002647 encode_compound_hdr(xdr, req, &hdr);
2648 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002649 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650}
2651
2652/*
2653 * DELEGRETURN request
2654 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002655static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2656 struct xdr_stream *xdr,
2657 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002660 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662
Chuck Lever9f06c712010-12-14 14:59:18 +00002663 encode_compound_hdr(xdr, req, &hdr);
2664 encode_sequence(xdr, &args->seq_args, &hdr);
2665 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002666 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002667 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002668 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669}
2670
2671/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002672 * Encode FS_LOCATIONS request
2673 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002674static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2675 struct xdr_stream *xdr,
2676 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002677{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002678 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002679 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002680 };
Benny Halevy28f56692009-04-01 09:22:09 -04002681 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002682
Chuck Lever9f06c712010-12-14 14:59:18 +00002683 encode_compound_hdr(xdr, req, &hdr);
2684 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002685 if (args->migration) {
2686 encode_putfh(xdr, args->fh, &hdr);
2687 replen = hdr.replen;
2688 encode_fs_locations(xdr, args->bitmask, &hdr);
2689 if (args->renew)
2690 encode_renew(xdr, args->clientid, &hdr);
2691 } else {
2692 encode_putfh(xdr, args->dir_fh, &hdr);
2693 encode_lookup(xdr, args->name, &hdr);
2694 replen = hdr.replen;
2695 encode_fs_locations(xdr, args->bitmask, &hdr);
2696 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002697
Chuck Leverb03d7352013-10-17 14:12:50 -04002698 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002699 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002700 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002701 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002702}
2703
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002704/*
2705 * Encode SECINFO request
2706 */
2707static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2708 struct xdr_stream *xdr,
2709 struct nfs4_secinfo_arg *args)
2710{
2711 struct compound_hdr hdr = {
2712 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2713 };
2714
2715 encode_compound_hdr(xdr, req, &hdr);
2716 encode_sequence(xdr, &args->seq_args, &hdr);
2717 encode_putfh(xdr, args->dir_fh, &hdr);
2718 encode_secinfo(xdr, args->name, &hdr);
2719 encode_nops(&hdr);
2720}
2721
Chuck Lever44c99932013-10-17 14:13:30 -04002722/*
2723 * Encode FSID_PRESENT request
2724 */
2725static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2726 struct xdr_stream *xdr,
2727 struct nfs4_fsid_present_arg *args)
2728{
2729 struct compound_hdr hdr = {
2730 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2731 };
2732
2733 encode_compound_hdr(xdr, req, &hdr);
2734 encode_sequence(xdr, &args->seq_args, &hdr);
2735 encode_putfh(xdr, args->fh, &hdr);
2736 encode_getfh(xdr, &hdr);
2737 if (args->renew)
2738 encode_renew(xdr, args->clientid, &hdr);
2739 encode_nops(&hdr);
2740}
2741
Benny Halevy99fe60d2009-04-01 09:22:29 -04002742#if defined(CONFIG_NFS_V4_1)
2743/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002744 * BIND_CONN_TO_SESSION request
2745 */
2746static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2747 struct xdr_stream *xdr,
2748 struct nfs_client *clp)
2749{
2750 struct compound_hdr hdr = {
2751 .minorversion = clp->cl_mvops->minor_version,
2752 };
2753
2754 encode_compound_hdr(xdr, req, &hdr);
2755 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2756 encode_nops(&hdr);
2757}
2758
2759/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002760 * EXCHANGE_ID request
2761 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002762static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2763 struct xdr_stream *xdr,
2764 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002765{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002766 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002767 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002768 };
2769
Chuck Lever9f06c712010-12-14 14:59:18 +00002770 encode_compound_hdr(xdr, req, &hdr);
2771 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002772 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002773}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002774
2775/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002776 * a CREATE_SESSION request
2777 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002778static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2779 struct xdr_stream *xdr,
2780 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002781{
Andy Adamsonfc931582009-04-01 09:22:31 -04002782 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002783 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002784 };
2785
Chuck Lever9f06c712010-12-14 14:59:18 +00002786 encode_compound_hdr(xdr, req, &hdr);
2787 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002788 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002789}
2790
2791/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002792 * a DESTROY_SESSION request
2793 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002794static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2795 struct xdr_stream *xdr,
2796 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002797{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002798 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002799 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002800 };
2801
Chuck Lever9f06c712010-12-14 14:59:18 +00002802 encode_compound_hdr(xdr, req, &hdr);
2803 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002804 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002805}
2806
2807/*
Trond Myklebust66245532012-05-25 17:18:09 -04002808 * a DESTROY_CLIENTID request
2809 */
2810static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2811 struct xdr_stream *xdr,
2812 struct nfs_client *clp)
2813{
2814 struct compound_hdr hdr = {
2815 .minorversion = clp->cl_mvops->minor_version,
2816 };
2817
2818 encode_compound_hdr(xdr, req, &hdr);
2819 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2820 encode_nops(&hdr);
2821}
2822
2823/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002824 * a SEQUENCE request
2825 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002826static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2827 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002828{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002829 struct compound_hdr hdr = {
2830 .minorversion = nfs4_xdr_minorversion(args),
2831 };
2832
Chuck Lever9f06c712010-12-14 14:59:18 +00002833 encode_compound_hdr(xdr, req, &hdr);
2834 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002835 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002836}
2837
2838/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002839 * a GET_LEASE_TIME request
2840 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002841static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2842 struct xdr_stream *xdr,
2843 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002844{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002845 struct compound_hdr hdr = {
2846 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2847 };
Fred Isamandae100c2011-07-30 20:52:37 -04002848 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002849
Chuck Lever9f06c712010-12-14 14:59:18 +00002850 encode_compound_hdr(xdr, req, &hdr);
2851 encode_sequence(xdr, &args->la_seq_args, &hdr);
2852 encode_putrootfh(xdr, &hdr);
2853 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002854 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002855}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002856
2857/*
2858 * a RECLAIM_COMPLETE request
2859 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002860static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2861 struct xdr_stream *xdr,
2862 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002863{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002864 struct compound_hdr hdr = {
2865 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2866 };
2867
Chuck Lever9f06c712010-12-14 14:59:18 +00002868 encode_compound_hdr(xdr, req, &hdr);
2869 encode_sequence(xdr, &args->seq_args, &hdr);
2870 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002871 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002872}
2873
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002874/*
2875 * Encode GETDEVICEINFO request
2876 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002877static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2878 struct xdr_stream *xdr,
2879 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002880{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002881 struct compound_hdr hdr = {
2882 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2883 };
2884
Chuck Lever9f06c712010-12-14 14:59:18 +00002885 encode_compound_hdr(xdr, req, &hdr);
2886 encode_sequence(xdr, &args->seq_args, &hdr);
2887 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002888
2889 /* set up reply kvec. Subtract notification bitmap max size (2)
2890 * so that notification bitmap is put in xdr_buf tail */
2891 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2892 args->pdev->pages, args->pdev->pgbase,
2893 args->pdev->pglen);
2894
2895 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002896}
2897
2898/*
2899 * Encode LAYOUTGET request
2900 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002901static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2902 struct xdr_stream *xdr,
2903 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002904{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002905 struct compound_hdr hdr = {
2906 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2907 };
2908
Chuck Lever9f06c712010-12-14 14:59:18 +00002909 encode_compound_hdr(xdr, req, &hdr);
2910 encode_sequence(xdr, &args->seq_args, &hdr);
2911 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2912 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002913
2914 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2915 args->layout.pages, 0, args->layout.pglen);
2916
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002917 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002918}
Andy Adamson863a3c62011-03-23 13:27:54 +00002919
2920/*
2921 * Encode LAYOUTCOMMIT request
2922 */
Benny Halevycbe82602011-05-22 19:52:37 +03002923static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2924 struct xdr_stream *xdr,
2925 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002926{
Benny Halevyac7db722011-05-22 19:53:48 +03002927 struct nfs4_layoutcommit_data *data =
2928 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002929 struct compound_hdr hdr = {
2930 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2931 };
2932
2933 encode_compound_hdr(xdr, req, &hdr);
2934 encode_sequence(xdr, &args->seq_args, &hdr);
2935 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002936 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002937 encode_getfattr(xdr, args->bitmask, &hdr);
2938 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002939}
2940
2941/*
2942 * Encode LAYOUTRETURN request
2943 */
2944static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2945 struct xdr_stream *xdr,
2946 struct nfs4_layoutreturn_args *args)
2947{
2948 struct compound_hdr hdr = {
2949 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2950 };
2951
2952 encode_compound_hdr(xdr, req, &hdr);
2953 encode_sequence(xdr, &args->seq_args, &hdr);
2954 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2955 encode_layoutreturn(xdr, args, &hdr);
2956 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002957}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002958
2959/*
2960 * Encode SECINFO_NO_NAME request
2961 */
2962static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2963 struct xdr_stream *xdr,
2964 struct nfs41_secinfo_no_name_args *args)
2965{
2966 struct compound_hdr hdr = {
2967 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2968 };
2969
2970 encode_compound_hdr(xdr, req, &hdr);
2971 encode_sequence(xdr, &args->seq_args, &hdr);
2972 encode_putrootfh(xdr, &hdr);
2973 encode_secinfo_no_name(xdr, args, &hdr);
2974 encode_nops(&hdr);
2975 return 0;
2976}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002977
2978/*
2979 * Encode TEST_STATEID request
2980 */
2981static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2982 struct xdr_stream *xdr,
2983 struct nfs41_test_stateid_args *args)
2984{
2985 struct compound_hdr hdr = {
2986 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2987 };
2988
2989 encode_compound_hdr(xdr, req, &hdr);
2990 encode_sequence(xdr, &args->seq_args, &hdr);
2991 encode_test_stateid(xdr, args, &hdr);
2992 encode_nops(&hdr);
2993}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002994
2995/*
2996 * Encode FREE_STATEID request
2997 */
2998static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2999 struct xdr_stream *xdr,
3000 struct nfs41_free_stateid_args *args)
3001{
3002 struct compound_hdr hdr = {
3003 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3004 };
3005
3006 encode_compound_hdr(xdr, req, &hdr);
3007 encode_sequence(xdr, &args->seq_args, &hdr);
3008 encode_free_stateid(xdr, args, &hdr);
3009 encode_nops(&hdr);
3010}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003011#endif /* CONFIG_NFS_V4_1 */
3012
Benny Halevy686841b2009-08-14 17:19:48 +03003013static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3014{
3015 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3016 "Remaining buffer length is %tu words.\n",
3017 func, xdr->end - xdr->p);
3018}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019
Trond Myklebust683b57b2006-06-09 09:34:22 -04003020static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021{
Al Viro8687b632006-10-19 23:28:48 -07003022 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023
Benny Halevyc0eae662009-08-14 17:20:14 +03003024 p = xdr_inline_decode(xdr, 4);
3025 if (unlikely(!p))
3026 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003027 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003028 p = xdr_inline_decode(xdr, *len);
3029 if (unlikely(!p))
3030 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 *string = (char *)p;
3032 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003033out_overflow:
3034 print_overflow_msg(__func__, xdr);
3035 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036}
3037
3038static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3039{
Al Viro8687b632006-10-19 23:28:48 -07003040 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041
Benny Halevyc0eae662009-08-14 17:20:14 +03003042 p = xdr_inline_decode(xdr, 8);
3043 if (unlikely(!p))
3044 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003045 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003046 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003047
Benny Halevyc0eae662009-08-14 17:20:14 +03003048 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3049 if (unlikely(!p))
3050 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 hdr->tag = (char *)p;
3052 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003053 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003054 if (unlikely(hdr->nops < 1))
3055 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003057out_overflow:
3058 print_overflow_msg(__func__, xdr);
3059 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060}
3061
Trond Myklebustc7848f62013-12-04 17:39:23 -05003062static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3063 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064{
Al Viro8687b632006-10-19 23:28:48 -07003065 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 uint32_t opnum;
3067 int32_t nfserr;
3068
Benny Halevyc0eae662009-08-14 17:20:14 +03003069 p = xdr_inline_decode(xdr, 8);
3070 if (unlikely(!p))
3071 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003072 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003073 if (unlikely(opnum != expected))
3074 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003075 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003076 if (nfserr == NFS_OK)
3077 *nfs_retval = 0;
3078 else
3079 *nfs_retval = nfs4_stat_to_errno(nfserr);
3080 return true;
3081out_bad_operation:
3082 dprintk("nfs: Server returned operation"
3083 " %d but we issued a request for %d\n",
3084 opnum, expected);
3085 *nfs_retval = -EREMOTEIO;
3086 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003087out_overflow:
3088 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003089 *nfs_retval = -EIO;
3090 return false;
3091}
3092
3093static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3094{
3095 int retval;
3096
3097 __decode_op_hdr(xdr, expected, &retval);
3098 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099}
3100
3101/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003102static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103{
Al Viro8687b632006-10-19 23:28:48 -07003104 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003105 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 char *str;
3107
Benny Halevyc0eae662009-08-14 17:20:14 +03003108 p = xdr_inline_decode(xdr, 12);
3109 if (likely(p))
3110 return decode_opaque_inline(xdr, &strlen, &str);
3111 print_overflow_msg(__func__, xdr);
3112 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113}
3114
3115static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3116{
Al Viro8687b632006-10-19 23:28:48 -07003117 uint32_t bmlen;
3118 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119
Benny Halevyc0eae662009-08-14 17:20:14 +03003120 p = xdr_inline_decode(xdr, 4);
3121 if (unlikely(!p))
3122 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003123 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124
Fred Isamandae100c2011-07-30 20:52:37 -04003125 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003126 p = xdr_inline_decode(xdr, (bmlen << 2));
3127 if (unlikely(!p))
3128 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003130 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003131 if (bmlen > 1) {
3132 bitmap[1] = be32_to_cpup(p++);
3133 if (bmlen > 2)
3134 bitmap[2] = be32_to_cpup(p);
3135 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 }
3137 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003138out_overflow:
3139 print_overflow_msg(__func__, xdr);
3140 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141}
3142
Trond Myklebust256e48b2012-06-21 11:18:13 -04003143static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144{
Al Viro8687b632006-10-19 23:28:48 -07003145 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146
Benny Halevyc0eae662009-08-14 17:20:14 +03003147 p = xdr_inline_decode(xdr, 4);
3148 if (unlikely(!p))
3149 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003150 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003151 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 return 0;
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
3158static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3159{
3160 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003161 int ret;
3162 ret = decode_attr_bitmap(xdr, bitmask);
3163 if (unlikely(ret < 0))
3164 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3166 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003167 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3168 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3169 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 return 0;
3171}
3172
3173static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3174{
Al Viro8687b632006-10-19 23:28:48 -07003175 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003176 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177
3178 *type = 0;
3179 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3180 return -EIO;
3181 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003182 p = xdr_inline_decode(xdr, 4);
3183 if (unlikely(!p))
3184 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003185 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003187 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 return -EIO;
3189 }
3190 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003191 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003193 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003194 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003195out_overflow:
3196 print_overflow_msg(__func__, xdr);
3197 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198}
3199
Chuck Lever264e6352012-03-01 17:02:05 -05003200static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3201 uint32_t *bitmap, uint32_t *type)
3202{
3203 __be32 *p;
3204
3205 *type = 0;
3206 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3207 return -EIO;
3208 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3209 p = xdr_inline_decode(xdr, 4);
3210 if (unlikely(!p))
3211 goto out_overflow;
3212 *type = be32_to_cpup(p);
3213 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3214 }
3215 dprintk("%s: expire type=0x%x\n", __func__, *type);
3216 return 0;
3217out_overflow:
3218 print_overflow_msg(__func__, xdr);
3219 return -EIO;
3220}
3221
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3223{
Al Viro8687b632006-10-19 23:28:48 -07003224 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003225 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226
3227 *change = 0;
3228 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3229 return -EIO;
3230 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003231 p = xdr_inline_decode(xdr, 8);
3232 if (unlikely(!p))
3233 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003234 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003236 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003238 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003240 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003241out_overflow:
3242 print_overflow_msg(__func__, xdr);
3243 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244}
3245
3246static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3247{
Al Viro8687b632006-10-19 23:28:48 -07003248 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003249 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250
3251 *size = 0;
3252 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3253 return -EIO;
3254 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003255 p = xdr_inline_decode(xdr, 8);
3256 if (unlikely(!p))
3257 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003258 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003260 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003262 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003263 return ret;
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
3269static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3270{
Al Viro8687b632006-10-19 23:28:48 -07003271 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272
3273 *res = 0;
3274 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3275 return -EIO;
3276 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003277 p = xdr_inline_decode(xdr, 4);
3278 if (unlikely(!p))
3279 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003280 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3282 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003283 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003285out_overflow:
3286 print_overflow_msg(__func__, xdr);
3287 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288}
3289
3290static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3291{
Al Viro8687b632006-10-19 23:28:48 -07003292 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293
3294 *res = 0;
3295 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3296 return -EIO;
3297 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003298 p = xdr_inline_decode(xdr, 4);
3299 if (unlikely(!p))
3300 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003301 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3303 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003304 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003306out_overflow:
3307 print_overflow_msg(__func__, xdr);
3308 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309}
3310
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003311static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312{
Al Viro8687b632006-10-19 23:28:48 -07003313 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003314 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315
3316 fsid->major = 0;
3317 fsid->minor = 0;
3318 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3319 return -EIO;
3320 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003321 p = xdr_inline_decode(xdr, 16);
3322 if (unlikely(!p))
3323 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003324 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003325 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003327 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003329 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 (unsigned long long)fsid->major,
3331 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003332 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003333out_overflow:
3334 print_overflow_msg(__func__, xdr);
3335 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336}
3337
3338static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3339{
Al Viro8687b632006-10-19 23:28:48 -07003340 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341
3342 *res = 60;
3343 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3344 return -EIO;
3345 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003346 p = xdr_inline_decode(xdr, 4);
3347 if (unlikely(!p))
3348 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003349 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3351 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003352 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003354out_overflow:
3355 print_overflow_msg(__func__, xdr);
3356 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357}
3358
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003359static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003360{
3361 __be32 *p;
3362
3363 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3364 return -EIO;
3365 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3366 p = xdr_inline_decode(xdr, 4);
3367 if (unlikely(!p))
3368 goto out_overflow;
3369 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003370 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003371 }
3372 return 0;
3373out_overflow:
3374 print_overflow_msg(__func__, xdr);
3375 return -EIO;
3376}
3377
3378static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3379{
3380 __be32 *p;
3381 int len;
3382
Trond Myklebust7ad07352010-10-23 15:34:20 -04003383 if (fh != NULL)
3384 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003385
3386 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3387 return -EIO;
3388 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3389 p = xdr_inline_decode(xdr, 4);
3390 if (unlikely(!p))
3391 goto out_overflow;
3392 len = be32_to_cpup(p);
3393 if (len > NFS4_FHSIZE)
3394 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003395 p = xdr_inline_decode(xdr, len);
3396 if (unlikely(!p))
3397 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003398 if (fh != NULL) {
3399 memcpy(fh->data, p, len);
3400 fh->size = len;
3401 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003402 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3403 }
3404 return 0;
3405out_overflow:
3406 print_overflow_msg(__func__, xdr);
3407 return -EIO;
3408}
3409
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3411{
Al Viro8687b632006-10-19 23:28:48 -07003412 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003414 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3416 return -EIO;
3417 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003418 p = xdr_inline_decode(xdr, 4);
3419 if (unlikely(!p))
3420 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003421 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3423 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003424 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003426out_overflow:
3427 print_overflow_msg(__func__, xdr);
3428 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429}
3430
3431static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3432{
Al Viro8687b632006-10-19 23:28:48 -07003433 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003434 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435
3436 *fileid = 0;
3437 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3438 return -EIO;
3439 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003440 p = xdr_inline_decode(xdr, 8);
3441 if (unlikely(!p))
3442 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003443 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003445 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003447 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003448 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003449out_overflow:
3450 print_overflow_msg(__func__, xdr);
3451 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452}
3453
Manoj Naik99baf622006-06-09 09:34:24 -04003454static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3455{
Al Viro8687b632006-10-19 23:28:48 -07003456 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003457 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003458
3459 *fileid = 0;
3460 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3461 return -EIO;
3462 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003463 p = xdr_inline_decode(xdr, 8);
3464 if (unlikely(!p))
3465 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003466 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003467 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003468 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003469 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003470 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003471 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003472out_overflow:
3473 print_overflow_msg(__func__, xdr);
3474 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003475}
3476
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3478{
Al Viro8687b632006-10-19 23:28:48 -07003479 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 int status = 0;
3481
3482 *res = 0;
3483 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3484 return -EIO;
3485 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003486 p = xdr_inline_decode(xdr, 8);
3487 if (unlikely(!p))
3488 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003489 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3491 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003492 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003494out_overflow:
3495 print_overflow_msg(__func__, xdr);
3496 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497}
3498
3499static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3500{
Al Viro8687b632006-10-19 23:28:48 -07003501 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502 int status = 0;
3503
3504 *res = 0;
3505 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3506 return -EIO;
3507 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003508 p = xdr_inline_decode(xdr, 8);
3509 if (unlikely(!p))
3510 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003511 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3513 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003514 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003516out_overflow:
3517 print_overflow_msg(__func__, xdr);
3518 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519}
3520
3521static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3522{
Al Viro8687b632006-10-19 23:28:48 -07003523 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524 int status = 0;
3525
3526 *res = 0;
3527 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3528 return -EIO;
3529 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003530 p = xdr_inline_decode(xdr, 8);
3531 if (unlikely(!p))
3532 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003533 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3535 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003536 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003538out_overflow:
3539 print_overflow_msg(__func__, xdr);
3540 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541}
3542
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003543static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3544{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003545 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003546 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003547 int status = 0;
3548
Benny Halevyc0eae662009-08-14 17:20:14 +03003549 p = xdr_inline_decode(xdr, 4);
3550 if (unlikely(!p))
3551 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003552 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003553 if (n == 0)
3554 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003555 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003556 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3557 dprintk("cannot parse %d components in path\n", n);
3558 goto out_eio;
3559 }
3560 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003561 struct nfs4_string *component = &path->components[path->ncomponents];
3562 status = decode_opaque_inline(xdr, &component->len, &component->data);
3563 if (unlikely(status != 0))
3564 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003565 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003566 pr_cont("%s%.*s ",
3567 (path->ncomponents != n ? "/ " : ""),
3568 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003569 }
3570out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003571 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003572root_path:
3573/* a root pathname is sent as a zero component4 */
3574 path->ncomponents = 1;
3575 path->components[0].len=0;
3576 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003577 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003578 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003579out_eio:
3580 dprintk(" status %d", status);
3581 status = -EIO;
3582 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003583out_overflow:
3584 print_overflow_msg(__func__, xdr);
3585 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003586}
3587
3588static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003589{
3590 int n;
Al Viro8687b632006-10-19 23:28:48 -07003591 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003592 int status = -EIO;
3593
3594 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3595 goto out;
3596 status = 0;
3597 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3598 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003599 status = -EIO;
3600 /* Ignore borken servers that return unrequested attrs */
3601 if (unlikely(res == NULL))
3602 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003603 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003604 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003605 if (unlikely(status != 0))
3606 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003607 p = xdr_inline_decode(xdr, 4);
3608 if (unlikely(!p))
3609 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003610 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003611 if (n <= 0)
3612 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003613 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003614 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003615 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003616
Trond Myklebust809b4262013-03-27 11:54:45 -04003617 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3618 break;
3619 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003620 p = xdr_inline_decode(xdr, 4);
3621 if (unlikely(!p))
3622 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003623 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003624
Chuck Lever02a29762012-03-01 17:00:31 -05003625 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003626 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3627 struct nfs4_string *server;
3628
3629 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003630 unsigned int i;
3631 dprintk("%s: using first %u of %u servers "
3632 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003633 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003634 NFS4_FS_LOCATION_MAXSERVERS,
3635 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003636 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003637 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003638 char *data;
3639 status = decode_opaque_inline(xdr, &len, &data);
3640 if (unlikely(status != 0))
3641 goto out_eio;
3642 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003643 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003644 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003645 server = &loc->servers[loc->nservers];
3646 status = decode_opaque_inline(xdr, &server->len, &server->data);
3647 if (unlikely(status != 0))
3648 goto out_eio;
3649 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003650 }
3651 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003652 if (unlikely(status != 0))
3653 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003654 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003655 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003656 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003657out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003658 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003659 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003660out_overflow:
3661 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003662out_eio:
3663 status = -EIO;
3664 goto out;
3665}
3666
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3668{
Al Viro8687b632006-10-19 23:28:48 -07003669 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 int status = 0;
3671
3672 *res = 0;
3673 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3674 return -EIO;
3675 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003676 p = xdr_inline_decode(xdr, 8);
3677 if (unlikely(!p))
3678 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003679 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3681 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003682 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003684out_overflow:
3685 print_overflow_msg(__func__, xdr);
3686 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687}
3688
3689static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3690{
Al Viro8687b632006-10-19 23:28:48 -07003691 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 int status = 0;
3693
3694 *maxlink = 1;
3695 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3696 return -EIO;
3697 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003698 p = xdr_inline_decode(xdr, 4);
3699 if (unlikely(!p))
3700 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003701 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3703 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003704 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003706out_overflow:
3707 print_overflow_msg(__func__, xdr);
3708 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709}
3710
3711static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3712{
Al Viro8687b632006-10-19 23:28:48 -07003713 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 int status = 0;
3715
3716 *maxname = 1024;
3717 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3718 return -EIO;
3719 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003720 p = xdr_inline_decode(xdr, 4);
3721 if (unlikely(!p))
3722 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003723 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3725 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003726 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003728out_overflow:
3729 print_overflow_msg(__func__, xdr);
3730 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731}
3732
3733static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3734{
Al Viro8687b632006-10-19 23:28:48 -07003735 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 int status = 0;
3737
3738 *res = 1024;
3739 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3740 return -EIO;
3741 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3742 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003743 p = xdr_inline_decode(xdr, 8);
3744 if (unlikely(!p))
3745 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003746 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747 if (maxread > 0x7FFFFFFF)
3748 maxread = 0x7FFFFFFF;
3749 *res = (uint32_t)maxread;
3750 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3751 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003752 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003754out_overflow:
3755 print_overflow_msg(__func__, xdr);
3756 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757}
3758
3759static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3760{
Al Viro8687b632006-10-19 23:28:48 -07003761 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762 int status = 0;
3763
3764 *res = 1024;
3765 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3766 return -EIO;
3767 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3768 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003769 p = xdr_inline_decode(xdr, 8);
3770 if (unlikely(!p))
3771 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003772 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773 if (maxwrite > 0x7FFFFFFF)
3774 maxwrite = 0x7FFFFFFF;
3775 *res = (uint32_t)maxwrite;
3776 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3777 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003778 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003780out_overflow:
3781 print_overflow_msg(__func__, xdr);
3782 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783}
3784
Trond Myklebustbca79472009-03-11 14:10:26 -04003785static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786{
Trond Myklebustbca79472009-03-11 14:10:26 -04003787 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003788 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003789 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790
3791 *mode = 0;
3792 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3793 return -EIO;
3794 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003795 p = xdr_inline_decode(xdr, 4);
3796 if (unlikely(!p))
3797 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003798 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003799 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003801 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003803 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003804 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003805out_overflow:
3806 print_overflow_msg(__func__, xdr);
3807 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808}
3809
3810static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3811{
Al Viro8687b632006-10-19 23:28:48 -07003812 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003813 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814
3815 *nlink = 1;
3816 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3817 return -EIO;
3818 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003819 p = xdr_inline_decode(xdr, 4);
3820 if (unlikely(!p))
3821 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003822 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003824 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003826 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003827 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003828out_overflow:
3829 print_overflow_msg(__func__, xdr);
3830 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831}
3832
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003833static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003834 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003835 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836{
Al Viro8687b632006-10-19 23:28:48 -07003837 uint32_t len;
3838 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003839 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840
Eric W. Biedermane5782072013-02-01 14:22:02 -08003841 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3843 return -EIO;
3844 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003845 p = xdr_inline_decode(xdr, 4);
3846 if (unlikely(!p))
3847 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003848 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003849 p = xdr_inline_decode(xdr, len);
3850 if (unlikely(!p))
3851 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003852 if (owner_name != NULL) {
3853 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3854 if (owner_name->data != NULL) {
3855 owner_name->len = len;
3856 ret = NFS_ATTR_FATTR_OWNER_NAME;
3857 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003858 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003859 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003860 ret = NFS_ATTR_FATTR_OWNER;
3861 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003863 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003865 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003866 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3868 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003869 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003870 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003871out_overflow:
3872 print_overflow_msg(__func__, xdr);
3873 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874}
3875
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003876static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003877 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003878 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879{
Al Viro8687b632006-10-19 23:28:48 -07003880 uint32_t len;
3881 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003882 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883
Eric W. Biedermane5782072013-02-01 14:22:02 -08003884 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3886 return -EIO;
3887 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003888 p = xdr_inline_decode(xdr, 4);
3889 if (unlikely(!p))
3890 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003891 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003892 p = xdr_inline_decode(xdr, len);
3893 if (unlikely(!p))
3894 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003895 if (group_name != NULL) {
3896 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3897 if (group_name->data != NULL) {
3898 group_name->len = len;
3899 ret = NFS_ATTR_FATTR_GROUP_NAME;
3900 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003901 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003902 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003903 ret = NFS_ATTR_FATTR_GROUP;
3904 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003906 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003908 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003909 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3911 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003912 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003913 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003914out_overflow:
3915 print_overflow_msg(__func__, xdr);
3916 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917}
3918
3919static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3920{
Al Viro8687b632006-10-19 23:28:48 -07003921 uint32_t major = 0, minor = 0;
3922 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003923 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924
3925 *rdev = MKDEV(0,0);
3926 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3927 return -EIO;
3928 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3929 dev_t tmp;
3930
Benny Halevyc0eae662009-08-14 17:20:14 +03003931 p = xdr_inline_decode(xdr, 8);
3932 if (unlikely(!p))
3933 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003934 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003935 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 tmp = MKDEV(major, minor);
3937 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3938 *rdev = tmp;
3939 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003940 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003942 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003943 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003944out_overflow:
3945 print_overflow_msg(__func__, xdr);
3946 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947}
3948
3949static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3950{
Al Viro8687b632006-10-19 23:28:48 -07003951 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 int status = 0;
3953
3954 *res = 0;
3955 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3956 return -EIO;
3957 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003958 p = xdr_inline_decode(xdr, 8);
3959 if (unlikely(!p))
3960 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003961 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3963 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003964 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003966out_overflow:
3967 print_overflow_msg(__func__, xdr);
3968 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969}
3970
3971static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3972{
Al Viro8687b632006-10-19 23:28:48 -07003973 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974 int status = 0;
3975
3976 *res = 0;
3977 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3978 return -EIO;
3979 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003980 p = xdr_inline_decode(xdr, 8);
3981 if (unlikely(!p))
3982 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003983 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3985 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003986 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003988out_overflow:
3989 print_overflow_msg(__func__, xdr);
3990 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991}
3992
3993static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3994{
Al Viro8687b632006-10-19 23:28:48 -07003995 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 int status = 0;
3997
3998 *res = 0;
3999 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4000 return -EIO;
4001 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004002 p = xdr_inline_decode(xdr, 8);
4003 if (unlikely(!p))
4004 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004005 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4007 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004008 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004010out_overflow:
4011 print_overflow_msg(__func__, xdr);
4012 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013}
4014
4015static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4016{
Al Viro8687b632006-10-19 23:28:48 -07004017 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004018 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019
4020 *used = 0;
4021 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4022 return -EIO;
4023 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004024 p = xdr_inline_decode(xdr, 8);
4025 if (unlikely(!p))
4026 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004027 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004029 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004031 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004033 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004034out_overflow:
4035 print_overflow_msg(__func__, xdr);
4036 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037}
4038
4039static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4040{
Al Viro8687b632006-10-19 23:28:48 -07004041 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 uint64_t sec;
4043 uint32_t nsec;
4044
Benny Halevyc0eae662009-08-14 17:20:14 +03004045 p = xdr_inline_decode(xdr, 12);
4046 if (unlikely(!p))
4047 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004048 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004049 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 time->tv_sec = (time_t)sec;
4051 time->tv_nsec = (long)nsec;
4052 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004053out_overflow:
4054 print_overflow_msg(__func__, xdr);
4055 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056}
4057
4058static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4059{
4060 int status = 0;
4061
4062 time->tv_sec = 0;
4063 time->tv_nsec = 0;
4064 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4065 return -EIO;
4066 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4067 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004068 if (status == 0)
4069 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4071 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004072 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 return status;
4074}
4075
4076static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4077{
4078 int status = 0;
4079
4080 time->tv_sec = 0;
4081 time->tv_nsec = 0;
4082 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4083 return -EIO;
4084 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4085 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004086 if (status == 0)
4087 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4089 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004090 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 return status;
4092}
4093
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004094static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4095 struct timespec *time)
4096{
4097 int status = 0;
4098
4099 time->tv_sec = 0;
4100 time->tv_nsec = 0;
4101 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4102 return -EIO;
4103 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4104 status = decode_attr_time(xdr, time);
4105 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4106 }
4107 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4108 (long)time->tv_nsec);
4109 return status;
4110}
4111
David Quigleyaa9c2662013-05-22 12:50:44 -04004112static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4113 struct nfs4_label *label)
4114{
4115 uint32_t pi = 0;
4116 uint32_t lfs = 0;
4117 __u32 len;
4118 __be32 *p;
4119 int status = 0;
4120
4121 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4122 return -EIO;
4123 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4124 p = xdr_inline_decode(xdr, 4);
4125 if (unlikely(!p))
4126 goto out_overflow;
4127 lfs = be32_to_cpup(p++);
4128 p = xdr_inline_decode(xdr, 4);
4129 if (unlikely(!p))
4130 goto out_overflow;
4131 pi = be32_to_cpup(p++);
4132 p = xdr_inline_decode(xdr, 4);
4133 if (unlikely(!p))
4134 goto out_overflow;
4135 len = be32_to_cpup(p++);
4136 p = xdr_inline_decode(xdr, len);
4137 if (unlikely(!p))
4138 goto out_overflow;
4139 if (len < NFS4_MAXLABELLEN) {
4140 if (label) {
4141 memcpy(label->label, p, len);
4142 label->len = len;
4143 label->pi = pi;
4144 label->lfs = lfs;
4145 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4146 }
4147 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4148 } else
4149 printk(KERN_WARNING "%s: label too long (%u)!\n",
4150 __func__, len);
4151 }
4152 if (label && label->label)
4153 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4154 (char *)label->label, label->len, label->pi, label->lfs);
4155 return status;
4156
4157out_overflow:
4158 print_overflow_msg(__func__, xdr);
4159 return -EIO;
4160}
4161
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4163{
4164 int status = 0;
4165
4166 time->tv_sec = 0;
4167 time->tv_nsec = 0;
4168 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4169 return -EIO;
4170 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4171 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004172 if (status == 0)
4173 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4175 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004176 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177 return status;
4178}
4179
Trond Myklebust256e48b2012-06-21 11:18:13 -04004180static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181{
4182 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004183 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184
4185 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004186 dprintk("%s: server returned incorrect attribute length: "
4187 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004188 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189 attrwords << 2,
4190 (attrwords < nwords) ? '<' : '>',
4191 nwords << 2);
4192 return -EIO;
4193 }
4194 return 0;
4195}
4196
4197static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4198{
Al Viro8687b632006-10-19 23:28:48 -07004199 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200
Benny Halevyc0eae662009-08-14 17:20:14 +03004201 p = xdr_inline_decode(xdr, 20);
4202 if (unlikely(!p))
4203 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004204 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004205 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004206 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004208out_overflow:
4209 print_overflow_msg(__func__, xdr);
4210 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211}
4212
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004213static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214{
Al Viro8687b632006-10-19 23:28:48 -07004215 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216 uint32_t supp, acc;
4217 int status;
4218
4219 status = decode_op_hdr(xdr, OP_ACCESS);
4220 if (status)
4221 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004222 p = xdr_inline_decode(xdr, 8);
4223 if (unlikely(!p))
4224 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004225 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004226 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004227 *supported = supp;
4228 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004230out_overflow:
4231 print_overflow_msg(__func__, xdr);
4232 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233}
4234
Benny Halevy07d30432009-08-14 17:19:52 +03004235static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004236{
Al Viro8687b632006-10-19 23:28:48 -07004237 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004238
4239 p = xdr_inline_decode(xdr, len);
4240 if (likely(p)) {
4241 memcpy(buf, p, len);
4242 return 0;
4243 }
4244 print_overflow_msg(__func__, xdr);
4245 return -EIO;
4246}
4247
4248static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4249{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004250 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004251}
4252
4253static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4254{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004255 int status;
4256
4257 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004258 if (status != -EIO)
4259 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004260 if (!status)
4261 status = decode_stateid(xdr, &res->stateid);
4262 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263}
4264
Benny Halevydb942bb2009-08-14 17:19:56 +03004265static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4266{
Chuck Levercd937102012-03-02 17:14:31 -05004267 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268}
4269
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004270static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4271{
4272 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4273}
4274
Fred Isaman0b7c0152012-04-20 14:47:39 -04004275static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277 int status;
4278
4279 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004280 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004281 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004282 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283}
4284
4285static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4286{
Al Viro8687b632006-10-19 23:28:48 -07004287 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288 uint32_t bmlen;
4289 int status;
4290
4291 status = decode_op_hdr(xdr, OP_CREATE);
4292 if (status)
4293 return status;
4294 if ((status = decode_change_info(xdr, cinfo)))
4295 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004296 p = xdr_inline_decode(xdr, 4);
4297 if (unlikely(!p))
4298 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004299 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004300 p = xdr_inline_decode(xdr, bmlen << 2);
4301 if (likely(p))
4302 return 0;
4303out_overflow:
4304 print_overflow_msg(__func__, xdr);
4305 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306}
4307
4308static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4309{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004310 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004311 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312 int status;
4313
4314 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4315 goto xdr_error;
4316 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4317 goto xdr_error;
4318 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4319 goto xdr_error;
4320 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4321 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004322 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4323 &res->fh_expire_type)) != 0)
4324 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4326 goto xdr_error;
4327 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4328 goto xdr_error;
4329 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4330 goto xdr_error;
4331 status = verify_attr_len(xdr, savep, attrlen);
4332xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004333 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334 return status;
4335}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004336
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4338{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004339 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004340 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004341 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004342
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4344 goto xdr_error;
4345 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4346 goto xdr_error;
4347 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4348 goto xdr_error;
4349
4350 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4351 goto xdr_error;
4352 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4353 goto xdr_error;
4354 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4355 goto xdr_error;
4356 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4357 goto xdr_error;
4358 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4359 goto xdr_error;
4360 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4361 goto xdr_error;
4362
4363 status = verify_attr_len(xdr, savep, attrlen);
4364xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004365 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366 return status;
4367}
4368
4369static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4370{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004371 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004372 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004374
Linus Torvalds1da177e2005-04-16 15:20:36 -07004375 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4376 goto xdr_error;
4377 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4378 goto xdr_error;
4379 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4380 goto xdr_error;
4381
4382 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4383 goto xdr_error;
4384 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4385 goto xdr_error;
4386
4387 status = verify_attr_len(xdr, savep, attrlen);
4388xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004389 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390 return status;
4391}
4392
Andy Adamson88034c32012-05-23 05:02:34 -04004393static int decode_threshold_hint(struct xdr_stream *xdr,
4394 uint32_t *bitmap,
4395 uint64_t *res,
4396 uint32_t hint_bit)
4397{
4398 __be32 *p;
4399
4400 *res = 0;
4401 if (likely(bitmap[0] & hint_bit)) {
4402 p = xdr_inline_decode(xdr, 8);
4403 if (unlikely(!p))
4404 goto out_overflow;
4405 xdr_decode_hyper(p, res);
4406 }
4407 return 0;
4408out_overflow:
4409 print_overflow_msg(__func__, xdr);
4410 return -EIO;
4411}
4412
4413static int decode_first_threshold_item4(struct xdr_stream *xdr,
4414 struct nfs4_threshold *res)
4415{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004416 __be32 *p;
4417 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004418 uint32_t bitmap[3] = {0,}, attrlen;
4419 int status;
4420
4421 /* layout type */
4422 p = xdr_inline_decode(xdr, 4);
4423 if (unlikely(!p)) {
4424 print_overflow_msg(__func__, xdr);
4425 return -EIO;
4426 }
4427 res->l_type = be32_to_cpup(p);
4428
4429 /* thi_hintset bitmap */
4430 status = decode_attr_bitmap(xdr, bitmap);
4431 if (status < 0)
4432 goto xdr_error;
4433
4434 /* thi_hintlist length */
4435 status = decode_attr_length(xdr, &attrlen, &savep);
4436 if (status < 0)
4437 goto xdr_error;
4438 /* thi_hintlist */
4439 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4440 if (status < 0)
4441 goto xdr_error;
4442 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4443 if (status < 0)
4444 goto xdr_error;
4445 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4446 THRESHOLD_RD_IO);
4447 if (status < 0)
4448 goto xdr_error;
4449 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4450 THRESHOLD_WR_IO);
4451 if (status < 0)
4452 goto xdr_error;
4453
4454 status = verify_attr_len(xdr, savep, attrlen);
4455 res->bm = bitmap[0];
4456
4457 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4458 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4459 res->wr_io_sz);
4460xdr_error:
4461 dprintk("%s ret=%d!\n", __func__, status);
4462 return status;
4463}
4464
4465/*
4466 * Thresholds on pNFS direct I/O vrs MDS I/O
4467 */
4468static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4469 uint32_t *bitmap,
4470 struct nfs4_threshold *res)
4471{
4472 __be32 *p;
4473 int status = 0;
4474 uint32_t num;
4475
4476 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4477 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004478 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004479 /* Did the server return an unrequested attribute? */
4480 if (unlikely(res == NULL))
4481 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004482 p = xdr_inline_decode(xdr, 4);
4483 if (unlikely(!p))
4484 goto out_overflow;
4485 num = be32_to_cpup(p);
4486 if (num == 0)
4487 return 0;
4488 if (num > 1)
4489 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4490 "drivers per filesystem not supported\n",
4491 __func__);
4492
4493 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004494 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004495 }
4496 return status;
4497out_overflow:
4498 print_overflow_msg(__func__, xdr);
4499 return -EIO;
4500}
4501
Bryan Schumakerae42c702010-10-21 16:33:17 -04004502static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4503 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004504 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004505 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506{
Trond Myklebustbca79472009-03-11 14:10:26 -04004507 int status;
4508 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004509 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004510 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004512 status = decode_attr_type(xdr, bitmap, &type);
4513 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004514 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004515 fattr->mode = 0;
4516 if (status != 0) {
4517 fattr->mode |= nfs_type2fmt[type];
4518 fattr->valid |= status;
4519 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004520
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004521 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
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
4526 status = decode_attr_size(xdr, bitmap, &fattr->size);
4527 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
4531 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4532 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
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004536 err = 0;
4537 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004538 if (status < 0)
4539 goto xdr_error;
4540
4541 status = decode_attr_filehandle(xdr, bitmap, fh);
4542 if (status < 0)
4543 goto xdr_error;
4544
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004545 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4546 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004548 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004549
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004550 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004551 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004552 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004553 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004554
4555 status = decode_attr_mode(xdr, bitmap, &fmode);
4556 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004558 if (status != 0) {
4559 fattr->mode |= fmode;
4560 fattr->valid |= status;
4561 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004562
4563 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4564 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004565 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004566 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004567
Trond Myklebust6926afd2012-01-07 13:22:46 -05004568 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004569 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004571 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004572
Trond Myklebust6926afd2012-01-07 13:22:46 -05004573 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004574 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004575 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004576 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004577
4578 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4579 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004581 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004582
4583 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4584 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004586 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004587
4588 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4589 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004591 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004592
4593 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4594 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004596 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004597
4598 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4599 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004601 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004602
Trond Myklebust28331a42011-04-27 13:47:52 -04004603 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004604 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004605 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004606 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004607
Andy Adamson88034c32012-05-23 05:02:34 -04004608 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4609 if (status < 0)
4610 goto xdr_error;
4611
David Quigleyaa9c2662013-05-22 12:50:44 -04004612 if (label) {
4613 status = decode_attr_security_label(xdr, bitmap, label);
4614 if (status < 0)
4615 goto xdr_error;
4616 fattr->valid |= status;
4617 }
4618
Bryan Schumakerae42c702010-10-21 16:33:17 -04004619xdr_error:
4620 dprintk("%s: xdr returned %d\n", __func__, -status);
4621 return status;
4622}
4623
4624static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004625 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004626 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004627{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004628 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004629 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004630 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004631 int status;
4632
4633 status = decode_op_hdr(xdr, OP_GETATTR);
4634 if (status < 0)
4635 goto xdr_error;
4636
4637 status = decode_attr_bitmap(xdr, bitmap);
4638 if (status < 0)
4639 goto xdr_error;
4640
4641 status = decode_attr_length(xdr, &attrlen, &savep);
4642 if (status < 0)
4643 goto xdr_error;
4644
David Quigleyaa9c2662013-05-22 12:50:44 -04004645 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4646 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004647 if (status < 0)
4648 goto xdr_error;
4649
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004650 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004652 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004653 return status;
4654}
4655
David Quigleyaa9c2662013-05-22 12:50:44 -04004656static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4657 struct nfs4_label *label, const struct nfs_server *server)
4658{
4659 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4660}
4661
Bryan Schumakerae42c702010-10-21 16:33:17 -04004662static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004663 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004664{
David Quigleyaa9c2662013-05-22 12:50:44 -04004665 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004666}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004667
Andy Adamson504913f2010-10-20 00:17:57 -04004668/*
4669 * Decode potentially multiple layout types. Currently we only support
4670 * one layout driver per file system.
4671 */
4672static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4673 uint32_t *layouttype)
4674{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004675 __be32 *p;
Andy Adamson504913f2010-10-20 00:17:57 -04004676 int num;
4677
4678 p = xdr_inline_decode(xdr, 4);
4679 if (unlikely(!p))
4680 goto out_overflow;
4681 num = be32_to_cpup(p);
4682
4683 /* pNFS is not supported by the underlying file system */
4684 if (num == 0) {
4685 *layouttype = 0;
4686 return 0;
4687 }
4688 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004689 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4690 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004691
4692 /* Decode and set first layout type, move xdr->p past unused types */
4693 p = xdr_inline_decode(xdr, num * 4);
4694 if (unlikely(!p))
4695 goto out_overflow;
4696 *layouttype = be32_to_cpup(p);
4697 return 0;
4698out_overflow:
4699 print_overflow_msg(__func__, xdr);
4700 return -EIO;
4701}
4702
4703/*
4704 * The type of file system exported.
4705 * Note we must ensure that layouttype is set in any non-error case.
4706 */
4707static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4708 uint32_t *layouttype)
4709{
4710 int status = 0;
4711
4712 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4713 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4714 return -EIO;
4715 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4716 status = decode_first_pnfs_layout_type(xdr, layouttype);
4717 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4718 } else
4719 *layouttype = 0;
4720 return status;
4721}
4722
Fred Isamandae100c2011-07-30 20:52:37 -04004723/*
4724 * The prefered block size for layout directed io
4725 */
4726static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4727 uint32_t *res)
4728{
4729 __be32 *p;
4730
4731 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4732 *res = 0;
4733 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4734 p = xdr_inline_decode(xdr, 4);
4735 if (unlikely(!p)) {
4736 print_overflow_msg(__func__, xdr);
4737 return -EIO;
4738 }
4739 *res = be32_to_cpup(p);
4740 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4741 }
4742 return 0;
4743}
4744
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4746{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004747 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004748 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 int status;
4750
4751 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4752 goto xdr_error;
4753 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4754 goto xdr_error;
4755 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4756 goto xdr_error;
4757
4758 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4759
4760 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4761 goto xdr_error;
4762 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4763 goto xdr_error;
4764 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4765 goto xdr_error;
4766 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4767 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4768 goto xdr_error;
4769 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004770 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4771 if (status != 0)
4772 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004773 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4774 if (status != 0)
4775 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004776 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4777 if (status)
4778 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004779
4780 status = verify_attr_len(xdr, savep, attrlen);
4781xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004782 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 return status;
4784}
4785
4786static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4787{
Al Viro8687b632006-10-19 23:28:48 -07004788 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789 uint32_t len;
4790 int status;
4791
Trond Myklebust99367812007-07-17 21:52:41 -04004792 /* Zero handle first to allow comparisons */
4793 memset(fh, 0, sizeof(*fh));
4794
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795 status = decode_op_hdr(xdr, OP_GETFH);
4796 if (status)
4797 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798
Benny Halevyc0eae662009-08-14 17:20:14 +03004799 p = xdr_inline_decode(xdr, 4);
4800 if (unlikely(!p))
4801 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004802 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803 if (len > NFS4_FHSIZE)
4804 return -EIO;
4805 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004806 p = xdr_inline_decode(xdr, len);
4807 if (unlikely(!p))
4808 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004809 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004811out_overflow:
4812 print_overflow_msg(__func__, xdr);
4813 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814}
4815
4816static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4817{
4818 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004819
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820 status = decode_op_hdr(xdr, OP_LINK);
4821 if (status)
4822 return status;
4823 return decode_change_info(xdr, cinfo);
4824}
4825
4826/*
4827 * We create the owner, so we know a proper owner.id length is 4.
4828 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004829static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004831 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004832 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004833 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004834
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004835 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004836 if (unlikely(!p))
4837 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004838 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004839 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004840 type = be32_to_cpup(p++); /* 4 byte read */
4841 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004842 fl->fl_start = (loff_t)offset;
4843 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4844 if (length == ~(uint64_t)0)
4845 fl->fl_end = OFFSET_MAX;
4846 fl->fl_type = F_WRLCK;
4847 if (type & 1)
4848 fl->fl_type = F_RDLCK;
4849 fl->fl_pid = 0;
4850 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004851 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4852 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4853 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004854 if (likely(p))
4855 return -NFS4ERR_DENIED;
4856out_overflow:
4857 print_overflow_msg(__func__, xdr);
4858 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004859}
4860
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004861static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863 int status;
4864
4865 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004866 if (status == -EIO)
4867 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004869 status = decode_stateid(xdr, &res->stateid);
4870 if (unlikely(status))
4871 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004873 status = decode_lock_denied(xdr, NULL);
4874 if (res->open_seqid != NULL)
4875 nfs_increment_open_seqid(status, res->open_seqid);
4876 nfs_increment_lock_seqid(status, res->lock_seqid);
4877out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 return status;
4879}
4880
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004881static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882{
4883 int status;
4884 status = decode_op_hdr(xdr, OP_LOCKT);
4885 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004886 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887 return status;
4888}
4889
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004890static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004892 int status;
4893
4894 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004895 if (status != -EIO)
4896 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004897 if (status == 0)
4898 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899 return status;
4900}
4901
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004902static int decode_release_lockowner(struct xdr_stream *xdr)
4903{
4904 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4905}
4906
Linus Torvalds1da177e2005-04-16 15:20:36 -07004907static int decode_lookup(struct xdr_stream *xdr)
4908{
4909 return decode_op_hdr(xdr, OP_LOOKUP);
4910}
4911
4912/* This is too sick! */
4913static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4914{
Andy Adamson05d564f2008-12-23 16:06:15 -05004915 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916 uint32_t limit_type, nblocks, blocksize;
4917
Benny Halevyc0eae662009-08-14 17:20:14 +03004918 p = xdr_inline_decode(xdr, 12);
4919 if (unlikely(!p))
4920 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004921 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004923 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004924 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004925 break;
4926 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004927 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004928 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004929 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930 }
4931 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004932out_overflow:
4933 print_overflow_msg(__func__, xdr);
4934 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935}
4936
4937static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4938{
Andy Adamson05d564f2008-12-23 16:06:15 -05004939 __be32 *p;
4940 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004941 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942
Benny Halevyc0eae662009-08-14 17:20:14 +03004943 p = xdr_inline_decode(xdr, 4);
4944 if (unlikely(!p))
4945 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004946 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4948 res->delegation_type = 0;
4949 return 0;
4950 }
Benny Halevy07d30432009-08-14 17:19:52 +03004951 status = decode_stateid(xdr, &res->delegation);
4952 if (unlikely(status))
4953 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004954 p = xdr_inline_decode(xdr, 4);
4955 if (unlikely(!p))
4956 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004957 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004958
Linus Torvalds1da177e2005-04-16 15:20:36 -07004959 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004960 case NFS4_OPEN_DELEGATE_READ:
4961 res->delegation_type = FMODE_READ;
4962 break;
4963 case NFS4_OPEN_DELEGATE_WRITE:
4964 res->delegation_type = FMODE_WRITE|FMODE_READ;
4965 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004966 return -EIO;
4967 }
David Howells7539bba2006-08-22 20:06:09 -04004968 return decode_ace(xdr, NULL, res->server->nfs_client);
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(struct xdr_stream *xdr, struct nfs_openres *res)
4975{
Andy Adamson05d564f2008-12-23 16:06:15 -05004976 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004977 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004978 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979
Trond Myklebustc7848f62013-12-04 17:39:23 -05004980 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
4981 return status;
4982 nfs_increment_open_seqid(status, res->seqid);
4983 if (status)
4984 return status;
4985 status = decode_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004986 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004987 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988
Andy Adamson05d564f2008-12-23 16:06:15 -05004989 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990
Benny Halevyc0eae662009-08-14 17:20:14 +03004991 p = xdr_inline_decode(xdr, 8);
4992 if (unlikely(!p))
4993 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004994 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004995 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004996 if (bmlen > 10)
4997 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998
Benny Halevyc0eae662009-08-14 17:20:14 +03004999 p = xdr_inline_decode(xdr, bmlen << 2);
5000 if (unlikely(!p))
5001 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005002 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5003 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005004 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005005 for (; i < NFS4_BITMAP_SIZE; i++)
5006 res->attrset[i] = 0;
5007
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008 return decode_delegation(xdr, res);
5009xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005010 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005012out_overflow:
5013 print_overflow_msg(__func__, xdr);
5014 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015}
5016
5017static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5018{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019 int status;
5020
Andy Adamson05d564f2008-12-23 16:06:15 -05005021 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005022 if (status != -EIO)
5023 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005024 if (!status)
5025 status = decode_stateid(xdr, &res->stateid);
5026 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005027}
5028
5029static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5030{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031 int status;
5032
5033 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005034 if (status != -EIO)
5035 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005036 if (!status)
5037 status = decode_stateid(xdr, &res->stateid);
5038 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005039}
5040
5041static int decode_putfh(struct xdr_stream *xdr)
5042{
5043 return decode_op_hdr(xdr, OP_PUTFH);
5044}
5045
5046static int decode_putrootfh(struct xdr_stream *xdr)
5047{
5048 return decode_op_hdr(xdr, OP_PUTROOTFH);
5049}
5050
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005051static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5052 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053{
Al Viro8687b632006-10-19 23:28:48 -07005054 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005055 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056 int status;
5057
5058 status = decode_op_hdr(xdr, OP_READ);
5059 if (status)
5060 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005061 p = xdr_inline_decode(xdr, 8);
5062 if (unlikely(!p))
5063 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005064 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005065 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005066 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005067 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005068 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069 "count %u > recvd %u\n", count, recvd);
5070 count = recvd;
5071 eof = 0;
5072 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073 res->eof = eof;
5074 res->count = count;
5075 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005076out_overflow:
5077 print_overflow_msg(__func__, xdr);
5078 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079}
5080
5081static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5082{
Chuck Leverbcecff72007-10-26 13:32:03 -04005083 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005084 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085
5086 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005087 if (!status)
5088 status = decode_verifier(xdr, readdir->verifier.data);
5089 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005090 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005091 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005092 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005093 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005094 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005095}
5096
5097static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5098{
5099 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005100 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005101 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102 int status;
5103
5104 status = decode_op_hdr(xdr, OP_READLINK);
5105 if (status)
5106 return status;
5107
5108 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005109 p = xdr_inline_decode(xdr, 4);
5110 if (unlikely(!p))
5111 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005112 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005114 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115 return -ENAMETOOLONG;
5116 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005117 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005118 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005119 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120 "count %u > recvd %u\n", len, recvd);
5121 return -EIO;
5122 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123 /*
5124 * The XDR encode routine has set things up so that
5125 * the link text will be copied directly into the
5126 * buffer. We just have to do overflow-checking,
5127 * and and null-terminate the text (the VFS expects
5128 * null-termination).
5129 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005130 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005131 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005132out_overflow:
5133 print_overflow_msg(__func__, xdr);
5134 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005135}
5136
5137static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5138{
5139 int status;
5140
5141 status = decode_op_hdr(xdr, OP_REMOVE);
5142 if (status)
5143 goto out;
5144 status = decode_change_info(xdr, cinfo);
5145out:
5146 return status;
5147}
5148
5149static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5150 struct nfs4_change_info *new_cinfo)
5151{
5152 int status;
5153
5154 status = decode_op_hdr(xdr, OP_RENAME);
5155 if (status)
5156 goto out;
5157 if ((status = decode_change_info(xdr, old_cinfo)))
5158 goto out;
5159 status = decode_change_info(xdr, new_cinfo);
5160out:
5161 return status;
5162}
5163
5164static int decode_renew(struct xdr_stream *xdr)
5165{
5166 return decode_op_hdr(xdr, OP_RENEW);
5167}
5168
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005169static int
5170decode_restorefh(struct xdr_stream *xdr)
5171{
5172 return decode_op_hdr(xdr, OP_RESTOREFH);
5173}
5174
J. Bruce Fields029d1052005-06-22 17:16:22 +00005175static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005176 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005177{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005178 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005179 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005180 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005181 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005182 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005183
Andy Adamsonbf118a32011-12-07 11:55:27 -05005184 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005185 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5186 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005187
Trond Myklebust519d3952012-08-14 17:30:10 -04005188 xdr_enter_page(xdr, xdr->buf->page_len);
5189
Trond Myklebustcff298c2012-08-14 17:14:17 -04005190 /* Calculate the offset of the page data */
5191 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005192
J. Bruce Fields029d1052005-06-22 17:16:22 +00005193 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5194 goto out;
5195 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5196 goto out;
5197
5198 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5199 return -EIO;
5200 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005201
Andy Adamsonbf118a32011-12-07 11:55:27 -05005202 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5203 * are stored with the acl data to handle the problem of
5204 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005205 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005206 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005207
5208 /* Check for receive buffer overflow */
5209 if (res->acl_len > (xdr->nwords << 2) ||
5210 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5211 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005212 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005213 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005214 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005215 } else
5216 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005217
5218out:
5219 return status;
5220}
5221
Linus Torvalds1da177e2005-04-16 15:20:36 -07005222static int
5223decode_savefh(struct xdr_stream *xdr)
5224{
5225 return decode_op_hdr(xdr, OP_SAVEFH);
5226}
5227
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005228static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005229{
Al Viro8687b632006-10-19 23:28:48 -07005230 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005231 uint32_t bmlen;
5232 int status;
5233
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234 status = decode_op_hdr(xdr, OP_SETATTR);
5235 if (status)
5236 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005237 p = xdr_inline_decode(xdr, 4);
5238 if (unlikely(!p))
5239 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005240 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005241 p = xdr_inline_decode(xdr, bmlen << 2);
5242 if (likely(p))
5243 return 0;
5244out_overflow:
5245 print_overflow_msg(__func__, xdr);
5246 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005247}
5248
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005249static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250{
Al Viro8687b632006-10-19 23:28:48 -07005251 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252 uint32_t opnum;
5253 int32_t nfserr;
5254
Benny Halevyc0eae662009-08-14 17:20:14 +03005255 p = xdr_inline_decode(xdr, 8);
5256 if (unlikely(!p))
5257 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005258 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005259 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005260 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005261 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262 return -EIO;
5263 }
Benny Halevycccddf42009-08-14 17:20:19 +03005264 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005265 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005266 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5267 if (unlikely(!p))
5268 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005269 p = xdr_decode_hyper(p, &res->clientid);
5270 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271 } else if (nfserr == NFSERR_CLID_INUSE) {
5272 uint32_t len;
5273
5274 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005275 p = xdr_inline_decode(xdr, 4);
5276 if (unlikely(!p))
5277 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005278 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005279 p = xdr_inline_decode(xdr, len);
5280 if (unlikely(!p))
5281 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282
5283 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005284 p = xdr_inline_decode(xdr, 4);
5285 if (unlikely(!p))
5286 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005287 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005288 p = xdr_inline_decode(xdr, len);
5289 if (unlikely(!p))
5290 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005291 return -NFSERR_CLID_INUSE;
5292 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005293 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005294
5295 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005296out_overflow:
5297 print_overflow_msg(__func__, xdr);
5298 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299}
5300
5301static int decode_setclientid_confirm(struct xdr_stream *xdr)
5302{
5303 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5304}
5305
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005306static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005307{
Al Viro8687b632006-10-19 23:28:48 -07005308 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005309 int status;
5310
5311 status = decode_op_hdr(xdr, OP_WRITE);
5312 if (status)
5313 return status;
5314
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005315 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005316 if (unlikely(!p))
5317 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005318 res->count = be32_to_cpup(p++);
5319 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005320 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005321out_overflow:
5322 print_overflow_msg(__func__, xdr);
5323 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005324}
5325
5326static int decode_delegreturn(struct xdr_stream *xdr)
5327{
5328 return decode_op_hdr(xdr, OP_DELEGRETURN);
5329}
5330
Chuck Leverfb15b262013-03-16 15:54:34 -04005331static int decode_secinfo_gss(struct xdr_stream *xdr,
5332 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005333{
Chuck Leverfb15b262013-03-16 15:54:34 -04005334 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005335 __be32 *p;
5336
5337 p = xdr_inline_decode(xdr, 4);
5338 if (unlikely(!p))
5339 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005340 oid_len = be32_to_cpup(p);
5341 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005342 goto out_err;
5343
Chuck Leverfb15b262013-03-16 15:54:34 -04005344 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005345 if (unlikely(!p))
5346 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005347 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5348 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005349
5350 p = xdr_inline_decode(xdr, 8);
5351 if (unlikely(!p))
5352 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005353 flavor->flavor_info.qop = be32_to_cpup(p++);
5354 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005355
5356 return 0;
5357
5358out_overflow:
5359 print_overflow_msg(__func__, xdr);
5360 return -EIO;
5361out_err:
5362 return -EINVAL;
5363}
5364
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005365static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005366{
Chuck Leverfb15b262013-03-16 15:54:34 -04005367 struct nfs4_secinfo4 *sec_flavor;
5368 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005369 int status;
5370 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005371
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005372 p = xdr_inline_decode(xdr, 4);
5373 if (unlikely(!p))
5374 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005375
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005376 res->flavors->num_flavors = 0;
5377 num_flavors = be32_to_cpup(p);
5378
5379 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005380 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005381 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005382 break;
5383
5384 p = xdr_inline_decode(xdr, 4);
5385 if (unlikely(!p))
5386 goto out_overflow;
5387 sec_flavor->flavor = be32_to_cpup(p);
5388
5389 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005390 status = decode_secinfo_gss(xdr, sec_flavor);
5391 if (status)
5392 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005393 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005394 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005395 }
5396
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005397 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005398out:
5399 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005400out_overflow:
5401 print_overflow_msg(__func__, xdr);
5402 return -EIO;
5403}
5404
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005405static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5406{
5407 int status = decode_op_hdr(xdr, OP_SECINFO);
5408 if (status)
5409 return status;
5410 return decode_secinfo_common(xdr, res);
5411}
5412
Benny Halevy99fe60d2009-04-01 09:22:29 -04005413#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005414static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5415{
5416 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5417 if (status)
5418 return status;
5419 return decode_secinfo_common(xdr, res);
5420}
5421
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005422static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5423{
5424 __be32 *p;
5425 uint32_t bitmap_words;
5426 unsigned int i;
5427
5428 p = xdr_inline_decode(xdr, 4);
5429 bitmap_words = be32_to_cpup(p++);
5430 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5431 return -EIO;
5432 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5433 for (i = 0; i < bitmap_words; i++)
5434 op_map->u.words[i] = be32_to_cpup(p++);
5435
5436 return 0;
5437}
5438
Benny Halevy99fe60d2009-04-01 09:22:29 -04005439static int decode_exchange_id(struct xdr_stream *xdr,
5440 struct nfs41_exchange_id_res *res)
5441{
5442 __be32 *p;
5443 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005444 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005445 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005446 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005447
5448 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5449 if (status)
5450 return status;
5451
Benny Halevyc0eae662009-08-14 17:20:14 +03005452 p = xdr_inline_decode(xdr, 8);
5453 if (unlikely(!p))
5454 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005455 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005456 p = xdr_inline_decode(xdr, 12);
5457 if (unlikely(!p))
5458 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005459 res->seqid = be32_to_cpup(p++);
5460 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005461
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005462 res->state_protect.how = be32_to_cpup(p);
5463 switch (res->state_protect.how) {
5464 case SP4_NONE:
5465 break;
5466 case SP4_MACH_CRED:
5467 status = decode_op_map(xdr, &res->state_protect.enforce);
5468 if (status)
5469 return status;
5470 status = decode_op_map(xdr, &res->state_protect.allow);
5471 if (status)
5472 return status;
5473 break;
5474 default:
5475 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005476 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005477 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005478
Chuck Leveracdeb692012-05-21 22:46:16 -04005479 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005480 p = xdr_inline_decode(xdr, 8);
5481 if (unlikely(!p))
5482 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005483 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005484
Chuck Leveracdeb692012-05-21 22:46:16 -04005485 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005486 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5487 if (unlikely(status))
5488 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005489 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5490 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005491 memcpy(res->server_owner->major_id, dummy_str, dummy);
5492 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005493
Chuck Leveracdeb692012-05-21 22:46:16 -04005494 /* server_scope4 */
5495 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5496 if (unlikely(status))
5497 return status;
5498 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5499 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005500 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5501 res->server_scope->server_scope_sz = dummy;
5502
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005503 /* Implementation Id */
5504 p = xdr_inline_decode(xdr, 4);
5505 if (unlikely(!p))
5506 goto out_overflow;
5507 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005508
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005509 if (impl_id_count) {
5510 /* nii_domain */
5511 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5512 if (unlikely(status))
5513 return status;
5514 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5515 return -EIO;
5516 memcpy(res->impl_id->domain, dummy_str, dummy);
5517
5518 /* nii_name */
5519 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5520 if (unlikely(status))
5521 return status;
5522 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5523 return -EIO;
5524 memcpy(res->impl_id->name, dummy_str, dummy);
5525
5526 /* nii_date */
5527 p = xdr_inline_decode(xdr, 12);
5528 if (unlikely(!p))
5529 goto out_overflow;
5530 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5531 res->impl_id->date.nseconds = be32_to_cpup(p);
5532
5533 /* if there's more than one entry, ignore the rest */
5534 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005535 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005536out_overflow:
5537 print_overflow_msg(__func__, xdr);
5538 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005539}
Andy Adamsonfc931582009-04-01 09:22:31 -04005540
5541static int decode_chan_attrs(struct xdr_stream *xdr,
5542 struct nfs4_channel_attrs *attrs)
5543{
5544 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005545 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005546
Benny Halevyc0eae662009-08-14 17:20:14 +03005547 p = xdr_inline_decode(xdr, 28);
5548 if (unlikely(!p))
5549 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005550 val = be32_to_cpup(p++); /* headerpadsz */
5551 if (val)
5552 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005553 attrs->max_rqst_sz = be32_to_cpup(p++);
5554 attrs->max_resp_sz = be32_to_cpup(p++);
5555 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5556 attrs->max_ops = be32_to_cpup(p++);
5557 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005558 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005559 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005560 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5561 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005562 return -EINVAL;
5563 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005564 if (nr_attrs == 1) {
5565 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5566 if (unlikely(!p))
5567 goto out_overflow;
5568 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005569 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005570out_overflow:
5571 print_overflow_msg(__func__, xdr);
5572 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005573}
5574
Benny Halevye78291e2009-08-14 17:20:00 +03005575static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5576{
5577 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005578}
5579
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005580static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5581 struct nfs41_bind_conn_to_session_res *res)
5582{
5583 __be32 *p;
5584 int status;
5585
5586 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5587 if (!status)
5588 status = decode_sessionid(xdr, &res->session->sess_id);
5589 if (unlikely(status))
5590 return status;
5591
5592 /* dir flags, rdma mode bool */
5593 p = xdr_inline_decode(xdr, 8);
5594 if (unlikely(!p))
5595 goto out_overflow;
5596
5597 res->dir = be32_to_cpup(p++);
5598 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5599 return -EIO;
5600 if (be32_to_cpup(p) == 0)
5601 res->use_conn_in_rdma_mode = false;
5602 else
5603 res->use_conn_in_rdma_mode = true;
5604
5605 return 0;
5606out_overflow:
5607 print_overflow_msg(__func__, xdr);
5608 return -EIO;
5609}
5610
Andy Adamsonfc931582009-04-01 09:22:31 -04005611static int decode_create_session(struct xdr_stream *xdr,
5612 struct nfs41_create_session_res *res)
5613{
5614 __be32 *p;
5615 int status;
5616 struct nfs_client *clp = res->client;
5617 struct nfs4_session *session = clp->cl_session;
5618
5619 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005620 if (!status)
5621 status = decode_sessionid(xdr, &session->sess_id);
5622 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005623 return status;
5624
Andy Adamsonfc931582009-04-01 09:22:31 -04005625 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005626 p = xdr_inline_decode(xdr, 8);
5627 if (unlikely(!p))
5628 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005629 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005630 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005631
5632 /* Channel attributes */
5633 status = decode_chan_attrs(xdr, &session->fc_attrs);
5634 if (!status)
5635 status = decode_chan_attrs(xdr, &session->bc_attrs);
5636 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005637out_overflow:
5638 print_overflow_msg(__func__, xdr);
5639 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005640}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005641
5642static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5643{
5644 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5645}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005646
Trond Myklebust66245532012-05-25 17:18:09 -04005647static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5648{
5649 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5650}
5651
Ricardo Labiaga180197532009-12-05 16:08:40 -05005652static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5653{
5654 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5655}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005656#endif /* CONFIG_NFS_V4_1 */
5657
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005658static int decode_sequence(struct xdr_stream *xdr,
5659 struct nfs4_sequence_res *res,
5660 struct rpc_rqst *rqstp)
5661{
5662#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005663 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005664 struct nfs4_sessionid id;
5665 u32 dummy;
5666 int status;
5667 __be32 *p;
5668
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005669 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005670 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005671 if (!res->sr_slot->table->session)
5672 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005673
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005674 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005675 if (!status)
5676 status = decode_sessionid(xdr, &id);
5677 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005678 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005679
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005680 /*
5681 * If the server returns different values for sessionID, slotID or
5682 * sequence number, the server is looney tunes.
5683 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005684 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005685 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005686
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005687 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005688 NFS4_MAX_SESSIONID_LEN)) {
5689 dprintk("%s Invalid session id\n", __func__);
5690 goto out_err;
5691 }
Benny Halevye78291e2009-08-14 17:20:00 +03005692
Benny Halevyc0eae662009-08-14 17:20:14 +03005693 p = xdr_inline_decode(xdr, 20);
5694 if (unlikely(!p))
5695 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005696
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005697 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005698 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005699 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005700 dprintk("%s Invalid sequence number\n", __func__);
5701 goto out_err;
5702 }
5703 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005704 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005705 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005706 dprintk("%s Invalid slot id\n", __func__);
5707 goto out_err;
5708 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005709 /* highest slot id */
5710 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005711 /* target highest slot id */
5712 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005713 /* result flags */
5714 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005715 status = 0;
5716out_err:
5717 res->sr_status = status;
5718 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005719out_overflow:
5720 print_overflow_msg(__func__, xdr);
5721 status = -EIO;
5722 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005723#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005724 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005725#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005726}
5727
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005728#if defined(CONFIG_NFS_V4_1)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005729static int decode_getdeviceinfo(struct xdr_stream *xdr,
5730 struct pnfs_device *pdev)
5731{
5732 __be32 *p;
5733 uint32_t len, type;
5734 int status;
5735
5736 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5737 if (status) {
5738 if (status == -ETOOSMALL) {
5739 p = xdr_inline_decode(xdr, 4);
5740 if (unlikely(!p))
5741 goto out_overflow;
5742 pdev->mincount = be32_to_cpup(p);
5743 dprintk("%s: Min count too small. mincnt = %u\n",
5744 __func__, pdev->mincount);
5745 }
5746 return status;
5747 }
5748
5749 p = xdr_inline_decode(xdr, 8);
5750 if (unlikely(!p))
5751 goto out_overflow;
5752 type = be32_to_cpup(p++);
5753 if (type != pdev->layout_type) {
5754 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5755 __func__, pdev->layout_type, type);
5756 return -EINVAL;
5757 }
5758 /*
5759 * Get the length of the opaque device_addr4. xdr_read_pages places
5760 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5761 * and places the remaining xdr data in xdr_buf->tail
5762 */
5763 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005764 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5765 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005766
5767 /* Parse notification bitmap, verifying that it is zero. */
5768 p = xdr_inline_decode(xdr, 4);
5769 if (unlikely(!p))
5770 goto out_overflow;
5771 len = be32_to_cpup(p);
5772 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005773 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005774
5775 p = xdr_inline_decode(xdr, 4 * len);
5776 if (unlikely(!p))
5777 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005778
5779 if (be32_to_cpup(p++) &
5780 ~(NOTIFY_DEVICEID4_CHANGE | NOTIFY_DEVICEID4_DELETE)) {
5781 dprintk("%s: unsupported notification\n",
5782 __func__);
5783 }
5784
5785 for (i = 1; i < len; i++) {
5786 if (be32_to_cpup(p++)) {
5787 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005788 __func__);
5789 return -EIO;
5790 }
5791 }
5792 }
5793 return 0;
5794out_overflow:
5795 print_overflow_msg(__func__, xdr);
5796 return -EIO;
5797}
5798
5799static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5800 struct nfs4_layoutget_res *res)
5801{
5802 __be32 *p;
5803 int status;
5804 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005805 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005806
5807 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5808 if (status)
5809 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005810 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005811 if (unlikely(!p))
5812 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005813 res->return_on_close = be32_to_cpup(p);
5814 decode_stateid(xdr, &res->stateid);
5815 p = xdr_inline_decode(xdr, 4);
5816 if (unlikely(!p))
5817 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005818 layout_count = be32_to_cpup(p);
5819 if (!layout_count) {
5820 dprintk("%s: server responded with empty layout array\n",
5821 __func__);
5822 return -EINVAL;
5823 }
5824
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005825 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005826 if (unlikely(!p))
5827 goto out_overflow;
5828 p = xdr_decode_hyper(p, &res->range.offset);
5829 p = xdr_decode_hyper(p, &res->range.length);
5830 res->range.iomode = be32_to_cpup(p++);
5831 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005832 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005833
5834 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5835 __func__,
5836 (unsigned long)res->range.offset,
5837 (unsigned long)res->range.length,
5838 res->range.iomode,
5839 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005840 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005841
Trond Myklebust64bd5772012-06-20 22:35:05 -04005842 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005843 if (res->layoutp->len > recvd) {
5844 dprintk("NFS: server cheating in layoutget reply: "
5845 "layout len %u > recvd %u\n",
5846 res->layoutp->len, recvd);
5847 return -EINVAL;
5848 }
5849
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005850 if (layout_count > 1) {
5851 /* We only handle a length one array at the moment. Any
5852 * further entries are just ignored. Note that this means
5853 * the client may see a response that is less than the
5854 * minimum it requested.
5855 */
5856 dprintk("%s: server responded with %d layouts, dropping tail\n",
5857 __func__, layout_count);
5858 }
5859
5860 return 0;
5861out_overflow:
5862 print_overflow_msg(__func__, xdr);
5863 return -EIO;
5864}
Andy Adamson863a3c62011-03-23 13:27:54 +00005865
Benny Halevycbe82602011-05-22 19:52:37 +03005866static int decode_layoutreturn(struct xdr_stream *xdr,
5867 struct nfs4_layoutreturn_res *res)
5868{
5869 __be32 *p;
5870 int status;
5871
5872 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5873 if (status)
5874 return status;
5875 p = xdr_inline_decode(xdr, 4);
5876 if (unlikely(!p))
5877 goto out_overflow;
5878 res->lrs_present = be32_to_cpup(p);
5879 if (res->lrs_present)
5880 status = decode_stateid(xdr, &res->stateid);
5881 return status;
5882out_overflow:
5883 print_overflow_msg(__func__, xdr);
5884 return -EIO;
5885}
5886
Andy Adamson863a3c62011-03-23 13:27:54 +00005887static int decode_layoutcommit(struct xdr_stream *xdr,
5888 struct rpc_rqst *req,
5889 struct nfs4_layoutcommit_res *res)
5890{
5891 __be32 *p;
5892 __u32 sizechanged;
5893 int status;
5894
5895 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005896 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005897 if (status)
5898 return status;
5899
5900 p = xdr_inline_decode(xdr, 4);
5901 if (unlikely(!p))
5902 goto out_overflow;
5903 sizechanged = be32_to_cpup(p);
5904
5905 if (sizechanged) {
5906 /* throw away new size */
5907 p = xdr_inline_decode(xdr, 8);
5908 if (unlikely(!p))
5909 goto out_overflow;
5910 }
5911 return 0;
5912out_overflow:
5913 print_overflow_msg(__func__, xdr);
5914 return -EIO;
5915}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005916
5917static int decode_test_stateid(struct xdr_stream *xdr,
5918 struct nfs41_test_stateid_res *res)
5919{
5920 __be32 *p;
5921 int status;
5922 int num_res;
5923
5924 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5925 if (status)
5926 return status;
5927
5928 p = xdr_inline_decode(xdr, 4);
5929 if (unlikely(!p))
5930 goto out_overflow;
5931 num_res = be32_to_cpup(p++);
5932 if (num_res != 1)
5933 goto out;
5934
5935 p = xdr_inline_decode(xdr, 4);
5936 if (unlikely(!p))
5937 goto out_overflow;
5938 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005939
5940 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005941out_overflow:
5942 print_overflow_msg(__func__, xdr);
5943out:
5944 return -EIO;
5945}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005946
5947static int decode_free_stateid(struct xdr_stream *xdr,
5948 struct nfs41_free_stateid_res *res)
5949{
Andy Adamson9f79fb42013-09-10 12:56:29 -04005950 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005951 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005952}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005953#endif /* CONFIG_NFS_V4_1 */
5954
Linus Torvalds1da177e2005-04-16 15:20:36 -07005955/*
Benny Halevy49c25592008-12-23 16:06:16 -05005956 * END OF "GENERIC" DECODE ROUTINES.
5957 */
5958
5959/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005960 * Decode OPEN_DOWNGRADE response
5961 */
Chuck Leverbf269552010-12-14 14:59:29 +00005962static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5963 struct xdr_stream *xdr,
5964 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005965{
Andy Adamson05d564f2008-12-23 16:06:15 -05005966 struct compound_hdr hdr;
5967 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005968
Chuck Leverbf269552010-12-14 14:59:29 +00005969 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005970 if (status)
5971 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005972 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005973 if (status)
5974 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005975 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005976 if (status)
5977 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005978 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005979 if (status != 0)
5980 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005981 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005982out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005983 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984}
5985
5986/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005987 * Decode ACCESS response
5988 */
Chuck Leverbf269552010-12-14 14:59:29 +00005989static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5990 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005991{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005992 struct compound_hdr hdr;
5993 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005994
Chuck Leverbf269552010-12-14 14:59:29 +00005995 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005996 if (status)
5997 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005998 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005999 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006000 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006001 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006002 if (status != 0)
6003 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006004 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006005 if (status != 0)
6006 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006007 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008out:
6009 return status;
6010}
6011
6012/*
6013 * Decode LOOKUP response
6014 */
Chuck Leverbf269552010-12-14 14:59:29 +00006015static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6016 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006017{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006018 struct compound_hdr hdr;
6019 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006020
Chuck Leverbf269552010-12-14 14:59:29 +00006021 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006022 if (status)
6023 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006024 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006025 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006026 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006027 status = decode_putfh(xdr);
6028 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006029 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006030 status = decode_lookup(xdr);
6031 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006032 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006033 status = decode_getfh(xdr, res->fh);
6034 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006035 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006036 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006037out:
6038 return status;
6039}
6040
6041/*
6042 * Decode LOOKUP_ROOT response
6043 */
Chuck Leverbf269552010-12-14 14:59:29 +00006044static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6045 struct xdr_stream *xdr,
6046 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006047{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006048 struct compound_hdr hdr;
6049 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006050
Chuck Leverbf269552010-12-14 14:59:29 +00006051 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006052 if (status)
6053 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006054 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006055 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006057 status = decode_putrootfh(xdr);
6058 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006059 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006060 status = decode_getfh(xdr, res->fh);
6061 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006062 status = decode_getfattr_label(xdr, res->fattr,
6063 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006064out:
6065 return status;
6066}
6067
6068/*
6069 * Decode REMOVE response
6070 */
Chuck Leverbf269552010-12-14 14:59:29 +00006071static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6072 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006073{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006074 struct compound_hdr hdr;
6075 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006076
Chuck Leverbf269552010-12-14 14:59:29 +00006077 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006078 if (status)
6079 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006080 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006081 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006082 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006083 status = decode_putfh(xdr);
6084 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006085 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006086 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006087out:
6088 return status;
6089}
6090
6091/*
6092 * Decode RENAME response
6093 */
Chuck Leverbf269552010-12-14 14:59:29 +00006094static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6095 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097 struct compound_hdr hdr;
6098 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006099
Chuck Leverbf269552010-12-14 14:59:29 +00006100 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006101 if (status)
6102 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006103 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006104 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006105 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006106 status = decode_putfh(xdr);
6107 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006108 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006109 status = decode_savefh(xdr);
6110 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006111 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006112 status = decode_putfh(xdr);
6113 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006115 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006116out:
6117 return status;
6118}
6119
6120/*
6121 * Decode LINK response
6122 */
Chuck Leverbf269552010-12-14 14:59:29 +00006123static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6124 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006126 struct compound_hdr hdr;
6127 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006128
Chuck Leverbf269552010-12-14 14:59:29 +00006129 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006130 if (status)
6131 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006132 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006133 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006134 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006135 status = decode_putfh(xdr);
6136 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006138 status = decode_savefh(xdr);
6139 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006140 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006141 status = decode_putfh(xdr);
6142 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006144 status = decode_link(xdr, &res->cinfo);
6145 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006146 goto out;
6147 /*
6148 * Note order: OP_LINK leaves the directory as the current
6149 * filehandle.
6150 */
Chuck Leverbf269552010-12-14 14:59:29 +00006151 status = decode_restorefh(xdr);
6152 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006153 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006154 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155out:
6156 return status;
6157}
6158
6159/*
6160 * Decode CREATE response
6161 */
Chuck Leverbf269552010-12-14 14:59:29 +00006162static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6163 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006165 struct compound_hdr hdr;
6166 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006167
Chuck Leverbf269552010-12-14 14:59:29 +00006168 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006169 if (status)
6170 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006171 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006172 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006174 status = decode_putfh(xdr);
6175 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006176 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006177 status = decode_create(xdr, &res->dir_cinfo);
6178 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006179 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006180 status = decode_getfh(xdr, res->fh);
6181 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006183 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006184out:
6185 return status;
6186}
6187
6188/*
6189 * Decode SYMLINK response
6190 */
Chuck Leverbf269552010-12-14 14:59:29 +00006191static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6192 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193{
Chuck Leverbf269552010-12-14 14:59:29 +00006194 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195}
6196
6197/*
6198 * Decode GETATTR response
6199 */
Chuck Leverbf269552010-12-14 14:59:29 +00006200static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6201 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203 struct compound_hdr hdr;
6204 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006205
Chuck Leverbf269552010-12-14 14:59:29 +00006206 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207 if (status)
6208 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006209 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006210 if (status)
6211 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006212 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006213 if (status)
6214 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006215 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216out:
6217 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218}
6219
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006220/*
6221 * Encode an SETACL request
6222 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006223static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6224 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006225{
Andy Adamson05d564f2008-12-23 16:06:15 -05006226 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006227 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006228 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006229
Chuck Lever9f06c712010-12-14 14:59:18 +00006230 encode_compound_hdr(xdr, req, &hdr);
6231 encode_sequence(xdr, &args->seq_args, &hdr);
6232 encode_putfh(xdr, args->fh, &hdr);
6233 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006234 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006235}
Andy Adamson05d564f2008-12-23 16:06:15 -05006236
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006237/*
6238 * Decode SETACL response
6239 */
6240static int
Chuck Leverbf269552010-12-14 14:59:29 +00006241nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006242 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006243{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006244 struct compound_hdr hdr;
6245 int status;
6246
Chuck Leverbf269552010-12-14 14:59:29 +00006247 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006248 if (status)
6249 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006250 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006251 if (status)
6252 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006253 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006254 if (status)
6255 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006256 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006257out:
6258 return status;
6259}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260
6261/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006262 * Decode GETACL response
6263 */
6264static int
Chuck Leverbf269552010-12-14 14:59:29 +00006265nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006266 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006267{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006268 struct compound_hdr hdr;
6269 int status;
6270
Trond Myklebust331818f2012-02-03 18:30:53 -05006271 if (res->acl_scratch != NULL) {
6272 void *p = page_address(res->acl_scratch);
6273 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6274 }
Chuck Leverbf269552010-12-14 14:59:29 +00006275 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006276 if (status)
6277 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006278 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006279 if (status)
6280 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006281 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006282 if (status)
6283 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006284 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006285
6286out:
6287 return status;
6288}
6289
6290/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006291 * Decode CLOSE response
6292 */
Chuck Leverbf269552010-12-14 14:59:29 +00006293static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6294 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295{
Andy Adamson05d564f2008-12-23 16:06:15 -05006296 struct compound_hdr hdr;
6297 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298
Chuck Leverbf269552010-12-14 14:59:29 +00006299 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006300 if (status)
6301 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006302 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006303 if (status)
6304 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006305 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006306 if (status)
6307 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006308 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006309 if (status != 0)
6310 goto out;
6311 /*
6312 * Note: Server may do delete on close for this file
6313 * in which case the getattr call will fail with
6314 * an ESTALE error. Shouldn't be a problem,
6315 * though, since fattr->valid will remain unset.
6316 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006317 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006318out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006319 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006320}
6321
6322/*
6323 * Decode OPEN response
6324 */
Chuck Leverbf269552010-12-14 14:59:29 +00006325static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6326 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006327{
Andy Adamson05d564f2008-12-23 16:06:15 -05006328 struct compound_hdr hdr;
6329 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006330
Chuck Leverbf269552010-12-14 14:59:29 +00006331 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006332 if (status)
6333 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006334 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006335 if (status)
6336 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006337 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006338 if (status)
6339 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006340 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006341 if (status)
6342 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006343 status = decode_getfh(xdr, &res->fh);
6344 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006346 if (res->access_request)
6347 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006348 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
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_CONFIRM response
6355 */
Chuck Leverbf269552010-12-14 14:59:29 +00006356static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6357 struct xdr_stream *xdr,
6358 struct nfs_open_confirmres *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_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006367 if (status)
6368 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006369 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006370out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006371 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372}
6373
6374/*
6375 * Decode OPEN response
6376 */
Chuck Leverbf269552010-12-14 14:59:29 +00006377static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6378 struct xdr_stream *xdr,
6379 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006380{
Andy Adamson05d564f2008-12-23 16:06:15 -05006381 struct compound_hdr hdr;
6382 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006383
Chuck Leverbf269552010-12-14 14:59:29 +00006384 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006385 if (status)
6386 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006387 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006388 if (status)
6389 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006390 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006391 if (status)
6392 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006393 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006394 if (status)
6395 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006396 if (res->access_request)
6397 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006398 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006399out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006400 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006401}
6402
6403/*
6404 * Decode SETATTR response
6405 */
Chuck Leverbf269552010-12-14 14:59:29 +00006406static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6407 struct xdr_stream *xdr,
6408 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006409{
Andy Adamson05d564f2008-12-23 16:06:15 -05006410 struct compound_hdr hdr;
6411 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006412
Chuck Leverbf269552010-12-14 14:59:29 +00006413 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006414 if (status)
6415 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006416 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006417 if (status)
6418 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006419 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006420 if (status)
6421 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006422 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006423 if (status)
6424 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006425 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006427 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006428}
6429
6430/*
6431 * Decode LOCK response
6432 */
Chuck Leverbf269552010-12-14 14:59:29 +00006433static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6434 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006436 struct compound_hdr hdr;
6437 int status;
6438
Chuck Leverbf269552010-12-14 14:59:29 +00006439 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440 if (status)
6441 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006442 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006443 if (status)
6444 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006445 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006446 if (status)
6447 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006448 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006449out:
6450 return status;
6451}
6452
6453/*
6454 * Decode LOCKT response
6455 */
Chuck Leverbf269552010-12-14 14:59:29 +00006456static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6457 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006458{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006459 struct compound_hdr hdr;
6460 int status;
6461
Chuck Leverbf269552010-12-14 14:59:29 +00006462 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006463 if (status)
6464 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006465 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006466 if (status)
6467 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006468 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006469 if (status)
6470 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006471 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472out:
6473 return status;
6474}
6475
6476/*
6477 * Decode LOCKU response
6478 */
Chuck Leverbf269552010-12-14 14:59:29 +00006479static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6480 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006481{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482 struct compound_hdr hdr;
6483 int status;
6484
Chuck Leverbf269552010-12-14 14:59:29 +00006485 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006486 if (status)
6487 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006488 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006489 if (status)
6490 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006491 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006492 if (status)
6493 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006494 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495out:
6496 return status;
6497}
6498
Chuck Leverbf269552010-12-14 14:59:29 +00006499static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6500 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006501{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006502 struct compound_hdr hdr;
6503 int status;
6504
Chuck Leverbf269552010-12-14 14:59:29 +00006505 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006506 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006507 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006508 return status;
6509}
6510
Linus Torvalds1da177e2005-04-16 15:20:36 -07006511/*
6512 * Decode READLINK response
6513 */
Chuck Leverbf269552010-12-14 14:59:29 +00006514static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6515 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006516 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006517{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518 struct compound_hdr hdr;
6519 int status;
6520
Chuck Leverbf269552010-12-14 14:59:29 +00006521 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006522 if (status)
6523 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006524 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006525 if (status)
6526 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006527 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006528 if (status)
6529 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006530 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006531out:
6532 return status;
6533}
6534
6535/*
6536 * Decode READDIR response
6537 */
Chuck Leverbf269552010-12-14 14:59:29 +00006538static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6539 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006540{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541 struct compound_hdr hdr;
6542 int status;
6543
Chuck Leverbf269552010-12-14 14:59:29 +00006544 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545 if (status)
6546 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006547 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006548 if (status)
6549 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006550 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551 if (status)
6552 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006553 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554out:
6555 return status;
6556}
6557
6558/*
6559 * Decode Read response
6560 */
Chuck Leverbf269552010-12-14 14:59:29 +00006561static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006562 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006563{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006564 struct compound_hdr hdr;
6565 int status;
6566
Chuck Leverbf269552010-12-14 14:59:29 +00006567 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006568 if (status)
6569 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006570 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006571 if (status)
6572 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006573 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574 if (status)
6575 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006576 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006577 if (!status)
6578 status = res->count;
6579out:
6580 return status;
6581}
6582
6583/*
6584 * Decode WRITE response
6585 */
Chuck Leverbf269552010-12-14 14:59:29 +00006586static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006587 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006588{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006589 struct compound_hdr hdr;
6590 int status;
6591
Chuck Leverbf269552010-12-14 14:59:29 +00006592 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593 if (status)
6594 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006595 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006596 if (status)
6597 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006598 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006599 if (status)
6600 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006601 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006602 if (status)
6603 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006604 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006605 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606 if (!status)
6607 status = res->count;
6608out:
6609 return status;
6610}
6611
6612/*
6613 * Decode COMMIT response
6614 */
Chuck Leverbf269552010-12-14 14:59:29 +00006615static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006616 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006618 struct compound_hdr hdr;
6619 int status;
6620
Chuck Leverbf269552010-12-14 14:59:29 +00006621 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622 if (status)
6623 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006624 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006625 if (status)
6626 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006627 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006628 if (status)
6629 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006630 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631out:
6632 return status;
6633}
6634
6635/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006636 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006637 */
Chuck Leverbf269552010-12-14 14:59:29 +00006638static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006639 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006641 struct compound_hdr hdr;
6642 int status;
6643
Chuck Leverbf269552010-12-14 14:59:29 +00006644 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006645 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006646 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006647 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006648 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006650 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006651 return status;
6652}
6653
6654/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006655 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006656 */
Chuck Leverbf269552010-12-14 14:59:29 +00006657static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006658 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006659{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006660 struct compound_hdr hdr;
6661 int status;
6662
Chuck Leverbf269552010-12-14 14:59:29 +00006663 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006664 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006665 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006666 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006668 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006669 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006670 return status;
6671}
6672
6673/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006674 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006675 */
Chuck Leverbf269552010-12-14 14:59:29 +00006676static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006677 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006678{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006679 struct compound_hdr hdr;
6680 int status;
6681
Chuck Leverbf269552010-12-14 14:59:29 +00006682 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006683 if (!status)
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)
Chuck Leverbf269552010-12-14 14:59:29 +00006686 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006687 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006688 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006689 return status;
6690}
6691
6692/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006693 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006694 */
Chuck Leverbf269552010-12-14 14:59:29 +00006695static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6696 struct xdr_stream *xdr,
6697 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006698{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699 struct compound_hdr hdr;
6700 int status;
6701
Chuck Leverbf269552010-12-14 14:59:29 +00006702 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006703 if (status)
6704 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006705 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006706 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006707 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006708 status = decode_putfh(xdr);
6709 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006710 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006711 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712out:
6713 return status;
6714}
6715
6716/*
6717 * Decode RENEW response
6718 */
Chuck Leverbf269552010-12-14 14:59:29 +00006719static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6720 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006721{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006722 struct compound_hdr hdr;
6723 int status;
6724
Chuck Leverbf269552010-12-14 14:59:29 +00006725 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006726 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006727 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006728 return status;
6729}
6730
6731/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006732 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006733 */
Chuck Leverbf269552010-12-14 14:59:29 +00006734static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6735 struct xdr_stream *xdr,
6736 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006737{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006738 struct compound_hdr hdr;
6739 int status;
6740
Chuck Leverbf269552010-12-14 14:59:29 +00006741 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006742 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006743 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006744 return status;
6745}
6746
6747/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006748 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749 */
Chuck Leverbf269552010-12-14 14:59:29 +00006750static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006751 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006752{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006753 struct compound_hdr hdr;
6754 int status;
6755
Chuck Leverbf269552010-12-14 14:59:29 +00006756 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006758 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006759 return status;
6760}
6761
6762/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006763 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006764 */
Chuck Leverbf269552010-12-14 14:59:29 +00006765static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6766 struct xdr_stream *xdr,
6767 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006769 struct compound_hdr hdr;
6770 int status;
6771
Chuck Leverbf269552010-12-14 14:59:29 +00006772 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006773 if (status)
6774 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006775 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006776 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006777 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006778 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006779 if (status != 0)
6780 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006781 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006782 if (status != 0)
6783 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006784 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006785out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006786 return status;
6787}
6788
Trond Myklebust683b57b2006-06-09 09:34:22 -04006789/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006790 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006791 */
Chuck Leverbf269552010-12-14 14:59:29 +00006792static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6793 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006794 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006795{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006796 struct compound_hdr hdr;
6797 int status;
6798
Chuck Leverbf269552010-12-14 14:59:29 +00006799 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006800 if (status)
6801 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006802 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006803 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006804 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006805 status = decode_putfh(xdr);
6806 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006807 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006808 if (res->migration) {
6809 xdr_enter_page(xdr, PAGE_SIZE);
6810 status = decode_getfattr_generic(xdr,
6811 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006812 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006813 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006814 if (status)
6815 goto out;
6816 if (res->renew)
6817 status = decode_renew(xdr);
6818 } else {
6819 status = decode_lookup(xdr);
6820 if (status)
6821 goto out;
6822 xdr_enter_page(xdr, PAGE_SIZE);
6823 status = decode_getfattr_generic(xdr,
6824 &res->fs_locations->fattr,
6825 NULL, res->fs_locations,
6826 NULL, res->fs_locations->server);
6827 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006828out:
6829 return status;
6830}
6831
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006832/*
6833 * Decode SECINFO response
6834 */
6835static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6836 struct xdr_stream *xdr,
6837 struct nfs4_secinfo_res *res)
6838{
6839 struct compound_hdr hdr;
6840 int status;
6841
6842 status = decode_compound_hdr(xdr, &hdr);
6843 if (status)
6844 goto out;
6845 status = decode_sequence(xdr, &res->seq_res, rqstp);
6846 if (status)
6847 goto out;
6848 status = decode_putfh(xdr);
6849 if (status)
6850 goto out;
6851 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006852out:
6853 return status;
6854}
6855
Chuck Lever44c99932013-10-17 14:13:30 -04006856/*
6857 * Decode FSID_PRESENT response
6858 */
6859static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6860 struct xdr_stream *xdr,
6861 struct nfs4_fsid_present_res *res)
6862{
6863 struct compound_hdr hdr;
6864 int status;
6865
6866 status = decode_compound_hdr(xdr, &hdr);
6867 if (status)
6868 goto out;
6869 status = decode_sequence(xdr, &res->seq_res, rqstp);
6870 if (status)
6871 goto out;
6872 status = decode_putfh(xdr);
6873 if (status)
6874 goto out;
6875 status = decode_getfh(xdr, res->fh);
6876 if (status)
6877 goto out;
6878 if (res->renew)
6879 status = decode_renew(xdr);
6880out:
6881 return status;
6882}
6883
Benny Halevy99fe60d2009-04-01 09:22:29 -04006884#if defined(CONFIG_NFS_V4_1)
6885/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006886 * Decode BIND_CONN_TO_SESSION response
6887 */
6888static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6889 struct xdr_stream *xdr,
6890 void *res)
6891{
6892 struct compound_hdr hdr;
6893 int status;
6894
6895 status = decode_compound_hdr(xdr, &hdr);
6896 if (!status)
6897 status = decode_bind_conn_to_session(xdr, res);
6898 return status;
6899}
6900
6901/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006902 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006903 */
Chuck Leverbf269552010-12-14 14:59:29 +00006904static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6905 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006906 void *res)
6907{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006908 struct compound_hdr hdr;
6909 int status;
6910
Chuck Leverbf269552010-12-14 14:59:29 +00006911 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006912 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006913 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006914 return status;
6915}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006916
6917/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006918 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006919 */
Chuck Leverbf269552010-12-14 14:59:29 +00006920static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6921 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006922 struct nfs41_create_session_res *res)
6923{
Andy Adamsonfc931582009-04-01 09:22:31 -04006924 struct compound_hdr hdr;
6925 int status;
6926
Chuck Leverbf269552010-12-14 14:59:29 +00006927 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006928 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006929 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006930 return status;
6931}
6932
6933/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006934 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006935 */
Chuck Leverbf269552010-12-14 14:59:29 +00006936static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6937 struct xdr_stream *xdr,
6938 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006939{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006940 struct compound_hdr hdr;
6941 int status;
6942
Chuck Leverbf269552010-12-14 14:59:29 +00006943 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006944 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006945 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006946 return status;
6947}
6948
6949/*
Trond Myklebust66245532012-05-25 17:18:09 -04006950 * Decode DESTROY_CLIENTID response
6951 */
6952static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6953 struct xdr_stream *xdr,
6954 void *res)
6955{
6956 struct compound_hdr hdr;
6957 int status;
6958
6959 status = decode_compound_hdr(xdr, &hdr);
6960 if (!status)
6961 status = decode_destroy_clientid(xdr, res);
6962 return status;
6963}
6964
6965/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006966 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006967 */
Chuck Leverbf269552010-12-14 14:59:29 +00006968static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6969 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006970 struct nfs4_sequence_res *res)
6971{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006972 struct compound_hdr hdr;
6973 int status;
6974
Chuck Leverbf269552010-12-14 14:59:29 +00006975 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006976 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006977 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006978 return status;
6979}
6980
6981/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006982 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006983 */
Chuck Leverbf269552010-12-14 14:59:29 +00006984static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6985 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006986 struct nfs4_get_lease_time_res *res)
6987{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006988 struct compound_hdr hdr;
6989 int status;
6990
Chuck Leverbf269552010-12-14 14:59:29 +00006991 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006992 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006993 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006994 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006995 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006996 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006997 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006998 return status;
6999}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007000
7001/*
7002 * Decode RECLAIM_COMPLETE response
7003 */
Chuck Leverbf269552010-12-14 14:59:29 +00007004static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7005 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007006 struct nfs41_reclaim_complete_res *res)
7007{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007008 struct compound_hdr hdr;
7009 int status;
7010
Chuck Leverbf269552010-12-14 14:59:29 +00007011 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007012 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007013 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007014 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307015 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007016 return status;
7017}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007018
7019/*
7020 * Decode GETDEVINFO response
7021 */
Chuck Leverbf269552010-12-14 14:59:29 +00007022static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7023 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007024 struct nfs4_getdeviceinfo_res *res)
7025{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007026 struct compound_hdr hdr;
7027 int status;
7028
Chuck Leverbf269552010-12-14 14:59:29 +00007029 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007030 if (status != 0)
7031 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007032 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007033 if (status != 0)
7034 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007035 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007036out:
7037 return status;
7038}
7039
7040/*
7041 * Decode LAYOUTGET response
7042 */
Chuck Leverbf269552010-12-14 14:59:29 +00007043static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7044 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007045 struct nfs4_layoutget_res *res)
7046{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007047 struct compound_hdr hdr;
7048 int status;
7049
Chuck Leverbf269552010-12-14 14:59:29 +00007050 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007051 if (status)
7052 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007053 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007054 if (status)
7055 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007056 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007057 if (status)
7058 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007059 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007060out:
7061 return status;
7062}
Andy Adamson863a3c62011-03-23 13:27:54 +00007063
7064/*
Benny Halevycbe82602011-05-22 19:52:37 +03007065 * Decode LAYOUTRETURN response
7066 */
7067static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7068 struct xdr_stream *xdr,
7069 struct nfs4_layoutreturn_res *res)
7070{
7071 struct compound_hdr hdr;
7072 int status;
7073
7074 status = decode_compound_hdr(xdr, &hdr);
7075 if (status)
7076 goto out;
7077 status = decode_sequence(xdr, &res->seq_res, rqstp);
7078 if (status)
7079 goto out;
7080 status = decode_putfh(xdr);
7081 if (status)
7082 goto out;
7083 status = decode_layoutreturn(xdr, res);
7084out:
7085 return status;
7086}
7087
7088/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007089 * Decode LAYOUTCOMMIT response
7090 */
7091static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7092 struct xdr_stream *xdr,
7093 struct nfs4_layoutcommit_res *res)
7094{
7095 struct compound_hdr hdr;
7096 int status;
7097
7098 status = decode_compound_hdr(xdr, &hdr);
7099 if (status)
7100 goto out;
7101 status = decode_sequence(xdr, &res->seq_res, rqstp);
7102 if (status)
7103 goto out;
7104 status = decode_putfh(xdr);
7105 if (status)
7106 goto out;
7107 status = decode_layoutcommit(xdr, rqstp, res);
7108 if (status)
7109 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007110 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007111out:
7112 return status;
7113}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007114
7115/*
7116 * Decode SECINFO_NO_NAME response
7117 */
7118static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7119 struct xdr_stream *xdr,
7120 struct nfs4_secinfo_res *res)
7121{
7122 struct compound_hdr hdr;
7123 int status;
7124
7125 status = decode_compound_hdr(xdr, &hdr);
7126 if (status)
7127 goto out;
7128 status = decode_sequence(xdr, &res->seq_res, rqstp);
7129 if (status)
7130 goto out;
7131 status = decode_putrootfh(xdr);
7132 if (status)
7133 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007134 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007135out:
7136 return status;
7137}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007138
7139/*
7140 * Decode TEST_STATEID response
7141 */
7142static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7143 struct xdr_stream *xdr,
7144 struct nfs41_test_stateid_res *res)
7145{
7146 struct compound_hdr hdr;
7147 int status;
7148
7149 status = decode_compound_hdr(xdr, &hdr);
7150 if (status)
7151 goto out;
7152 status = decode_sequence(xdr, &res->seq_res, rqstp);
7153 if (status)
7154 goto out;
7155 status = decode_test_stateid(xdr, res);
7156out:
7157 return status;
7158}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007159
7160/*
7161 * Decode FREE_STATEID response
7162 */
7163static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7164 struct xdr_stream *xdr,
7165 struct nfs41_free_stateid_res *res)
7166{
7167 struct compound_hdr hdr;
7168 int status;
7169
7170 status = decode_compound_hdr(xdr, &hdr);
7171 if (status)
7172 goto out;
7173 status = decode_sequence(xdr, &res->seq_res, rqstp);
7174 if (status)
7175 goto out;
7176 status = decode_free_stateid(xdr, res);
7177out:
7178 return status;
7179}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007180#endif /* CONFIG_NFS_V4_1 */
7181
Chuck Lever573c4e12010-12-14 14:58:11 +00007182/**
7183 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7184 * the local page cache.
7185 * @xdr: XDR stream where entry resides
7186 * @entry: buffer to fill in with entry data
7187 * @plus: boolean indicating whether this should be a readdirplus entry
7188 *
7189 * Returns zero if successful, otherwise a negative errno value is
7190 * returned.
7191 *
7192 * This function is not invoked during READDIR reply decoding, but
7193 * rather whenever an application invokes the getdents(2) system call
7194 * on a directory already in our cache.
7195 */
7196int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7197 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007198{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007199 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007200 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007201 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007202 __be32 *p = xdr_inline_decode(xdr, 4);
7203 if (unlikely(!p))
7204 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007205 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007206 p = xdr_inline_decode(xdr, 4);
7207 if (unlikely(!p))
7208 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007209 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007210 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007211 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007212 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007213 }
7214
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007215 p = xdr_inline_decode(xdr, 12);
7216 if (unlikely(!p))
7217 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007218 entry->prev_cookie = entry->cookie;
7219 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007220 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007221
Trond Myklebust9af8c222010-10-24 11:52:55 -04007222 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007223 if (unlikely(!p))
7224 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007225 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007226
7227 /*
7228 * In case the server doesn't return an inode number,
7229 * we fake one here. (We don't use inode number 0,
7230 * since glibc seems to choke on it...)
7231 */
7232 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007233 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007234
Trond Myklebust9af8c222010-10-24 11:52:55 -04007235 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007236 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007237
Trond Myklebust256e48b2012-06-21 11:18:13 -04007238 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007239 goto out_overflow;
7240
Chuck Lever573c4e12010-12-14 14:58:11 +00007241 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007242 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007243 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007244 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7245 entry->ino = entry->fattr->mounted_on_fileid;
7246 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007247 entry->ino = entry->fattr->fileid;
7248
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007249 entry->d_type = DT_UNKNOWN;
7250 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7251 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7252
Chuck Lever573c4e12010-12-14 14:58:11 +00007253 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007254
7255out_overflow:
7256 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007257 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007258}
7259
7260/*
7261 * We need to translate between nfs status return values and
7262 * the local errno values which may not be the same.
7263 */
7264static struct {
7265 int stat;
7266 int errno;
7267} nfs_errtbl[] = {
7268 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007269 { NFS4ERR_PERM, -EPERM },
7270 { NFS4ERR_NOENT, -ENOENT },
7271 { NFS4ERR_IO, -errno_NFSERR_IO},
7272 { NFS4ERR_NXIO, -ENXIO },
7273 { NFS4ERR_ACCESS, -EACCES },
7274 { NFS4ERR_EXIST, -EEXIST },
7275 { NFS4ERR_XDEV, -EXDEV },
7276 { NFS4ERR_NOTDIR, -ENOTDIR },
7277 { NFS4ERR_ISDIR, -EISDIR },
7278 { NFS4ERR_INVAL, -EINVAL },
7279 { NFS4ERR_FBIG, -EFBIG },
7280 { NFS4ERR_NOSPC, -ENOSPC },
7281 { NFS4ERR_ROFS, -EROFS },
7282 { NFS4ERR_MLINK, -EMLINK },
7283 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7284 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7285 { NFS4ERR_DQUOT, -EDQUOT },
7286 { NFS4ERR_STALE, -ESTALE },
7287 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007288 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7289 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7290 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007291 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007292 { NFS4ERR_BADTYPE, -EBADTYPE },
7293 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007294 { NFS4ERR_SYMLINK, -ELOOP },
7295 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7296 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007297 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007298};
7299
7300/*
7301 * Convert an NFS error code to a local one.
7302 * This one is used jointly by NFSv2 and NFSv3.
7303 */
7304static int
David Howells0a8ea432006-08-22 20:06:08 -04007305nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007306{
7307 int i;
7308 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7309 if (nfs_errtbl[i].stat == stat)
7310 return nfs_errtbl[i].errno;
7311 }
7312 if (stat <= 10000 || stat > 10100) {
7313 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007314 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007315 }
7316 /* If we cannot translate the error, the recovery routines should
7317 * handle it.
7318 * Note: remaining NFSv4 error codes have values > 10000, so should
7319 * not conflict with native Linux error codes.
7320 */
Benny Halevy856dff32008-03-31 17:39:06 +03007321 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007322}
7323
Linus Torvalds1da177e2005-04-16 15:20:36 -07007324#define PROC(proc, argtype, restype) \
7325[NFSPROC4_CLNT_##proc] = { \
7326 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007327 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007328 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007329 .p_arglen = NFS4_##argtype##_sz, \
7330 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007331 .p_statidx = NFSPROC4_CLNT_##proc, \
7332 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007333}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007334
7335struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007336 PROC(READ, enc_read, dec_read),
7337 PROC(WRITE, enc_write, dec_write),
7338 PROC(COMMIT, enc_commit, dec_commit),
7339 PROC(OPEN, enc_open, dec_open),
7340 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7341 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7342 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7343 PROC(CLOSE, enc_close, dec_close),
7344 PROC(SETATTR, enc_setattr, dec_setattr),
7345 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7346 PROC(RENEW, enc_renew, dec_renew),
7347 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7348 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7349 PROC(LOCK, enc_lock, dec_lock),
7350 PROC(LOCKT, enc_lockt, dec_lockt),
7351 PROC(LOCKU, enc_locku, dec_locku),
7352 PROC(ACCESS, enc_access, dec_access),
7353 PROC(GETATTR, enc_getattr, dec_getattr),
7354 PROC(LOOKUP, enc_lookup, dec_lookup),
7355 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7356 PROC(REMOVE, enc_remove, dec_remove),
7357 PROC(RENAME, enc_rename, dec_rename),
7358 PROC(LINK, enc_link, dec_link),
7359 PROC(SYMLINK, enc_symlink, dec_symlink),
7360 PROC(CREATE, enc_create, dec_create),
7361 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7362 PROC(STATFS, enc_statfs, dec_statfs),
7363 PROC(READLINK, enc_readlink, dec_readlink),
7364 PROC(READDIR, enc_readdir, dec_readdir),
7365 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7366 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7367 PROC(GETACL, enc_getacl, dec_getacl),
7368 PROC(SETACL, enc_setacl, dec_setacl),
7369 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7370 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007371 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007372 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007373#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007374 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7375 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7376 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7377 PROC(SEQUENCE, enc_sequence, dec_sequence),
7378 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7379 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7380 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7381 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007382 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007383 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007384 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007385 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007386 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007387 PROC(BIND_CONN_TO_SESSION,
7388 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007389 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007390#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007391};
7392
Trond Myklebusta613fa12012-01-20 13:53:56 -05007393const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007394 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007395 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007396 .procs = nfs4_procedures
7397};
7398
7399/*
7400 * Local variables:
7401 * c-basic-offset: 8
7402 * End:
7403 */